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);
}
});
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations