use of org.phoebus.ui.docking.SplitDock in project phoebus by ControlSystemStudio.
the class MementoHelper method closePaneOrSplit.
/**
* Close a DockPane or SplitDock and all tabs held within.
*
* <p>Dock items must have been prepared to close.
*
* @param node Node, either a dock item or split pane, that will be closed.
* @return boolean <code>true</code> if all the tabs close successfully.
*/
public static boolean closePaneOrSplit(final Node node) {
if (node instanceof DockPane) {
// Close every dock item in the dock pane.
final DockPane pane = (DockPane) node;
final List<DockItem> items = pane.getDockItems();
for (final DockItem item : items) item.close();
} else if (node instanceof SplitDock) {
final SplitDock split = (SplitDock) node;
// We are altering the size of the list we are iterating over...
final List<Node> items = new ArrayList<>(split.getItems());
// If a node fails to close, return false.
for (Node item : items) if (!closePaneOrSplit(item))
return false;
// and thus not triggering a merge..
if (split.getItems().size() > 0)
split.merge();
} else {
logger.log(Level.WARNING, "Cannot close " + node);
return false;
}
return true;
}
use of org.phoebus.ui.docking.SplitDock in project phoebus by ControlSystemStudio.
the class MementoHelper method savePaneOrSplit.
/**
* @param memento
* @param item DockPane or SplitDock
*/
private static void savePaneOrSplit(final MementoTree memento, final Node node) {
if (node instanceof DockPane) {
final DockPane pane = (DockPane) node;
final MementoTree pane_memento = memento.createChild(PANE);
if (pane.isFixed())
pane_memento.setBoolean(FIXED, true);
if (pane.getName().length() > 0)
pane_memento.setString(NAME, pane.getName());
pane_memento.setNumber(SELECTED, pane.getSelectionModel().getSelectedIndex());
for (DockItem item : pane.getDockItems()) saveDockItem(pane_memento, item);
} else if (node instanceof SplitDock) {
final SplitDock split = (SplitDock) node;
final MementoTree split_memento = memento.createChild(SPLIT);
split_memento.setNumber(POS, split.getDividerPosition());
if (!split.isHorizontal())
split_memento.setBoolean(HORIZONTAL, false);
for (Node sub : split.getItems()) savePaneOrSplit(split_memento, sub);
} else
logger.log(Level.WARNING, "Cannot persist " + node);
}
use of org.phoebus.ui.docking.SplitDock in project phoebus by ControlSystemStudio.
the class MementoHelper method restorePaneOrSplit.
/**
* @param pane Initial, empty pane that might be filled with items or split
* @param children
* @return <code>true</code> if any tab item was restored
*/
private static boolean restorePaneOrSplit(final DockPane pane, final MementoTree content) {
boolean any = false;
if (content.getName().equals(PANE)) {
// Fill given pane with tabs
for (MementoTree item_memento : content.getChildren()) any |= restoreDockItem(item_memento, pane);
// Maybe select a specific tab
// If the new tab is inside a SplitDock,
// it won't actually exist until the content of the SplitDock's SplitPane
// is rendered on the next UI tick, resulting in a NullPointerException
// deep inside JFX calling TabPane$TabPaneSelectionModel.select
// By deferring to a later UI tick, the tab selection succeeds
content.getNumber(SELECTED).ifPresent(index -> Platform.runLater(() -> {
// so check once more
if (index.intValue() < pane.getTabs().size())
pane.getSelectionModel().select(index.intValue());
}));
content.getString(NAME).ifPresent(pane::setName);
// If pane is 'fixed', mark as such _after_ all items have been restored
// to prevent changes from now on
content.getBoolean(FIXED).ifPresent(fixed -> {
// then wait another tick
if (fixed)
Platform.runLater(() -> pane.deferUntilInScene(scene -> Platform.runLater(() -> pane.setFixed(true))));
});
} else if (content.getName().equals(SPLIT)) {
// Split the original pane
final SplitDock split = pane.split(content.getBoolean(HORIZONTAL).orElse(true));
// Fill split's items
final List<Node> first_second_pane = split.getItems();
final List<MementoTree> first_second_mememto = content.getChildren();
any |= restorePaneOrSplit((DockPane) first_second_pane.get(0), first_second_mememto.get(0));
any |= restorePaneOrSplit((DockPane) first_second_pane.get(1), first_second_mememto.get(1));
// The divider position needs to be set at the end, after the complete scene has been restored.
// Otherwise the SplitPane self-adjusts the position when the sub-elements are rendered,
// replacing a position set now.
content.getNumber(POS).ifPresent(num -> {
UpdateThrottle.TIMER.schedule(() -> Platform.runLater(() -> split.setDividerPosition(num.doubleValue())), 300, TimeUnit.MILLISECONDS);
});
} else
logger.log(Level.WARNING, "Expect <pane> or <split>, got " + content);
return any;
}
Aggregations