corefx - updated context menu logic to be contained within classes, fixed issue with service display in details panel for nodes with no default services
This commit is contained in:
parent
c419518559
commit
4f5ac43a06
10 changed files with 162 additions and 70 deletions
|
@ -184,8 +184,10 @@ public class Controller implements Initializable {
|
|||
Integer nodeId = nodeIdOptional.get();
|
||||
MobilityConfig mobilityConfig = mobilityConfigMap.get(nodeId);
|
||||
CoreNode node = networkGraph.getVertex(nodeId);
|
||||
mobilityPlayer.show(node, mobilityConfig);
|
||||
Platform.runLater(() -> bottom.getChildren().add(mobilityPlayer));
|
||||
if (node != null) {
|
||||
mobilityPlayer.show(node, mobilityConfig);
|
||||
Platform.runLater(() -> bottom.getChildren().add(mobilityPlayer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package com.core.graph;
|
||||
|
||||
import com.core.Controller;
|
||||
import com.core.data.CoreNode;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.scene.control.MenuItem;
|
||||
|
||||
abstract class AbstractNodeContextMenu extends GraphContextMenu {
|
||||
final CoreNode coreNode;
|
||||
|
||||
AbstractNodeContextMenu(Controller controller, CoreNode coreNode) {
|
||||
super(controller);
|
||||
this.coreNode = coreNode;
|
||||
}
|
||||
|
||||
void addMenuItem(String text, EventHandler<ActionEvent> handler) {
|
||||
MenuItem menuItem = new MenuItem(text);
|
||||
menuItem.setOnAction(handler);
|
||||
getItems().add(menuItem);
|
||||
}
|
||||
}
|
|
@ -9,17 +9,12 @@ import edu.uci.ics.jung.algorithms.layout.GraphElementAccessor;
|
|||
import edu.uci.ics.jung.algorithms.layout.Layout;
|
||||
import edu.uci.ics.jung.visualization.control.EditingPopupGraphMousePlugin;
|
||||
import javafx.application.Platform;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.scene.control.ContextMenu;
|
||||
import javafx.scene.control.MenuItem;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CorePopupGraphMousePlugin<V, E> extends EditingPopupGraphMousePlugin<V, E> {
|
||||
private static final Logger logger = LogManager.getLogger();
|
||||
|
@ -45,15 +40,13 @@ public class CorePopupGraphMousePlugin<V, E> extends EditingPopupGraphMousePlugi
|
|||
final CoreNode node = pickSupport.getVertex(graphLayout, p.getX(), p.getY());
|
||||
final CoreLink link = pickSupport.getEdge(graphLayout, p.getX(), p.getY());
|
||||
|
||||
ContextMenu contextMenu = new ContextMenu();
|
||||
|
||||
// edge picked
|
||||
final ContextMenu contextMenu;
|
||||
if (node != null) {
|
||||
List<MenuItem> menuItems = handleNodeContext(node);
|
||||
contextMenu.getItems().addAll(menuItems);
|
||||
contextMenu = handleNodeContext(node);
|
||||
} else if (link != null) {
|
||||
List<MenuItem> menuItems = handleLinkContext(link);
|
||||
contextMenu.getItems().addAll(menuItems);
|
||||
contextMenu = new LinkContextMenu(controller, link);
|
||||
} else {
|
||||
contextMenu = new ContextMenu();
|
||||
}
|
||||
|
||||
if (!contextMenu.getItems().isEmpty()) {
|
||||
|
@ -63,60 +56,23 @@ public class CorePopupGraphMousePlugin<V, E> extends EditingPopupGraphMousePlugi
|
|||
}
|
||||
}
|
||||
|
||||
private MenuItem createMenuItem(String text, EventHandler<ActionEvent> handler) {
|
||||
MenuItem menuItem = new MenuItem(text);
|
||||
menuItem.setOnAction(handler);
|
||||
return menuItem;
|
||||
}
|
||||
|
||||
private List<MenuItem> handleNodeContext(final CoreNode node) {
|
||||
boolean isRunning = controller.getCoreClient().isRunning();
|
||||
|
||||
List<MenuItem> menuItems = new ArrayList<>();
|
||||
|
||||
private ContextMenu handleNodeContext(final CoreNode node) {
|
||||
ContextMenu contextMenu = new ContextMenu();
|
||||
switch (node.getType()) {
|
||||
case NodeType.DEFAULT:
|
||||
menuItems.add(createMenuItem("Services",
|
||||
event -> controller.getNodeServicesDialog().showDialog(node)));
|
||||
contextMenu = new NodeContextMenu(controller, node);
|
||||
break;
|
||||
case NodeType.WLAN:
|
||||
menuItems.add(createMenuItem("WLAN Settings",
|
||||
event -> controller.getNodeWlanDialog().showDialog(node)));
|
||||
menuItems.add(createMenuItem("Mobility",
|
||||
event -> controller.getMobilityDialog().showDialog(node)));
|
||||
menuItems.add(createMenuItem("Link MDRs",
|
||||
event -> networkGraph.linkMdrs(node)));
|
||||
contextMenu = new WlanContextMenu(controller, node);
|
||||
break;
|
||||
case NodeType.EMANE:
|
||||
menuItems.add(createMenuItem("EMANE Settings",
|
||||
event -> controller.getNodeEmaneDialog().showDialog(node)));
|
||||
menuItems.add(createMenuItem("Mobility",
|
||||
event -> controller.getMobilityDialog().showDialog(node)));
|
||||
menuItems.add(createMenuItem("Link MDRs",
|
||||
event -> networkGraph.linkMdrs(node)));
|
||||
contextMenu = new EmaneContextMenu(controller, node);
|
||||
break;
|
||||
default:
|
||||
logger.warn("no context menu for node: {}", node.getType());
|
||||
break;
|
||||
}
|
||||
|
||||
if (!isRunning) {
|
||||
menuItems.add(createMenuItem("Delete Node",
|
||||
event -> controller.deleteNode(node)));
|
||||
}
|
||||
|
||||
return menuItems;
|
||||
}
|
||||
|
||||
private List<MenuItem> handleLinkContext(final CoreLink link) {
|
||||
boolean isRunning = controller.getCoreClient().isRunning();
|
||||
|
||||
List<MenuItem> menuItems = new ArrayList<>();
|
||||
|
||||
if (!isRunning) {
|
||||
menuItems.add(createMenuItem("Delete Link",
|
||||
event -> networkGraph.removeLink(link)));
|
||||
}
|
||||
|
||||
return menuItems;
|
||||
return contextMenu;
|
||||
}
|
||||
}
|
||||
|
|
23
corefx/src/main/java/com/core/graph/EmaneContextMenu.java
Normal file
23
corefx/src/main/java/com/core/graph/EmaneContextMenu.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package com.core.graph;
|
||||
|
||||
import com.core.Controller;
|
||||
import com.core.data.CoreNode;
|
||||
|
||||
class EmaneContextMenu extends AbstractNodeContextMenu {
|
||||
EmaneContextMenu(Controller controller, CoreNode coreNode) {
|
||||
super(controller, coreNode);
|
||||
setup();
|
||||
}
|
||||
|
||||
private void setup() {
|
||||
addMenuItem("EMANE Settings",
|
||||
event -> controller.getNodeEmaneDialog().showDialog(coreNode));
|
||||
if (!controller.getCoreClient().isRunning()) {
|
||||
addMenuItem("Mobility",
|
||||
event -> controller.getMobilityDialog().showDialog(coreNode));
|
||||
addMenuItem("Link MDRs",
|
||||
event -> controller.getNetworkGraph().linkMdrs(coreNode));
|
||||
addMenuItem("Delete Node", event -> controller.deleteNode(coreNode));
|
||||
}
|
||||
}
|
||||
}
|
22
corefx/src/main/java/com/core/graph/GraphContextMenu.java
Normal file
22
corefx/src/main/java/com/core/graph/GraphContextMenu.java
Normal file
|
@ -0,0 +1,22 @@
|
|||
package com.core.graph;
|
||||
|
||||
import com.core.Controller;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.scene.control.ContextMenu;
|
||||
import javafx.scene.control.MenuItem;
|
||||
|
||||
abstract class GraphContextMenu extends ContextMenu {
|
||||
final Controller controller;
|
||||
|
||||
GraphContextMenu(Controller controller) {
|
||||
super();
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
void addMenuItem(String text, EventHandler<ActionEvent> handler) {
|
||||
MenuItem menuItem = new MenuItem(text);
|
||||
menuItem.setOnAction(handler);
|
||||
getItems().add(menuItem);
|
||||
}
|
||||
}
|
21
corefx/src/main/java/com/core/graph/LinkContextMenu.java
Normal file
21
corefx/src/main/java/com/core/graph/LinkContextMenu.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
package com.core.graph;
|
||||
|
||||
import com.core.Controller;
|
||||
import com.core.data.CoreLink;
|
||||
|
||||
class LinkContextMenu extends GraphContextMenu {
|
||||
final CoreLink coreLink;
|
||||
|
||||
LinkContextMenu(Controller controller, CoreLink coreLink) {
|
||||
super(controller);
|
||||
this.coreLink = coreLink;
|
||||
setup();
|
||||
}
|
||||
|
||||
private void setup() {
|
||||
if (!controller.getCoreClient().isRunning()) {
|
||||
addMenuItem("Delete Link",
|
||||
event -> controller.getNetworkGraph().removeLink(coreLink));
|
||||
}
|
||||
}
|
||||
}
|
21
corefx/src/main/java/com/core/graph/NodeContextMenu.java
Normal file
21
corefx/src/main/java/com/core/graph/NodeContextMenu.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
package com.core.graph;
|
||||
|
||||
import com.core.Controller;
|
||||
import com.core.data.CoreNode;
|
||||
|
||||
class NodeContextMenu extends AbstractNodeContextMenu {
|
||||
NodeContextMenu(Controller controller, CoreNode coreNode) {
|
||||
super(controller, coreNode);
|
||||
setup();
|
||||
}
|
||||
|
||||
private void setup() {
|
||||
if (controller.getCoreClient().isRunning()) {
|
||||
addMenuItem("Manage Services", event -> {
|
||||
});
|
||||
} else {
|
||||
addMenuItem("Services", event -> controller.getNodeServicesDialog().showDialog(coreNode));
|
||||
addMenuItem("Delete Node", event -> controller.deleteNode(coreNode));
|
||||
}
|
||||
}
|
||||
}
|
23
corefx/src/main/java/com/core/graph/WlanContextMenu.java
Normal file
23
corefx/src/main/java/com/core/graph/WlanContextMenu.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package com.core.graph;
|
||||
|
||||
import com.core.Controller;
|
||||
import com.core.data.CoreNode;
|
||||
|
||||
class WlanContextMenu extends AbstractNodeContextMenu {
|
||||
WlanContextMenu(Controller controller, CoreNode coreNode) {
|
||||
super(controller, coreNode);
|
||||
setup();
|
||||
}
|
||||
|
||||
private void setup() {
|
||||
addMenuItem("WLAN Settings",
|
||||
event -> controller.getNodeWlanDialog().showDialog(coreNode));
|
||||
if (!controller.getCoreClient().isRunning()) {
|
||||
addMenuItem("Mobility",
|
||||
event -> controller.getMobilityDialog().showDialog(coreNode));
|
||||
addMenuItem("Link MDRs",
|
||||
event -> controller.getNetworkGraph().linkMdrs(coreNode));
|
||||
addMenuItem("Delete Node", event -> controller.deleteNode(coreNode));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,6 +22,7 @@ import javafx.scene.layout.GridPane;
|
|||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
public class NodeDetails extends ScrollPane {
|
||||
|
@ -105,15 +106,17 @@ public class NodeDetails extends ScrollPane {
|
|||
// display custom or default node services
|
||||
Set<String> services = node.getServices();
|
||||
if (services.isEmpty()) {
|
||||
services = controller.getDefaultServices().get(node.getModel());
|
||||
services = controller.getDefaultServices().getOrDefault(node.getModel(), Collections.emptySet());
|
||||
}
|
||||
if (!services.isEmpty()) {
|
||||
addSeparator();
|
||||
addLabel("Services");
|
||||
JFXListView<String> listView = new JFXListView<>();
|
||||
listView.setMouseTransparent(true);
|
||||
listView.setFocusTraversable(false);
|
||||
listView.getItems().setAll(services);
|
||||
gridPane.add(listView, 0, index++, 2, 1);
|
||||
}
|
||||
addSeparator();
|
||||
addLabel("Services");
|
||||
JFXListView<String> listView = new JFXListView<>();
|
||||
listView.setMouseTransparent(true);
|
||||
listView.setFocusTraversable(false);
|
||||
listView.getItems().setAll(services);
|
||||
gridPane.add(listView, 0, index++, 2, 1);
|
||||
|
||||
JFXScrollPane.smoothScrolling(scrollPane);
|
||||
}
|
||||
|
|
|
@ -38,9 +38,8 @@ public class NodeEmaneDialog extends StageDialog {
|
|||
}
|
||||
|
||||
public void setModels(List<String> models) {
|
||||
modelCombo.getItems().clear();
|
||||
models.stream().sorted()
|
||||
.forEach(model -> modelCombo.getItems().add(model));
|
||||
models.sort(String::compareTo);
|
||||
modelCombo.getItems().setAll(models);
|
||||
modelCombo.getSelectionModel().selectFirst();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue