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() {
|
||||
nodesButton.setTooltip(new Tooltip("Network Nodes (host, pc, etc)"));
|
||||
nodesList.getSelectionModel().selectedItemProperty().addListener((ov, old, current) -> {
|
||||
if (current == null) {
|
||||
return;
|
||||
|
@ -211,6 +212,7 @@ public class GraphToolbar extends VBox {
|
|||
}
|
||||
|
||||
private void setupDevicesButton() {
|
||||
devicesButton.setTooltip(new Tooltip("Device Nodes (WLAN, EMANE, Switch, etc)"));
|
||||
devicesList.getSelectionModel().selectedItemProperty().addListener((ov, old, current) -> {
|
||||
if (current == null) {
|
||||
return;
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package com.core.ui;
|
||||
|
||||
import com.core.Controller;
|
||||
import com.core.data.CoreNode;
|
||||
import com.core.client.rest.GetServices;
|
||||
import com.core.data.CoreNode;
|
||||
import com.jfoenix.controls.JFXButton;
|
||||
import com.jfoenix.controls.JFXComboBox;
|
||||
import com.jfoenix.controls.JFXListView;
|
||||
import com.jfoenix.controls.JFXScrollPane;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
|
@ -16,21 +17,29 @@ import java.util.*;
|
|||
|
||||
public class NodeServicesDialog extends StageDialog {
|
||||
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;
|
||||
|
||||
@FXML
|
||||
private JFXComboBox<String> comboBox;
|
||||
|
||||
@FXML
|
||||
private GridPane gridPane;
|
||||
|
||||
@FXML
|
||||
private ScrollPane scrollPane;
|
||||
|
||||
private Map<String, List<ServiceItem>> serviceItemGroups = new HashMap<>();
|
||||
@FXML
|
||||
private JFXListView<String> groupListView;
|
||||
|
||||
// TODO: get this from core itself
|
||||
private Map<String, Set<String>> defaultServices = new HashMap<>();
|
||||
@FXML
|
||||
private JFXListView<String> activeListView;
|
||||
|
||||
@FXML
|
||||
private JFXButton removeButton;
|
||||
|
||||
@FXML
|
||||
private JFXButton editButton;
|
||||
|
||||
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("host", new HashSet<>(Arrays.asList("DefaultRoute", "SSH")));
|
||||
|
||||
comboBox.valueProperty().addListener((ov, previous, current) -> {
|
||||
groupListView.getSelectionModel().selectedItemProperty().addListener((ov, previous, current) -> {
|
||||
if (current == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
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) {
|
||||
comboBox.getItems().clear();
|
||||
serviceItemGroups.clear();
|
||||
|
||||
getServices.getGroups().keySet().stream()
|
||||
.sorted()
|
||||
.forEach(group -> {
|
||||
comboBox.getItems().add(group);
|
||||
|
||||
groupListView.getItems().add(group);
|
||||
getServices.getGroups().get(group).stream()
|
||||
.sorted()
|
||||
.forEach(service -> {
|
||||
|
@ -82,33 +107,46 @@ public class NodeServicesDialog extends StageDialog {
|
|||
List<ServiceItem> items = serviceItemGroups.computeIfAbsent(
|
||||
group, k -> new ArrayList<>());
|
||||
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);
|
||||
|
||||
comboBox.getSelectionModel().selectFirst();
|
||||
}
|
||||
|
||||
private void updateItems(String group) {
|
||||
logger.debug("updating services for group: {}", group);
|
||||
clear();
|
||||
clearAvailableServices();
|
||||
List<ServiceItem> items = serviceItemGroups.get(group);
|
||||
for (ServiceItem item : items) {
|
||||
gridPane.addRow(index++, item.getCheckBox(), item.getButton());
|
||||
gridPane.addRow(index++, item.getCheckBox());
|
||||
}
|
||||
}
|
||||
|
||||
private void clear() {
|
||||
if (!gridPane.getChildren().isEmpty()) {
|
||||
gridPane.getChildren().remove(0, gridPane.getChildren().size());
|
||||
}
|
||||
private void clearAvailableServices() {
|
||||
gridPane.getChildren().clear();
|
||||
index = 0;
|
||||
}
|
||||
|
||||
public void showDialog(CoreNode node) {
|
||||
this.node = node;
|
||||
comboBox.getSelectionModel().selectFirst();
|
||||
setTitle(String.format("%s - Services", node.getName()));
|
||||
groupListView.getSelectionModel().selectFirst();
|
||||
activeListView.getItems().clear();
|
||||
|
||||
Set<String> nodeServices = node.getServices();
|
||||
if (nodeServices.isEmpty()) {
|
||||
|
@ -119,10 +157,13 @@ public class NodeServicesDialog extends StageDialog {
|
|||
for (ServiceItem item : items) {
|
||||
boolean selected = nodeServices.contains(item.getService());
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +1,15 @@
|
|||
package com.core.ui;
|
||||
|
||||
import com.jfoenix.controls.JFXButton;
|
||||
import com.jfoenix.controls.JFXCheckBox;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ServiceItem {
|
||||
private String service;
|
||||
private JFXButton button = new JFXButton("Edit");
|
||||
private JFXCheckBox checkBox;
|
||||
|
||||
public ServiceItem(String service) {
|
||||
this.service = 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"?>
|
||||
|
||||
<?import com.jfoenix.controls.JFXComboBox?>
|
||||
<?import com.jfoenix.controls.JFXButton?>
|
||||
<?import com.jfoenix.controls.JFXListView?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.ScrollPane?>
|
||||
<?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" 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>
|
||||
<JFXComboBox fx:id="comboBox" maxWidth="1.7976931348623157E308">
|
||||
<VBox.margin>
|
||||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
||||
</VBox.margin>
|
||||
</JFXComboBox>
|
||||
<ScrollPane fx:id="scrollPane" fitToWidth="true" prefHeight="342.0" prefWidth="580.0" VBox.vgrow="ALWAYS">
|
||||
<VBox.margin>
|
||||
<Insets bottom="10.0" left="10.0" right="10.0" />
|
||||
</VBox.margin>
|
||||
<content>
|
||||
<GridPane fx:id="gridPane" hgap="5.0" vgap="5.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" percentWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<padding>
|
||||
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||
</padding>
|
||||
<VBox spacing="10.0" GridPane.columnIndex="1">
|
||||
<children>
|
||||
<Label alignment="CENTER" maxWidth="1.7976931348623157E308" text="Available Services" />
|
||||
<ScrollPane fx:id="scrollPane" fitToWidth="true" style="-fx-background: white;" VBox.vgrow="ALWAYS">
|
||||
<VBox.margin>
|
||||
<Insets />
|
||||
</VBox.margin>
|
||||
<content>
|
||||
<GridPane fx:id="gridPane" vgap="10.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" vgrow="NEVER" />
|
||||
</rowConstraints>
|
||||
<padding>
|
||||
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||
</padding>
|
||||
</GridPane>
|
||||
</content>
|
||||
</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>
|
||||
</content>
|
||||
</ScrollPane>
|
||||
</children>
|
||||
</VBox>
|
||||
</children>
|
||||
</VBox>
|
||||
<padding>
|
||||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
||||
</padding>
|
||||
</GridPane>
|
||||
|
|
Loading…
Reference in a new issue