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:
Blake J. Harnden 2018-11-28 11:46:13 -08:00
parent c419518559
commit 4f5ac43a06
10 changed files with 162 additions and 70 deletions

View file

@ -184,8 +184,10 @@ public class Controller implements Initializable {
Integer nodeId = nodeIdOptional.get(); Integer nodeId = nodeIdOptional.get();
MobilityConfig mobilityConfig = mobilityConfigMap.get(nodeId); MobilityConfig mobilityConfig = mobilityConfigMap.get(nodeId);
CoreNode node = networkGraph.getVertex(nodeId); CoreNode node = networkGraph.getVertex(nodeId);
mobilityPlayer.show(node, mobilityConfig); if (node != null) {
Platform.runLater(() -> bottom.getChildren().add(mobilityPlayer)); mobilityPlayer.show(node, mobilityConfig);
Platform.runLater(() -> bottom.getChildren().add(mobilityPlayer));
}
} }
} }

View file

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

View file

@ -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.algorithms.layout.Layout;
import edu.uci.ics.jung.visualization.control.EditingPopupGraphMousePlugin; import edu.uci.ics.jung.visualization.control.EditingPopupGraphMousePlugin;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.ContextMenu; import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
public class CorePopupGraphMousePlugin<V, E> extends EditingPopupGraphMousePlugin<V, E> { public class CorePopupGraphMousePlugin<V, E> extends EditingPopupGraphMousePlugin<V, E> {
private static final Logger logger = LogManager.getLogger(); 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 CoreNode node = pickSupport.getVertex(graphLayout, p.getX(), p.getY());
final CoreLink link = pickSupport.getEdge(graphLayout, p.getX(), p.getY()); final CoreLink link = pickSupport.getEdge(graphLayout, p.getX(), p.getY());
ContextMenu contextMenu = new ContextMenu(); final ContextMenu contextMenu;
// edge picked
if (node != null) { if (node != null) {
List<MenuItem> menuItems = handleNodeContext(node); contextMenu = handleNodeContext(node);
contextMenu.getItems().addAll(menuItems);
} else if (link != null) { } else if (link != null) {
List<MenuItem> menuItems = handleLinkContext(link); contextMenu = new LinkContextMenu(controller, link);
contextMenu.getItems().addAll(menuItems); } else {
contextMenu = new ContextMenu();
} }
if (!contextMenu.getItems().isEmpty()) { if (!contextMenu.getItems().isEmpty()) {
@ -63,60 +56,23 @@ public class CorePopupGraphMousePlugin<V, E> extends EditingPopupGraphMousePlugi
} }
} }
private MenuItem createMenuItem(String text, EventHandler<ActionEvent> handler) { private ContextMenu handleNodeContext(final CoreNode node) {
MenuItem menuItem = new MenuItem(text); ContextMenu contextMenu = new ContextMenu();
menuItem.setOnAction(handler);
return menuItem;
}
private List<MenuItem> handleNodeContext(final CoreNode node) {
boolean isRunning = controller.getCoreClient().isRunning();
List<MenuItem> menuItems = new ArrayList<>();
switch (node.getType()) { switch (node.getType()) {
case NodeType.DEFAULT: case NodeType.DEFAULT:
menuItems.add(createMenuItem("Services", contextMenu = new NodeContextMenu(controller, node);
event -> controller.getNodeServicesDialog().showDialog(node)));
break; break;
case NodeType.WLAN: case NodeType.WLAN:
menuItems.add(createMenuItem("WLAN Settings", contextMenu = new WlanContextMenu(controller, node);
event -> controller.getNodeWlanDialog().showDialog(node)));
menuItems.add(createMenuItem("Mobility",
event -> controller.getMobilityDialog().showDialog(node)));
menuItems.add(createMenuItem("Link MDRs",
event -> networkGraph.linkMdrs(node)));
break; break;
case NodeType.EMANE: case NodeType.EMANE:
menuItems.add(createMenuItem("EMANE Settings", contextMenu = new EmaneContextMenu(controller, node);
event -> controller.getNodeEmaneDialog().showDialog(node)));
menuItems.add(createMenuItem("Mobility",
event -> controller.getMobilityDialog().showDialog(node)));
menuItems.add(createMenuItem("Link MDRs",
event -> networkGraph.linkMdrs(node)));
break; break;
default: default:
logger.warn("no context menu for node: {}", node.getType());
break; break;
} }
if (!isRunning) { return contextMenu;
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;
} }
} }

View 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));
}
}
}

View 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);
}
}

View 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));
}
}
}

View 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));
}
}
}

View 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));
}
}
}

View file

@ -22,6 +22,7 @@ import javafx.scene.layout.GridPane;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import java.util.Collections;
import java.util.Set; import java.util.Set;
public class NodeDetails extends ScrollPane { public class NodeDetails extends ScrollPane {
@ -105,16 +106,18 @@ public class NodeDetails extends ScrollPane {
// display custom or default node services // display custom or default node services
Set<String> services = node.getServices(); Set<String> services = node.getServices();
if (services.isEmpty()) { if (services.isEmpty()) {
services = controller.getDefaultServices().get(node.getModel()); services = controller.getDefaultServices().getOrDefault(node.getModel(), Collections.emptySet());
} }
addSeparator(); if (!services.isEmpty()) {
addLabel("Services"); addSeparator();
JFXListView<String> listView = new JFXListView<>(); addLabel("Services");
listView.setMouseTransparent(true); JFXListView<String> listView = new JFXListView<>();
listView.setFocusTraversable(false); listView.setMouseTransparent(true);
listView.getItems().setAll(services); listView.setFocusTraversable(false);
gridPane.add(listView, 0, index++, 2, 1); listView.getItems().setAll(services);
gridPane.add(listView, 0, index++, 2, 1);
}
JFXScrollPane.smoothScrolling(scrollPane); JFXScrollPane.smoothScrolling(scrollPane);
} }

View file

@ -38,9 +38,8 @@ public class NodeEmaneDialog extends StageDialog {
} }
public void setModels(List<String> models) { public void setModels(List<String> models) {
modelCombo.getItems().clear(); models.sort(String::compareTo);
models.stream().sorted() modelCombo.getItems().setAll(models);
.forEach(model -> modelCombo.getItems().add(model));
modelCombo.getSelectionModel().selectFirst(); modelCombo.getSelectionModel().selectFirst();
} }