corefx - updated node types dialog to display services for a given node type

This commit is contained in:
Blake J. Harnden 2018-11-26 14:18:07 -08:00
parent 61f80ffb9c
commit eacb4d0cc0
7 changed files with 54 additions and 10 deletions

View file

@ -80,10 +80,6 @@ public class Controller implements Initializable {
private GuiPreferencesDialog guiPreferencesDialog = new GuiPreferencesDialog(this);
public void connectToCore(String coreUrl) {
// clear out any previously set information
bottom.getChildren().remove(mobilityPlayer);
mobilityDialog.setNode(null);
coreWebSocket.stop();
ExecutorService executorService = Executors.newSingleThreadExecutor();
@ -131,6 +127,10 @@ public class Controller implements Initializable {
// clear graph
networkGraph.reset();
// clear out any previously set information
bottom.getChildren().remove(mobilityPlayer);
mobilityDialog.setNode(null);
// get session to join
Session session = coreClient.getSession(joinId);
SessionState sessionState = SessionState.get(session.getState());
@ -168,6 +168,7 @@ public class Controller implements Initializable {
// update other components for new session
graphToolbar.setRunButton(coreClient.isRunning());
hooksDialog.updateHooks();
nodeTypesDialog.updateDefaultServices();
// display first mobility script in player
Map<Integer, MobilityConfig> mobilityConfigMap = coreClient.getMobilityConfigs();

View file

@ -31,6 +31,8 @@ public interface ICoreClient {
Map<String, List<String>> getServices() throws IOException;
Map<String, List<String>> defaultServices() throws IOException;
CoreService getService(CoreNode node, String serviceName) throws IOException;
boolean setService(CoreNode node, String serviceName, CoreService service) throws IOException;

View file

@ -128,6 +128,13 @@ public class CoreRestClient implements ICoreClient {
return WebUtils.postFile(url, file);
}
@Override
public Map<String, List<String>> defaultServices() throws IOException {
String url = getUrl(String.format("sessions/%s/services/default", sessionId));
GetDefaultServices getDefaultServices = WebUtils.getJson(url, GetDefaultServices.class);
return getDefaultServices.getDefaults();
}
@Override
public CoreService getService(CoreNode node, String serviceName) throws IOException {
String url = getUrl(String.format("sessions/%s/nodes/%s/services/%s", sessionId, node.getId(), serviceName));

View file

@ -0,0 +1,16 @@
package com.core.client.rest;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class GetDefaultServices {
private Map<String, List<String>> defaults = new HashMap<>();
}

View file

@ -72,7 +72,7 @@ public class NetworkGraph {
// node render properties
renderContext.setVertexLabelTransformer(CoreNode::getName);
renderContext.setVertexShapeTransformer(node -> {
double offset = -(IconUtils.ICON_SIZE / 2);
double offset = -(IconUtils.ICON_SIZE / 2.0);
return new Ellipse2D.Double(offset, offset, IconUtils.ICON_SIZE, IconUtils.ICON_SIZE);
});
renderContext.setVertexIconTransformer(vertex -> {
@ -348,8 +348,8 @@ public class NetworkGraph {
public void addNode(CoreNode node) {
vertexId = Math.max(node.getId() + 1, node.getId());
Double x = Math.abs(node.getPosition().getX());
Double y = Math.abs(node.getPosition().getY());
double x = Math.abs(node.getPosition().getX());
double y = Math.abs(node.getPosition().getY());
logger.info("adding session node: {}", node);
graph.addVertex(node);
graphLayout.setLocation(node, x, y);
@ -363,8 +363,8 @@ public class NetworkGraph {
node.getPosition().setY(nodeData.getPosition().getY());
// set graph node location
Double x = Math.abs(node.getPosition().getX());
Double y = Math.abs(node.getPosition().getY());
double x = Math.abs(node.getPosition().getX());
double y = Math.abs(node.getPosition().getY());
graphLayout.setLocation(node, x, y);
graphViewer.repaint();
}

View file

@ -15,13 +15,17 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class NodeTypesDialog extends StageDialog {
private static final Logger logger = LogManager.getLogger();
private final Map<String, NodeType> nodeTypeMap = new HashMap<>();
private NodeType selectedNodeType;
private Map<String, List<String>> defaultServices = new HashMap<>();
@FXML private JFXListView<String> listView;
@FXML private JFXTextField modelTextField;
@FXML private JFXTextField displayTextField;
@ -31,6 +35,7 @@ public class NodeTypesDialog extends StageDialog {
@FXML private JFXButton saveButton;
@FXML private JFXButton addButton;
@FXML private JFXButton deleteButton;
@FXML private JFXListView<String> nodeServicesListView;
public NodeTypesDialog(Controller controller) {
super(controller, "/fxml/node_types_dialog.fxml");
@ -48,6 +53,8 @@ public class NodeTypesDialog extends StageDialog {
iconTextField.setText(nodeType.getIcon());
iconImage.setImage(new Image(nodeType.getIcon()));
selectedNodeType = nodeType;
List<String> services = defaultServices.getOrDefault(nodeType.getModel(), Collections.emptyList());
nodeServicesListView.getItems().setAll(services);
});
iconButton.setOnAction(event -> {
@ -79,6 +86,15 @@ public class NodeTypesDialog extends StageDialog {
});
}
public void updateDefaultServices() {
try {
defaultServices = getCoreClient().defaultServices();
listView.getSelectionModel().selectFirst();
} catch (IOException ex) {
Toast.error("Error getting default services", ex);
}
}
public void showDialog() {
listView.getItems().clear();
nodeTypeMap.clear();

View file

@ -11,7 +11,7 @@
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<GridPane hgap="10.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" vgap="10.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.171">
<GridPane hgap="10.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" vgap="10.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" percentWidth="33.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
@ -66,6 +66,8 @@
<JFXButton fx:id="iconButton" maxWidth="1.7976931348623157E308" styleClass="core-button" text="Find" GridPane.columnIndex="1" />
</children>
</GridPane>
<Label text="Services" />
<JFXListView fx:id="nodeServicesListView" VBox.vgrow="ALWAYS" />
</children>
<GridPane.margin>
<Insets />