quickAccessElementId, model); if (quickAccessElement != null) { moveControl(quickAccessElement.getParent(), quickAccessElement); if (QUICK_ACCESS_ID.equals(quickAccessElement.getElementId())) { if (model.getTags().contains(QUICK_ACCESS_HIDDEN)) { if (!quickAccessElement.getTags().contains( IPresentationEngine.HIDDEN_EXPLICITLY)) { quickAccessElement.getTags().add(IPresentationEngine.HIDDEN_EXPLICITLY); quickAccessElement.getTags().add(IPresentationEngine.HIDDEN_EXPLICITLY);
@Override protected Control createControl(Composite parent) { IEclipseContext localContext = EclipseContextFactory.create(); final Composite newComposite = new Composite(parent, SWT.NONE); newComposite.setLayout(new FillLayout()); localContext.set(Composite.class, newComposite); localContext.set(MToolControl.class, model); final IEclipseContext parentContext = modelService.getContainingContext(model); if (model.getObject() == null) { final Object tcImpl = contribFactory.create(model.getContributionURI(), parentContext, localContext); model.setObject(tcImpl); newComposite.addDisposeListener(e -> { ContextInjectionFactory.uninject(tcImpl, parentContext); model.setObject(null); }); } model.setWidget(newComposite); newComposite.setData(AbstractPartRenderer.OWNING_ME, model); newComposite.setData(this); return newComposite; }
if (slElement == null) { slElement = modelService.createModelElement(MToolControl.class); slElement.setElementId(STATUS_LINE_ID); slElement.setContributionURI(TRIM_CONTRIBUTION_URI); bottomTrim.getChildren().add(slElement); slElement.setToBeRendered(statusLineVisible); slElement.getTags().add(TrimBarLayout.SPACER); if (hsElement == null) { hsElement = modelService.createModelElement(MToolControl.class); hsElement.setElementId("org.eclipse.ui.HeapStatus"); //$NON-NLS-1$ hsElement.setContributionURI(TRIM_CONTRIBUTION_URI); hsElement.getTags().add(IPresentationEngine.DRAGGABLE); bottomTrim.getChildren().add(hsElement); hsElement.setToBeRendered(getShowHeapStatus()); if (pbElement == null) { pbElement = modelService.createModelElement(MToolControl.class); pbElement.setElementId("org.eclipse.ui.ProgressBar"); //$NON-NLS-1$ pbElement.getTags().add(IPresentationEngine.DRAGGABLE); pbElement.setContributionURI(TRIM_CONTRIBUTION_URI); bottomTrim.getChildren().add(pbElement); pbElement.setToBeRendered(getWindowConfigurer().getShowProgressIndicator());
@Inject @Optional private void subscribeTopicAppStartup( @UIEventTopic(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE) Event event) { List<MToolControl> toolControls = modelService.findElements( application, null, MToolControl.class, null); for (MToolControl toolControl : toolControls) { if (toolControl.getTags().contains( IPresentationEngine.HIDDEN_EXPLICITLY)) { toolControl.setVisible(false); } } }
private MToolBarElement createToolControlAddition(IConfigurationElement element) { String id = MenuHelper.getId(element); MToolControl control = MenuFactoryImpl.eINSTANCE.createToolControl(); control.setElementId(id); control.setContributionURI(CompatibilityWorkbenchWindowControlContribution.CONTROL_CONTRIBUTION_URI); ControlContributionRegistry.add(id, element); control.setVisibleWhen(MenuHelper.getVisibleWhen(element)); createIdentifierTracker(control); return control; }
/** * Install the Intro Launch Bar into the provided window. * * @param window * the window to host the launch bar * @param modelRoot * the current intro configuration, with pages * @param element * the launch bar configuration * @return the launch bar instance */ public static IntroLaunchBar create(IWorkbenchWindow window, IntroModelRoot modelRoot, IntroLaunchBarElement element) { EModelService modelService = window.getService(EModelService.class); MTrimmedWindow trimmedWindow = window.getService(MTrimmedWindow.class); MToolControl trimControl = modelService.createModelElement(MToolControl.class); trimControl.setElementId(LAUNCHBAR_ID); trimControl.setContributionURI(BUNDLECLASS_URI); // Must record sufficient information so as to be able to obtain the // launch configuration on workspace restart trimControl.getPersistedState().put(INTRO_CONFIG_ID, modelRoot.getId()); trimControl.getPersistedState().put(LAST_PAGE_ID, modelRoot.getCurrentPageId()); trimControl.getTags().add(IPresentationEngine.DRAGGABLE); MTrimBar bar = modelService.getTrim(trimmedWindow, determineLocation(element)); bar.getChildren().add(trimControl); // should now be rendered return (IntroLaunchBar) trimControl.getObject(); }
MToolControl toolControl = (MToolControl) element; if (((Object) toolControl.getParent()) instanceof MToolBar) { IRendererFactory factory = context.get(IRendererFactory.class); AbstractPartRenderer renderer = factory.getRenderer( toolControl.getParent(), parent); if (renderer instanceof ToolBarManagerRenderer) { return null; toolControl.getContributionURI(), parentContext, localContext); toolControl.setObject(tcImpl); Control[] kids = parentComp.getChildren();
public void handleEvent(Event event) { Object changedObject = event.getProperty(EventTags.ELEMENT); // Only care about MPerspective id changes if (!(changedObject instanceof MPerspective)) return; MPerspective perspective = (MPerspective) changedObject; String newID = (String) event.getProperty(UIEvents.EventTags.NEW_VALUE); String oldID = (String) event.getProperty(UIEvents.EventTags.OLD_VALUE); // pattern is trimStackID(perspectiveID) newID = '(' + newID + ')'; oldID = '(' + oldID + ')'; // Search the trim for the window containing the perspective MWindow perspWin = modelService.getTopLevelWindowFor(perspective); if (perspWin == null) return; List<MToolControl> trimStacks = modelService.findElements(perspWin, null, MToolControl.class, null); for (MToolControl trimStack : trimStacks) { // Only care about MToolControls that are TrimStacks if (TrimStack.CONTRIBUTION_URI.equals(trimStack.getContributionURI())) trimStack.setElementId(trimStack.getElementId().replace(oldID, newID)); } } };
if (fullId.equals(tc.getElementId())) { tc.setToBeRendered(true); String perspId = '(' + oldPersp.getElementId() + ')'; for (MToolControl tc : tcList) { if (tc.getObject() instanceof TrimStack && tc.getElementId().contains(perspId)) { TrimStack ts = (TrimStack) tc.getObject(); ts.showStack(false); tc.setToBeRendered(false);
/** * Remove all traces of any launch bars found in the model. Required on startup as the * {@linkplain IntroLaunchBar} instances may not be have been rendered yet and so are * disconnected from the {@link IntroPlugin}'s state. * * @param workbench * the workbench to process */ public static void destroyAll(IWorkbench workbench) { EModelService modelService = workbench.getService(EModelService.class); MApplication application = workbench.getService(MApplication.class); List<MToolControl> candidates = modelService.findElements(application, MToolControl.class, EModelService.IN_TRIM, toolControl -> LAUNCHBAR_ID.equals(toolControl.getElementId()) && BUNDLECLASS_URI.equals(((MToolControl) toolControl).getContributionURI())); for (MToolControl trimControl : candidates) { if (trimControl.getParent() != null) { trimControl.getParent().getChildren().remove(trimControl); } } }
@Override public void dragStart(DnDInfo info) { super.dragStart(info); if (dragElement instanceof MToolControl) { MToolControl tc = (MToolControl) dragElement; if (tc.getObject() instanceof TrimStack) { TrimStack ts = (TrimStack) tc.getObject(); ts.showStack(false); } } if (dropAgent == null) attachToCursor(info); }
private MToolControl addTrimElement(MTrimBar bottomTrim, IConfigurationElement ice, String id, boolean isBefore, String relTo, String classSpec) { // is it already in the trim ? MUIElement existingTrim = modelService.find(id, bottomTrim); if (existingTrim != null) { iceMap.put((MToolControl) existingTrim, ice); return (MToolControl) existingTrim; } // Ok, create one but only if we can site it correctly int insertIndex = bottomTrim.getChildren().size(); if (relTo != null) { MUIElement foundRel = modelService.find(relTo, bottomTrim); if (foundRel == null) return null; insertIndex = bottomTrim.getChildren().indexOf(foundRel); if (!isBefore) insertIndex++; } MToolControl newTrimElement = modelService.createModelElement(MToolControl.class); newTrimElement.setElementId(id); newTrimElement.setToBeRendered(classSpec != null); if (classSpec != null) { newTrimElement .setContributionURI("bundleclass://org.eclipse.ui.workbench/org.eclipse.ui.internal.LegacyTrim"); //$NON-NLS-1$ } newTrimElement.setContributorURI(URIHelper.constructPlatformURI(ice.getContributor())); iceMap.put(newTrimElement, ice); bottomTrim.getChildren().add(insertIndex, newTrimElement); return newTrimElement; }
if (tc.getObject() instanceof TrimStack && tc.getElementId().contains(perspId)) { tc.setVisible(true); String perspId = '(' + oldPersp.getElementId() + ')'; for (MToolControl tc : tcList) { if (tc.getObject() instanceof TrimStack && tc.getElementId().contains(perspId)) { TrimStack ts = (TrimStack) tc.getObject(); ts.showStack(false); tc.setVisible(false);
if (windowReader.hasStatusLine()) { MToolControl statusLine = modelService.createModelElement(MToolControl.class); statusLine.setElementId(WorkbenchWindow.STATUS_LINE_ID); statusLine.setContributionURI(WorkbenchWindow.TRIM_CONTRIBUTION_URI); statusLine.getTags().add(TrimBarLayout.SPACER); statusBar.getChildren().add(statusLine);
private SideValue getLocation() { MElementContainer<?> parent = trimControl.getParent(); while (parent != null) { if (parent instanceof MTrimBar) { return ((MTrimBar) parent).getSide(); } parent = parent.getParent(); } return SideValue.BOTTOM; }
@Override public Object execute(ExecutionEvent executionEvent) { final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(executionEvent); if (window == null) { return null; } MWindow mWindow = ((WorkbenchWindow) window).getModel(); EModelService modelService = mWindow.getContext().get(EModelService.class); MToolControl searchField = (MToolControl) modelService.find("SearchField", mWindow); //$NON-NLS-1$ if (searchField != null && searchField.isVisible()) { Control control = (Control) searchField.getWidget(); // the workbench configurer may override visibility; if so, // focus should not change if (control != null && control.isVisible()) { Control previousFocusControl = control.getDisplay().getFocusControl(); control.setFocus(); SearchField field = (SearchField) searchField.getObject(); field.activate(previousFocusControl); return null; } } // open the original/legacy QuickAccess Dialog if the toolbars are // hidden or if the search field isn't available (maybe because the // dialog is explicitly wanted) displayQuickAccessDialog(window, executionEvent.getCommand()); return null; }
private boolean isHideable(MToolControl toolControl) { return toolControl.getTags().contains(HIDEABLE); }
private int getFixedSides() { MUIElement tcParent = toolControl.getParent(); if (!(tcParent instanceof MTrimBar)) { return 0; } MTrimBar bar = (MTrimBar) tcParent; Composite trimComp = (Composite) bar.getWidget(); Rectangle trimBounds = trimComp.getBounds(); Point trimCenter = new Point(trimBounds.width / 2, trimBounds.height / 2); // adjusted to // (0,0) Control trimCtrl = (Control) toolControl.getWidget(); Rectangle ctrlBounds = trimCtrl.getBounds(); Point ctrlCenter = new Point(ctrlBounds.x + (ctrlBounds.width / 2), ctrlBounds.y + (ctrlBounds.height / 2)); if (bar.getSide() == SideValue.LEFT) { int verticalValue = ctrlCenter.y < trimCenter.y ? SWT.TOP : SWT.BOTTOM; return SWT.LEFT | verticalValue; } else if (bar.getSide() == SideValue.RIGHT) { int verticalValue = ctrlCenter.y < trimCenter.y ? SWT.TOP : SWT.BOTTOM; return SWT.RIGHT | verticalValue; } else if (bar.getSide() == SideValue.TOP) { int horizontalValue = ctrlCenter.x < trimCenter.x ? SWT.LEFT : SWT.RIGHT; return SWT.TOP | horizontalValue; } else if (bar.getSide() == SideValue.BOTTOM) { int horizontalValue = ctrlCenter.x < trimCenter.x ? SWT.LEFT : SWT.RIGHT; return SWT.BOTTOM | horizontalValue; } return SWT.BOTTOM | SWT.RIGHT; }
void construct(MWindow window, MToolControl toolControl, Composite composite) { IConfigurationElement configurationElement = ControlContributionRegistry.get(toolControl .getElementId()); if (configurationElement != null) { contribution = (WorkbenchWindowControlContribution) Util.safeLoadExecutableExtension( MUIElement parent = toolControl.getParent(); while (!(parent instanceof MTrimBar) && parent != null) { parent = parent.getParent();