Search in sources :

Example 1 with DockItem

use of org.phoebus.ui.docking.DockItem in project phoebus by ControlSystemStudio.

the class PhoebusApplication method createMenu.

private MenuBar createMenu(final Stage stage) {
    final MenuBar menuBar = new MenuBar();
    // For Mac OS X, use it's menu bar on top of screen
    if (PlatformInfo.is_mac_os_x)
        menuBar.setUseSystemMenuBar(true);
    // File
    final MenuItem open = new MenuItem(Messages.Open, ImageCache.getImageView(getClass(), "/icons/fldr_obj.png"));
    open.setOnAction(event -> fileOpen(stage, false));
    final MenuItem open_with = new MenuItem(Messages.OpenWith, ImageCache.getImageView(getClass(), "/icons/fldr_obj.png"));
    open_with.setOnAction(event -> fileOpen(stage, true));
    top_resources_menu = new Menu(Messages.TopResources, ImageCache.getImageView(getClass(), "/icons/fldr_obj.png"));
    top_resources_menu.setDisable(true);
    final MenuItem file_save = new MenuItem(Messages.Save, ImageCache.getImageView(getClass(), "/icons/save_edit.png"));
    file_save.setOnAction(event -> JobManager.schedule(Messages.Save, monitor -> active_item_with_input.get().save(monitor)));
    final MenuItem file_save_as = new MenuItem(Messages.SaveAs, ImageCache.getImageView(getClass(), "/icons/saveas_edit.png"));
    file_save_as.setOnAction(event -> JobManager.schedule(Messages.SaveAs, monitor -> active_item_with_input.get().save_as(monitor)));
    final MenuItem exit = new MenuItem(Messages.Exit);
    exit.setOnAction(event -> closeMainStage());
    final Menu file = new Menu(Messages.File, null, open, open_with, top_resources_menu, new SeparatorMenuItem(), file_save, file_save_as, new SeparatorMenuItem(), exit);
    file.setOnShowing(event -> {
        final DockItemWithInput input_item = active_item_with_input.get();
        if (input_item == null) {
            file_save.setDisable(true);
            file_save_as.setDisable(true);
        } else {
            file_save.setDisable(!input_item.isDirty());
            file_save_as.setDisable(!input_item.isSaveAsSupported());
        }
    });
    menuBar.getMenus().add(file);
    // Application Contributions
    final Menu applicationsMenu = new Menu(Messages.Applications);
    final MenuTreeNode node = MenuEntryService.getInstance().getMenuEntriesTree();
    addMenuNode(applicationsMenu, node);
    menuBar.getMenus().add(applicationsMenu);
    // Window
    show_tabs = new CheckMenuItem(Messages.AlwaysShowTabs);
    show_tabs.setSelected(DockPane.isAlwaysShowingTabs());
    show_tabs.setOnAction(event -> DockPane.alwaysShowTabs(show_tabs.isSelected()));
    show_toolbar = new CheckMenuItem(Messages.ShowToolbar);
    show_toolbar.setOnAction(event -> showToolbar(show_toolbar.isSelected()));
    show_statusbar = new CheckMenuItem(Messages.ShowStatusbar);
    show_statusbar.setOnAction(event -> showStatusbar(show_statusbar.isSelected()));
    save_layout = new SaveLayoutMenuItem(this, memento_files);
    delete_layouts = new DeleteLayoutsMenuItem(this, memento_files);
    final Menu menu = new Menu(Messages.Window, null, show_tabs, show_toolbar, show_statusbar, new SeparatorMenuItem(), selectTabMenu, closeAllTabsMenuItem, new SeparatorMenuItem(), save_layout, load_layout, delete_layouts, new SeparatorMenuItem(), /* Full Screen placeholder */
    new FullScreenAction(stage));
    // Update Full screen action when shown to get correct enter/exit FS mode
    menu.setOnShowing(event -> {
        // Last menu item
        final int full_screen_index = menu.getItems().size() - 1;
        final FullScreenAction full_screen = new FullScreenAction(stage);
        if (!AuthorizationService.hasAuthorization("full_screen"))
            full_screen.setDisable(true);
        menu.getItems().set(full_screen_index, full_screen);
    });
    menuBar.getMenus().add(menu);
    // Help
    final MenuItem content = createMenuItem(new OpenHelp());
    final MenuItem about = createMenuItem(new OpenAbout());
    menuBar.getMenus().add(new Menu(Messages.Help, null, about, content));
    selectTabMenu.getParentMenu().setOnShowing(e -> {
        List<MenuItem> menuItems = new ArrayList<>();
        for (Stage s : DockStage.getDockStages()) {
            for (DockPane dockPane : DockStage.getDockPanes(s)) {
                for (DockItem dockItem : dockPane.getDockItems()) {
                    CheckMenuItem menuItem = new CheckMenuItem(dockItem.getLabel());
                    menuItem.setSelected(dockItem.isSelected());
                    menuItem.setOnAction(ae -> dockItem.select());
                    menuItems.add(menuItem);
                }
            }
        }
        menuItems.sort(Comparator.comparing(MenuItem::getText));
        selectTabMenu.getItems().clear();
        selectTabMenu.getItems().addAll(menuItems);
    });
    closeAllTabsMenuItem.setOnAction(ae -> closeAllTabs());
    return menuBar;
}
Also used : Button(javafx.scene.control.Button) JobManager(org.phoebus.framework.jobs.JobManager) Arrays(java.util.Arrays) CheckMenuItem(javafx.scene.control.CheckMenuItem) DockPaneListener(org.phoebus.ui.docking.DockPaneListener) VBox(javafx.scene.layout.VBox) KeyCombination(javafx.scene.input.KeyCombination) Preferences(org.phoebus.ui.Preferences) Application(javafx.application.Application) FullScreenAction(org.phoebus.ui.javafx.FullScreenAction) MenuTreeNode(org.phoebus.ui.application.MenuEntryService.MenuTreeNode) AlertType(javafx.scene.control.Alert.AlertType) Map(java.util.Map) DockPane(org.phoebus.ui.docking.DockPane) URI(java.net.URI) Alert(javafx.scene.control.Alert) MenuEntry(org.phoebus.ui.spi.MenuEntry) ImageCache(org.phoebus.ui.javafx.ImageCache) ResponsivenessMonitor(org.phoebus.ui.monitoring.ResponsivenessMonitor) MenuItem(javafx.scene.control.MenuItem) OpenHelp(org.phoebus.ui.help.OpenHelp) Collection(java.util.Collection) AppDescriptor(org.phoebus.framework.spi.AppDescriptor) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Platform(javafx.application.Platform) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) List(java.util.List) SubJobMonitor(org.phoebus.framework.jobs.SubJobMonitor) MenuButton(javafx.scene.control.MenuButton) AppResourceDescriptor(org.phoebus.framework.spi.AppResourceDescriptor) Optional(java.util.Optional) BorderPane(javafx.scene.layout.BorderPane) Welcome(org.phoebus.ui.welcome.Welcome) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) DialogHelper(org.phoebus.ui.dialog.DialogHelper) ButtonType(javafx.scene.control.ButtonType) MouseEvent(javafx.scene.input.MouseEvent) JobMonitor(org.phoebus.framework.jobs.JobMonitor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AuthorizationService(org.phoebus.security.authorization.AuthorizationService) ApplicationService(org.phoebus.framework.workbench.ApplicationService) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) StatusBar(org.phoebus.ui.statusbar.StatusBar) ResourceParser(org.phoebus.framework.util.ResourceParser) OpenFileDialog(org.phoebus.ui.dialog.OpenFileDialog) WeakReference(java.lang.ref.WeakReference) Tooltip(javafx.scene.control.Tooltip) DockItemWithInput(org.phoebus.ui.docking.DockItemWithInput) MementoHelper(org.phoebus.ui.internal.MementoHelper) KeyCode(javafx.scene.input.KeyCode) ListPickerDialog(org.phoebus.ui.dialog.ListPickerDialog) Dialog(javafx.scene.control.Dialog) MenuBar(javafx.scene.control.MenuBar) PlatformInfo(org.phoebus.ui.javafx.PlatformInfo) Iterator(java.util.Iterator) ToolBar(javafx.scene.control.ToolBar) DockStage(org.phoebus.ui.docking.DockStage) Node(javafx.scene.Node) MementoTree(org.phoebus.framework.persistence.MementoTree) DockItem(org.phoebus.ui.docking.DockItem) OpenAbout(org.phoebus.ui.help.OpenAbout) FileInputStream(java.io.FileInputStream) File(java.io.File) Menu(javafx.scene.control.Menu) KeyCodeCombination(javafx.scene.input.KeyCodeCombination) TimeUnit(java.util.concurrent.TimeUnit) ActionEvent(javafx.event.ActionEvent) Stage(javafx.stage.Stage) XMLMementoTree(org.phoebus.framework.persistence.XMLMementoTree) ImageView(javafx.scene.image.ImageView) Window(javafx.stage.Window) Locations(org.phoebus.framework.workbench.Locations) Comparator(java.util.Comparator) Image(javafx.scene.image.Image) DockPane(org.phoebus.ui.docking.DockPane) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) MenuBar(javafx.scene.control.MenuBar) FullScreenAction(org.phoebus.ui.javafx.FullScreenAction) CheckMenuItem(javafx.scene.control.CheckMenuItem) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) MenuTreeNode(org.phoebus.ui.application.MenuEntryService.MenuTreeNode) OpenHelp(org.phoebus.ui.help.OpenHelp) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) OpenAbout(org.phoebus.ui.help.OpenAbout) CheckMenuItem(javafx.scene.control.CheckMenuItem) DockItemWithInput(org.phoebus.ui.docking.DockItemWithInput) DockStage(org.phoebus.ui.docking.DockStage) Stage(javafx.stage.Stage) Menu(javafx.scene.control.Menu) DockItem(org.phoebus.ui.docking.DockItem)

Example 2 with DockItem

use of org.phoebus.ui.docking.DockItem in project phoebus by ControlSystemStudio.

the class Probe method create.

@Override
public AppInstance create() {
    ProbeInstance probeInstance = new ProbeInstance(this);
    final DockItem tab = new DockItem(probeInstance, probeInstance.create());
    // Clear PV when tab is closed
    tab.addClosedNotification(() -> probeInstance.setPV(""));
    DockPane.getActiveDockPane().addTab(tab);
    PVAutocompleteMenu.INSTANCE.attachField(probeInstance.getPVField());
    return probeInstance;
}
Also used : DockItem(org.phoebus.ui.docking.DockItem)

Example 3 with DockItem

use of org.phoebus.ui.docking.DockItem in project phoebus by ControlSystemStudio.

the class PVTreeApplication method create.

@Override
public PVTree create() {
    final PVTree pv_tree = new PVTree(this);
    final DockItem tab = new DockItem(pv_tree, pv_tree.create());
    tab.addClosedNotification(() -> pv_tree.dispose());
    DockPane.getActiveDockPane().addTab(tab);
    return pv_tree;
}
Also used : DockItem(org.phoebus.ui.docking.DockItem)

Example 4 with DockItem

use of org.phoebus.ui.docking.DockItem 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 5 with DockItem

use of org.phoebus.ui.docking.DockItem 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)

Aggregations

DockItem (org.phoebus.ui.docking.DockItem)5 Node (javafx.scene.Node)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 DockPane (org.phoebus.ui.docking.DockPane)2 SplitDock (org.phoebus.ui.docking.SplitDock)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 WeakReference (java.lang.ref.WeakReference)1 URI (java.net.URI)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Optional (java.util.Optional)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1