/** * 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); } } }
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)); } } };
@SuppressWarnings("null") @Override protected void doProcessContent(MToolControl element) { WToolControl<N> widget = getWidget(element); if( widget == null ) { getLogger().error("Could not find widget for '"+element+"'"); //$NON-NLS-1$ //$NON-NLS-2$ return; } Class<?> cl = widget.getWidget().getClass(); IEclipseContext modelContext = getModelContext(element); if( modelContext == null ) { getLogger().error("The model context is null - impossible to proceed"); //$NON-NLS-1$ return; } IEclipseContext context = modelContext.createChild("ToolControl"); //$NON-NLS-1$ do { context.set(cl.getName(), widget.getWidget()); cl = cl.getSuperclass(); } while (!cl.getName().equals("java.lang.Object")); //$NON-NLS-1$ populateModelInterfaces(element, context, MToolControl.class); IContributionFactory contributionFactory = (IContributionFactory) context.get(IContributionFactory.class.getName()); Object newPart = contributionFactory.create(element.getContributionURI(), context); element.setObject(newPart); element.getTransientData().put(LOCAL_CONTEXT, context); }
for (MToolControl trimStack : trimStacks) { if (TrimStack.CONTRIBUTION_URI.equals(trimStack.getContributionURI())) { trimStack.setElementId(trimStack.getElementId().replace(oldID, newID));
@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.getName(), newComposite); localContext.set(MToolControl.class.getName(), 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(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { ContextInjectionFactory.uninject(tcImpl, parentContext); model.setObject(null); } }); } model.setWidget(newComposite); newComposite.setData(AbstractPartRenderer.OWNING_ME, model); newComposite.setData(this); return newComposite; }
@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; }
toolControl.getContributionURI(), parentContext, localContext); toolControl.setObject(tcImpl); Control[] kids = parentComp.getChildren();
toolControl.getContributionURI(), parentContext, localContext); toolControl.setObject(tcImpl); Control[] kids = parentComp.getChildren();