From a2f6ba7e979cb7efbd2f9f20b65894febc66a83a Mon Sep 17 00:00:00 2001 From: "Blake J. Harnden" Date: Fri, 12 Jul 2019 14:44:41 -0700 Subject: [PATCH] corefx - updates to support creating an rj45 node --- corefx/src/main/java/com/core/Controller.java | 2 + .../java/com/core/client/ICoreClient.java | 4 +- .../com/core/client/grpc/CoreGrpcClient.java | 11 +++++ .../java/com/core/graph/NetworkGraph.java | 2 + .../java/com/core/ui/dialogs/Rj45Dialog.java | 45 +++++++++++++++++++ .../java/com/core/ui/dialogs/StageDialog.java | 16 +++++-- .../src/main/resources/fxml/rj45_dialog.fxml | 30 +++++++++++++ 7 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 corefx/src/main/java/com/core/ui/dialogs/Rj45Dialog.java create mode 100644 corefx/src/main/resources/fxml/rj45_dialog.fxml diff --git a/corefx/src/main/java/com/core/Controller.java b/corefx/src/main/java/com/core/Controller.java index 5eb9d2ff..a9aa5021 100644 --- a/corefx/src/main/java/com/core/Controller.java +++ b/corefx/src/main/java/com/core/Controller.java @@ -70,6 +70,7 @@ public class Controller implements Initializable { private GraphToolbar graphToolbar = new GraphToolbar(this); // dialogs + private Rj45Dialog rj45Dialog = new Rj45Dialog(this); private SessionsDialog sessionsDialog = new SessionsDialog(this); private ServiceDialog serviceDialog = new ServiceDialog(this); private NodeServicesDialog nodeServicesDialog = new NodeServicesDialog(this); @@ -277,6 +278,7 @@ public class Controller implements Initializable { connectDialog.setOwner(window); guiPreferencesDialog.setOwner(window); nodeTypeCreateDialog.setOwner(window); + rj45Dialog.setOwner(window); } private void showMobilityScriptDialogs() { diff --git a/corefx/src/main/java/com/core/client/ICoreClient.java b/corefx/src/main/java/com/core/client/ICoreClient.java index 868e433e..4060956f 100644 --- a/corefx/src/main/java/com/core/client/ICoreClient.java +++ b/corefx/src/main/java/com/core/client/ICoreClient.java @@ -1,8 +1,6 @@ package com.core.client; import com.core.Controller; -import com.core.data.ServiceFile; -import com.core.data.WlanConfig; import com.core.data.*; import java.io.File; @@ -116,4 +114,6 @@ public interface ICoreClient { boolean setLocationConfig(LocationConfig config) throws IOException; void initialize(Controller controller); + + List getInterfaces() throws IOException; } diff --git a/corefx/src/main/java/com/core/client/grpc/CoreGrpcClient.java b/corefx/src/main/java/com/core/client/grpc/CoreGrpcClient.java index 9ae6c722..665dd1a4 100644 --- a/corefx/src/main/java/com/core/client/grpc/CoreGrpcClient.java +++ b/corefx/src/main/java/com/core/client/grpc/CoreGrpcClient.java @@ -1280,4 +1280,15 @@ public class CoreGrpcClient implements ICoreClient { private void handleFileEvents(CoreProto.FileEvent event) { logger.info("file event: {}", event); } + + @Override + public List getInterfaces() throws IOException { + CoreProto.GetInterfacesRequest request = CoreProto.GetInterfacesRequest.newBuilder().build(); + try { + CoreProto.GetInterfacesResponse response = blockingStub.getInterfaces(request); + return response.getInterfacesList(); + } catch (StatusRuntimeException ex) { + throw new IOException(ex); + } + } } diff --git a/corefx/src/main/java/com/core/graph/NetworkGraph.java b/corefx/src/main/java/com/core/graph/NetworkGraph.java index 20e61243..145bdc4c 100644 --- a/corefx/src/main/java/com/core/graph/NetworkGraph.java +++ b/corefx/src/main/java/com/core/graph/NetworkGraph.java @@ -467,6 +467,8 @@ public class NetworkGraph { node.setEmane(emaneModel); } else if (node.getType() == NodeType.DOCKER || node.getType() == NodeType.LXC) { node.setImage("ubuntu"); + } else if (node.getType() == NodeType.RJ45) { + Platform.runLater(() -> controller.getRj45Dialog().showDialog(node)); } logger.info("adding user created node: {}", node); diff --git a/corefx/src/main/java/com/core/ui/dialogs/Rj45Dialog.java b/corefx/src/main/java/com/core/ui/dialogs/Rj45Dialog.java new file mode 100644 index 00000000..5e6028ba --- /dev/null +++ b/corefx/src/main/java/com/core/ui/dialogs/Rj45Dialog.java @@ -0,0 +1,45 @@ +package com.core.ui.dialogs; + +import com.core.Controller; +import com.core.data.CoreNode; +import com.core.ui.Toast; +import com.jfoenix.controls.JFXButton; +import com.jfoenix.controls.JFXComboBox; +import javafx.fxml.FXML; +import javafx.stage.Modality; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.IOException; +import java.util.List; + +public class Rj45Dialog extends StageDialog { + private static final Logger logger = LogManager.getLogger(); + @FXML private JFXComboBox interfacesComboBox; + private JFXButton saveButton; + + public Rj45Dialog(Controller controller) { + super(controller, "/fxml/rj45_dialog.fxml", 600, 150); + setTitle("Select RJ45 Interface"); + saveButton = createButton("Save"); + addCancelButton(); + } + + public void showDialog(CoreNode node) { + try { + List interfaces = getCoreClient().getInterfaces(); + logger.info("local interfaces: {}", interfaces); + interfacesComboBox.getItems().setAll(interfaces); + interfacesComboBox.getSelectionModel().selectFirst(); + saveButton.setOnAction(event -> { + String name = interfacesComboBox.getSelectionModel().getSelectedItem(); + node.setName(name); + getController().getNetworkGraph().getGraphViewer().repaint(); + close(); + }); + show(); + } catch (IOException ex) { + Toast.error("Failed to get RJ45 interfaces", ex); + } + } +} diff --git a/corefx/src/main/java/com/core/ui/dialogs/StageDialog.java b/corefx/src/main/java/com/core/ui/dialogs/StageDialog.java index f6d3a603..e96d222d 100644 --- a/corefx/src/main/java/com/core/ui/dialogs/StageDialog.java +++ b/corefx/src/main/java/com/core/ui/dialogs/StageDialog.java @@ -28,6 +28,8 @@ import java.io.IOException; @Data public class StageDialog { private static final Logger logger = LogManager.getLogger(); + private static final int STAGE_WIDTH = 800; + private static final int STAGE_HEIGHT = 600; private final Controller controller; private final Stage stage = new Stage(StageStyle.DECORATED); private final Scene scene; @@ -35,10 +37,18 @@ public class StageDialog { private final HBox buttonBar = new HBox(); public StageDialog(Controller controller, String fxmlPath) { - this(controller, fxmlPath, Modality.APPLICATION_MODAL); + this(controller, fxmlPath, Modality.APPLICATION_MODAL, STAGE_WIDTH, STAGE_HEIGHT); + } + + public StageDialog(Controller controller, String fxmlPath, int width, int height) { + this(controller, fxmlPath, Modality.APPLICATION_MODAL, width, height); } public StageDialog(Controller controller, String fxmlPath, Modality modality) { + this(controller, fxmlPath, modality, STAGE_WIDTH, STAGE_HEIGHT); + } + + public StageDialog(Controller controller, String fxmlPath, Modality modality, int width, int height) { this.controller = controller; JFXDecorator decorator = new JFXDecorator(stage, gridPane); @@ -49,8 +59,8 @@ public class StageDialog { scene = new Scene(decorator); stage.setScene(scene); - stage.setWidth(800); - stage.setHeight(600); + stage.setWidth(width); + stage.setHeight(height); scene.setOnKeyPressed(event -> { if (KeyCode.ESCAPE == event.getCode()) { stage.close(); diff --git a/corefx/src/main/resources/fxml/rj45_dialog.fxml b/corefx/src/main/resources/fxml/rj45_dialog.fxml new file mode 100644 index 00000000..3ae18ea3 --- /dev/null +++ b/corefx/src/main/resources/fxml/rj45_dialog.fxml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +