use of org.eclipse.jface.action.ToolBarManager in project eclipse.platform.ui by eclipse-platform.
the class CompatibilityView method createPartControl.
@Override
protected boolean createPartControl(IWorkbenchPart legacyPart, Composite parent) {
clearMenuItems();
part.getContext().set(IViewPart.class, (IViewPart) legacyPart);
final IEclipseContext partContext = getModel().getContext();
IRendererFactory rendererFactory = partContext.get(IRendererFactory.class);
// Some views (i.e. Console) require that the actual ToolBar be
// instantiated before they are
final IActionBars actionBars = ((IViewPart) legacyPart).getViewSite().getActionBars();
ToolBarManager tbm = (ToolBarManager) actionBars.getToolBarManager();
Composite toolBarParent = new Composite(parent, SWT.NONE);
tbm.createControl(toolBarParent);
MenuManager mm = (MenuManager) actionBars.getMenuManager();
MMenu menu = getViewMenu();
if (menu == null) {
menu = modelService.createModelElement(MMenu.class);
// If the id contains a ':' use the part before it as the descriptor
// id
String partId = part.getElementId();
int colonIndex = partId.indexOf(':');
String descId = colonIndex == -1 ? partId : partId.substring(0, colonIndex);
menu.setElementId(descId);
menu.getTags().add(StackRenderer.TAG_VIEW_MENU);
menu.getTags().add(ContributionsAnalyzer.MC_MENU);
part.getMenus().add(menu);
}
AbstractPartRenderer apr = rendererFactory.getRenderer(menu, parent);
if (apr instanceof MenuManagerRenderer) {
MenuManagerRenderer renderer = (MenuManagerRenderer) apr;
renderer.linkModelToManager(menu, mm);
}
// Construct the toolbar (if necessary)
MToolBar toolbar = part.getToolbar();
if (toolbar == null) {
toolbar = modelService.createModelElement(MToolBar.class);
// If the id contains a ':' use the part before it as the descriptor
// id
String partId = part.getElementId();
int colonIndex = partId.indexOf(':');
String descId = colonIndex == -1 ? partId : partId.substring(0, colonIndex);
toolbar.setElementId(descId);
part.setToolbar(toolbar);
} else {
// clear out the model entries so they can be re-created by
// contributions
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=402561
toolbar.getChildren().clear();
}
apr = rendererFactory.getRenderer(toolbar, parent);
if (apr instanceof ToolBarManagerRenderer) {
((ToolBarManagerRenderer) apr).linkModelToManager(toolbar, tbm);
}
super.createPartControl(legacyPart, parent);
ViewDescriptor desc = reference.getDescriptor();
if (desc != null && desc.getPluginId() != null) {
parent.setData(new ContributionInfo(desc.getPluginId(), ContributionInfoMessages.ContributionInfo_View, null));
}
// dispose the tb, it will be re-created when the tab is shown
toolBarParent.dispose();
apr = rendererFactory.getRenderer(menu, parent);
if (apr instanceof MenuManagerRenderer) {
MenuManagerRenderer renderer = (MenuManagerRenderer) apr;
// create opaque items for any contribution items that were added
// directly to the manager
renderer.reconcileManagerToModel(mm, menu);
}
apr = rendererFactory.getRenderer(toolbar, parent);
if (apr instanceof ToolBarManagerRenderer) {
// create opaque items for any contribution items that were added
// directly to the manager
((ToolBarManagerRenderer) apr).reconcileManagerToModel(tbm, toolbar);
}
final AtomicBoolean toolbarContributed = new AtomicBoolean();
final IContextFunction func = new ContextFunction() {
@Override
public Object compute(IEclipseContext context, String contextKey) {
if (toolbarContributed.getAndSet(true)) {
// fix for bug 448873: don't contribute to the toolbar twice
return null;
}
final ViewActionBuilder actionBuilder = new ViewActionBuilder();
actionBuilder.readActionExtensions(getView());
ActionDescriptor[] actionDescriptors = actionBuilder.getExtendedActions();
if (actionDescriptors != null) {
IHandlerService hs = partContext.get(IHandlerService.class);
for (ActionDescriptor actionDescriptor : actionDescriptors) {
if (actionDescriptor != null) {
IAction action = actionDescriptor.getAction();
if (action != null && action.getActionDefinitionId() != null) {
hs.activateHandler(action.getActionDefinitionId(), new ActionHandler(action));
}
}
}
}
actionBars.updateActionBars();
Runnable dispose = actionBuilder::dispose;
return dispose;
}
};
if (toolbar.getWidget() == null) {
toolbar.getTransientData().put(ToolBarManagerRenderer.POST_PROCESSING_FUNCTION, func);
} else {
toolbar.getTransientData().put(ToolBarManagerRenderer.POST_PROCESSING_DISPOSE, func.compute(partContext, null));
}
return true;
}
use of org.eclipse.jface.action.ToolBarManager in project eclipse.platform.ui by eclipse-platform.
the class WorkbenchMenuService method clearContributions.
/**
* Disposes contributions created by service for given part. See bug 537046.
*
* @param site
* @param part
*/
@Override
public void clearContributions(PartSite site, MPart part) {
List<MToolBar> toolbars = getContributedToolbars(part);
IEclipseContext context = part.getContext();
IRendererFactory rendererFactory = context.get(IRendererFactory.class);
IActionBars actionBars = site.getActionBars();
if (toolbars != null) {
for (MToolBar mToolBar : toolbars) {
((Notifier) mToolBar).eAdapters().clear();
AbstractPartRenderer apr = rendererFactory.getRenderer(mToolBar, null);
if (apr instanceof ToolBarManagerRenderer) {
ToolBarManager tbm = (ToolBarManager) actionBars.getToolBarManager();
ToolBarManagerRenderer tbmr = (ToolBarManagerRenderer) apr;
tbmr.clearModelToManager(mToolBar, tbm);
CompatibilityView.clearOpaqueToolBarItems(tbmr, mToolBar);
}
mToolBar.getTransientData().remove(ToolBarManagerRenderer.POST_PROCESSING_FUNCTION);
final IPresentationEngine engine = context.get(IPresentationEngine.class);
engine.removeGui(mToolBar);
mToolBar.getTransientData().remove(ModelUtils.CONTAINING_PARENT);
}
}
List<MMenu> menus = getContributedMenus(part);
if (menus != null) {
for (MMenu mMenu : menus) {
((Notifier) mMenu).eAdapters().clear();
AbstractPartRenderer apr = rendererFactory.getRenderer(mMenu, null);
if (apr instanceof MenuManagerRenderer) {
MenuManager tbm = (MenuManager) actionBars.getMenuManager();
MenuManagerRenderer tbmr = (MenuManagerRenderer) apr;
tbmr.clearModelToManager(mMenu, tbm);
CompatibilityView.clearOpaqueMenuItems(tbmr, mMenu);
}
final IPresentationEngine engine = context.get(IPresentationEngine.class);
engine.removeGui(mMenu);
mMenu.getTransientData().remove(ModelUtils.CONTAINING_PARENT);
}
}
}
use of org.eclipse.jface.action.ToolBarManager in project eclipse.platform.ui by eclipse-platform.
the class SupportTray method createContents.
@Override
protected Control createContents(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
if (providesSupport(getCurrentStatusAdapter()) == null && getBooleanValue(IStatusDialogConstants.TRAY_OPENED)) {
}
GridLayout layout = new GridLayout();
layout.marginWidth = layout.marginHeight = 0;
layout.verticalSpacing = 0;
container.setLayout(layout);
GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
container.setLayoutData(layoutData);
container.addListener(SWT.Dispose, event -> destroyImages());
if (!hideSupportButtons) {
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
toolBarManager.createControl(container);
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
gd.grabExcessHorizontalSpace = true;
toolBarManager.getControl().setLayoutData(gd);
Label separator = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL);
gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.heightHint = 1;
separator.setLayoutData(gd);
createActions();
toolBarManager.add(closeAction);
toolBarManager.update(true);
}
supportArea = new Composite(container, SWT.NONE);
layout = new GridLayout();
layout.marginWidth = layout.marginHeight = 0;
layout.verticalSpacing = 0;
supportArea.setLayout(layout);
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
gd.horizontalSpan = 1;
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
supportArea.setLayoutData(gd);
if (lastSelectedStatus != null)
createSupportArea(supportArea, lastSelectedStatus);
Point shellSize = supportArea.getShell().getSize();
Point desiredSize = supportArea.getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT);
if (desiredSize.y > shellSize.y) {
supportArea.getShell().setSize(shellSize.x, Math.min(desiredSize.y, 500));
}
return container;
}
use of org.eclipse.jface.action.ToolBarManager in project eclipse.platform.ui by eclipse-platform.
the class ApplicationActionBarAdvisor method fillCoolBar.
@Override
protected void fillCoolBar(ICoolBarManager coolBar) {
IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.LEFT);
coolBar.add(new ToolBarContributionItem(toolbar, "main"));
for (Action action : switchToThemeActions) {
toolbar.add(action);
}
}
use of org.eclipse.jface.action.ToolBarManager in project eclipse.platform.ui by eclipse-platform.
the class ToolBarManagerRendererTest method testDynamicItem_Reconcile_RemoveOneByID.
@Test
public void testDynamicItem_Reconcile_RemoveOneByID() {
MToolItem toolItem1 = ems.createModelElement(MDirectToolItem.class);
toolItem1.setElementId("Item1");
toolBar.getChildren().add(toolItem1);
MToolItem toolItem2 = ems.createModelElement(MDirectToolItem.class);
toolItem2.setElementId("Item2");
toolBar.getChildren().add(toolItem2);
contextRule.createAndRunWorkbench(window);
ToolBarManagerRenderer renderer = getToolBarManagerRenderer();
ToolBarManager tbm = getToolBarManager();
assertEquals(2, toolBar.getChildren().size());
assertEquals(2, tbm.getSize());
tbm.remove("Item1");
renderer.reconcileManagerToModel(tbm, toolBar);
assertEquals(1, toolBar.getChildren().size());
assertEquals(1, tbm.getSize());
assertEquals("Item2", tbm.getItems()[0].getId());
}
Aggregations