private IEditorPart getEditor(MPart part) { if (part != null) { Object clientObject = part.getObject(); if (clientObject instanceof CompatibilityEditor) { return ((CompatibilityEditor) clientObject).getEditor(); } } return getActiveEditor(); }
@Inject void setPart(@Optional @Named(IServiceConstants.ACTIVE_PART) final MPart part) { activePart = null; if (part != null) { Object client = part.getObject(); if (client instanceof CompatibilityPart) { IWorkbenchPart workbenchPart = ((CompatibilityPart) client).getPart(); activePart = workbenchPart; } else if (client != null) { if (part.getTransientData().get(E4PartWrapper.E4_WRAPPER_KEY) instanceof E4PartWrapper) { activePart = (IWorkbenchPart) part.getTransientData().get( E4PartWrapper.E4_WRAPPER_KEY); } } } }
private void firePartVisible(MPart part) { Object client = part.getObject(); if (client instanceof CompatibilityPart) { IWorkbenchPart workbenchPart = getWrappedPart((CompatibilityPart) client); if (workbenchPart == null) { return; } final IWorkbenchPartReference partReference = getReference(workbenchPart); for (final IPartListener2 listener : partListener2List) { SafeRunner.run(new SafeRunnable() { @Override public void run() throws Exception { listener.partVisible(partReference); } }); } } else { Integer val = partEvents.get(part); if (val == null) { partEvents.put(part, Integer.valueOf(FIRE_PART_VISIBLE)); } else { partEvents.put(part, Integer.valueOf(val.intValue() | FIRE_PART_VISIBLE)); } } }
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); } } }
@Execute public void save(MPart part, IEclipseContext context) { if( part.isDirty() ) { ContextInjectionFactory.invoke(part.getObject(), Persist.class,context); } } }
public void firePartHidden(MPart part) { Object client = part.getObject(); if (client instanceof CompatibilityPart) { IWorkbenchPart workbenchPart = getWrappedPart((CompatibilityPart) client); if (workbenchPart == null) { return; } final IWorkbenchPartReference partReference = getReference(workbenchPart); for (final IPartListener2 listener : partListener2List) { SafeRunner.run(new SafeRunnable() { @Override public void run() throws Exception { listener.partHidden(partReference); } }); } } }
@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 boolean saveParts(Collection<MPart> dirtyParts, boolean confirm) { ArrayList<IWorkbenchPart> saveableParts = new ArrayList<>(); for (MPart part : dirtyParts) { Object object = part.getObject(); if (object instanceof CompatibilityPart) { IWorkbenchPart workbenchPart = ((CompatibilityPart) object).getPart(); if (SaveableHelper.isSaveable(workbenchPart)) { saveableParts.add(workbenchPart); } } } if (saveableParts.isEmpty()) { return super.saveParts(dirtyParts, confirm); } SaveablesList saveablesList = (SaveablesList) PlatformUI.getWorkbench() .getService(ISaveablesLifecycleListener.class); Object saveResult = saveablesList.preCloseParts(saveableParts, true, WorkbenchWindow.this); return saveResult != null; } };
@Override public boolean save(MPart dirtyPart, boolean confirm) { Object object = dirtyPart.getObject(); if (object instanceof CompatibilityPart) { IWorkbenchPart workbenchPart = ((CompatibilityPart) object).getPart(); if (SaveableHelper.isSaveable(workbenchPart)) { SaveablesList saveablesList = (SaveablesList) PlatformUI.getWorkbench() .getService(ISaveablesLifecycleListener.class); Object saveResult = saveablesList.preCloseParts( Collections.singletonList(workbenchPart), true, WorkbenchWindow.this); return saveResult != null; } } return super.save(dirtyPart, confirm); }
private IWorkbenchPart getWorkbenchPart(MPart part) { if (part != null) { Object clientObject = part.getObject(); if (clientObject instanceof CompatibilityPart) { return ((CompatibilityPart) clientObject).getPart(); } else if (clientObject != null) { if (part.getTransientData().get(E4PartWrapper.E4_WRAPPER_KEY) instanceof E4PartWrapper) { return (IWorkbenchPart) part.getTransientData().get( E4PartWrapper.E4_WRAPPER_KEY); } ViewReference viewReference = getViewReference(part); if (viewReference != null) { E4PartWrapper legacyPart = E4PartWrapper.getE4PartWrapper(part); try { viewReference.initialize(legacyPart); } catch (PartInitException e) { WorkbenchPlugin.log(e); } part.getTransientData().put(E4PartWrapper.E4_WRAPPER_KEY, legacyPart); return legacyPart; } } } return null; }
@Override public Save promptToSave(MPart dirtyPart) { Object object = dirtyPart.getObject(); if (object instanceof CompatibilityPart) { IWorkbenchPart part = ((CompatibilityPart) object).getPart(); ISaveablePart saveable = SaveableHelper.getSaveable(part); if (saveable != null) { if (!saveable.isSaveOnCloseNeeded()) { return Save.NO; } return SaveableHelper.savePart(saveable, part, WorkbenchWindow.this, true) ? Save.NO : Save.CANCEL; } } return defaultSaveHandler.promptToSave(dirtyPart); }
@Focus void setFocus() { MPart ap = findInnerActive(myPart); if (ap == null) { if (Policy.DEBUG_FOCUS) { WorkbenchSWTActivator.trace(Policy.DEBUG_FOCUS_FLAG, "Focus not set, no selected element in: " + myPart, //$NON-NLS-1$ new IllegalStateException()); } return; } Control ctrl = (Control) ap.getWidget(); Object object = ap.getObject(); if (object != null && ctrl != null && !ctrl.isDisposed()) { ContextInjectionFactory.invoke(object, Focus.class, ap.getContext(), null); } else { if (Policy.DEBUG_FOCUS) { WorkbenchSWTActivator.trace(Policy.DEBUG_FOCUS_FLAG, "Focus not set, object is null or widget is disposed: " + object, new IllegalStateException()); //$NON-NLS-1$ } } }
/** * @return the <code>ViewIntroAdapterPart</code> for this workbench, <code>null</code> if it * cannot be found. */ /*package*/ViewIntroAdapterPart getViewIntroAdapterPart() { for (IWorkbenchWindow iWorkbenchWindow : this.workbench.getWorkbenchWindows()) { WorkbenchWindow window = (WorkbenchWindow) iWorkbenchWindow; MUIElement introPart = window.modelService.find(IIntroConstants.INTRO_VIEW_ID, window.getModel()); if (introPart instanceof MPlaceholder) { MPlaceholder introPH = (MPlaceholder) introPart; MPart introModelPart = (MPart) introPH.getRef(); CompatibilityView compatView = (CompatibilityView) introModelPart.getObject(); if (compatView != null) { Object obj = compatView.getPart(); if (obj instanceof ViewIntroAdapterPart) return (ViewIntroAdapterPart) obj; } } } return null; }
@Override public boolean setFocus() { if (!beingFocused) { try { // we are currently asking the part to take focus beingFocused = true; // delegate an attempt to set the focus here to the // part's implementation (if there is one) Object object = part.getObject(); if (object != null && isEnabled()) { IPresentationEngine pe = part.getContext().get( IPresentationEngine.class); pe.focusGui(part); return true; } return super.setFocus(); } finally { // we are done, unset our flag beingFocused = false; } } // already being focused, likely some strange recursive call, // just return return true; } };
@Override public void partDeactivated(MPart part) { firePartDeactivated(part); Object client = part.getObject(); if (client instanceof CompatibilityPart) { IWorkbenchPart workbenchPart = getWrappedPart((CompatibilityPart) client); if (workbenchPart == null) { return; } IWorkbenchPartSite site = workbenchPart.getSite(); // if it's an editor, we only want to disable the actions ((PartSite) site).deactivateActionBars(site instanceof ViewSite); } WorkbenchWindow wwindow = (WorkbenchWindow) getWorkbenchWindow(); if (!wwindow.isClosing()) { wwindow.getStatusLineManager().update(false); } }
private void handlePostSelectionChanged(MPart part, Object selection, boolean targeted) { selection = createCompatibilitySelection(selection); Object client = part.getObject(); if (client instanceof CompatibilityPart) { IWorkbenchPart workbenchPart = ((CompatibilityPart) client).getPart(); if (targeted) { notifyListeners(workbenchPart, (ISelection) selection, part.getElementId(), targetedPostSelectionListeners); } else { notifyListeners(workbenchPart, (ISelection) selection, postSelectionListeners); } } else if (client != null) { if (part.getTransientData().get(E4PartWrapper.E4_WRAPPER_KEY) instanceof E4PartWrapper) { IWorkbenchPart workbenchPart = (IWorkbenchPart) part.getTransientData() .get(E4PartWrapper.E4_WRAPPER_KEY); if (targeted) { notifyListeners(workbenchPart, (ISelection) selection, part.getElementId(), targetedPostSelectionListeners); } else { notifyListeners(workbenchPart, (ISelection) selection, postSelectionListeners); } } } }
private ActionDescriptor getDescriptor(IEclipseContext context) { switch (type) { case ActionDescriptor.T_WORKBENCH: IWorkbenchWindow window = context.get(IWorkbenchWindow.class); return window == null ? null : new ActionDescriptor(element, type, window); case ActionDescriptor.T_EDITOR: return new ActionDescriptor(element, type, null); case ActionDescriptor.T_VIEW: MPart part = context.get(MPart.class); if (part != null) { Object object = part.getObject(); if (object instanceof CompatibilityPart) { return new ActionDescriptor(element, type, ((CompatibilityPart) object).getPart()); } } return null; default: return null; } }
private IServiceLocator getServiceLocator(EObject object) { if (object instanceof MPart) { CompatibilityPart part = (CompatibilityPart) ((MPart) object).getObject(); return part.getReference().getSite(); } else if (object instanceof MWindow) { IWorkbenchWindow workbenchWindow = ((MWindow) object).getContext().get( IWorkbenchWindow.class); if (workbenchWindow != null) { return workbenchWindow; } } else if (object instanceof MApplication || object == null) { return PlatformUI.getWorkbench(); } return getServiceLocator(object.eContainer()); }
private void updateActivations(MPart part) { if (activationList.size() > 1) { deactivateLastEditor(part); } activationList.remove(part); activationList.add(0, part); updateActivePartSources(part); updateActiveEditorSources(part); Object client = part.getObject(); if (client instanceof CompatibilityPart) { IWorkbenchPart workbenchPart = getWrappedPart((CompatibilityPart) client); if (workbenchPart != null) { PartSite site = (PartSite) workbenchPart.getSite(); site.activateActionBars(true); IActionBars actionBars = site.getActionBars(); if (actionBars instanceof EditorActionBars) { ((EditorActionBars) actionBars).partChanged(workbenchPart); } } } ((WorkbenchWindow) getWorkbenchWindow()).getStatusLineManager().update(false); IWorkbenchPart workbenchPart = getWorkbenchPart(part); actionSwitcher.updateActivePart(workbenchPart); }
@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; }