void handleDocumentModified(Event<SourceFileChange> event) { String uri = event.getData().input.getURI(); modelService.findElements(application, MPart.class, EModelService.ANYWHERE, (e) -> { if( e instanceof MPart) { return ((MPart) e).getContext() != null && uri.equals(((MPart) e).getContext().getLocal(Constants.DOCUMENT_URL)); } return false; }).forEach((e) -> { ((MPart)e).setDirty(true); }); }
public Object getSelection(String partId) { MPart part = partService.findPart(partId); if (part == null) { return null; } IEclipseContext partContext = part.getContext(); if (partContext == null) { return null; } return partContext.get(OUT_SELECTION); }
/** * Adds a listener that toggles standby state if the view pane is zoomed. */ private void addZoomListener() { ViewSite site = (ViewSite) getViewSite(); MPart introModelPart = site.getModel(); if (introModelPart == null || introModelPart.getContext() == null) return; eventBroker = introModelPart.getContext().get(IEventBroker.class); eventBroker.subscribe(UIEvents.ApplicationElement.TOPIC_TAGS, zoomChangeListener); }
@PersistState void persistState() { ContextInjectionFactory.invoke(wrapped, PersistState.class, part.getContext(), null); }
void handleDocumentSaved(Event<SourceFileInput> event) { Input<?> input = event.getData(); String tmpUri = ((URIProvider)input).getURI(); String uri = tmpUri; modelService.findElements(application, MPart.class, EModelService.ANYWHERE, (e) -> { if( e instanceof MPart) { return ((MPart) e).getContext() != null && uri.equals(((MPart) e).getContext().getLocal(Constants.DOCUMENT_URL)); } return false; }).forEach((e) -> { ((MPart)e).setDirty(false); }); }
/** * Disposes of the 3.x part's site if it has one. Subclasses may override * but must call <code>super.disposeSite()</code> in its implementation. */ void disposeSite(PartSite site) { site.dispose(); if (part.getTags().contains(IWorkbenchConstants.TAG_USE_DEPENDENCY_INJECTION)) { ContextInjectionFactory.uninject(legacyPart, part.getContext()); } legacyPart = null; }
private boolean isActiveChild(MPart part) { IEclipseContext context = part.getContext(); return context != null && context.getParent().getActiveChild() == context; }
@Override public final void registerContextMenu(final String menuId, final MenuManager menuManager, final ISelectionProvider selectionProvider, final boolean includeEditorInput) { if (menuExtenders == null) { menuExtenders = new ArrayList(1); } PartSite.registerContextMenu(menuId, menuManager, selectionProvider, includeEditorInput, getPart(), getModel().getContext(), menuExtenders); } }
private void handleContextSet(Event event) { Object element = event.getProperty(UIEvents.EventTags.ELEMENT); MPart part = getModel(); if (element == part) { IEclipseContext context = part.getContext(); if (context != null) { context.set(getClass().getName(), this); unsubscribe(); } } }
@Override public void selectionChanged(SelectionChangedEvent e) { ESelectionService selectionService = part.getContext().get(ESelectionService.class); selectionService.setSelection(e.getSelection()); }
private MPart getActivationCandidate(MPart part) { // get all the possible parts that we can possibly activate Collection<MPart> candidates = part.getContext().get(EPartService.class).getParts(); return findActivationCandidate(candidates, part); }
@Override public void setFocus() { Object object = wrappedPart.getObject(); IEclipseContext context = wrappedPart.getContext(); if (object != null && context != null) { ContextInjectionFactory.invoke(object, Focus.class, context); if (Policy.DEBUG_FOCUS) { Activator.trace(Policy.DEBUG_FOCUS_FLAG, "Focused: " + object, null); //$NON-NLS-1$ } } else { if (Policy.DEBUG_FOCUS) { Activator.trace(Policy.DEBUG_FOCUS_FLAG, "Focus not set, object or context missing: " + object + ", " + context, //$NON-NLS-1$ //$NON-NLS-2$ new IllegalStateException()); } } } }
@Override public void selectionChanged(SelectionChangedEvent e) { MPart part = page.findPart(activePart); ESelectionService selectionService = part.getContext().get(ESelectionService.class); selectionService.setSelection(e.getSelection()); }
public void createViewReferenceForPart(final MPart part, String viewId) { // If the id contains a ':' use the part before it as the descriptor id int colonIndex = viewId.indexOf(':'); String descId = colonIndex == -1 ? viewId : viewId.substring(0, colonIndex); IViewDescriptor desc = getWorkbenchWindow().getWorkbench().getViewRegistry().find(descId); final ViewReference ref = new ViewReference(window.getContext(), this, part, (ViewDescriptor) desc); if (contains(ref)) { return; } IEclipseContext partContext = part.getContext(); if (partContext == null) { ref.subscribe(); } else { partContext.set(ViewReference.class.getName(), ref); } addViewReference(ref); }
/** * Dispose of the menu extender. Should only be called when the part * is disposed. */ public void dispose() { clearStaticActions(); Platform.getExtensionRegistry().removeRegistryChangeListener(this); menu.removeMenuListener(this); if (menuModel != null) { // unlink ourselves from the renderer IRendererFactory factory = modelPart.getContext().get(IRendererFactory.class); AbstractPartRenderer obj = factory.getRenderer(menuModel, null); if (obj instanceof MenuManagerRenderer) { MenuManagerRenderer renderer = (MenuManagerRenderer) obj; unlink(renderer, menuModel); renderer.clearModelToManager(menuModel, menu); } modelPart.getMenus().remove(menuModel); } }
void callingAllParts(Class<? extends Annotation> clz) { List<MPart> parts = ms.findElements(myPart, null, MPart.class); for (MPart part : parts) { if (part == myPart) { continue; } Control ctrl = (Control) part.getWidget(); if (part.getObject() != null && ctrl != null && !ctrl.isDisposed()) { ContextInjectionFactory.invoke(part.getObject(), clz, part.getContext(), null); } } }
@Inject void setPart(@Optional @Named(IServiceConstants.ACTIVE_PART) final MPart part) { if (part == null) { activePart = null; context.set(IServiceConstants.ACTIVE_SELECTION, null); } else if (activePart != part) { activePart = part; IEclipseContext partContext = part.getContext(); if (partContext.containsKey(OUT_POST_SELECTION)) { Object selection = partContext.get(OUT_POST_SELECTION); context.set(IServiceConstants.ACTIVE_SELECTION, selection); } else if (partContext.containsKey(OUT_SELECTION)) { Object selection = partContext.get(OUT_SELECTION); context.set(IServiceConstants.ACTIVE_SELECTION, selection); } track(part); } }
/** * well, this goes to the renderer. * * @param mgr */ private void addMenuContributions(IMenuManager mgr) { IRendererFactory factory = modelPart.getContext().get(IRendererFactory.class); AbstractPartRenderer obj = factory.getRenderer(menuModel, null); if (obj instanceof MenuManagerRenderer) { MenuManagerRenderer renderer = (MenuManagerRenderer) obj; renderer.reconcileManagerToModel(menu, menuModel); renderer.processContributions(menuModel, menuModel.getElementId(), false, true); // double cast because we're bad people renderer.processContents((MElementContainer<MUIElement>) ((Object) menuModel)); } }
void activate(MPart part, boolean activateBranch) { IEclipseContext context = part.getContext(); if (activateBranch) { context.activateBranch(); } else { IEclipseContext parent = context.getParent(); do { context.activate(); context = parent; parent = parent.getParent(); } while (parent.get(MWindow.class) != null); } prepend(part); }
@Override public boolean savePart(MPart part, boolean confirm) { if (!part.isDirty()) { return true; } if (saveHandler != null) { return saveHandler.save(part, confirm); } Object client = part.getObject(); try { ContextInjectionFactory.invoke(client, Persist.class, part.getContext()); } catch (InjectionException e) { log("Failed to persist contents of part", "Failed to persist contents of part ({0})", //$NON-NLS-1$ //$NON-NLS-2$ part.getElementId(), e); return false; } catch (RuntimeException e) { log("Failed to persist contents of part via DI", //$NON-NLS-1$ "Failed to persist contents of part ({0}) via DI", part.getElementId(), e); //$NON-NLS-1$ return false; } return true; }