Merge branch 'rel/5.3' of git-ssh.web.boeing.com:Boeing-CORE/CORE into rel/5.3

This commit is contained in:
bharnden 2018-11-25 12:15:00 -08:00
commit 080a03c8be
6 changed files with 122 additions and 52 deletions

View file

@ -195,7 +195,7 @@ public class Controller implements Initializable {
} }
} }
decorator.setTitle(String.format("CORE (Session %s)", sessionId)); Platform.runLater(() -> decorator.setTitle(String.format("CORE (Session %s)", sessionId)));
} }
public boolean startSession() throws IOException { public boolean startSession() throws IOException {

View file

@ -14,12 +14,16 @@ import java.util.Set;
public interface ICoreClient { public interface ICoreClient {
void setUrl(String url); void setUrl(String url);
Integer currentSession();
void updateSession(Integer sessionId); void updateSession(Integer sessionId);
void updateState(SessionState state); void updateState(SessionState state);
SessionOverview createSession() throws IOException; SessionOverview createSession() throws IOException;
boolean deleteSession(Integer sessionId) throws IOException;
List<SessionOverview> getSessions() throws IOException; List<SessionOverview> getSessions() throws IOException;
Session getSession(Integer sessionId) throws IOException; Session getSession(Integer sessionId) throws IOException;

View file

@ -23,6 +23,11 @@ public class CoreRestClient implements ICoreClient {
this.baseUrl = url; this.baseUrl = url;
} }
@Override
public Integer currentSession() {
return sessionId;
}
@Override @Override
public void updateState(SessionState state) { public void updateState(SessionState state) {
sessionState = state; sessionState = state;
@ -43,6 +48,13 @@ public class CoreRestClient implements ICoreClient {
return WebUtils.post(url, SessionOverview.class); return WebUtils.post(url, SessionOverview.class);
} }
@Override
public boolean deleteSession(Integer sessionId) throws IOException {
String path = String.format("sessions/%s", sessionId);
String url = getUrl(path);
return WebUtils.delete(url);
}
public Map<String, List<String>> getServices() throws IOException { public Map<String, List<String>> getServices() throws IOException {
String url = getUrl("services"); String url = getUrl("services");
GetServices getServices = WebUtils.getJson(url, GetServices.class); GetServices getServices = WebUtils.getJson(url, GetServices.class);

View file

@ -168,50 +168,48 @@ public class GraphToolbar extends VBox {
private void setupNodesButton() { private void setupNodesButton() {
nodesButton.setTooltip(new Tooltip("Network Nodes (host, pc, etc)")); nodesButton.setTooltip(new Tooltip("Network Nodes (host, pc, etc)"));
nodesList.getSelectionModel().selectedItemProperty().addListener((ov, old, current) -> { nodesList.setOnMouseClicked(event -> {
if (current == null) { Label selectedLabel = nodesList.getSelectionModel().getSelectedItem();
if (selectedLabel == null) {
return; return;
} }
updateButtonValues(nodesButton, current); updateButtonValues(nodesButton, selectedLabel);
selectedNodeType = NodeType.get((int) current.getUserData()); selectedNodeType = NodeType.get((int) selectedLabel.getUserData());
logger.info("selected node type: {}", selectedNodeType); logger.info("selected node type: {}", selectedNodeType);
setSelectedEditButton(nodesButton); setSelectedEditButton(nodesButton);
devicesList.getSelectionModel().clearSelection(); devicesList.getSelectionModel().clearSelection();
controller.getNetworkGraph().setNodeType(selectedNodeType); controller.getNetworkGraph().setNodeType(selectedNodeType);
logger.info("node selected: {} - type: {}", current, selectedNodeType); logger.info("node selected: {} - type: {}", selectedLabel, selectedNodeType);
setEditMode();
}); });
JFXPopup popup = new JFXPopup(nodesList); JFXPopup popup = new JFXPopup(nodesList);
nodesButton.setOnAction(event -> { nodesButton.setOnAction(event -> popup.show(nodesButton, JFXPopup.PopupVPosition.TOP,
setEditMode(); JFXPopup.PopupHPosition.LEFT, nodesButton.getWidth(), 0));
popup.show(nodesButton, JFXPopup.PopupVPosition.TOP,
JFXPopup.PopupHPosition.LEFT, nodesButton.getWidth(), 0);
});
} }
private void setupDevicesButton() { private void setupDevicesButton() {
devicesButton.setTooltip(new Tooltip("Device Nodes (WLAN, EMANE, Switch, etc)")); devicesButton.setTooltip(new Tooltip("Device Nodes (WLAN, EMANE, Switch, etc)"));
devicesList.getSelectionModel().selectedItemProperty().addListener((ov, old, current) -> { devicesList.setOnMouseClicked(event -> {
if (current == null) { Label selectedLabel = devicesList.getSelectionModel().getSelectedItem();
if (selectedLabel == null) {
return; return;
} }
updateButtonValues(devicesButton, current); updateButtonValues(devicesButton, selectedLabel);
selectedNodeType = NodeType.get((int) current.getUserData()); selectedNodeType = NodeType.get((int) selectedLabel.getUserData());
logger.info("selected node type: {}", selectedNodeType); logger.info("selected node type: {}", selectedNodeType);
controller.getNetworkGraph().setNodeType(selectedNodeType); controller.getNetworkGraph().setNodeType(selectedNodeType);
setSelectedEditButton(devicesButton); setSelectedEditButton(devicesButton);
nodesList.getSelectionModel().clearSelection(); nodesList.getSelectionModel().clearSelection();
logger.info("device selected: {} - type: {}", current, selectedNodeType); logger.info("device selected: {} - type: {}", selectedLabel, selectedNodeType);
setEditMode();
}); });
JFXPopup popup = new JFXPopup(devicesList); JFXPopup popup = new JFXPopup(devicesList);
devicesButton.setOnAction(event -> { devicesButton.setOnAction(event -> popup.show(devicesButton, JFXPopup.PopupVPosition.TOP,
setEditMode(); JFXPopup.PopupHPosition.LEFT, devicesButton.getWidth(), 0));
popup.show(devicesButton, JFXPopup.PopupVPosition.TOP,
JFXPopup.PopupHPosition.LEFT, devicesButton.getWidth(), 0);
});
} }
@FXML @FXML

View file

@ -15,6 +15,8 @@ import org.apache.logging.log4j.Logger;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class SessionsDialog extends StageDialog { public class SessionsDialog extends StageDialog {
@ -23,47 +25,98 @@ public class SessionsDialog extends StageDialog {
@FXML private TableColumn<SessionRow, Integer> sessionIdColumn; @FXML private TableColumn<SessionRow, Integer> sessionIdColumn;
@FXML private TableColumn<SessionRow, String> stateColumn; @FXML private TableColumn<SessionRow, String> stateColumn;
@FXML private TableColumn<SessionRow, Integer> nodeCountColumn; @FXML private TableColumn<SessionRow, Integer> nodeCountColumn;
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
private final JFXButton joinButton;
private final JFXButton deleteButton;
public SessionsDialog(Controller controller) { public SessionsDialog(Controller controller) {
super(controller, "/fxml/sessions_dialog.fxml"); super(controller, "/fxml/sessions_dialog.fxml");
setTitle("Sessions"); setTitle("Sessions");
// add dialog buttons
addCreateButton();
deleteButton = createDeleteButton();
joinButton = createJoinButton();
addCancelButton();
// update table cell factories
sessionIdColumn.setCellValueFactory(new PropertyValueFactory<>("id"));
stateColumn.setCellValueFactory(new PropertyValueFactory<>("state"));
nodeCountColumn.setCellValueFactory(new PropertyValueFactory<>("nodes"));
// handle table row selection
sessionsTable.getSelectionModel().selectedItemProperty().addListener((ov, prev, current) -> {
if (current != null) {
boolean isCurrentSession = current.getId().equals(controller.getCoreClient().currentSession());
deleteButton.setDisable(isCurrentSession);
joinButton.setDisable(isCurrentSession);
} else {
deleteButton.setDisable(true);
joinButton.setDisable(true);
}
});
}
private void addCreateButton() {
JFXButton createButton = createButton("New"); JFXButton createButton = createButton("New");
createButton.setOnAction(event -> { createButton.setOnAction(event -> {
close(); logger.info("creating new session");
new Thread(() -> { executorService.submit(() -> {
try { try {
SessionOverview sessionOverview = getCoreClient().createSession(); SessionOverview sessionOverview = getCoreClient().createSession();
controller.joinSession(sessionOverview.getId()); getController().joinSession(sessionOverview.getId());
Toast.success(String.format("Created Session %s", sessionOverview.getId())); Toast.success(String.format("Created Session %s", sessionOverview.getId()));
} catch (IOException ex) { } catch (IOException ex) {
Toast.error("Error creating new session", ex); Toast.error("Error creating new session", ex);
} }
}).start();
}); });
JFXButton joinButton = createButton("Join");
joinButton.setOnAction(event -> {
SessionRow row = sessionsTable.getSelectionModel().getSelectedItem();
logger.info("selected session: {}", row);
try {
controller.joinSession(row.getId());
Toast.info(String.format("Joined Session %s", row.getId()));
} catch (IOException ex) {
Toast.error(String.format("Error joining session: %s", row.getId()), ex);
}
close(); close();
}); });
joinButton.setDisable(true); }
addCancelButton();
sessionIdColumn.setCellValueFactory(new PropertyValueFactory<>("id")); private JFXButton createJoinButton() {
stateColumn.setCellValueFactory(new PropertyValueFactory<>("state")); JFXButton button = createButton("Join");
nodeCountColumn.setCellValueFactory(new PropertyValueFactory<>("nodes")); button.setDisable(true);
sessionsTable.getSelectionModel().selectedItemProperty().addListener((ov, prev, current) -> { button.setOnAction(event -> {
joinButton.setDisable(current == null); SessionRow row = sessionsTable.getSelectionModel().getSelectedItem();
Integer sessionId = row.getId();
logger.info("joining session: {}", sessionId);
executorService.submit(() -> {
try {
getController().joinSession(sessionId);
Toast.info(String.format("Joined Session %s", sessionId));
} catch (IOException ex) {
Toast.error(String.format("Error joining session: %s", sessionId), ex);
}
}); });
close();
});
return button;
}
private JFXButton createDeleteButton() {
JFXButton button = createButton("Delete");
button.setDisable(true);
button.setOnAction(event -> {
SessionRow row = sessionsTable.getSelectionModel().getSelectedItem();
Integer sessionId = row.getId();
logger.info("deleting session: {}", sessionId);
executorService.submit(() -> {
try {
boolean result = getCoreClient().deleteSession(sessionId);
if (result) {
sessionsTable.getItems().remove(row);
sessionsTable.getSelectionModel().clearSelection();
Toast.info(String.format("Deleted Session %s", sessionId));
} else {
Toast.error(String.format("Failure to delete session %s", sessionId));
}
} catch (IOException ex) {
Toast.error(String.format("Error deleting session: %s", sessionId), ex);
}
});
});
return button;
} }
@Data @Data
@ -72,7 +125,7 @@ public class SessionsDialog extends StageDialog {
private String state; private String state;
private Integer nodes; private Integer nodes;
public SessionRow(SessionOverview sessionOverview) { SessionRow(SessionOverview sessionOverview) {
id = sessionOverview.getId(); id = sessionOverview.getId();
state = SessionState.get(sessionOverview.getState()).name(); state = SessionState.get(sessionOverview.getState()).name();
nodes = sessionOverview.getNodes(); nodes = sessionOverview.getNodes();
@ -80,12 +133,15 @@ public class SessionsDialog extends StageDialog {
} }
public void showDialog() throws IOException { public void showDialog() throws IOException {
sessionsTable.getItems().clear();
List<SessionOverview> sessions = getCoreClient().getSessions(); List<SessionOverview> sessions = getCoreClient().getSessions();
sessionsTable.getItems().addAll(sessions.stream() List<SessionRow> rows = sessions.stream().map(SessionRow::new).collect(Collectors.toList());
.map(SessionRow::new) sessionsTable.getItems().setAll(rows);
.collect(Collectors.toList()));
show(); show();
} }
@Override
public void close() {
sessionsTable.getSelectionModel().clearSelection();
super.close();
}
} }

View file

@ -12,7 +12,7 @@
} }
.details-label { .details-label {
-fx-background-color: slategrey; -fx-background-color: black;
-fx-pref-width: Infinity; -fx-pref-width: Infinity;
-fx-text-fill: white; -fx-text-fill: white;
-fx-alignment: center; -fx-alignment: center;