Merge branch 'rel/5.3' of git-ssh.web.boeing.com:Boeing-CORE/CORE into rel/5.3
This commit is contained in:
		
						commit
						080a03c8be
					
				
					 6 changed files with 122 additions and 52 deletions
				
			
		|  | @ -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 { | ||||
|  |  | |||
|  | @ -14,12 +14,16 @@ import java.util.Set; | |||
| public interface ICoreClient { | ||||
|     void setUrl(String url); | ||||
| 
 | ||||
|     Integer currentSession(); | ||||
| 
 | ||||
|     void updateSession(Integer sessionId); | ||||
| 
 | ||||
|     void updateState(SessionState state); | ||||
| 
 | ||||
|     SessionOverview createSession() throws IOException; | ||||
| 
 | ||||
|     boolean deleteSession(Integer sessionId) throws IOException; | ||||
| 
 | ||||
|     List<SessionOverview> getSessions() throws IOException; | ||||
| 
 | ||||
|     Session getSession(Integer sessionId) throws IOException; | ||||
|  |  | |||
|  | @ -23,6 +23,11 @@ public class CoreRestClient implements ICoreClient { | |||
|         this.baseUrl = url; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public Integer currentSession() { | ||||
|         return sessionId; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void updateState(SessionState state) { | ||||
|         sessionState = state; | ||||
|  | @ -43,6 +48,13 @@ public class CoreRestClient implements ICoreClient { | |||
|         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 { | ||||
|         String url = getUrl("services"); | ||||
|         GetServices getServices = WebUtils.getJson(url, GetServices.class); | ||||
|  |  | |||
|  | @ -168,50 +168,48 @@ 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) { | ||||
|         nodesList.setOnMouseClicked(event -> { | ||||
|             Label selectedLabel = nodesList.getSelectionModel().getSelectedItem(); | ||||
|             if (selectedLabel == null) { | ||||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             updateButtonValues(nodesButton, current); | ||||
|             selectedNodeType = NodeType.get((int) current.getUserData()); | ||||
|             updateButtonValues(nodesButton, selectedLabel); | ||||
|             selectedNodeType = NodeType.get((int) selectedLabel.getUserData()); | ||||
|             logger.info("selected node type: {}", selectedNodeType); | ||||
|             setSelectedEditButton(nodesButton); | ||||
|             devicesList.getSelectionModel().clearSelection(); | ||||
|             controller.getNetworkGraph().setNodeType(selectedNodeType); | ||||
|             logger.info("node selected: {} - type: {}", current, selectedNodeType); | ||||
|             logger.info("node selected: {} - type: {}", selectedLabel, selectedNodeType); | ||||
|             setEditMode(); | ||||
|         }); | ||||
| 
 | ||||
|         JFXPopup popup = new JFXPopup(nodesList); | ||||
|         nodesButton.setOnAction(event -> { | ||||
|             setEditMode(); | ||||
|             popup.show(nodesButton, JFXPopup.PopupVPosition.TOP, | ||||
|                     JFXPopup.PopupHPosition.LEFT, nodesButton.getWidth(), 0); | ||||
|         }); | ||||
|         nodesButton.setOnAction(event -> popup.show(nodesButton, JFXPopup.PopupVPosition.TOP, | ||||
|                 JFXPopup.PopupHPosition.LEFT, nodesButton.getWidth(), 0)); | ||||
|     } | ||||
| 
 | ||||
|     private void setupDevicesButton() { | ||||
|         devicesButton.setTooltip(new Tooltip("Device Nodes (WLAN, EMANE, Switch, etc)")); | ||||
|         devicesList.getSelectionModel().selectedItemProperty().addListener((ov, old, current) -> { | ||||
|             if (current == null) { | ||||
|         devicesList.setOnMouseClicked(event -> { | ||||
|             Label selectedLabel = devicesList.getSelectionModel().getSelectedItem(); | ||||
|             if (selectedLabel == null) { | ||||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             updateButtonValues(devicesButton, current); | ||||
|             selectedNodeType = NodeType.get((int) current.getUserData()); | ||||
|             updateButtonValues(devicesButton, selectedLabel); | ||||
|             selectedNodeType = NodeType.get((int) selectedLabel.getUserData()); | ||||
|             logger.info("selected node type: {}", selectedNodeType); | ||||
|             controller.getNetworkGraph().setNodeType(selectedNodeType); | ||||
|             setSelectedEditButton(devicesButton); | ||||
|             nodesList.getSelectionModel().clearSelection(); | ||||
|             logger.info("device selected: {} - type: {}", current, selectedNodeType); | ||||
|             logger.info("device selected: {} - type: {}", selectedLabel, selectedNodeType); | ||||
|             setEditMode(); | ||||
|         }); | ||||
| 
 | ||||
|         JFXPopup popup = new JFXPopup(devicesList); | ||||
|         devicesButton.setOnAction(event -> { | ||||
|             setEditMode(); | ||||
|             popup.show(devicesButton, JFXPopup.PopupVPosition.TOP, | ||||
|                     JFXPopup.PopupHPosition.LEFT, devicesButton.getWidth(), 0); | ||||
|         }); | ||||
|         devicesButton.setOnAction(event -> popup.show(devicesButton, JFXPopup.PopupVPosition.TOP, | ||||
|                 JFXPopup.PopupHPosition.LEFT, devicesButton.getWidth(), 0)); | ||||
|     } | ||||
| 
 | ||||
|     @FXML | ||||
|  |  | |||
|  | @ -15,6 +15,8 @@ import org.apache.logging.log4j.Logger; | |||
| 
 | ||||
| import java.io.IOException; | ||||
| import java.util.List; | ||||
| import java.util.concurrent.ExecutorService; | ||||
| import java.util.concurrent.Executors; | ||||
| import java.util.stream.Collectors; | ||||
| 
 | ||||
| public class SessionsDialog extends StageDialog { | ||||
|  | @ -23,47 +25,98 @@ public class SessionsDialog extends StageDialog { | |||
|     @FXML private TableColumn<SessionRow, Integer> sessionIdColumn; | ||||
|     @FXML private TableColumn<SessionRow, String> stateColumn; | ||||
|     @FXML private TableColumn<SessionRow, Integer> nodeCountColumn; | ||||
|     private final ExecutorService executorService = Executors.newSingleThreadExecutor(); | ||||
|     private final JFXButton joinButton; | ||||
|     private final JFXButton deleteButton; | ||||
| 
 | ||||
|     public SessionsDialog(Controller controller) { | ||||
|         super(controller, "/fxml/sessions_dialog.fxml"); | ||||
| 
 | ||||
|         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"); | ||||
|         createButton.setOnAction(event -> { | ||||
|             close(); | ||||
|             new Thread(() -> { | ||||
|             logger.info("creating new session"); | ||||
|             executorService.submit(() -> { | ||||
|                 try { | ||||
|                     SessionOverview sessionOverview = getCoreClient().createSession(); | ||||
|                     controller.joinSession(sessionOverview.getId()); | ||||
|                     getController().joinSession(sessionOverview.getId()); | ||||
|                     Toast.success(String.format("Created Session %s", sessionOverview.getId())); | ||||
|                 } catch (IOException 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(); | ||||
|         }); | ||||
|         joinButton.setDisable(true); | ||||
|         addCancelButton(); | ||||
|     } | ||||
| 
 | ||||
|         sessionIdColumn.setCellValueFactory(new PropertyValueFactory<>("id")); | ||||
|         stateColumn.setCellValueFactory(new PropertyValueFactory<>("state")); | ||||
|         nodeCountColumn.setCellValueFactory(new PropertyValueFactory<>("nodes")); | ||||
|         sessionsTable.getSelectionModel().selectedItemProperty().addListener((ov, prev, current) -> { | ||||
|             joinButton.setDisable(current == null); | ||||
|     private JFXButton createJoinButton() { | ||||
|         JFXButton button = createButton("Join"); | ||||
|         button.setDisable(true); | ||||
|         button.setOnAction(event -> { | ||||
|             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 | ||||
|  | @ -72,7 +125,7 @@ public class SessionsDialog extends StageDialog { | |||
|         private String state; | ||||
|         private Integer nodes; | ||||
| 
 | ||||
|         public SessionRow(SessionOverview sessionOverview) { | ||||
|         SessionRow(SessionOverview sessionOverview) { | ||||
|             id = sessionOverview.getId(); | ||||
|             state = SessionState.get(sessionOverview.getState()).name(); | ||||
|             nodes = sessionOverview.getNodes(); | ||||
|  | @ -80,12 +133,15 @@ public class SessionsDialog extends StageDialog { | |||
|     } | ||||
| 
 | ||||
|     public void showDialog() throws IOException { | ||||
|         sessionsTable.getItems().clear(); | ||||
|         List<SessionOverview> sessions = getCoreClient().getSessions(); | ||||
|         sessionsTable.getItems().addAll(sessions.stream() | ||||
|                 .map(SessionRow::new) | ||||
|                 .collect(Collectors.toList())); | ||||
| 
 | ||||
|         List<SessionRow> rows = sessions.stream().map(SessionRow::new).collect(Collectors.toList()); | ||||
|         sessionsTable.getItems().setAll(rows); | ||||
|         show(); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void close() { | ||||
|         sessionsTable.getSelectionModel().clearSelection(); | ||||
|         super.close(); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -12,7 +12,7 @@ | |||
| } | ||||
| 
 | ||||
| .details-label { | ||||
|     -fx-background-color: slategrey; | ||||
|     -fx-background-color: black; | ||||
|     -fx-pref-width: Infinity; | ||||
|     -fx-text-fill: white; | ||||
|     -fx-alignment: center; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue