Search in sources :

Example 1 with IToolBarContributionItem

use of org.eclipse.jface.internal.provisional.action.IToolBarContributionItem in project eclipse.platform.ui by eclipse-platform.

the class WorkbenchActionBuilder method updatePinActionToolbar.

/**
 * Update the pin action's tool bar
 */
void updatePinActionToolbar() {
    ICoolBarManager coolBarManager = getActionBarConfigurer().getCoolBarManager();
    IContributionItem cbItem = coolBarManager.find(IWorkbenchActionConstants.TOOLBAR_NAVIGATE);
    if (!(cbItem instanceof IToolBarContributionItem)) {
        // This should not happen
        IDEWorkbenchPlugin.log(// $NON-NLS-1$
        "Navigation toolbar contribution item is missing");
        return;
    }
    IToolBarContributionItem toolBarItem = (IToolBarContributionItem) cbItem;
    IToolBarManager toolBarManager = toolBarItem.getToolBarManager();
    if (toolBarManager == null) {
        // error if this happens, navigation toolbar assumed to always exist
        // $NON-NLS-1$
        IDEWorkbenchPlugin.log("Navigate toolbar is missing");
        return;
    }
    IPreferenceStore store = WorkbenchPlugin.getDefault().getPreferenceStore();
    boolean reuseEditors = store.getBoolean(IPreferenceConstants.REUSE_EDITORS_BOOLEAN);
    IContributionItem pinItem = toolBarManager.find(IWorkbenchCommandConstants.WINDOW_PIN_EDITOR);
    if (pinItem != null) {
        pinItem.setVisible(reuseEditors);
    }
    toolBarManager.markDirty();
    toolBarManager.update(false);
    toolBarItem.update(ICoolBarManager.SIZE);
    window.getShell().getDisplay().asyncExec(() -> {
        if (window.getShell() != null && !window.getShell().isDisposed()) {
            ICommandService commandService = window.getService(ICommandService.class);
            commandService.refreshElements(IWorkbenchCommandConstants.WINDOW_PIN_EDITOR, null);
        }
    });
}
Also used : IToolBarManager(org.eclipse.jface.action.IToolBarManager) IContributionItem(org.eclipse.jface.action.IContributionItem) IToolBarContributionItem(org.eclipse.jface.internal.provisional.action.IToolBarContributionItem) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) ICommandService(org.eclipse.ui.commands.ICommandService) ICoolBarManager(org.eclipse.jface.action.ICoolBarManager)

Example 2 with IToolBarContributionItem

use of org.eclipse.jface.internal.provisional.action.IToolBarContributionItem in project eclipse.platform.ui by eclipse-platform.

the class CoolBarToTrimManager method add.

private void add(MTrimBar trimBar, int idx, IContributionItem item) {
    // Special check to make sure that new additions are *before* the SPACER
    if (idx == -1) {
        MUIElement spacer = modelService.find(WorkbenchWindow.PERSPECTIVE_SPACER_ID, trimBar);
        if (spacer != null) {
            idx = trimBar.getChildren().indexOf(spacer);
        }
    }
    if (item instanceof IToolBarContributionItem) {
        IToolBarContributionItem tbc = (IToolBarContributionItem) item;
        IToolBarManager mgr = tbc.getToolBarManager();
        if (!(mgr instanceof ToolBarManager)) {
            return;
        }
        ToolBarManager manager = (ToolBarManager) mgr;
        if (renderer.getToolBarModel(manager) != null) {
            return;
        }
        List<MToolBar> toolbars = modelService.findElements(window, item.getId(), MToolBar.class);
        MToolBar toolBar = toolbars.isEmpty() ? null : toolbars.get(0);
        boolean tbFound = toolBar != null;
        if (!tbFound) {
            toolBar = modelService.createModelElement(MToolBar.class);
        } else {
            toolBar.getChildren().clear();
        }
        toolBar.setElementId(item.getId());
        toolBar.getTransientData().put(OBJECT, item);
        String toolbarLabel = getToolbarLabel(application, item.getId());
        if (toolbarLabel != null) {
            // $NON-NLS-1$
            toolBar.getTransientData().put("Name", toolbarLabel);
        }
        renderer.linkModelToManager(toolBar, manager);
        toolBar.setToBeRendered(true);
        if (!tbFound) {
            if (idx < 0) {
                trimBar.getChildren().add(toolBar);
            } else {
                trimBar.getChildren().add(idx, toolBar);
            }
        }
        workbenchTrimElements.add(toolBar);
        manager.setOverrides(toolbarOverrides);
    } else if (item instanceof IContributionManager) {
        throw new IllegalStateException();
    } else if (item instanceof AbstractGroupMarker) {
        if (item.getId() == null) {
            return;
        }
        for (MTrimElement toolBar : topTrim.getChildren()) {
            if (item.getId().equals(toolBar.getElementId()) && toolBar.getTags().contains(TOOLBAR_SEPARATOR)) {
                // already in the coolbar
                return;
            }
        }
        MToolBarSeparator separator = modelService.createModelElement(MToolBarSeparator.class);
        separator.setToBeRendered(false);
        separator.setElementId(item.getId());
        List<MToolBar> toolbars = modelService.findElements(window, item.getId(), MToolBar.class);
        MToolBar toolBar = toolbars.isEmpty() ? null : toolbars.get(0);
        boolean tbFound = toolBar != null;
        if (!tbFound) {
            toolBar = modelService.createModelElement(MToolBar.class);
        } else {
            toolBar.getChildren().clear();
        }
        toolBar.getTransientData().put(OBJECT, item);
        toolBar.getTags().add(TOOLBAR_SEPARATOR);
        toolBar.setElementId(item.getId());
        toolBar.getChildren().add(separator);
        toolBar.setToBeRendered(false);
        if (!tbFound) {
            if (idx < 0) {
                topTrim.getChildren().add(toolBar);
            } else {
                topTrim.getChildren().add(idx, toolBar);
            }
        }
        workbenchTrimElements.add(toolBar);
    }
}
Also used : IToolBarContributionItem(org.eclipse.jface.internal.provisional.action.IToolBarContributionItem) IToolBarManager(org.eclipse.jface.action.IToolBarManager) ToolBarManager(org.eclipse.jface.action.ToolBarManager) MToolBar(org.eclipse.e4.ui.model.application.ui.menu.MToolBar) IToolBarManager(org.eclipse.jface.action.IToolBarManager) MTrimElement(org.eclipse.e4.ui.model.application.ui.basic.MTrimElement) AbstractGroupMarker(org.eclipse.jface.action.AbstractGroupMarker) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) MToolBarSeparator(org.eclipse.e4.ui.model.application.ui.menu.MToolBarSeparator) IContributionManager(org.eclipse.jface.action.IContributionManager)

Example 3 with IToolBarContributionItem

use of org.eclipse.jface.internal.provisional.action.IToolBarContributionItem in project eclipse.platform.ui by eclipse-platform.

the class EditorActionBars method createToolBarContributionItem.

/*
	 * Creates a new tool bar contribution item on the given manager -- using the
	 * stored data to initialize some of its properties.
	 */
IToolBarContributionItem createToolBarContributionItem(final IToolBarManager manager, PlaceholderContributionItem item) {
    IToolBarContributionItem toolBarContributionItem = new ToolBarContributionItem2(manager, item.getId());
    toolBarContributionItem.setCurrentHeight(item.getHeight());
    toolBarContributionItem.setCurrentWidth(item.getWidth());
    toolBarContributionItem.setMinimumItemsToShow(item.getMinimumItemsToShow());
    toolBarContributionItem.setUseChevron(item.getUseChevron());
    return toolBarContributionItem;
}
Also used : ToolBarContributionItem2(org.eclipse.jface.internal.provisional.action.ToolBarContributionItem2) IToolBarContributionItem(org.eclipse.jface.internal.provisional.action.IToolBarContributionItem)

