gui - updated service dialog display based on feedback
This commit is contained in:
parent
09cdc24427
commit
fd559c1c4f
4 changed files with 128 additions and 58 deletions
|
@ -192,6 +192,7 @@ public class GraphToolbar extends VBox {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupNodesButton() {
|
private void setupNodesButton() {
|
||||||
|
nodesButton.setTooltip(new Tooltip("Network Nodes (host, pc, etc)"));
|
||||||
nodesList.getSelectionModel().selectedItemProperty().addListener((ov, old, current) -> {
|
nodesList.getSelectionModel().selectedItemProperty().addListener((ov, old, current) -> {
|
||||||
if (current == null) {
|
if (current == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -211,6 +212,7 @@ public class GraphToolbar extends VBox {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupDevicesButton() {
|
private void setupDevicesButton() {
|
||||||
|
devicesButton.setTooltip(new Tooltip("Device Nodes (WLAN, EMANE, Switch, etc)"));
|
||||||
devicesList.getSelectionModel().selectedItemProperty().addListener((ov, old, current) -> {
|
devicesList.getSelectionModel().selectedItemProperty().addListener((ov, old, current) -> {
|
||||||
if (current == null) {
|
if (current == null) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
package com.core.ui;
|
package com.core.ui;
|
||||||
|
|
||||||
import com.core.Controller;
|
import com.core.Controller;
|
||||||
import com.core.data.CoreNode;
|
|
||||||
import com.core.client.rest.GetServices;
|
import com.core.client.rest.GetServices;
|
||||||
|
import com.core.data.CoreNode;
|
||||||
import com.jfoenix.controls.JFXButton;
|
import com.jfoenix.controls.JFXButton;
|
||||||
import com.jfoenix.controls.JFXComboBox;
|
import com.jfoenix.controls.JFXListView;
|
||||||
import com.jfoenix.controls.JFXScrollPane;
|
import com.jfoenix.controls.JFXScrollPane;
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.ScrollPane;
|
import javafx.scene.control.ScrollPane;
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
|
@ -16,21 +17,29 @@ import java.util.*;
|
||||||
|
|
||||||
public class NodeServicesDialog extends StageDialog {
|
public class NodeServicesDialog extends StageDialog {
|
||||||
private static final Logger logger = LogManager.getLogger();
|
private static final Logger logger = LogManager.getLogger();
|
||||||
|
private final Map<String, List<ServiceItem>> serviceItemGroups = new HashMap<>();
|
||||||
|
private final Map<String, ServiceItem> serviceItemMap = new HashMap<>();
|
||||||
|
// TODO: get this from core itself
|
||||||
|
private final Map<String, Set<String>> defaultServices = new HashMap<>();
|
||||||
private CoreNode node;
|
private CoreNode node;
|
||||||
|
|
||||||
@FXML
|
|
||||||
private JFXComboBox<String> comboBox;
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private GridPane gridPane;
|
private GridPane gridPane;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private ScrollPane scrollPane;
|
private ScrollPane scrollPane;
|
||||||
|
|
||||||
private Map<String, List<ServiceItem>> serviceItemGroups = new HashMap<>();
|
@FXML
|
||||||
|
private JFXListView<String> groupListView;
|
||||||
|
|
||||||
// TODO: get this from core itself
|
@FXML
|
||||||
private Map<String, Set<String>> defaultServices = new HashMap<>();
|
private JFXListView<String> activeListView;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private JFXButton removeButton;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private JFXButton editButton;
|
||||||
|
|
||||||
private int index = 0;
|
private int index = 0;
|
||||||
|
|
||||||
|
@ -57,24 +66,40 @@ public class NodeServicesDialog extends StageDialog {
|
||||||
defaultServices.put("router", new HashSet<>(Arrays.asList("zebra", "OSPFv2", "OSPFv3", "IPForward")));
|
defaultServices.put("router", new HashSet<>(Arrays.asList("zebra", "OSPFv2", "OSPFv3", "IPForward")));
|
||||||
defaultServices.put("host", new HashSet<>(Arrays.asList("DefaultRoute", "SSH")));
|
defaultServices.put("host", new HashSet<>(Arrays.asList("DefaultRoute", "SSH")));
|
||||||
|
|
||||||
comboBox.valueProperty().addListener((ov, previous, current) -> {
|
groupListView.getSelectionModel().selectedItemProperty().addListener((ov, previous, current) -> {
|
||||||
if (current == null) {
|
if (current == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateItems(current);
|
updateItems(current);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
activeListView.getSelectionModel().selectedItemProperty().addListener((ov, previous, current) -> {
|
||||||
|
boolean isDisabled = current == null;
|
||||||
|
removeButton.setDisable(isDisabled);
|
||||||
|
editButton.setDisable(isDisabled);
|
||||||
|
});
|
||||||
|
|
||||||
|
removeButton.setOnAction(event -> {
|
||||||
|
String service = activeListView.getSelectionModel().getSelectedItem();
|
||||||
|
activeListView.getItems().remove(service);
|
||||||
|
ServiceItem serviceItem = serviceItemMap.get(service);
|
||||||
|
serviceItem.getCheckBox().setSelected(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
editButton.setOnAction(event -> {
|
||||||
|
String service = activeListView.getSelectionModel().getSelectedItem();
|
||||||
|
getController().getServiceDialog().showDialog(node, service);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setServices(GetServices getServices) {
|
public void setServices(GetServices getServices) {
|
||||||
comboBox.getItems().clear();
|
|
||||||
serviceItemGroups.clear();
|
serviceItemGroups.clear();
|
||||||
|
|
||||||
getServices.getGroups().keySet().stream()
|
getServices.getGroups().keySet().stream()
|
||||||
.sorted()
|
.sorted()
|
||||||
.forEach(group -> {
|
.forEach(group -> {
|
||||||
comboBox.getItems().add(group);
|
groupListView.getItems().add(group);
|
||||||
|
|
||||||
getServices.getGroups().get(group).stream()
|
getServices.getGroups().get(group).stream()
|
||||||
.sorted()
|
.sorted()
|
||||||
.forEach(service -> {
|
.forEach(service -> {
|
||||||
|
@ -82,33 +107,46 @@ public class NodeServicesDialog extends StageDialog {
|
||||||
List<ServiceItem> items = serviceItemGroups.computeIfAbsent(
|
List<ServiceItem> items = serviceItemGroups.computeIfAbsent(
|
||||||
group, k -> new ArrayList<>());
|
group, k -> new ArrayList<>());
|
||||||
items.add(serviceItem);
|
items.add(serviceItem);
|
||||||
|
|
||||||
|
if (serviceItem.getCheckBox().isSelected()) {
|
||||||
|
activeListView.getItems().add(serviceItem.getService());
|
||||||
|
}
|
||||||
|
|
||||||
|
serviceItem.getCheckBox().setOnAction(event -> {
|
||||||
|
if (serviceItem.getCheckBox().isSelected()) {
|
||||||
|
activeListView.getItems().add(service);
|
||||||
|
FXCollections.sort(activeListView.getItems());
|
||||||
|
} else {
|
||||||
|
activeListView.getItems().remove(service);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
serviceItemMap.put(service, serviceItem);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
groupListView.getSelectionModel().selectFirst();
|
||||||
JFXScrollPane.smoothScrolling(scrollPane);
|
JFXScrollPane.smoothScrolling(scrollPane);
|
||||||
|
|
||||||
comboBox.getSelectionModel().selectFirst();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateItems(String group) {
|
private void updateItems(String group) {
|
||||||
logger.debug("updating services for group: {}", group);
|
logger.debug("updating services for group: {}", group);
|
||||||
clear();
|
clearAvailableServices();
|
||||||
List<ServiceItem> items = serviceItemGroups.get(group);
|
List<ServiceItem> items = serviceItemGroups.get(group);
|
||||||
for (ServiceItem item : items) {
|
for (ServiceItem item : items) {
|
||||||
gridPane.addRow(index++, item.getCheckBox(), item.getButton());
|
gridPane.addRow(index++, item.getCheckBox());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clear() {
|
private void clearAvailableServices() {
|
||||||
if (!gridPane.getChildren().isEmpty()) {
|
gridPane.getChildren().clear();
|
||||||
gridPane.getChildren().remove(0, gridPane.getChildren().size());
|
|
||||||
}
|
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showDialog(CoreNode node) {
|
public void showDialog(CoreNode node) {
|
||||||
this.node = node;
|
this.node = node;
|
||||||
comboBox.getSelectionModel().selectFirst();
|
|
||||||
setTitle(String.format("%s - Services", node.getName()));
|
setTitle(String.format("%s - Services", node.getName()));
|
||||||
|
groupListView.getSelectionModel().selectFirst();
|
||||||
|
activeListView.getItems().clear();
|
||||||
|
|
||||||
Set<String> nodeServices = node.getServices();
|
Set<String> nodeServices = node.getServices();
|
||||||
if (nodeServices.isEmpty()) {
|
if (nodeServices.isEmpty()) {
|
||||||
|
@ -119,10 +157,13 @@ public class NodeServicesDialog extends StageDialog {
|
||||||
for (ServiceItem item : items) {
|
for (ServiceItem item : items) {
|
||||||
boolean selected = nodeServices.contains(item.getService());
|
boolean selected = nodeServices.contains(item.getService());
|
||||||
item.getCheckBox().setSelected(selected);
|
item.getCheckBox().setSelected(selected);
|
||||||
item.setEditHandler(event -> getController().getServiceDialog().showDialog(node, item.getService()));
|
if (item.getCheckBox().isSelected()) {
|
||||||
|
activeListView.getItems().add(item.getService());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FXCollections.sort(activeListView.getItems());
|
||||||
show();
|
show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,15 @@
|
||||||
package com.core.ui;
|
package com.core.ui;
|
||||||
|
|
||||||
import com.jfoenix.controls.JFXButton;
|
|
||||||
import com.jfoenix.controls.JFXCheckBox;
|
import com.jfoenix.controls.JFXCheckBox;
|
||||||
import javafx.event.ActionEvent;
|
|
||||||
import javafx.event.EventHandler;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class ServiceItem {
|
public class ServiceItem {
|
||||||
private String service;
|
private String service;
|
||||||
private JFXButton button = new JFXButton("Edit");
|
|
||||||
private JFXCheckBox checkBox;
|
private JFXCheckBox checkBox;
|
||||||
|
|
||||||
public ServiceItem(String service) {
|
public ServiceItem(String service) {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
checkBox = new JFXCheckBox(service);
|
checkBox = new JFXCheckBox(service);
|
||||||
button.getStyleClass().add("core-button");
|
|
||||||
button.setMaxWidth(Double.MAX_VALUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEditHandler(EventHandler<ActionEvent> handler) {
|
|
||||||
button.setOnAction(handler);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,38 +1,75 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import com.jfoenix.controls.JFXComboBox?>
|
<?import com.jfoenix.controls.JFXButton?>
|
||||||
|
<?import com.jfoenix.controls.JFXListView?>
|
||||||
<?import javafx.geometry.Insets?>
|
<?import javafx.geometry.Insets?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
<?import javafx.scene.control.ScrollPane?>
|
<?import javafx.scene.control.ScrollPane?>
|
||||||
<?import javafx.scene.layout.ColumnConstraints?>
|
<?import javafx.scene.layout.ColumnConstraints?>
|
||||||
<?import javafx.scene.layout.GridPane?>
|
<?import javafx.scene.layout.GridPane?>
|
||||||
<?import javafx.scene.layout.RowConstraints?>
|
<?import javafx.scene.layout.RowConstraints?>
|
||||||
<?import javafx.scene.layout.VBox?>
|
<?import javafx.scene.layout.VBox?>
|
||||||
|
|
||||||
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
|
<GridPane hgap="10.0" prefHeight="600.0" prefWidth="800.0" vgap="10.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" percentWidth="33.3" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" percentWidth="33.3" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" percentWidth="33.3" />
|
||||||
|
</columnConstraints>
|
||||||
|
<rowConstraints>
|
||||||
|
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
|
||||||
|
</rowConstraints>
|
||||||
<children>
|
<children>
|
||||||
<JFXComboBox fx:id="comboBox" maxWidth="1.7976931348623157E308">
|
<VBox spacing="10.0" GridPane.columnIndex="1">
|
||||||
<VBox.margin>
|
<children>
|
||||||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
<Label alignment="CENTER" maxWidth="1.7976931348623157E308" text="Available Services" />
|
||||||
</VBox.margin>
|
<ScrollPane fx:id="scrollPane" fitToWidth="true" style="-fx-background: white;" VBox.vgrow="ALWAYS">
|
||||||
</JFXComboBox>
|
<VBox.margin>
|
||||||
<ScrollPane fx:id="scrollPane" fitToWidth="true" prefHeight="342.0" prefWidth="580.0" VBox.vgrow="ALWAYS">
|
<Insets />
|
||||||
<VBox.margin>
|
</VBox.margin>
|
||||||
<Insets bottom="10.0" left="10.0" right="10.0" />
|
<content>
|
||||||
</VBox.margin>
|
<GridPane fx:id="gridPane" vgap="10.0">
|
||||||
<content>
|
<columnConstraints>
|
||||||
<GridPane fx:id="gridPane" hgap="5.0" vgap="5.0">
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||||
<columnConstraints>
|
</columnConstraints>
|
||||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
<rowConstraints>
|
||||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" percentWidth="10.0" prefWidth="100.0" />
|
<RowConstraints minHeight="10.0" vgrow="NEVER" />
|
||||||
</columnConstraints>
|
</rowConstraints>
|
||||||
<rowConstraints>
|
<padding>
|
||||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||||
</rowConstraints>
|
</padding>
|
||||||
<padding>
|
</GridPane>
|
||||||
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
</content>
|
||||||
</padding>
|
</ScrollPane>
|
||||||
|
</children>
|
||||||
|
</VBox>
|
||||||
|
<VBox spacing="10.0">
|
||||||
|
<children>
|
||||||
|
<Label alignment="CENTER" maxWidth="1.7976931348623157E308" text="Service Groups" />
|
||||||
|
<JFXListView fx:id="groupListView" VBox.vgrow="ALWAYS" />
|
||||||
|
</children>
|
||||||
|
</VBox>
|
||||||
|
<VBox spacing="10.0" GridPane.columnIndex="2">
|
||||||
|
<children>
|
||||||
|
<Label alignment="CENTER" maxWidth="1.7976931348623157E308" text="Selected Services" />
|
||||||
|
<JFXListView fx:id="activeListView" VBox.vgrow="ALWAYS" />
|
||||||
|
<GridPane hgap="10.0">
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
|
||||||
|
</columnConstraints>
|
||||||
|
<rowConstraints>
|
||||||
|
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
|
||||||
|
</rowConstraints>
|
||||||
|
<children>
|
||||||
|
<JFXButton fx:id="removeButton" disable="true" maxWidth="1.7976931348623157E308" styleClass="core-button" text="Remove" GridPane.columnIndex="1" />
|
||||||
|
<JFXButton fx:id="editButton" disable="true" maxWidth="1.7976931348623157E308" styleClass="core-button" text="Edit" />
|
||||||
|
</children>
|
||||||
</GridPane>
|
</GridPane>
|
||||||
</content>
|
</children>
|
||||||
</ScrollPane>
|
</VBox>
|
||||||
</children>
|
</children>
|
||||||
</VBox>
|
<padding>
|
||||||
|
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
||||||
|
</padding>
|
||||||
|
</GridPane>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue