Search in sources :

Example 1 with SplitDock

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;
}
Also used : DockPane(org.phoebus.ui.docking.DockPane) Node(javafx.scene.Node) SplitDock(org.phoebus.ui.docking.SplitDock) ArrayList(java.util.ArrayList) List(java.util.List) DockItem(org.phoebus.ui.docking.DockItem)

Example 2 with SplitDock

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);
}
Also used : DockPane(org.phoebus.ui.docking.DockPane) MementoTree(org.phoebus.framework.persistence.MementoTree) XMLMementoTree(org.phoebus.framework.persistence.XMLMementoTree) Node(javafx.scene.Node) SplitDock(org.phoebus.ui.docking.SplitDock) DockItem(org.phoebus.ui.docking.DockItem)

Example 3 with SplitDock

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;
}
Also used : ApplicationService(org.phoebus.framework.workbench.ApplicationService) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) URI(java.net.URI) DockPane(org.phoebus.ui.docking.DockPane) PhoebusApplication.logger(org.phoebus.ui.application.PhoebusApplication.logger) DockItemWithInput(org.phoebus.ui.docking.DockItemWithInput) UpdateThrottle(org.phoebus.ui.javafx.UpdateThrottle) Rectangle2D(javafx.geometry.Rectangle2D) PhoebusApplication(org.phoebus.ui.application.PhoebusApplication) DockStage(org.phoebus.ui.docking.DockStage) MementoTree(org.phoebus.framework.persistence.MementoTree) AppInstance(org.phoebus.framework.spi.AppInstance) Node(javafx.scene.Node) FileOutputStream(java.io.FileOutputStream) AppDescriptor(org.phoebus.framework.spi.AppDescriptor) DockItem(org.phoebus.ui.docking.DockItem) Screen(javafx.stage.Screen) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Platform(javafx.application.Platform) SplitDock(org.phoebus.ui.docking.SplitDock) List(java.util.List) XMLMementoTree(org.phoebus.framework.persistence.XMLMementoTree) Stage(javafx.stage.Stage) AppResourceDescriptor(org.phoebus.framework.spi.AppResourceDescriptor) MementoTree(org.phoebus.framework.persistence.MementoTree) XMLMementoTree(org.phoebus.framework.persistence.XMLMementoTree) SplitDock(org.phoebus.ui.docking.SplitDock) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Node (javafx.scene.Node)3 DockItem (org.phoebus.ui.docking.DockItem)3 DockPane (org.phoebus.ui.docking.DockPane)3 SplitDock (org.phoebus.ui.docking.SplitDock)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 MementoTree (org.phoebus.framework.persistence.MementoTree)2 XMLMementoTree (org.phoebus.framework.persistence.XMLMementoTree)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 URI (java.net.URI)1 TimeUnit (java.util.concurrent.TimeUnit)1 Level (java.util.logging.Level)1 Platform (javafx.application.Platform)1 Rectangle2D (javafx.geometry.Rectangle2D)1 Screen (javafx.stage.Screen)1 Stage (javafx.stage.Stage)1 AppDescriptor (org.phoebus.framework.spi.AppDescriptor)1 AppInstance (org.phoebus.framework.spi.AppInstance)1 AppResourceDescriptor (org.phoebus.framework.spi.AppResourceDescriptor)1