Example 4 with IToolBarContributionItem

use of org.eclipse.jface.internal.provisional.action.IToolBarContributionItem in project eclipse.platform.ui by eclipse-platform.

the class EditorActionBars method getToolBarManager.

/**
 * Returns the tool bar manager. If items are added or removed from the manager
 * be sure to call <code>updateActionBars</code>. Overridden to support
 * CoolBars.
 *
 * @return the tool bar manager
 */
@Override
public IToolBarManager getToolBarManager() {
    // by pass the sub coolBar and use the real cool bar.
    ICoolBarManager coolBarManager = getCastedParent().getCoolBarManager();
    if (coolBarManager == null) {
        return null;
    }
    // otherwise the references to it below will fail
    if (coolBarManager.find(IWorkbenchActionConstants.GROUP_EDITOR) == null) {
        coolBarManager.add(new GroupMarker(IWorkbenchActionConstants.GROUP_EDITOR));
    }
    if (toolBarContributionItem == null) {
        IContributionItem foundItem = coolBarManager.find(type);
        if ((foundItem instanceof IToolBarContributionItem)) {
            toolBarContributionItem = (IToolBarContributionItem) foundItem;
            coolItemToolBarMgr = toolBarContributionItem.getToolBarManager();
            if (coolItemToolBarMgr == null) {
                coolItemToolBarMgr = new ToolBarManager2(SWT.FLAT);
                toolBarContributionItem = new ToolBarContributionItem2(coolItemToolBarMgr, type);
                // Add editor item to group
                coolBarManager.prependToGroup(IWorkbenchActionConstants.GROUP_EDITOR, toolBarContributionItem);
            }
        } else {
            coolItemToolBarMgr = new ToolBarManager2(SWT.FLAT);
            if ((coolBarManager instanceof ContributionManager) && (foundItem instanceof PlaceholderContributionItem)) {
                PlaceholderContributionItem placeholder = (PlaceholderContributionItem) foundItem;
                toolBarContributionItem = createToolBarContributionItem(coolItemToolBarMgr, placeholder);
                // Restore from a placeholder
                ((ContributionManager) coolBarManager).replaceItem(type, toolBarContributionItem);
            } else {
                toolBarContributionItem = new ToolBarContributionItem2(coolItemToolBarMgr, type);
                // Add editor item to group
                coolBarManager.prependToGroup(IWorkbenchActionConstants.GROUP_EDITOR, toolBarContributionItem);
            }
        }
        ((ContributionManager) coolItemToolBarMgr).setOverrides(new Overrides());
        toolBarContributionItem.setVisible(getActive());
        coolItemToolBarMgr.markDirty();
    }
    return coolItemToolBarMgr;
}
Also used : ToolBarManager2(org.eclipse.jface.internal.provisional.action.ToolBarManager2) ToolBarContributionItem2(org.eclipse.jface.internal.provisional.action.ToolBarContributionItem2) IContributionItem(org.eclipse.jface.action.IContributionItem) ContributionManager(org.eclipse.jface.action.ContributionManager) SubContributionManager(org.eclipse.jface.action.SubContributionManager) IContributionManager(org.eclipse.jface.action.IContributionManager) IContributionManagerOverrides(org.eclipse.jface.action.IContributionManagerOverrides) GroupMarker(org.eclipse.jface.action.GroupMarker) IToolBarContributionItem(org.eclipse.jface.internal.provisional.action.IToolBarContributionItem) ICoolBarManager(org.eclipse.jface.action.ICoolBarManager)

Example 5 with IToolBarContributionItem

use of org.eclipse.jface.internal.provisional.action.IToolBarContributionItem in project eclipse.platform.ui by eclipse-platform.

the class ActionSetActionBars method getToolBarManager.

/**
 * Returns the correct tool bar for the given action id. If this action is an
 * adjunct type the it returns the toolbar manager from the cool bar manager.
 *
 * @param actionId the id of the action
 * @return the tool bar manager
 */
