corefx - added session create to sessions dialog

This commit is contained in:
Blake J. Harnden 2018-11-29 13:36:01 -08:00
parent 6f0e22cc28
commit 77e8006570
3 changed files with 27 additions and 10 deletions

View file

@ -128,7 +128,7 @@ public class Controller implements Initializable {
nodeEmaneDialog.setModels(emaneModels);
}
public void joinSession(Integer joinId) throws IOException {
public void joinSession(Integer sessionId) throws IOException {
// clear graph
networkGraph.reset();
@ -137,15 +137,15 @@ public class Controller implements Initializable {
mobilityDialog.setNode(null);
// get session to join
Session session = coreClient.getSession(joinId);
Session session = coreClient.getSession(sessionId);
SessionState sessionState = SessionState.get(session.getState());
// update client to use this session
coreClient.updateSession(joinId);
coreClient.updateSession(sessionId);
coreClient.updateState(sessionState);
// display all nodes
logger.info("joining core session({}) state({}): {}", joinId, sessionState, session);
logger.info("joining core session({}) state({}): {}", sessionId, sessionState, session);
for (CoreNode node : session.getNodes()) {
NodeType nodeType = NodeType.find(node.getType(), node.getModel());
if (nodeType == null) {
@ -370,12 +370,12 @@ public class Controller implements Initializable {
}
@FXML
private void onJoinSessionMenu(ActionEvent event) {
logger.info("join sessions menu clicked!");
private void onSessionMenu(ActionEvent event) {
logger.info("sessions menu clicked");
try {
sessionsDialog.showDialog();
} catch (IOException ex) {
logger.error("error getting session dialog", ex);
Toast.error("Error retrieving sessions", ex);
}
}

View file

@ -29,24 +29,41 @@ public class SessionsDialog extends StageDialog {
setTitle("Sessions");
JFXButton createButton = createButton("New");
createButton.setOnAction(event -> {
close();
new Thread(() -> {
try {
SessionOverview sessionOverview = getCoreClient().createSession();
controller.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 {
getController().joinSession(row.getId());
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);
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);
});
}
@Data

View file

@ -27,13 +27,13 @@
<MenuItem mnemonicParsing="false" onAction="#onOpenXmlAction" text="Open XML" />
</items>
</Menu>
<MenuItem mnemonicParsing="false" onAction="#onSessionMenu" text="Sessions" />
<MenuItem mnemonicParsing="false" onAction="#onOptionsMenuNodeTypes" text="Nodes" />
<MenuItem mnemonicParsing="false" onAction="#onOptionsMenuPreferences" text="Preferences" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Session">
<items>
<MenuItem mnemonicParsing="false" onAction="#onJoinSessionMenu" text="Join" />
<MenuItem mnemonicParsing="false" onAction="#onSessionHooksMenu" text="Hooks" />
<MenuItem mnemonicParsing="false" onAction="#onOptionsMenuLocation" text="Location" />
<MenuItem mnemonicParsing="false" onAction="#onOptionsMenuBackground" text="Background" />