Cleanup sprotty live beans view

This commit is contained in:
Kris De Volder
2019-08-27 13:05:44 -07:00
parent c49a9f0c83
commit 9708319ea7
18 changed files with 4807 additions and 33830 deletions

View File

@@ -3,15 +3,12 @@ package org.springframework.ide.vscode.boot.app.diagram;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.function.Consumer;
import org.eclipse.sprotty.ActionMessage;
import org.eclipse.sprotty.DefaultDiagramServer;
import org.eclipse.sprotty.Dimension;
import org.eclipse.sprotty.IDiagramServer;
import org.eclipse.sprotty.ILayoutEngine;
import org.eclipse.sprotty.Point;
import org.eclipse.sprotty.RequestModelAction;
import org.eclipse.sprotty.SCompartment;
import org.eclipse.sprotty.SEdge;
import org.eclipse.sprotty.SGraph;
@@ -21,88 +18,42 @@ import org.eclipse.sprotty.SNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.ide.vscode.boot.java.handlers.RunningAppProvider;
import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp;
import org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean;
import org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel;
import org.springframework.ide.vscode.commons.sprotty.scan.DiagramServerManager;
import org.springframework.ide.vscode.commons.util.ExceptionUtil;
import org.springframework.ide.vscode.commons.sprotty.scan.DiagramGenerator;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
@Component
public class LiveBeansDiagramServerManager implements DiagramServerManager {
public class LiveBeanDiagramGenerator implements DiagramGenerator {
public static final SGraph EMPTY_GRAPH = new SGraph(((Consumer<SGraph>) (SGraph it) -> {
it.setType("NONE");
it.setId("EMPTY");
}));
private static final Logger log = LoggerFactory.getLogger(LiveBeansDiagramServerManager.class);
private Cache<String, IDiagramServer> servers = CacheBuilder.newBuilder().build();
@Autowired
private RunningAppProvider runningAppProvider;
private static final Logger log = LoggerFactory.getLogger(LiveBeanDiagramGenerator.class);
@Autowired
private ILayoutEngine layoutEngine;
RunningAppProvider runningAppProvider;
@Autowired
private ApplicationContext appContext;
private Consumer<ActionMessage> remoteEndpoint;
private IDiagramServer getDiagramServer(String clientId) {
try {
return servers.get(clientId, () -> {
DefaultDiagramServer diagramServer = new DefaultDiagramServer(clientId);
diagramServer.setRemoteEndpoint(this::sendMessageToRemoteEndpoint);
diagramServer.setLayoutEngine(layoutEngine);
diagramServer.setModel(generateModel(clientId));
return diagramServer;
});
} catch (ExecutionException e) {
throw ExceptionUtil.unchecked(e);
public SGraph generateModel(String clientId, RequestModelAction modelRequest) {
String processStr = modelRequest.getOptions().get("target");
if (processStr.startsWith("process-")) {
processStr = processStr.substring("process-".length());
}
}
public void setRemoteEndpoint(Consumer<ActionMessage> remoteEndpoint) {
Assert.isNull(this.remoteEndpoint, "Can only be set once!");
this.remoteEndpoint = remoteEndpoint;
}
private void sendMessageToRemoteEndpoint(ActionMessage message) {
if (remoteEndpoint != null) {
remoteEndpoint.accept(message);
}
}
public void sendMessageToServer(ActionMessage message) {
IDiagramServer server = getDiagramServer(message.getClientId());
if (server != null) {
server.accept(message);
}
}
private SGraph generateModel(String clientId) {
int process = Integer.parseInt(processStr);
try {
Collection<SpringBootApp> apps = runningAppProvider.getAllRunningSpringApps();
if (!apps.isEmpty()) {
String indexStr = clientId.substring(clientId.lastIndexOf('-') + 1);
int index = Integer.valueOf(indexStr);
for (SpringBootApp springBootApp : apps) {
if (--index == 0) {
return toSprottyGraph(springBootApp);
}
int index = 0;
for (SpringBootApp app : apps) {
if (++index == process) {
return toSprottyGraph(app);
}
}
} catch (Exception e) {
log.error("{}", e);
log.error("", e);
}
return EMPTY_GRAPH;
}
@@ -164,4 +115,5 @@ public class LiveBeansDiagramServerManager implements DiagramServerManager {
}
}

File diff suppressed because one or more lines are too long

View File

@@ -1,46 +0,0 @@
/********************************************************************************
* Copyright (c) 2017-2018 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
.sprotty-node {
fill: #aae;
stroke: #66b;
stroke-width: 3;
}
.sprotty-text {
font-size: 16pt;
text-anchor: middle;
}
.sprotty-edge {
fill: none;
stroke: #488;
stroke-width: 2;
}
.sprotty-node.selected {
stroke: #dd8;
stroke-width: 6;
}
.sprotty-missing {
stroke-width: 1;
stroke: #f00;
fill: #f00;
font-family: SansSerif;
font-size: 14pt;
text-anchor: middle;
}

View File

@@ -1,38 +0,0 @@
/********************************************************************************
* Copyright (c) 2017-2018 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
.copyright {
margin-top: 10px;
text-align: right;
font-size: 10px;
color: #888;
}
.help {
margin-top: 24px;
text-align: right;
font-size: 16px;
color: #888;
}
svg {
margin-top: 15px;
width: 100%;
height: 500px;
border-style: solid;
border-width: 1px;
border-color: #bbb;
}

View File

@@ -11,7 +11,7 @@
</head>
<body>
<div class="container">
<div class="row" id="sprotty-app" data-app="circlegraph">
<div class="row" id="sprotty-app" client-id="livebeans" target="process-1">
<div class="col-md-10">
<h1>sprotty Circles Example</h1>
<p>
@@ -25,7 +25,7 @@
</div>
<div class="row">
<div class="col-md-12">
<div id="spring-boot" class="sprotty"/>
<div id="livebeans" class="sprotty"/>
</div>
<div class="copyright">
&copy; 2017 <a href="http://typefox.io">TypeFox GmbH</a>.