corefx - updates to support creating an rj45 node

This commit is contained in:
Blake J. Harnden 2019-07-12 14:44:41 -07:00
parent bcd2584eb8
commit a2f6ba7e97
7 changed files with 105 additions and 5 deletions

View file

@ -70,6 +70,7 @@ public class Controller implements Initializable {
private GraphToolbar graphToolbar = new GraphToolbar(this); private GraphToolbar graphToolbar = new GraphToolbar(this);
// dialogs // dialogs
private Rj45Dialog rj45Dialog = new Rj45Dialog(this);
private SessionsDialog sessionsDialog = new SessionsDialog(this); private SessionsDialog sessionsDialog = new SessionsDialog(this);
private ServiceDialog serviceDialog = new ServiceDialog(this); private ServiceDialog serviceDialog = new ServiceDialog(this);
private NodeServicesDialog nodeServicesDialog = new NodeServicesDialog(this); private NodeServicesDialog nodeServicesDialog = new NodeServicesDialog(this);
@ -277,6 +278,7 @@ public class Controller implements Initializable {
connectDialog.setOwner(window); connectDialog.setOwner(window);
guiPreferencesDialog.setOwner(window); guiPreferencesDialog.setOwner(window);
nodeTypeCreateDialog.setOwner(window); nodeTypeCreateDialog.setOwner(window);
rj45Dialog.setOwner(window);
} }
private void showMobilityScriptDialogs() { private void showMobilityScriptDialogs() {

View file

@ -1,8 +1,6 @@
package com.core.client; package com.core.client;
import com.core.Controller; import com.core.Controller;
import com.core.data.ServiceFile;
import com.core.data.WlanConfig;
import com.core.data.*; import com.core.data.*;
import java.io.File; import java.io.File;
@ -116,4 +114,6 @@ public interface ICoreClient {
boolean setLocationConfig(LocationConfig config) throws IOException; boolean setLocationConfig(LocationConfig config) throws IOException;
void initialize(Controller controller); void initialize(Controller controller);
List<String> getInterfaces() throws IOException;
} }

View file

@ -1280,4 +1280,15 @@ public class CoreGrpcClient implements ICoreClient {
private void handleFileEvents(CoreProto.FileEvent event) { private void handleFileEvents(CoreProto.FileEvent event) {
logger.info("file event: {}", event); logger.info("file event: {}", event);
} }
@Override
public List<String> 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);
}
}
} }

View file

@ -467,6 +467,8 @@ public class NetworkGraph {
node.setEmane(emaneModel); node.setEmane(emaneModel);
} else if (node.getType() == NodeType.DOCKER || node.getType() == NodeType.LXC) { } else if (node.getType() == NodeType.DOCKER || node.getType() == NodeType.LXC) {
node.setImage("ubuntu"); node.setImage("ubuntu");
} else if (node.getType() == NodeType.RJ45) {
Platform.runLater(() -> controller.getRj45Dialog().showDialog(node));
} }
logger.info("adding user created node: {}", node); logger.info("adding user created node: {}", node);

View file

@ -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<String> 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<String> 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);
}
}
}

View file

@ -28,6 +28,8 @@ import java.io.IOException;
@Data @Data
public class StageDialog { public class StageDialog {
private static final Logger logger = LogManager.getLogger(); 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 Controller controller;
private final Stage stage = new Stage(StageStyle.DECORATED); private final Stage stage = new Stage(StageStyle.DECORATED);
private final Scene scene; private final Scene scene;
@ -35,10 +37,18 @@ public class StageDialog {
private final HBox buttonBar = new HBox(); private final HBox buttonBar = new HBox();
public StageDialog(Controller controller, String fxmlPath) { 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) { 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; this.controller = controller;
JFXDecorator decorator = new JFXDecorator(stage, gridPane); JFXDecorator decorator = new JFXDecorator(stage, gridPane);
@ -49,8 +59,8 @@ public class StageDialog {
scene = new Scene(decorator); scene = new Scene(decorator);
stage.setScene(scene); stage.setScene(scene);
stage.setWidth(800); stage.setWidth(width);
stage.setHeight(600); stage.setHeight(height);
scene.setOnKeyPressed(event -> { scene.setOnKeyPressed(event -> {
if (KeyCode.ESCAPE == event.getCode()) { if (KeyCode.ESCAPE == event.getCode()) {
stage.close(); stage.close();

View file

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXComboBox?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
<children>
<GridPane hgap="10.0" VBox.vgrow="ALWAYS">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" percentWidth="30.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" percentWidth="70.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Interface" />
<JFXComboBox fx:id="interfacesComboBox" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" />
</children>
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</GridPane>
</children>
</VBox>