initial basics for working with mobility scripts
This commit is contained in:
parent
1d73f28248
commit
2815554487
11 changed files with 182 additions and 33 deletions
|
@ -1,9 +1,13 @@
|
|||
package com.core;
|
||||
|
||||
import com.core.client.ICoreClient;
|
||||
import com.core.client.rest.*;
|
||||
import com.core.client.rest.ConfigOption;
|
||||
import com.core.client.rest.CoreRestClient;
|
||||
import com.core.client.rest.GetConfig;
|
||||
import com.core.client.rest.SetConfig;
|
||||
import com.core.data.CoreLink;
|
||||
import com.core.data.CoreNode;
|
||||
import com.core.data.MobilityConfig;
|
||||
import com.core.graph.NetworkGraph;
|
||||
import com.core.ui.*;
|
||||
import com.core.utils.ConfigUtils;
|
||||
|
@ -16,6 +20,7 @@ import javafx.fxml.FXML;
|
|||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.FileChooser;
|
||||
import javafx.stage.Stage;
|
||||
import lombok.Data;
|
||||
|
@ -59,6 +64,7 @@ public class Controller implements Initializable {
|
|||
private NodeDetails nodeDetails = new NodeDetails();
|
||||
private LinkDetails linkDetails = new LinkDetails(networkGraph);
|
||||
private GraphToolbar graphToolbar = new GraphToolbar(this);
|
||||
private MobilityPlayer mobilityPlayer = new MobilityPlayer(this);
|
||||
|
||||
// dialogs
|
||||
private SessionsDialog sessionsDialog = new SessionsDialog(this);
|
||||
|
@ -96,6 +102,32 @@ public class Controller implements Initializable {
|
|||
});
|
||||
}
|
||||
|
||||
public void sessionStarted() {
|
||||
// configure and add mobility player
|
||||
VBox vBox = (VBox) borderPane.getTop();
|
||||
CoreNode node = mobilityDialog.getNode();
|
||||
if (node != null) {
|
||||
MobilityConfig mobilityConfig = mobilityDialog.getMobilityScripts().get(node.getId());
|
||||
if (mobilityConfig != null) {
|
||||
mobilityPlayer.show(node, mobilityConfig);
|
||||
vBox.getChildren().add(mobilityPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void sessionStopped() {
|
||||
VBox vBox = (VBox) borderPane.getTop();
|
||||
vBox.getChildren().remove(mobilityPlayer);
|
||||
}
|
||||
|
||||
public void deleteNode(CoreNode node) {
|
||||
networkGraph.removeNode(node);
|
||||
CoreNode mobilityNode = mobilityDialog.getNode();
|
||||
if (mobilityNode != null && mobilityNode.getId().equals(node.getId())) {
|
||||
mobilityDialog.setNode(null);
|
||||
}
|
||||
}
|
||||
|
||||
public void setWindow(Stage window) {
|
||||
this.window = window;
|
||||
sessionsDialog.setOwner(window);
|
||||
|
|
|
@ -350,6 +350,6 @@ public class CoreRestClient implements ICoreClient {
|
|||
@Override
|
||||
public boolean mobilityAction(CoreNode node, String action) throws IOException {
|
||||
String url = getUrl(String.format("sessions/%s/nodes/%s/mobility/%s", sessionId, node.getId(), action));
|
||||
return WebUtils.putJson(url, null);
|
||||
return WebUtils.putJson(url);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ public class CorePopupGraphMousePlugin<V, E> extends EditingPopupGraphMousePlugi
|
|||
|
||||
if (!isRunning) {
|
||||
menuItems.add(createMenuItem("Delete Node",
|
||||
event -> networkGraph.removeNode(node)));
|
||||
event -> controller.deleteNode(node)));
|
||||
}
|
||||
|
||||
return menuItems;
|
||||
|
|
|
@ -58,6 +58,7 @@ public class NetworkGraph {
|
|||
private Set<NodeType> nodeTypes = new HashSet<>();
|
||||
private CorePopupGraphMousePlugin customPopupPlugin;
|
||||
private CoreAnnotatingGraphMousePlugin<CoreNode, CoreLink> customAnnotatingPlugin;
|
||||
private RadioIcon radioIcon = new RadioIcon();
|
||||
|
||||
public NetworkGraph(Controller controller) {
|
||||
this.controller = controller;
|
||||
|
@ -77,12 +78,13 @@ public class NetworkGraph {
|
|||
return new Ellipse2D.Double(offset, offset, IconUtils.ICON_SIZE, IconUtils.ICON_SIZE);
|
||||
});
|
||||
renderContext.setVertexIconTransformer(vertex -> {
|
||||
LayeredIcon layeredIcon = IconUtils.getIcon(vertex.getIcon());
|
||||
LayeredIcon icon = IconUtils.getIcon(vertex.getIcon());
|
||||
if (hasWirelessLink(vertex)) {
|
||||
RadioIcon radioIcon = new RadioIcon();
|
||||
layeredIcon.add(radioIcon);
|
||||
icon.add(radioIcon);
|
||||
} else {
|
||||
icon.remove(radioIcon);
|
||||
}
|
||||
return layeredIcon;
|
||||
return icon;
|
||||
});
|
||||
|
||||
// edge render properties
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.core.ui;
|
||||
|
||||
import com.core.Controller;
|
||||
import com.core.data.CoreNode;
|
||||
import com.core.data.MobilityConfig;
|
||||
import com.core.data.NodeType;
|
||||
import com.core.data.SessionState;
|
||||
import com.core.utils.IconUtils;
|
||||
|
@ -252,6 +254,7 @@ public class GraphToolbar extends VBox {
|
|||
|
||||
boolean result = controller.getCoreClient().start();
|
||||
if (result) {
|
||||
controller.sessionStarted();
|
||||
Toast.success("Session Started");
|
||||
setRunButton(true);
|
||||
}
|
||||
|
@ -266,6 +269,7 @@ public class GraphToolbar extends VBox {
|
|||
try {
|
||||
boolean result = controller.getCoreClient().setState(SessionState.SHUTDOWN);
|
||||
if (result) {
|
||||
controller.sessionStopped();
|
||||
Toast.success("Session Stopped");
|
||||
setRunButton(false);
|
||||
}
|
||||
|
|
|
@ -10,12 +10,16 @@ import javafx.event.ActionEvent;
|
|||
import javafx.fxml.FXML;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.stage.FileChooser;
|
||||
import lombok.Data;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class MobilityDialog extends StageDialog {
|
||||
private static final Logger logger = LogManager.getLogger();
|
||||
|
||||
|
@ -43,6 +47,7 @@ public class MobilityDialog extends StageDialog {
|
|||
@FXML
|
||||
private JFXTextField stopTextField;
|
||||
|
||||
private Map<Integer, MobilityConfig> mobilityScripts = new HashMap<>();
|
||||
private CoreNode node;
|
||||
|
||||
public MobilityDialog(Controller controller) {
|
||||
|
@ -65,9 +70,9 @@ public class MobilityDialog extends StageDialog {
|
|||
|
||||
try {
|
||||
controller.getCoreClient().setMobilityConfig(node, mobilityConfig);
|
||||
mobilityScripts.put(node.getId(), mobilityConfig);
|
||||
} catch (IOException ex) {
|
||||
logger.error("error setting mobility configuration", ex);
|
||||
Toast.error("error setting mobility configuration");
|
||||
Toast.error("error setting mobility configuration", ex);
|
||||
}
|
||||
|
||||
close();
|
||||
|
@ -108,8 +113,7 @@ public class MobilityDialog extends StageDialog {
|
|||
pauseTextField.setText(mobilityConfig.getPauseScript());
|
||||
stopTextField.setText(mobilityConfig.getStopScript());
|
||||
} catch (IOException ex) {
|
||||
logger.error("error getting mobility config", ex);
|
||||
Toast.error("error getting mobility config");
|
||||
Toast.error("error getting mobility config", ex);
|
||||
}
|
||||
|
||||
show();
|
||||
|
|
65
corefx/src/main/java/com/core/ui/MobilityPlayer.java
Normal file
65
corefx/src/main/java/com/core/ui/MobilityPlayer.java
Normal file
|
@ -0,0 +1,65 @@
|
|||
package com.core.ui;
|
||||
|
||||
import com.core.Controller;
|
||||
import com.core.data.CoreNode;
|
||||
import com.core.data.MobilityConfig;
|
||||
import com.jfoenix.controls.JFXButton;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.HBox;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class MobilityPlayer extends HBox {
|
||||
private static final Logger logger = LogManager.getLogger();
|
||||
|
||||
@FXML
|
||||
private Label label;
|
||||
|
||||
@FXML
|
||||
private JFXButton playButton;
|
||||
|
||||
@FXML
|
||||
private JFXButton pauseButton;
|
||||
|
||||
@FXML
|
||||
private JFXButton stopButton;
|
||||
|
||||
private Controller controller;
|
||||
private CoreNode node;
|
||||
private MobilityConfig mobilityConfig;
|
||||
|
||||
public MobilityPlayer(Controller controller) {
|
||||
this.controller = controller;
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/mobility_player.fxml"));
|
||||
loader.setRoot(this);
|
||||
loader.setController(this);
|
||||
|
||||
try {
|
||||
loader.load();
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
playButton.setOnAction(event -> action("start"));
|
||||
pauseButton.setOnAction(event -> action("pause"));
|
||||
stopButton.setOnAction(event -> action("stop"));
|
||||
}
|
||||
|
||||
private void action(String action) {
|
||||
try {
|
||||
controller.getCoreClient().mobilityAction(node, action);
|
||||
} catch (IOException ex) {
|
||||
Toast.error(String.format("mobility error: %s", action), ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void show(CoreNode node, MobilityConfig mobilityConfig) {
|
||||
this.node = node;
|
||||
this.mobilityConfig = mobilityConfig;
|
||||
label.setText(String.format("%s - %s", node.getName(), mobilityConfig.getFile()));
|
||||
}
|
||||
}
|
|
@ -37,6 +37,13 @@ public final class Toast {
|
|||
}
|
||||
|
||||
public static void error(String message) {
|
||||
error(message, null);
|
||||
}
|
||||
|
||||
public static void error(String message, Exception ex) {
|
||||
if (ex != null) {
|
||||
logger.error(message, ex);
|
||||
}
|
||||
JFXSnackbar.SnackbarEvent snackbarEvent = new JFXSnackbar.SnackbarEvent(message,
|
||||
"toast-error", "X", TIMEOUT, true, event -> snackbar.close());
|
||||
snackbar.enqueue(snackbarEvent);
|
||||
|
|
|
@ -98,6 +98,18 @@ public final class WebUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean putJson(String url) throws IOException {
|
||||
logger.debug("put json: {}", url);
|
||||
RequestBody body = new FormBody.Builder().build();
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.put(body)
|
||||
.build();
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
return response.isSuccessful();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean putJson(String url, String json) throws IOException {
|
||||
logger.debug("put json: {} - {}", url, json);
|
||||
RequestBody body = RequestBody.create(JSON, json);
|
||||
|
|
|
@ -7,12 +7,15 @@
|
|||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
<?import javafx.scene.layout.StackPane?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
|
||||
<StackPane fx:id="stackPane" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.core.Controller">
|
||||
<children>
|
||||
<BorderPane fx:id="borderPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0">
|
||||
<top>
|
||||
<MenuBar BorderPane.alignment="CENTER">
|
||||
<VBox BorderPane.alignment="CENTER">
|
||||
<children>
|
||||
<MenuBar>
|
||||
<menus>
|
||||
<Menu mnemonicParsing="false" text="File">
|
||||
<items>
|
||||
|
@ -36,6 +39,8 @@
|
|||
</Menu>
|
||||
</menus>
|
||||
</MenuBar>
|
||||
</children>
|
||||
</VBox>
|
||||
</top>
|
||||
<center>
|
||||
<AnchorPane>
|
||||
|
|
18
corefx/src/main/resources/fxml/mobility_player.fxml
Normal file
18
corefx/src/main/resources/fxml/mobility_player.fxml
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import com.jfoenix.controls.JFXButton?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
|
||||
<fx:root alignment="CENTER" maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" spacing="10.0" type="HBox" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<children>
|
||||
<Label fx:id="label" maxHeight="1.7976931348623157E308" text="Label" />
|
||||
<JFXButton fx:id="playButton" styleClass="core-button" text="Play" />
|
||||
<JFXButton fx:id="pauseButton" styleClass="core-button" text="Pause" />
|
||||
<JFXButton fx:id="stopButton" styleClass="core-button" text="Stop" />
|
||||
</children>
|
||||
<padding>
|
||||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
||||
</padding>
|
||||
</fx:root>
|
Loading…
Reference in a new issue