diff options
Diffstat (limited to 'bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPartReference.java')
-rw-r--r-- | bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPartReference.java | 501 |
1 files changed, 250 insertions, 251 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPartReference.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPartReference.java index fe02abece8b..66313b7f06a 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPartReference.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPartReference.java @@ -60,94 +60,95 @@ import org.osgi.service.event.EventHandler; public abstract class WorkbenchPartReference implements IWorkbenchPartReference, ISizeProvider { /** - * Internal property ID: Indicates that the underlying part was created - */ - public static final int INTERNAL_PROPERTY_OPENED = 0x211; - - /** - * Internal property ID: Indicates that the underlying part was destroyed - */ - public static final int INTERNAL_PROPERTY_CLOSED = 0x212; - - /** - * Internal property ID: Indicates that the result of IEditorReference.isPinned() - */ - public static final int INTERNAL_PROPERTY_PINNED = 0x213; - - /** - * Internal property ID: Indicates that the result of getVisible() has changed - */ - public static final int INTERNAL_PROPERTY_VISIBLE = 0x214; - - /** - * Internal property ID: Indicates that the result of isZoomed() has changed - */ - public static final int INTERNAL_PROPERTY_ZOOMED = 0x215; - - /** - * Internal property ID: Indicates that the part has an active child and the - * active child has changed. (fired by PartStack) - */ - public static final int INTERNAL_PROPERTY_ACTIVE_CHILD_CHANGED = 0x216; - - /** - * Internal property ID: Indicates that changed in the min / max - * state has changed - */ - public static final int INTERNAL_PROPERTY_MAXIMIZED = 0x217; - - // State constants ////////////////////////////// - - /** - * State constant indicating that the part is not created yet - */ - public static int STATE_LAZY = 0; - - /** - * State constant indicating that the part is in the process of being created - */ - public static int STATE_CREATION_IN_PROGRESS = 1; - - /** - * State constant indicating that the part has been created - */ - public static int STATE_CREATED = 2; - - /** - * State constant indicating that the reference has been disposed (the reference shouldn't be - * used anymore) - */ - public static int STATE_DISPOSED = 3; + * Internal property ID: Indicates that the underlying part was created + */ + public static final int INTERNAL_PROPERTY_OPENED = 0x211; + + /** + * Internal property ID: Indicates that the underlying part was destroyed + */ + public static final int INTERNAL_PROPERTY_CLOSED = 0x212; + + /** + * Internal property ID: Indicates that the result of + * IEditorReference.isPinned() + */ + public static final int INTERNAL_PROPERTY_PINNED = 0x213; + + /** + * Internal property ID: Indicates that the result of getVisible() has changed + */ + public static final int INTERNAL_PROPERTY_VISIBLE = 0x214; + + /** + * Internal property ID: Indicates that the result of isZoomed() has changed + */ + public static final int INTERNAL_PROPERTY_ZOOMED = 0x215; + + /** + * Internal property ID: Indicates that the part has an active child and the + * active child has changed. (fired by PartStack) + */ + public static final int INTERNAL_PROPERTY_ACTIVE_CHILD_CHANGED = 0x216; + + /** + * Internal property ID: Indicates that changed in the min / max state has + * changed + */ + public static final int INTERNAL_PROPERTY_MAXIMIZED = 0x217; + + // State constants ////////////////////////////// + + /** + * State constant indicating that the part is not created yet + */ + public static int STATE_LAZY = 0; + + /** + * State constant indicating that the part is in the process of being created + */ + public static int STATE_CREATION_IN_PROGRESS = 1; + + /** + * State constant indicating that the part has been created + */ + public static int STATE_CREATED = 2; + + /** + * State constant indicating that the reference has been disposed (the reference + * shouldn't be used anymore) + */ + public static int STATE_DISPOSED = 3; static String MEMENTO_KEY = "memento"; //$NON-NLS-1$ - /** - * Current state of the reference. Used to detect recursive creation errors, disposed - * references, etc. - */ - private int state = STATE_LAZY; + /** + * Current state of the reference. Used to detect recursive creation errors, + * disposed references, etc. + */ + private int state = STATE_LAZY; protected IWorkbenchPart legacyPart; - private boolean pinned = false; + private boolean pinned = false; - /** - * API listener list - */ + /** + * API listener list + */ private ListenerList<IPropertyListener> propChangeListeners = new ListenerList<>(); - /** - * Internal listener list. Listens to the INTERNAL_PROPERTY_* property change events that are not yet API. - * TODO: Make these properties API in 3.2 - */ + /** + * Internal listener list. Listens to the INTERNAL_PROPERTY_* property change + * events that are not yet API. TODO: Make these properties API in 3.2 + */ private ListenerList<IPropertyListener> internalPropChangeListeners = new ListenerList<>(); private ListenerList<IPropertyChangeListener> partChangeListeners = new ListenerList<>(); - protected Map propertyCache = new HashMap(); + protected Map propertyCache = new HashMap(); - private IPropertyListener propertyChangeListener = (source, propId) -> partPropertyChanged(source, propId); + private IPropertyListener propertyChangeListener = (source, propId) -> partPropertyChanged(source, propId); - private IPropertyChangeListener partPropertyChangeListener = event -> partPropertyChanged(event); + private IPropertyChangeListener partPropertyChangeListener = event -> partPropertyChanged(event); private IWorkbenchPage page; @@ -157,8 +158,8 @@ public abstract class WorkbenchPartReference implements IWorkbenchPartReference, private EventHandler contextEventHandler; - public WorkbenchPartReference(IEclipseContext windowContext, IWorkbenchPage page, MPart part) { - this.windowContext = windowContext; + public WorkbenchPartReference(IEclipseContext windowContext, IWorkbenchPage page, MPart part) { + this.windowContext = windowContext; this.page = page; this.part = part; @@ -189,8 +190,7 @@ public abstract class WorkbenchPartReference implements IWorkbenchPartReference, public void subscribe() { IEventBroker broker = windowContext.get(IEventBroker.class); - broker.subscribe(UIEvents.Context.TOPIC_CONTEXT, - createContextEventHandler()); + broker.subscribe(UIEvents.Context.TOPIC_CONTEXT, createContextEventHandler()); } public void unsubscribe() { @@ -201,87 +201,88 @@ public abstract class WorkbenchPartReference implements IWorkbenchPartReference, } } - public boolean isDisposed() { - return state == STATE_DISPOSED; - } + public boolean isDisposed() { + return state == STATE_DISPOSED; + } - protected void checkReference() { - if (state == STATE_DISPOSED) { - throw new RuntimeException("Error: IWorkbenchPartReference disposed"); //$NON-NLS-1$ - } - } + protected void checkReference() { + if (state == STATE_DISPOSED) { + throw new RuntimeException("Error: IWorkbenchPartReference disposed"); //$NON-NLS-1$ + } + } public MPart getModel() { return part; } - - protected void partPropertyChanged(Object source, int propId) { + protected void partPropertyChanged(Object source, int propId) { firePropertyChange(propId); - // Let the model manager know as well - if (propId == IWorkbenchPartConstants.PROP_DIRTY) { - IWorkbenchPart actualPart = getPart(false); - if (actualPart != null) { - SaveablesList modelManager = (SaveablesList) actualPart.getSite().getService(ISaveablesLifecycleListener.class); - modelManager.dirtyChanged(actualPart); - } - } - } - - protected void partPropertyChanged(PropertyChangeEvent event) { - firePartPropertyChange(event); - } - - /** - * Releases any references maintained by this part reference - * when its actual part becomes known (not called when it is disposed). - */ - protected void releaseReferences() { - - } - - /* package */ void addInternalPropertyListener(IPropertyListener listener) { - internalPropChangeListeners.add(listener); - } - - /* package */ void removeInternalPropertyListener(IPropertyListener listener) { - internalPropChangeListeners.remove(listener); - } - - protected void fireInternalPropertyChange(int id) { + // Let the model manager know as well + if (propId == IWorkbenchPartConstants.PROP_DIRTY) { + IWorkbenchPart actualPart = getPart(false); + if (actualPart != null) { + SaveablesList modelManager = (SaveablesList) actualPart.getSite() + .getService(ISaveablesLifecycleListener.class); + modelManager.dirtyChanged(actualPart); + } + } + } + + protected void partPropertyChanged(PropertyChangeEvent event) { + firePartPropertyChange(event); + } + + /** + * Releases any references maintained by this part reference when its actual + * part becomes known (not called when it is disposed). + */ + protected void releaseReferences() { + + } + + /* package */ void addInternalPropertyListener(IPropertyListener listener) { + internalPropChangeListeners.add(listener); + } + + /* package */ void removeInternalPropertyListener(IPropertyListener listener) { + internalPropChangeListeners.remove(listener); + } + + protected void fireInternalPropertyChange(int id) { for (IPropertyListener listener : internalPropChangeListeners) { listener.propertyChanged(this, id); - } - } + } + } - /** - * @see IWorkbenchPart - */ - @Override + /** + * @see IWorkbenchPart + */ + @Override public void addPropertyListener(IPropertyListener listener) { - // The properties of a disposed reference will never change, so don't - // add listeners - if (isDisposed()) { - return; - } - - propChangeListeners.add(listener); - } - - /** - * @see IWorkbenchPart - */ - @Override - public void removePropertyListener(IPropertyListener listener) { - // Currently I'm not calling checkReference here for fear of breaking things late in 3.1, but it may - // make sense to do so later. For now we just turn it into a NOP if the reference is disposed. - if (isDisposed()) { - return; - } - propChangeListeners.remove(listener); - } + // The properties of a disposed reference will never change, so don't + // add listeners + if (isDisposed()) { + return; + } + propChangeListeners.add(listener); + } + + /** + * @see IWorkbenchPart + */ + @Override + public void removePropertyListener(IPropertyListener listener) { + // Currently I'm not calling checkReference here for fear of breaking things + // late in 3.1, but it may + // make sense to do so later. For now we just turn it into a NOP if the + // reference is disposed. + if (isDisposed()) { + return; + } + propChangeListeners.remove(listener); + } @Override public String getTitle() { @@ -291,8 +292,7 @@ public abstract class WorkbenchPartReference implements IWorkbenchPartReference, @Override public String getTitleToolTip() { - String toolTip = (String) part.getTransientData().get( - IPresentationEngine.OVERRIDE_TITLE_TOOL_TIP_KEY); + String toolTip = (String) part.getTransientData().get(IPresentationEngine.OVERRIDE_TITLE_TOOL_TIP_KEY); if (toolTip == null || toolTip.length() == 0) toolTip = part.getLocalizedTooltip(); return Util.safeString(toolTip); @@ -307,23 +307,25 @@ public abstract class WorkbenchPartReference implements IWorkbenchPartReference, return colonIndex == -1 ? id : id.substring(0, colonIndex); } - /** - * Computes a new title for the part. Subclasses may override to change the default behavior. - * - * @return the title for the part - */ - protected String computeTitle() { - return getRawTitle(); - } - - /** - * Returns the unmodified title for the part, or the empty string if none - * - * @return the unmodified title, as set by the IWorkbenchPart. Returns the empty string if none. - */ - protected final String getRawTitle() { + /** + * Computes a new title for the part. Subclasses may override to change the + * default behavior. + * + * @return the title for the part + */ + protected String computeTitle() { + return getRawTitle(); + } + + /** + * Returns the unmodified title for the part, or the empty string if none + * + * @return the unmodified title, as set by the IWorkbenchPart. Returns the empty + * string if none. + */ + protected final String getRawTitle() { return Util.safeString(legacyPart.getTitle()); - } + } @Override public final Image getTitleImage() { @@ -331,8 +333,7 @@ public abstract class WorkbenchPartReference implements IWorkbenchPartReference, return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_DEF_VIEW); } - WorkbenchWindow wbw = (WorkbenchWindow) PlatformUI.getWorkbench() - .getActiveWorkbenchWindow(); + WorkbenchWindow wbw = (WorkbenchWindow) PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (part != null && wbw.getModel().getRenderer() instanceof SWTPartRenderer) { SWTPartRenderer r = (SWTPartRenderer) wbw.getModel().getRenderer(); Image image = r.getImage(part); @@ -344,26 +345,26 @@ public abstract class WorkbenchPartReference implements IWorkbenchPartReference, return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_DEF_VIEW); } - /* package */ void fireVisibilityChange() { - fireInternalPropertyChange(INTERNAL_PROPERTY_VISIBLE); - } + /* package */ void fireVisibilityChange() { + fireInternalPropertyChange(INTERNAL_PROPERTY_VISIBLE); + } - /* package */ void fireZoomChange() { - fireInternalPropertyChange(INTERNAL_PROPERTY_ZOOMED); - } + /* package */ void fireZoomChange() { + fireInternalPropertyChange(INTERNAL_PROPERTY_ZOOMED); + } protected void firePropertyChange(int id) { - immediateFirePropertyChange(id); - } + immediateFirePropertyChange(id); + } - private void immediateFirePropertyChange(int id) { - UIListenerLogging.logPartReferencePropertyChange(this, id); + private void immediateFirePropertyChange(int id) { + UIListenerLogging.logPartReferencePropertyChange(this, id); for (IPropertyListener listener : propChangeListeners) { listener.propertyChanged(legacyPart, id); - } + } - fireInternalPropertyChange(id); - } + fireInternalPropertyChange(id); + } public abstract PartSite getSite(); @@ -375,20 +376,19 @@ public abstract class WorkbenchPartReference implements IWorkbenchPartReference, workbenchPart.addPropertyListener(propertyChangeListener); if (workbenchPart instanceof IWorkbenchPart3) { - ((IWorkbenchPart3) workbenchPart) - .addPartPropertyListener(partPropertyChangeListener); + ((IWorkbenchPart3) workbenchPart).addPartPropertyListener(partPropertyChangeListener); } } } - @Override + @Override public final IWorkbenchPart getPart(boolean restore) { - if (isDisposed()) { - return null; - } + if (isDisposed()) { + return null; + } - if (legacyPart == null) { + if (legacyPart == null) { if (restore && part.getWidget() == null) { // create the underlying client object backed by the part model // with the rendering engine @@ -407,14 +407,14 @@ public abstract class WorkbenchPartReference implements IWorkbenchPartReference, legacyPart = compatibilityPart.getPart(); } } else if (part.getObject() != null) { - if (part.getTransientData().get(E4PartWrapper.E4_WRAPPER_KEY) instanceof E4PartWrapper) { - return (IWorkbenchPart) part.getTransientData().get(E4PartWrapper.E4_WRAPPER_KEY); + if (part.getTransientData().get(E4PartWrapper.E4_WRAPPER_KEY) instanceof E4PartWrapper) { + return (IWorkbenchPart) part.getTransientData().get(E4PartWrapper.E4_WRAPPER_KEY); } - } + } } return legacyPart; - } + } public abstract IWorkbenchPart createPart() throws PartInitException; @@ -426,85 +426,84 @@ public abstract class WorkbenchPartReference implements IWorkbenchPartReference, // To be implemented by subclasses } - /** - * - */ + /** + * + */ private void doDisposePart() { if (legacyPart != null) { - fireInternalPropertyChange(INTERNAL_PROPERTY_CLOSED); - // Don't let exceptions in client code bring us down. Log them and continue. - try { + fireInternalPropertyChange(INTERNAL_PROPERTY_CLOSED); + // Don't let exceptions in client code bring us down. Log them and continue. + try { legacyPart.removePropertyListener(propertyChangeListener); if (legacyPart instanceof IWorkbenchPart3) { - ((IWorkbenchPart3) legacyPart) - .removePartPropertyListener(partPropertyChangeListener); - } - } catch (Exception e) { - WorkbenchPlugin.log(e); - } + ((IWorkbenchPart3) legacyPart).removePartPropertyListener(partPropertyChangeListener); + } + } catch (Exception e) { + WorkbenchPlugin.log(e); + } legacyPart = null; - } - } + } + } - public void setPinned(boolean newPinned) { - if (isDisposed()) { - return; - } + public void setPinned(boolean newPinned) { + if (isDisposed()) { + return; + } - if (newPinned == pinned) { - return; - } + if (newPinned == pinned) { + return; + } - pinned = newPinned; + pinned = newPinned; immediateFirePropertyChange(IWorkbenchPartConstants.PROP_TITLE); - if (pinned) - part.getTags().add(IPresentationEngine.ADORNMENT_PIN); - else - part.getTags().remove(IPresentationEngine.ADORNMENT_PIN); + if (pinned) + part.getTags().add(IPresentationEngine.ADORNMENT_PIN); + else + part.getTags().remove(IPresentationEngine.ADORNMENT_PIN); - fireInternalPropertyChange(INTERNAL_PROPERTY_PINNED); - } + fireInternalPropertyChange(INTERNAL_PROPERTY_PINNED); + } - public boolean isPinned() { - return pinned; - } + public boolean isPinned() { + return pinned; + } - @Override + @Override public String getPartProperty(String key) { if (legacyPart != null) { if (legacyPart instanceof IWorkbenchPart3) { return ((IWorkbenchPart3) legacyPart).getPartProperty(key); } } else { - return (String)propertyCache.get(key); + return (String) propertyCache.get(key); } return null; } - @Override + @Override public void addPartPropertyListener(IPropertyChangeListener listener) { - if (isDisposed()) { - return; - } - partChangeListeners.add(listener); - } + if (isDisposed()) { + return; + } + partChangeListeners.add(listener); + } - @Override + @Override public void removePartPropertyListener(IPropertyChangeListener listener) { - if (isDisposed()) { - return; - } - partChangeListeners.remove(listener); - } + if (isDisposed()) { + return; + } + partChangeListeners.remove(listener); + } - protected void firePartPropertyChange(PropertyChangeEvent event) { + protected void firePartPropertyChange(PropertyChangeEvent event) { for (IPropertyChangeListener l : partChangeListeners) { l.propertyChange(event); } } - protected void createPartProperties(IWorkbenchPart3 workbenchPart) { + protected void createPartProperties(IWorkbenchPart3 workbenchPart) { Iterator i = propertyCache.entrySet().iterator(); while (i.hasNext()) { Map.Entry e = (Map.Entry) i.next(); @@ -512,26 +511,26 @@ public abstract class WorkbenchPartReference implements IWorkbenchPartReference, } } - @Override - public int computePreferredSize(boolean width, int availableParallel, - int availablePerpendicular, int preferredResult) { + @Override + public int computePreferredSize(boolean width, int availableParallel, int availablePerpendicular, + int preferredResult) { ISizeProvider sizeProvider = Adapters.adapt(legacyPart, ISizeProvider.class); - if (sizeProvider != null) { - return sizeProvider.computePreferredSize(width, availableParallel, availablePerpendicular, preferredResult); - } + if (sizeProvider != null) { + return sizeProvider.computePreferredSize(width, availableParallel, availablePerpendicular, preferredResult); + } - return preferredResult; - } + return preferredResult; + } - @Override + @Override public int getSizeFlags(boolean width) { ISizeProvider sizeProvider = Adapters.adapt(legacyPart, ISizeProvider.class); - if (sizeProvider != null) { - return sizeProvider.getSizeFlags(width); - } - return 0; - } + if (sizeProvider != null) { + return sizeProvider.getSizeFlags(width); + } + return 0; + } @Override public IWorkbenchPage getPage() { |