public IToolBarManager getToolBarManager(String actionId) {
    // Check if a tool bar manager for an adjunct type is being requested
    String toolBarId = actionSetId;
    boolean isAdjunctType = false;
    if (!actionId.equals(actionSetId)) {
        // Adjunct type
        toolBarId = actionId;
        isAdjunctType = true;
    }
    // Rereive the cool bar manager
    ICoolBarManager coolBarManager = getCastedParent().getCoolBarManager();
    if (coolBarManager == null) {
        return null;
    }
    // and the tool bar being requested is not for an adjunct action
    if ((coolItemToolBarMgr != null) && (!isAdjunctType)) {
        return coolItemToolBarMgr;
    }
    // Search for toolBarId in the cool Bar manager
    IContributionItem cbItem = coolBarManager.find(toolBarId);
    // item
    if (cbItem instanceof IToolBarContributionItem) {
        IToolBarContributionItem tbcbItem = (IToolBarContributionItem) cbItem;
        coolItemToolBarMgr = tbcbItem.getToolBarManager();
        // contribution type
        if (!isAdjunctType) {
            toolBarContributionItem = tbcbItem;
        }
    } else {
        coolItemToolBarMgr = actionBarConfigurer.createToolBarManager();
        // If this is not an adjunct type then create a tool bar
        // contribution item
        // we don't create one for an adjunct type because another action
        // set action bars contains one
        IContributionItem toolBarContributionItem = actionBarConfigurer.createToolBarContributionItem(coolItemToolBarMgr, toolBarId);
        toolBarContributionItem.setParent(coolItemToolBarMgr);
        toolBarContributionItem.setVisible(getActive());
        coolItemToolBarMgr.markDirty();
        // Now add the tool bar contribution Item to the cool bar manager
        IContributionItem refItem = findAlphabeticalOrder(IWorkbenchActionConstants.MB_ADDITIONS, toolBarId, coolBarManager);
        if (refItem != null) {
            coolBarManager.insertAfter(refItem.getId(), toolBarContributionItem);
        } else {
            coolBarManager.add(toolBarContributionItem);
        }
    }
    return coolItemToolBarMgr;
}
Also used : IContributionItem(org.eclipse.jface.action.IContributionItem) IToolBarContributionItem(org.eclipse.jface.internal.provisional.action.IToolBarContributionItem) ICoolBarManager(org.eclipse.jface.action.ICoolBarManager)

Aggregations

IToolBarContributionItem (org.eclipse.jface.internal.provisional.action.IToolBarContributionItem)8 IContributionItem (org.eclipse.jface.action.IContributionItem)6 IToolBarManager (org.eclipse.jface.action.IToolBarManager)5 ICoolBarManager (org.eclipse.jface.action.ICoolBarManager)4 IContributionManager (org.eclipse.jface.action.IContributionManager)3 MToolBar (org.eclipse.e4.ui.model.application.ui.menu.MToolBar)2 MToolBarElement (org.eclipse.e4.ui.model.application.ui.menu.MToolBarElement)2 AbstractGroupMarker (org.eclipse.jface.action.AbstractGroupMarker)2 ContributionManager (org.eclipse.jface.action.ContributionManager)2 ToolBarManager (org.eclipse.jface.action.ToolBarManager)2 ToolBarContributionItem2 (org.eclipse.jface.internal.provisional.action.ToolBarContributionItem2)2 ICommandService (org.eclipse.ui.commands.ICommandService)2 Command (org.eclipse.core.commands.Command)1 IProject (org.eclipse.core.resources.IProject)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 MUIElement (org.eclipse.e4.ui.model.application.ui.MUIElement)1 MTrimElement (org.eclipse.e4.ui.model.application.ui.basic.MTrimElement)1 MHandledToolItem (org.eclipse.e4.ui.model.application.ui.menu.MHandledToolItem)1 MToolBarSeparator (org.eclipse.e4.ui.model.application.ui.menu.MToolBarSeparator)1 MToolItem (org.eclipse.e4.ui.model.application.ui.menu.MToolItem)1