use of org.phoebus.ui.docking.DockStage in project phoebus by ControlSystemStudio.
the class PhoebusApplication method restoreState.
/**
* Restore stages from memento
*
* @return <code>true</code> if any tab was restored
*/
private boolean restoreState(final MementoTree memento) {
boolean any = false;
if (memento == null)
return any;
// There should be just one, empty stage
final List<Stage> stages = DockStage.getDockStages();
if (stages.size() > 1 || stages.stream().map(DockStage::getDockPanes).count() > 1) {
// More than one stage, or a stage with more than one pane
logger.log(Level.WARNING, "Expected single, empty stage for restoring state", new Exception("Stack Trace"));
final StringBuilder buf = new StringBuilder();
buf.append("Found:\n");
for (Stage stage : stages) DockStage.dump(buf, stage);
logger.log(Level.WARNING, buf.toString());
}
try {
// Global settings
memento.getString(LAST_OPENED_FILE).ifPresent(path -> last_opened_file = new File(path));
memento.getString(DEFAULT_APPLICATION).ifPresent(app -> default_application = app);
memento.getBoolean(SHOW_TABS).ifPresent(show -> {
DockPane.alwaysShowTabs(show);
show_tabs.setSelected(show);
});
memento.getBoolean(SHOW_MENU).ifPresent(this::showMenu);
memento.getBoolean(SHOW_TOOLBAR).ifPresent(show -> {
showToolbar(show);
show_toolbar.setSelected(show);
});
memento.getBoolean(SHOW_STATUSBAR).ifPresent(show -> {
showStatusbar(show);
show_statusbar.setSelected(show);
});
// Settings for each stage
for (MementoTree stage_memento : memento.getChildren()) {
final String id = stage_memento.getName();
Stage stage = DockStage.getDockStageByID(id);
if (stage == null) {
// Create new Stage with that ID
stage = new Stage();
DockStage.configureStage(stage);
stage.getProperties().put(DockStage.KEY_ID, id);
stage.show();
}
any |= MementoHelper.restoreStage(stage_memento, stage);
}
} catch (Throwable ex) {
logger.log(Level.WARNING, "Error restoring saved state", ex);
}
return any;
}
Aggregations