Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 56997 Details for
Bug 89834
[Presentations] Allow for unanticipated parameters for part appearance and behavior
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
part Properties v04
properties-v04.txt (text/plain), 54.75 KB, created by
Paul Webster
on 2007-01-16 22:09:59 EST
(
hide
)
Description:
part Properties v04
Filename:
MIME Type:
Creator:
Paul Webster
Created:
2007-01-16 22:09:59 EST
Size:
54.75 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ui.workbench >Index: Eclipse UI/org/eclipse/ui/internal/EditorReference.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/EditorReference.java,v >retrieving revision 1.21 >diff -u -r1.21 EditorReference.java >--- Eclipse UI/org/eclipse/ui/internal/EditorReference.java 20 Dec 2006 15:16:47 -0000 1.21 >+++ Eclipse UI/org/eclipse/ui/internal/EditorReference.java 17 Jan 2007 02:59:45 -0000 >@@ -33,6 +33,7 @@ > import org.eclipse.ui.IWorkbenchPage; > import org.eclipse.ui.IWorkbenchPart; > import org.eclipse.ui.IWorkbenchPart2; >+import org.eclipse.ui.IWorkbenchPart3; > import org.eclipse.ui.IWorkbenchPartConstants; > import org.eclipse.ui.PartInitException; > import org.eclipse.ui.PlatformUI; >@@ -140,7 +141,16 @@ > String partName = memento > .getString(IWorkbenchConstants.TAG_PART_NAME); > >- // For compatibility set the part name to the title if not found >+ IMemento propBag = memento.getChild(IWorkbenchConstants.TAG_PROPERTIES); >+ if (propBag != null) { >+ IMemento[] props = propBag >+ .getChildren(IWorkbenchConstants.TAG_PROPERTY); >+ for (int i = 0; i < props.length; i++) { >+ propertyCache.put(props[i].getID(), props[i].getTextData()); >+ } >+ } >+ >+ // For compatibility set the part name to the title if not found > if (partName == null) { > partName = title; > } >@@ -592,6 +602,9 @@ > multiEditorChildren = manager.openMultiEditor(this, > (MultiEditor) part, (MultiEditorInput) editorInput); > } >+ if (part instanceof IWorkbenchPart3) { >+ createPartProperties((IWorkbenchPart3)part); >+ } > } finally { > UIStats.end(UIStats.CREATE_PART, this, editorID); > } >Index: Eclipse UI/org/eclipse/ui/internal/IWorkbenchConstants.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/IWorkbenchConstants.java,v >retrieving revision 1.75 >diff -u -r1.75 IWorkbenchConstants.java >--- Eclipse UI/org/eclipse/ui/internal/IWorkbenchConstants.java 10 Nov 2006 12:51:44 -0000 1.75 >+++ Eclipse UI/org/eclipse/ui/internal/IWorkbenchConstants.java 17 Jan 2007 02:59:45 -0000 >@@ -120,6 +120,10 @@ > > public static final String TAG_PART_NAME = "partName"; //$NON-NLS-1$ > >+ public static final String TAG_PROPERTIES = "properties"; //$NON-NLS-1$ >+ >+ public static final String TAG_PROPERTY = "property"; //$NON-NLS-1$ >+ > public static final String TAG_PART_TRIMSTATE = "inTrim"; //$NON-NLS-1$ > > public static final String TAG_RELATIVE = "relative"; //$NON-NLS-1$ >Index: Eclipse UI/org/eclipse/ui/internal/ViewFactory.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ViewFactory.java,v >retrieving revision 1.59 >diff -u -r1.59 ViewFactory.java >--- Eclipse UI/org/eclipse/ui/internal/ViewFactory.java 8 May 2006 20:55:34 -0000 1.59 >+++ Eclipse UI/org/eclipse/ui/internal/ViewFactory.java 17 Jan 2007 02:59:46 -0000 >@@ -11,12 +11,14 @@ > package org.eclipse.ui.internal; > > import java.util.HashMap; >+import java.util.Iterator; > import java.util.List; >+import java.util.Map; > > import org.eclipse.core.runtime.IExtension; > import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.MultiStatus; >-import org.eclipse.core.runtime.Platform; >+import org.eclipse.core.runtime.SafeRunner; > import org.eclipse.core.runtime.Status; > import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler; > import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker; >@@ -25,6 +27,7 @@ > import org.eclipse.ui.IMemento; > import org.eclipse.ui.IViewPart; > import org.eclipse.ui.IViewReference; >+import org.eclipse.ui.IWorkbenchPart3; > import org.eclipse.ui.PartInitException; > import org.eclipse.ui.PlatformUI; > import org.eclipse.ui.views.IViewDescriptor; >@@ -301,8 +304,24 @@ > final IViewReference viewRef = ref; > final IViewPart view = (IViewPart) ref.getPart(false); > if (view != null) { >- Platform.run(new SafeRunnable() { >+ SafeRunner.run(new SafeRunnable() { > public void run() { >+ if (view instanceof IWorkbenchPart3) { >+ Map properties = ((IWorkbenchPart3) view) >+ .getPartProperties(); >+ if (!properties.isEmpty()) { >+ IMemento propBag = viewMemento >+ .createChild(IWorkbenchConstants.TAG_PROPERTIES); >+ Iterator i = properties.entrySet().iterator(); >+ while (i.hasNext()) { >+ Map.Entry entry = (Map.Entry) i.next(); >+ IMemento p = propBag.createChild( >+ IWorkbenchConstants.TAG_PROPERTY, >+ (String) entry.getKey()); >+ p.putTextData((String) entry.getValue()); >+ } >+ } >+ } > view.saveState(viewMemento > .createChild(IWorkbenchConstants.TAG_VIEW_STATE)); > } >@@ -319,6 +338,7 @@ > }); > } else { > IMemento mem = null; >+ IMemento props = null; > > // if we've created the reference once, any previous workbench > // state memento is there. After once, there is no previous >@@ -326,9 +346,16 @@ > if (ref instanceof ViewReference) { > mem = ((ViewReference) ref).getMemento(); > if (mem!=null) { >+ props = mem.getChild(IWorkbenchConstants.TAG_PROPERTIES); >+ } >+ if (mem!=null) { > mem = mem.getChild(IWorkbenchConstants.TAG_VIEW_STATE); > } > } >+ if (props != null) { >+ viewMemento.createChild(IWorkbenchConstants.TAG_PROPERTIES) >+ .putMemento(props); >+ } > if (mem != null) { > IMemento child = viewMemento > .createChild(IWorkbenchConstants.TAG_VIEW_STATE); >Index: Eclipse UI/org/eclipse/ui/internal/EditorManager.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/EditorManager.java,v >retrieving revision 1.124 >diff -u -r1.124 EditorManager.java >--- Eclipse UI/org/eclipse/ui/internal/EditorManager.java 12 Jan 2007 20:21:37 -0000 1.124 >+++ Eclipse UI/org/eclipse/ui/internal/EditorManager.java 17 Jan 2007 02:59:44 -0000 >@@ -77,6 +77,7 @@ > import org.eclipse.ui.IViewPart; > import org.eclipse.ui.IWorkbenchPage; > import org.eclipse.ui.IWorkbenchPart; >+import org.eclipse.ui.IWorkbenchPart3; > import org.eclipse.ui.IWorkbenchPartReference; > import org.eclipse.ui.IWorkbenchWindow; > import org.eclipse.ui.PartInitException; >@@ -1600,6 +1601,23 @@ > > editorMem.putString(IWorkbenchConstants.TAG_PART_NAME, > editorRef.getPartName()); >+ >+ if (editor instanceof IWorkbenchPart3) { >+ Map properties = ((IWorkbenchPart3) editor) >+ .getPartProperties(); >+ if (!properties.isEmpty()) { >+ IMemento propBag = editorMem >+ .createChild(IWorkbenchConstants.TAG_PROPERTIES); >+ Iterator i = properties.entrySet().iterator(); >+ while (i.hasNext()) { >+ Map.Entry entry = (Map.Entry) i.next(); >+ IMemento p = propBag.createChild( >+ IWorkbenchConstants.TAG_PROPERTY, >+ (String) entry.getKey()); >+ p.putTextData((String) entry.getValue()); >+ } >+ } >+ } > > if (editorRef.isPinned()) { > editorMem.putString(IWorkbenchConstants.TAG_PINNED, "true"); //$NON-NLS-1$ >Index: Eclipse UI/org/eclipse/ui/internal/ViewReference.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ViewReference.java,v >retrieving revision 1.18 >diff -u -r1.18 ViewReference.java >--- Eclipse UI/org/eclipse/ui/internal/ViewReference.java 6 Dec 2006 21:14:55 -0000 1.18 >+++ Eclipse UI/org/eclipse/ui/internal/ViewReference.java 17 Jan 2007 02:59:46 -0000 >@@ -27,6 +27,7 @@ > import org.eclipse.ui.IWorkbenchPage; > import org.eclipse.ui.IWorkbenchPart; > import org.eclipse.ui.IWorkbenchPart2; >+import org.eclipse.ui.IWorkbenchPart3; > import org.eclipse.ui.PartInitException; > import org.eclipse.ui.PlatformUI; > import org.eclipse.ui.internal.misc.StatusUtil; >@@ -67,6 +68,14 @@ > > if (memento != null) { > name = memento.getString(IWorkbenchConstants.TAG_PART_NAME); >+ IMemento propBag = memento.getChild(IWorkbenchConstants.TAG_PROPERTIES); >+ if (propBag != null) { >+ IMemento[] props = propBag >+ .getChildren(IWorkbenchConstants.TAG_PROPERTY); >+ for (int i = 0; i < props.length; i++) { >+ propertyCache.put(props[i].getID(), props[i].getTextData()); >+ } >+ } > } > if (name == null) { > name = title; >@@ -307,6 +316,9 @@ > UIStats.end(UIStats.CREATE_PART, view, label); > } > >+ if (view instanceof IWorkbenchPart3) { >+ createPartProperties((IWorkbenchPart3)view); >+ } > // Create site > site = new ViewSite(this, view, factory.page, desc); > actionBars = new ViewActionBars(factory.page.getActionBars(), site, >Index: Eclipse UI/org/eclipse/ui/internal/WorkbenchPartReference.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPartReference.java,v >retrieving revision 1.43 >diff -u -r1.43 WorkbenchPartReference.java >--- Eclipse UI/org/eclipse/ui/internal/WorkbenchPartReference.java 20 Dec 2006 02:38:11 -0000 1.43 >+++ Eclipse UI/org/eclipse/ui/internal/WorkbenchPartReference.java 17 Jan 2007 02:59:47 -0000 >@@ -11,12 +11,17 @@ > package org.eclipse.ui.internal; > > import java.util.BitSet; >+import java.util.HashMap; >+import java.util.Iterator; >+import java.util.Map; > > import org.eclipse.core.runtime.Assert; > import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.ListenerList; > import org.eclipse.jface.resource.ImageDescriptor; > import org.eclipse.jface.resource.JFaceResources; >+import org.eclipse.jface.util.IPropertyChangeListener; >+import org.eclipse.jface.util.PropertyChangeEvent; > import org.eclipse.osgi.util.NLS; > import org.eclipse.swt.events.DisposeEvent; > import org.eclipse.swt.events.DisposeListener; >@@ -29,6 +34,7 @@ > import org.eclipse.ui.ISharedImages; > import org.eclipse.ui.IWorkbenchPart; > import org.eclipse.ui.IWorkbenchPart2; >+import org.eclipse.ui.IWorkbenchPart3; > import org.eclipse.ui.IWorkbenchPartConstants; > import org.eclipse.ui.IWorkbenchPartReference; > import org.eclipse.ui.IWorkbenchPartSite; >@@ -137,10 +143,14 @@ > */ > private ListenerList internalPropChangeListeners = new ListenerList(); > >+ private ListenerList partChangeListeners = new ListenerList(); >+ > private String partName; > > private String contentDescription; > >+ protected Map propertyCache = new HashMap(); >+ > /** > * Used to remember which events have been queued. > */ >@@ -163,6 +173,12 @@ > } > }; > >+ private IPropertyChangeListener partPropertyChangeListener = new IPropertyChangeListener() { >+ public void propertyChange(PropertyChangeEvent event) { >+ partPropertyChanged(event); >+ } >+ }; >+ > public WorkbenchPartReference() { > //no-op > } >@@ -283,6 +299,10 @@ > } > } > } >+ >+ protected void partPropertyChanged(PropertyChangeEvent event) { >+ firePartPropertyChange(event); >+ } > > /** > * Refreshes all cached values with the values from the real part >@@ -571,6 +591,9 @@ > // object that should dispose this control, and it will remove the listener before it does so. > getPane().getControl().addDisposeListener(prematureDisposeListener); > part.addPropertyListener(propertyChangeListener); >+ if (part instanceof IWorkbenchPart3) { >+ ((IWorkbenchPart3)part).addPartPropertyListener(partPropertyChangeListener); >+ } > > refreshFromPart(); > releaseReferences(); >@@ -646,6 +669,7 @@ > } > > clearListenerList(internalPropChangeListeners); >+ clearListenerList(partChangeListeners); > Image oldImage = image; > ImageDescriptor oldDescriptor = imageDescriptor; > image = null; >@@ -684,6 +708,9 @@ > // Don't let exceptions in client code bring us down. Log them and continue. > try { > part.removePropertyListener(propertyChangeListener); >+ if (part instanceof IWorkbenchPart3) { >+ ((IWorkbenchPart3)part).removePartPropertyListener(partPropertyChangeListener); >+ } > part.dispose(); > } catch (Exception e) { > WorkbenchPlugin.log(e); >@@ -712,4 +739,52 @@ > return pinned; > } > >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.IWorkbenchPartReference#getPartProperty(java.lang.String) >+ */ >+ public String getPartProperty(String key) { >+ if (part != null) { >+ if (part instanceof IWorkbenchPart3) { >+ return ((IWorkbenchPart3) part).getPartProperty(key); >+ } >+ } else { >+ return (String)propertyCache.get(key); >+ } >+ return null; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.IWorkbenchPartReference#addPartPropertyListener(org.eclipse.jface.util.IPropertyChangeListener) >+ */ >+ public void addPartPropertyListener(IPropertyChangeListener listener) { >+ if (isDisposed()) { >+ return; >+ } >+ partChangeListeners.add(listener); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.IWorkbenchPartReference#removePartPropertyListener(org.eclipse.jface.util.IPropertyChangeListener) >+ */ >+ public void removePartPropertyListener(IPropertyChangeListener listener) { >+ if (isDisposed()) { >+ return; >+ } >+ partChangeListeners.remove(listener); >+ } >+ >+ protected void firePartPropertyChange(PropertyChangeEvent event) { >+ Object[] l = partChangeListeners.getListeners(); >+ for (int i = 0; i < l.length; i++) { >+ ((IPropertyChangeListener) l[i]).propertyChange(event); >+ } >+ } >+ >+ protected void createPartProperties(IWorkbenchPart3 workbenchPart) { >+ Iterator i = propertyCache.entrySet().iterator(); >+ while (i.hasNext()) { >+ Map.Entry e = (Map.Entry) i.next(); >+ workbenchPart.setPartProperty((String) e.getKey(), (String) e.getValue()); >+ } >+ } > } >Index: Eclipse UI/org/eclipse/ui/internal/PartPane.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/PartPane.java,v >retrieving revision 1.86 >diff -u -r1.86 PartPane.java >--- Eclipse UI/org/eclipse/ui/internal/PartPane.java 11 Dec 2006 04:39:37 -0000 1.86 >+++ Eclipse UI/org/eclipse/ui/internal/PartPane.java 17 Jan 2007 02:59:45 -0000 >@@ -12,6 +12,8 @@ > > import org.eclipse.core.runtime.ListenerList; > import org.eclipse.jface.action.MenuManager; >+import org.eclipse.jface.util.IPropertyChangeListener; >+import org.eclipse.jface.util.PropertyChangeEvent; > import org.eclipse.swt.SWT; > import org.eclipse.swt.events.FocusAdapter; > import org.eclipse.swt.events.FocusEvent; >@@ -50,7 +52,8 @@ > * LayoutPart and downcasting. The getPresentablePart() method only applies to PartPanes, and > * should be removed from LayoutPart. > */ >-public abstract class PartPane extends LayoutPart implements IPropertyListener, Listener { >+public abstract class PartPane extends LayoutPart implements IPropertyListener, >+ Listener, IPropertyChangeListener { > > public static final String PROP_ZOOMED = "zoomed"; //$NON-NLS-1$ > >@@ -58,6 +61,7 @@ > > private MenuManager paneMenuManager; > private ListenerList listeners = new ListenerList(); >+ private ListenerList partListeners = new ListenerList(); > > protected IWorkbenchPartReference partReference; > >@@ -135,6 +139,7 @@ > } > > partReference.addPropertyListener(this); >+ partReference.addPartPropertyListener(this); > // Create view form. > control = new Composite(parent, SWT.NONE); > control.setLayout(new FillLayout()); >@@ -176,6 +181,7 @@ > } > > partReference.removePropertyListener(this); >+ partReference.removePartPropertyListener(this); > } > > /** >@@ -600,8 +606,30 @@ > ((IPropertyListener) listeners[i]).propertyChanged(this, propertyId); > } > } >- >+ > public void propertyChanged(Object source, int propId) { > firePropertyChange(propId); > } >+ >+ public void addPartPropertyListener(IPropertyChangeListener listener) { >+ partListeners.add(listener); >+ } >+ >+ public void removePartPropertyListener(IPropertyChangeListener listener) { >+ partListeners.remove(listener); >+ } >+ >+ public void firePartPropertyChange(PropertyChangeEvent event) { >+ Object[] l = partListeners.getListeners(); >+ for (int i = 0; i < l.length; i++) { >+ ((IPropertyChangeListener)l[i]).propertyChange(event); >+ } >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) >+ */ >+ public void propertyChange(PropertyChangeEvent event) { >+ firePartPropertyChange(event); >+ } > } >Index: Eclipse UI/org/eclipse/ui/part/WorkbenchPart.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/WorkbenchPart.java,v >retrieving revision 1.51 >diff -u -r1.51 WorkbenchPart.java >--- Eclipse UI/org/eclipse/ui/part/WorkbenchPart.java 11 Jan 2007 15:28:10 -0000 1.51 >+++ Eclipse UI/org/eclipse/ui/part/WorkbenchPart.java 17 Jan 2007 02:59:47 -0000 >@@ -10,22 +10,27 @@ > *******************************************************************************/ > package org.eclipse.ui.part; > >-import com.ibm.icu.text.MessageFormat; >+import java.util.Collections; >+import java.util.HashMap; >+import java.util.Map; > > import org.eclipse.core.commands.common.EventManager; > import org.eclipse.core.runtime.Assert; > import org.eclipse.core.runtime.IConfigurationElement; > import org.eclipse.core.runtime.IExecutableExtension; >+import org.eclipse.core.runtime.ListenerList; > import org.eclipse.core.runtime.Platform; > import org.eclipse.jface.resource.ImageDescriptor; > import org.eclipse.jface.resource.JFaceResources; >+import org.eclipse.jface.util.IPropertyChangeListener; >+import org.eclipse.jface.util.PropertyChangeEvent; > import org.eclipse.jface.window.Window; > import org.eclipse.swt.graphics.Image; > import org.eclipse.swt.widgets.Composite; > import org.eclipse.ui.IPropertyListener; > import org.eclipse.ui.ISharedImages; > import org.eclipse.ui.IWorkbenchPart; >-import org.eclipse.ui.IWorkbenchPart2; >+import org.eclipse.ui.IWorkbenchPart3; > import org.eclipse.ui.IWorkbenchPartConstants; > import org.eclipse.ui.IWorkbenchPartSite; > import org.eclipse.ui.PlatformUI; >@@ -34,6 +39,8 @@ > import org.eclipse.ui.internal.util.Util; > import org.eclipse.ui.plugin.AbstractUIPlugin; > >+import com.ibm.icu.text.MessageFormat; >+ > /** > * Abstract base implementation of all workbench parts. > * <p> >@@ -46,7 +53,7 @@ > * @see org.eclipse.ui.part.EditorPart > */ > public abstract class WorkbenchPart extends EventManager implements >- IWorkbenchPart2, IExecutableExtension, IWorkbenchPartOrientation { >+ IWorkbenchPart3, IExecutableExtension, IWorkbenchPartOrientation { > private String title = ""; //$NON-NLS-1$ > > private ImageDescriptor imageDescriptor; >@@ -62,6 +69,8 @@ > private String partName = ""; //$NON-NLS-1$ > > private String contentDescription = ""; //$NON-NLS-1$ >+ >+ private ListenerList partChangeListeners = new ListenerList(); > > /** > * Creates a new workbench part. >@@ -103,6 +112,7 @@ > // should not be notifying anyone after the part > // has been disposed. > clearListeners(); >+ partChangeListeners.clear(); > } > > /** >@@ -462,4 +472,58 @@ > return Window.getDefaultOrientation(); > } > >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.IWorkbenchPart3#addPartPropertyListener(org.eclipse.jface.util.IPropertyChangeListener) >+ */ >+ public void addPartPropertyListener(IPropertyChangeListener listener) { >+ partChangeListeners.add(listener); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.IWorkbenchPart3#removePartPropertyListener(org.eclipse.jface.util.IPropertyChangeListener) >+ */ >+ public void removePartPropertyListener(IPropertyChangeListener listener) { >+ partChangeListeners.remove(listener); >+ } >+ >+ protected void firePartPropertyChanged(String key, String oldValue, String newValue) { >+ final PropertyChangeEvent event = new PropertyChangeEvent(this, key, oldValue, newValue); >+ Object[] l = partChangeListeners.getListeners(); >+ for (int i = 0; i < l.length; i++) { >+ try { >+ ((IPropertyChangeListener)l[i]).propertyChange(event); >+ } catch (RuntimeException e) { >+ WorkbenchPlugin.log(e); >+ } >+ } >+ } >+ >+ private Map partProperties = new HashMap(); >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.IWorkbenchPart3#setPartProperty(java.lang.String, java.lang.String) >+ */ >+ public void setPartProperty(String key, String value) { >+ String oldValue = (String) partProperties.get(key); >+ if (value==null) { >+ partProperties.remove(key); >+ } else { >+ partProperties.put(key, value); >+ } >+ firePartPropertyChanged(key, oldValue, value); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.IWorkbenchPart3#getPartProperty(java.lang.String) >+ */ >+ public String getPartProperty(String key) { >+ return (String)partProperties.get(key); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.IWorkbenchPart3#getPartProperties() >+ */ >+ public Map getPartProperties() { >+ return Collections.unmodifiableMap(partProperties); >+ } > } >Index: Eclipse UI/org/eclipse/ui/IWorkbenchPartReference.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IWorkbenchPartReference.java,v >retrieving revision 1.13 >diff -u -r1.13 IWorkbenchPartReference.java >--- Eclipse UI/org/eclipse/ui/IWorkbenchPartReference.java 8 May 2006 20:55:31 -0000 1.13 >+++ Eclipse UI/org/eclipse/ui/IWorkbenchPartReference.java 17 Jan 2007 02:59:43 -0000 >@@ -11,6 +11,7 @@ > > package org.eclipse.ui; > >+import org.eclipse.jface.util.IPropertyChangeListener; > import org.eclipse.swt.graphics.Image; > > /** >@@ -93,4 +94,34 @@ > */ > public boolean isDirty(); > >+ /** >+ * Return an arbitrary property from the reference. If the part has been >+ * instantiated, it just delegates to the part. If not, then it looks in its >+ * own cache of properties. If the property is not available or the part has >+ * never been instantiated, it can return <code>null</code>. >+ * >+ * @param key >+ * The property to return. Must not be <code>null</code>. >+ * @return The String property, or <code>null</code>. >+ * @since 3.3 >+ */ >+ public String getPartProperty(String key); >+ >+ /** >+ * Add a listener for changes in the arbitrary properties set. >+ * >+ * @param listener >+ * Must not be <code>null</code>. >+ * @since 3.3 >+ */ >+ public void addPartPropertyListener(IPropertyChangeListener listener); >+ >+ /** >+ * Remove a listener for changes in the arbitrary properties set. >+ * >+ * @param listener >+ * Must not be <code>null</code>. >+ * @since 3.3 >+ */ >+ public void removePartPropertyListener(IPropertyChangeListener listener); > } >Index: Eclipse UI/org/eclipse/ui/internal/presentations/PresentablePart.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/presentations/PresentablePart.java,v >retrieving revision 1.10 >diff -u -r1.10 PresentablePart.java >--- Eclipse UI/org/eclipse/ui/internal/presentations/PresentablePart.java 24 Oct 2005 19:06:49 -0000 1.10 >+++ Eclipse UI/org/eclipse/ui/internal/presentations/PresentablePart.java 17 Jan 2007 02:59:47 -0000 >@@ -13,6 +13,9 @@ > import java.util.ArrayList; > import java.util.List; > >+import org.eclipse.core.runtime.ListenerList; >+import org.eclipse.jface.util.IPropertyChangeListener; >+import org.eclipse.jface.util.PropertyChangeEvent; > import org.eclipse.swt.graphics.Image; > import org.eclipse.swt.graphics.Point; > import org.eclipse.swt.graphics.Rectangle; >@@ -46,6 +49,10 @@ > > // Lazily initialized. Use getPropertyListenerProxy() to access. > private IPropertyListener lazyPropertyListenerProxy; >+ >+ private ListenerList partPropertyChangeListeners = new ListenerList(); >+ >+ private IPropertyChangeListener lazyPartPropertyChangeListener; > > // Lazily initialized. Use getMenu() to access > private IPartMenu viewMenu; >@@ -75,6 +82,7 @@ > public PresentablePart(PartPane part, Composite parent) { > this.part = part; > getPane().addPropertyListener(getPropertyListenerProxy()); >+ getPane().addPartPropertyListener(getPartPropertyListenerProxy()); > } > > public PartPane getPane() { >@@ -92,19 +100,35 @@ > > return lazyPropertyListenerProxy; > } >+ >+ private IPropertyChangeListener getPartPropertyListenerProxy() { >+ if (lazyPartPropertyChangeListener == null) { >+ lazyPartPropertyChangeListener = new IPropertyChangeListener() { >+ public void propertyChange(PropertyChangeEvent event) { >+ PropertyChangeEvent e = new PropertyChangeEvent(this, >+ event.getProperty(), event.getOldValue(), event.getNewValue()); >+ firePartPropertyChange(e); >+ } >+ }; >+ } >+ return lazyPartPropertyChangeListener; >+ } > > /** >- * Detach this PresentablePart from the real part. No further methods should be invoked >- * on this object. >- */ >+ * Detach this PresentablePart from the real part. No further methods should >+ * be invoked on this object. >+ */ > public void dispose() { > // Ensure that the property listener is detached (necessary to prevent leaks) > getPane().removePropertyListener(getPropertyListenerProxy()); >+ getPane().removePartPropertyListener(getPartPropertyListenerProxy()); > > // Null out the various fields to ease garbage collection (optional) > part = null; > listeners.clear(); > listeners = null; >+ partPropertyChangeListeners.clear(); >+ partPropertyChangeListeners = null; > } > > public void firePropertyChange(int propertyId) { >@@ -121,6 +145,21 @@ > listeners.remove(listener); > } > >+ protected void firePartPropertyChange(PropertyChangeEvent event) { >+ Object[] l = partPropertyChangeListeners.getListeners(); >+ for (int i = 0; i < l.length; i++) { >+ ((IPropertyChangeListener) l[i]).propertyChange(event); >+ } >+ } >+ >+ public void addPartPropertyListener(IPropertyChangeListener listener) { >+ partPropertyChangeListeners.add(listener); >+ } >+ >+ public void removePartPropertyListener(IPropertyChangeListener listener) { >+ partPropertyChangeListeners.remove(listener); >+ } >+ > /* (non-Javadoc) > * @see org.eclipse.ui.presentations.IPresentablePart#setBounds(org.eclipse.swt.graphics.Rectangle) > */ >@@ -351,4 +390,11 @@ > } > } > >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.presentations.IPresentablePart#getPartProperty(java.lang.String) >+ */ >+ public String getPartProperty(String key) { >+ return getPartReference().getPartProperty(key); >+ } >+ > } >Index: Eclipse UI/org/eclipse/ui/presentations/IPresentablePart.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/presentations/IPresentablePart.java,v >retrieving revision 1.19 >diff -u -r1.19 IPresentablePart.java >--- Eclipse UI/org/eclipse/ui/presentations/IPresentablePart.java 8 May 2006 20:55:49 -0000 1.19 >+++ Eclipse UI/org/eclipse/ui/presentations/IPresentablePart.java 17 Jan 2007 02:59:47 -0000 >@@ -10,6 +10,7 @@ > *******************************************************************************/ > package org.eclipse.ui.presentations; > >+import org.eclipse.jface.util.IPropertyChangeListener; > import org.eclipse.swt.graphics.Image; > import org.eclipse.swt.graphics.Rectangle; > import org.eclipse.swt.widgets.Control; >@@ -226,4 +227,43 @@ > */ > public Control getControl(); > >+ /** >+ * Get a property from the part's arbitrary property set. >+ * <p> >+ * <b>Note:</b> this is a different set of properties than the ones covered >+ * by the PROP_* constants. >+ * </p> >+ * >+ * @param key >+ * The property key to retrieve. Must not be <code>null</code>. >+ * @return the property, or <code>null</code> if that property is not set. >+ * @since 3.3 >+ */ >+ public String getPartProperty(String key); >+ >+ /** >+ * Add a listener for changes in the arbitrary properties set. >+ * <p> >+ * <b>Note:</b> this is a different set of properties than the ones covered >+ * by the PROP_* constants. >+ * </p> >+ * >+ * @param listener >+ * Must not be <code>null</code>. >+ * @since 3.3 >+ */ >+ public void addPartPropertyListener(IPropertyChangeListener listener); >+ >+ /** >+ * Remove a change listener from the arbitrary properties set. >+ * <p> >+ * <b>Note:</b> this is a different set of properties than the ones covered >+ * by the PROP_* constants. >+ * </p> >+ * >+ * @param listener >+ * Must not be <code>null</code>. >+ * @since 3.3 >+ */ >+ public void removePartPropertyListener(IPropertyChangeListener listener); > } >Index: Eclipse UI/org/eclipse/ui/IWorkbenchPart3.java >=================================================================== >RCS file: Eclipse UI/org/eclipse/ui/IWorkbenchPart3.java >diff -N Eclipse UI/org/eclipse/ui/IWorkbenchPart3.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI/org/eclipse/ui/IWorkbenchPart3.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,85 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.ui; >+ >+import java.util.Map; >+ >+import org.eclipse.jface.util.IPropertyChangeListener; >+ >+/** >+ * A part can provide arbitrary properties. The properties will be persisted >+ * between sessions by the part reference, and will be available from the part >+ * reference as well as the part. The properties can only be set on a part, not >+ * on the reference. The properties will be available to the IPresentablePart. >+ * <p> >+ * Setting a property must fire a PropertyChangeEvent. >+ * </p> >+ * >+ * @since 3.3 >+ */ >+public interface IWorkbenchPart3 extends IWorkbenchPart2 { >+ /** >+ * Add a listener for changes in the arbitrary properties set. >+ * <p> >+ * <b>Note:</b> this is a different set of properties than the ones covered >+ * by the IWorkbenchPartConstants.PROP_* constants. >+ * </p> >+ * >+ * @param listener >+ * Must not be <code>null</code>. >+ */ >+ public void addPartPropertyListener(IPropertyChangeListener listener); >+ >+ /** >+ * Remove a change listener from the arbitrary properties set. >+ * <p> >+ * <b>Note:</b> this is a different set of properties than the ones covered >+ * by the IWorkbenchPartConstants.PROP_* constants. >+ * </p> >+ * >+ * @param listener >+ * Must not be <code>null</code>. >+ */ >+ public void removePartPropertyListener(IPropertyChangeListener listener); >+ >+ /** >+ * Return the value for the arbitrary property key, or <code>null</code>. >+ * >+ * @param key >+ * the arbitrary property. Must not be <code>null</code>. >+ * @return the property value, or <code>null</code>. >+ */ >+ public String getPartProperty(String key); >+ >+ /** >+ * Set an arbitrary property on the part. It is the implementor's >+ * responsibility to fire the corresponding PropertyChangeEvent. >+ * <p> >+ * A default implementation has been added to WorkbenchPart. >+ * </p> >+ * >+ * @param key >+ * the arbitrary property. Must not be <code>null</code>. >+ * @param value >+ * the property value. A <code>null</code> value will remove >+ * that property. >+ */ >+ public void setPartProperty(String key, String value); >+ >+ /** >+ * Return an unmodifiable map of the arbitrary properties. This method can >+ * be used to save the properties during workbench save/restore. >+ * >+ * @return A Map of the properties. Must not be <code>null</code>. >+ */ >+ public Map getPartProperties(); >+} >#P org.eclipse.ui.tests.performance >Index: src/org/eclipse/ui/tests/performance/presentations/TestPresentablePart.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.tests.performance/src/org/eclipse/ui/tests/performance/presentations/TestPresentablePart.java,v >retrieving revision 1.2 >diff -u -r1.2 TestPresentablePart.java >--- src/org/eclipse/ui/tests/performance/presentations/TestPresentablePart.java 8 May 2006 20:52:14 -0000 1.2 >+++ src/org/eclipse/ui/tests/performance/presentations/TestPresentablePart.java 17 Jan 2007 02:59:48 -0000 >@@ -11,8 +11,12 @@ > package org.eclipse.ui.tests.performance.presentations; > > import java.util.ArrayList; >+import java.util.HashMap; > import java.util.List; >+import java.util.Map; > >+import org.eclipse.core.runtime.ListenerList; >+import org.eclipse.jface.util.IPropertyChangeListener; > import org.eclipse.swt.SWT; > import org.eclipse.swt.events.DisposeEvent; > import org.eclipse.swt.events.DisposeListener; >@@ -175,5 +179,30 @@ > toRemove.dispose(); > firePropertyChange(IPresentablePart.PROP_TOOLBAR); > } >+ >+ private ListenerList partPropertyListeners = new ListenerList(); >+ >+ private Map partProperties = new HashMap(); >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.presentations.IPresentablePart#addPartPropertyListener(org.eclipse.jface.util.IPropertyChangeListener) >+ */ >+ public void addPartPropertyListener(IPropertyChangeListener listener) { >+ partPropertyListeners.add(listener); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.presentations.IPresentablePart#getPartProperty(java.lang.String) >+ */ >+ public String getPartProperty(String key) { >+ return (String) partProperties.get(key); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.presentations.IPresentablePart#removePartPropertyListener(org.eclipse.jface.util.IPropertyChangeListener) >+ */ >+ public void removePartPropertyListener(IPropertyChangeListener listener) { >+ partPropertyListeners.remove(listener); >+ } > > } >#P org.eclipse.ui.tests >Index: Eclipse UI Tests/org/eclipse/ui/tests/api/ApiTestSuite.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/ApiTestSuite.java,v >retrieving revision 1.52 >diff -u -r1.52 ApiTestSuite.java >--- Eclipse UI Tests/org/eclipse/ui/tests/api/ApiTestSuite.java 25 Oct 2006 14:51:54 -0000 1.52 >+++ Eclipse UI Tests/org/eclipse/ui/tests/api/ApiTestSuite.java 17 Jan 2007 02:59:49 -0000 >@@ -13,6 +13,7 @@ > import junit.framework.Test; > import junit.framework.TestSuite; > >+import org.eclipse.ui.tests.api.workbenchpart.ArbitraryPropertyTest; > import org.eclipse.ui.tests.api.workbenchpart.OverriddenTitleTest; > import org.eclipse.ui.tests.api.workbenchpart.RawIViewPartTest; > import org.eclipse.ui.tests.api.workbenchpart.ViewPartTitleTest; >@@ -76,5 +77,6 @@ > addTest(new TestSuite(XMLMementoTest.class)); > addTest(new TestSuite(TrimLayoutTest.class)); > addTest(new TestSuite(IWorkbenchPartTestableTests.class)); >+ addTest(new TestSuite(ArbitraryPropertyTest.class)); > } > } >Index: UI-Session Tests.launch >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.tests/UI-Session Tests.launch,v >retrieving revision 1.3 >diff -u -r1.3 UI-Session Tests.launch >--- UI-Session Tests.launch 17 Aug 2006 15:21:27 -0000 1.3 >+++ UI-Session Tests.launch 17 Jan 2007 02:59:49 -0000 >@@ -16,13 +16,13 @@ > <stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/pde-junit"/> > <booleanAttribute key="clearws" value="true"/> > <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.ui.tests.session.SessionTests"/> >-<stringAttribute key="pde.version" value="3.2a"/> >+<stringAttribute key="pde.version" value="3.3"/> > <stringAttribute key="templateConfig" value=""/> > <booleanAttribute key="default" value="true"/> > <booleanAttribute key="clearConfig" value="true"/> > <booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/> >-<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/> > <booleanAttribute key="useDefaultConfigArea" value="false"/> >+<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/> > <booleanAttribute key="useDefaultConfig" value="true"/> > <stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> > <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.ui.tests"/> >Index: Eclipse UI Tests/org/eclipse/ui/tests/session/SessionTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/session/SessionTests.java,v >retrieving revision 1.11 >diff -u -r1.11 SessionTests.java >--- Eclipse UI Tests/org/eclipse/ui/tests/session/SessionTests.java 10 Nov 2006 12:52:03 -0000 1.11 >+++ Eclipse UI Tests/org/eclipse/ui/tests/session/SessionTests.java 17 Jan 2007 02:59:49 -0000 >@@ -29,8 +29,8 @@ > * > */ > public SessionTests() { >- addHandlerStateTests(); >- addIntroTests(); >+// addHandlerStateTests(); >+// addIntroTests(); > addEditorTests(); > addViewStateTests(); > } >@@ -39,10 +39,12 @@ > * Add editor tests that involve starting and stopping sessions. > */ > private void addEditorTests() { >+// addTest(new WorkbenchSessionTest("editorSessionTests", >+// Bug95357Test.class)); >+// addTest(new WorkbenchSessionTest("editorSessionTests", >+// EditorWithStateTest.class)); > addTest(new WorkbenchSessionTest("editorSessionTests", >- Bug95357Test.class)); >- addTest(new WorkbenchSessionTest("editorSessionTests", >- EditorWithStateTest.class)); >+ ArbitraryPropertiesEditorTest.class)); > } > > /** >@@ -70,9 +72,11 @@ > * workspace for these particular session tests. > */ > private void addViewStateTests() { >+// addTest(new WorkbenchSessionTest("editorSessionTests", >+// Bug98800Test.class)); >+// addTest(new WorkbenchSessionTest("editorSessionTests", >+// Bug108033Test.class)); > addTest(new WorkbenchSessionTest("editorSessionTests", >- Bug98800Test.class)); >- addTest(new WorkbenchSessionTest("editorSessionTests", >- Bug108033Test.class)); >+ ArbitraryPropertiesViewTest.class)); > } > } >Index: Eclipse UI Tests/org/eclipse/ui/tests/session/ArbitraryPropertiesViewTest.java >=================================================================== >RCS file: Eclipse UI Tests/org/eclipse/ui/tests/session/ArbitraryPropertiesViewTest.java >diff -N Eclipse UI Tests/org/eclipse/ui/tests/session/ArbitraryPropertiesViewTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI Tests/org/eclipse/ui/tests/session/ArbitraryPropertiesViewTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,141 @@ >+/******************************************************************************* >+ * Copyright (c) 2004, 2005 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.ui.tests.session; >+ >+import junit.framework.TestCase; >+import junit.framework.TestSuite; >+ >+import org.eclipse.jface.util.IPropertyChangeListener; >+import org.eclipse.jface.util.PropertyChangeEvent; >+import org.eclipse.ui.IViewPart; >+import org.eclipse.ui.IViewReference; >+import org.eclipse.ui.IWorkbench; >+import org.eclipse.ui.IWorkbenchPage; >+import org.eclipse.ui.IWorkbenchPart3; >+import org.eclipse.ui.PlatformUI; >+ >+/** >+ * If a view is not activated during a session, it's part is not instantiated. >+ * This tests that case, and the outcome should be the view has it's last >+ * session state when it is finally instantiated in the workbench. >+ * >+ * @since 3.3 >+ */ >+public class ArbitraryPropertiesViewTest extends TestCase { >+ /** >+ * >+ */ >+ private static final String USER_PROP = "org.eclipse.ui.tests.users"; >+ >+ private static final String PROBLEM_VIEW_ID = "org.eclipse.ui.views.ProblemView"; >+ >+ private static final String VIEW_WITH_STATE_ID = "org.eclipse.ui.tests.session.ViewWithState"; >+ >+ public static TestSuite suite() { >+ return new TestSuite(ArbitraryPropertiesViewTest.class); >+ } >+ >+ public ArbitraryPropertiesViewTest(String testName) { >+ super(testName); >+ } >+ >+ /** >+ * This is the first part of a 3 part tests. First instantiate a view and >+ * set a state. >+ * >+ * @throws Throwable >+ */ >+ public void testActivateView() throws Throwable { >+ final IWorkbench workbench = PlatformUI.getWorkbench(); >+ final IWorkbenchPage page = workbench.getActiveWorkbenchWindow() >+ .getActivePage(); >+ >+ IViewPart v = page.showView(VIEW_WITH_STATE_ID); >+ >+ // put another view in front of our view >+ page.showView(PROBLEM_VIEW_ID); >+ >+ IWorkbenchPart3 wp = (IWorkbenchPart3) v; >+ wp.setPartProperty(USER_PROP, "pwebster"); >+ } >+ >+ /** >+ * The second session doesn't activate the view, so it should not be >+ * instantiated. >+ * >+ * @throws Throwable >+ */ >+ public void testSecondOpening() throws Throwable { >+ final IWorkbench workbench = PlatformUI.getWorkbench(); >+ final IWorkbenchPage page = workbench.getActiveWorkbenchWindow() >+ .getActivePage(); >+ >+ IViewReference[] views = page.getViewReferences(); >+ for (int i = 0; i < views.length; i++) { >+ IViewReference ref = views[i]; >+ if (ref.getId().equals(VIEW_WITH_STATE_ID)) { >+ assertNull("The view should not be instantiated", ref >+ .getPart(false)); >+ assertEquals("pwebster", ref.getPartProperty(USER_PROP)); >+ } >+ } >+ } >+ >+ static class PropListener implements IPropertyChangeListener { >+ public int count = 0; >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) >+ */ >+ public void propertyChange(PropertyChangeEvent event) { >+ count++; >+ } >+ }; >+ >+ /** >+ * Activate the view and it's state should re-appear. >+ * >+ * @throws Throwable >+ */ >+ public void testPartInstantiation() throws Throwable { >+ final IWorkbench workbench = PlatformUI.getWorkbench(); >+ final IWorkbenchPage page = workbench.getActiveWorkbenchWindow() >+ .getActivePage(); >+ >+ IViewReference[] views = page.getViewReferences(); >+ for (int i = 0; i < views.length; i++) { >+ System.err.println("views: " + views[i].getId()); >+ } >+ >+ IViewReference ref = page.findViewReference(VIEW_WITH_STATE_ID); >+ assertEquals("pwebster", ref.getPartProperty(USER_PROP)); >+ PropListener listener = new PropListener(); >+ ref.addPartPropertyListener(listener); >+ >+ IViewPart v = null; >+ try { >+ v = page.showView(VIEW_WITH_STATE_ID); >+ IWorkbenchPart3 wp = (IWorkbenchPart3) v; >+ assertEquals("pwebster", wp.getPartProperty(USER_PROP)); >+ assertEquals(0, listener.count); >+ } finally { >+ ref.removePartPropertyListener(listener); >+ } >+ // the state should not be saved between a close and >+ // an open in the same session >+ page.hideView(v); >+ v = page.showView(VIEW_WITH_STATE_ID); >+ IWorkbenchPart3 wp = (IWorkbenchPart3) v; >+ assertNull(wp.getPartProperty(USER_PROP)); >+ } >+} >Index: Eclipse UI Tests/org/eclipse/ui/tests/session/ArbitraryPropertiesEditorTest.java >=================================================================== >RCS file: Eclipse UI Tests/org/eclipse/ui/tests/session/ArbitraryPropertiesEditorTest.java >diff -N Eclipse UI Tests/org/eclipse/ui/tests/session/ArbitraryPropertiesEditorTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI Tests/org/eclipse/ui/tests/session/ArbitraryPropertiesEditorTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,154 @@ >+/******************************************************************************* >+ * Copyright (c) 2004, 2005 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.ui.tests.session; >+ >+import junit.framework.TestCase; >+import junit.framework.TestSuite; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.jface.util.IPropertyChangeListener; >+import org.eclipse.jface.util.PropertyChangeEvent; >+import org.eclipse.ui.IEditorInput; >+import org.eclipse.ui.IEditorPart; >+import org.eclipse.ui.IEditorReference; >+import org.eclipse.ui.IWorkbench; >+import org.eclipse.ui.IWorkbenchPage; >+import org.eclipse.ui.IWorkbenchPart3; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.ide.IDE; >+import org.eclipse.ui.part.FileEditorInput; >+import org.eclipse.ui.tests.api.workbenchpart.TitleTestEditor; >+import org.eclipse.ui.tests.harness.util.FileUtil; >+ >+/** >+ * If a view is not activated during a session, it's part is not instantiated. >+ * This tests that case, and the outcome should be the view has it's last >+ * session state when it is finally instantiated in the workbench. >+ * >+ * @since 3.3 >+ */ >+public class ArbitraryPropertiesEditorTest extends TestCase { >+ /** >+ * >+ */ >+ private static final String USER_PROP = "org.eclipse.ui.tests.users"; >+ >+ private static final String EDITOR_ID = "org.eclipse.ui.tests.TitleTestEditor"; >+ >+ public static TestSuite suite() { >+ return new TestSuite(ArbitraryPropertiesEditorTest.class); >+ } >+ >+ public ArbitraryPropertiesEditorTest(String testName) { >+ super(testName); >+ } >+ >+ /** >+ * This is the first part of a 3 part tests. First instantiate a view and >+ * set a state. >+ * >+ * @throws Throwable >+ */ >+ public void testOpenEditor() throws Throwable { >+ final IWorkbench workbench = PlatformUI.getWorkbench(); >+ final IWorkbenchPage page = workbench.getActiveWorkbenchWindow() >+ .getActivePage(); >+ >+ IProject proj = FileUtil.createProject("EditorSessionTest"); >+ IFile file = FileUtil.createFile("state.txt", proj); >+ >+ TitleTestEditor editor = (TitleTestEditor) page.openEditor( >+ new FileEditorInput(file), EDITOR_ID); >+ >+ // this makes the second file active on the first >+ file = FileUtil.createFile("state_active.txt", proj); >+ IDE.openEditor(page, file); >+ >+ editor.setPartProperty(USER_PROP, "pwebster"); >+ } >+ >+ /** >+ * The second session doesn't activate the view, so it should not be >+ * instantiated. >+ * >+ * @throws Throwable >+ */ >+ public void testSecondOpening() throws Throwable { >+ final IWorkbench workbench = PlatformUI.getWorkbench(); >+ final IWorkbenchPage page = workbench.getActiveWorkbenchWindow() >+ .getActivePage(); >+ IEditorReference[] editors = page.getEditorReferences(); >+ for (int i = 0; i < editors.length; i++) { >+ IEditorReference ref = editors[i]; >+ if (ref.getEditorInput().getName().equals("state.txt")) { >+ assertNull("The editor should not be instantiated", ref >+ .getPart(false)); >+ assertEquals("pwebster", ref.getPartProperty(USER_PROP)); >+ } >+ } >+ } >+ >+ static class PropListener implements IPropertyChangeListener { >+ public int count = 0; >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) >+ */ >+ public void propertyChange(PropertyChangeEvent event) { >+ count++; >+ } >+ }; >+ >+ /** >+ * Activate the view and it's state should re-appear. >+ * >+ * @throws Throwable >+ */ >+ public void testPartInstantiation() throws Throwable { >+ final IWorkbench workbench = PlatformUI.getWorkbench(); >+ final IWorkbenchPage page = workbench.getActiveWorkbenchWindow() >+ .getActivePage(); >+ >+ IEditorReference ref = null; >+ IEditorReference[] editors = page.getEditorReferences(); >+ for (int i = 0; i < editors.length; i++) { >+ if (editors[i].getEditorInput().getName().equals("state.txt")) { >+ ref = editors[i]; >+ } >+ } >+ >+ assertEquals("pwebster", ref.getPartProperty(USER_PROP)); >+ PropListener listener = new PropListener(); >+ ref.addPartPropertyListener(listener); >+ >+ try { >+ >+ IWorkbenchPart3 wp = (IWorkbenchPart3) ref.getPart(true); >+ assertEquals("pwebster", wp.getPartProperty(USER_PROP)); >+ assertEquals(0, listener.count); >+ } finally { >+ ref.removePartPropertyListener(listener); >+ } >+ >+ IEditorInput input = ref.getEditorInput(); >+ >+ // the state should not be saved between a close and >+ // an open in the same session >+ page.closeEditor((IEditorPart) ref.getPart(true), false); >+ >+ TitleTestEditor editor = (TitleTestEditor) page.openEditor(input, >+ EDITOR_ID); >+ assertNull(editor.getPartProperty(USER_PROP)); >+ } >+} >Index: Eclipse UI Tests/org/eclipse/ui/tests/api/workbenchpart/ArbitraryPropertyTest.java >=================================================================== >RCS file: Eclipse UI Tests/org/eclipse/ui/tests/api/workbenchpart/ArbitraryPropertyTest.java >diff -N Eclipse UI Tests/org/eclipse/ui/tests/api/workbenchpart/ArbitraryPropertyTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI Tests/org/eclipse/ui/tests/api/workbenchpart/ArbitraryPropertyTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,176 @@ >+/******************************************************************************* >+ * Copyright (c) 2004, 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.ui.tests.api.workbenchpart; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IStorage; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.jface.util.IPropertyChangeListener; >+import org.eclipse.jface.util.PropertyChangeEvent; >+import org.eclipse.ui.IEditorReference; >+import org.eclipse.ui.IFileEditorInput; >+import org.eclipse.ui.IPersistableElement; >+import org.eclipse.ui.IViewReference; >+import org.eclipse.ui.internal.WorkbenchPage; >+import org.eclipse.ui.internal.WorkbenchWindow; >+import org.eclipse.ui.tests.harness.util.UITestCase; >+ >+/** >+ * @since 3.0 >+ */ >+public class ArbitraryPropertyTest extends UITestCase { >+ /** >+ * >+ */ >+ private static final String EDITOR_ID = "org.eclipse.ui.tests.TitleTestEditor"; >+ >+ /** >+ * >+ */ >+ private static final String USER_PROP = "org.eclipse.ui.test.user"; >+ >+ final static String VIEW_ID = "org.eclipse.ui.tests.workbenchpart.OverriddenTitleView"; >+ >+ /** >+ * @param testName >+ */ >+ public ArbitraryPropertyTest(String testName) { >+ super(testName); >+ } >+ >+ WorkbenchWindow window; >+ >+ WorkbenchPage page; >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.ui.tests.harness.util.UITestCase#doSetUp() >+ */ >+ protected void doSetUp() throws Exception { >+ super.doSetUp(); >+ window = (WorkbenchWindow) openTestWindow(); >+ page = (WorkbenchPage) window.getActivePage(); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.ui.tests.util.UITestCase#doTearDown() >+ */ >+ protected void doTearDown() throws Exception { >+ super.doTearDown(); >+ } >+ >+ static class PropListener implements IPropertyChangeListener { >+ String firedProp = null; >+ >+ String firedOV = null; >+ >+ String firedNV = null; >+ >+ public void propertyChange(PropertyChangeEvent event) { >+ firedProp = event.getProperty(); >+ firedOV = (String) event.getOldValue(); >+ firedNV = (String) event.getNewValue(); >+ } >+ }; >+ >+ public void testViewProperties() throws Exception { >+ OverriddenTitleView view = (OverriddenTitleView) page.showView(VIEW_ID); >+ IViewReference ref = (IViewReference) page.getReference(view); >+ >+ PropListener viewListener = new PropListener(); >+ view.addPartPropertyListener(viewListener); >+ PropListener refListener = new PropListener(); >+ ref.addPartPropertyListener(refListener); >+ >+ view.setPartProperty(USER_PROP, "pwebster"); >+ >+ try { >+ assertEquals("pwebster", view.getPartProperty(USER_PROP)); >+ assertEquals("pwebster", ref.getPartProperty(USER_PROP)); >+ >+ assertEquals(USER_PROP, viewListener.firedProp); >+ assertNull(viewListener.firedOV); >+ assertEquals("pwebster", viewListener.firedNV); >+ assertEquals(USER_PROP, refListener.firedProp); >+ assertNull(refListener.firedOV); >+ assertEquals("pwebster", refListener.firedNV); >+ } finally { >+ view.removePartPropertyListener(viewListener); >+ ref.removePartPropertyListener(refListener); >+ } >+ } >+ >+ public void testEditorProperties() throws Exception { >+ IFileEditorInput input = new IFileEditorInput() { >+ public boolean exists() { >+ return true; >+ } >+ >+ public ImageDescriptor getImageDescriptor() { >+ return null; >+ } >+ >+ public String getName() { >+ return "MyInputFile"; >+ } >+ >+ public IPersistableElement getPersistable() { >+ return null; >+ } >+ >+ public String getToolTipText() { >+ return "My Input File"; >+ } >+ >+ public Object getAdapter(Class adapter) { >+ return null; >+ } >+ >+ public IFile getFile() { >+ return null; >+ } >+ >+ public IStorage getStorage() throws CoreException { >+ if (false) throw new CoreException(null); >+ return null; >+ } >+ }; >+ TitleTestEditor editor = (TitleTestEditor) page.openEditor(input, >+ EDITOR_ID); >+ IEditorReference ref = (IEditorReference) page.getReference(editor); >+ >+ PropListener editorListener = new PropListener(); >+ editor.addPartPropertyListener(editorListener); >+ PropListener refListener = new PropListener(); >+ ref.addPartPropertyListener(refListener); >+ >+ editor.setPartProperty(USER_PROP, "pwebster"); >+ >+ try { >+ assertEquals("pwebster", editor.getPartProperty(USER_PROP)); >+ assertEquals("pwebster", ref.getPartProperty(USER_PROP)); >+ >+ assertEquals(USER_PROP, editorListener.firedProp); >+ assertNull(editorListener.firedOV); >+ assertEquals("pwebster", editorListener.firedNV); >+ assertEquals(USER_PROP, refListener.firedProp); >+ assertNull(refListener.firedOV); >+ assertEquals("pwebster", refListener.firedNV); >+ } finally { >+ editor.removePartPropertyListener(editorListener); >+ ref.removePartPropertyListener(refListener); >+ } >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 89834
:
56661
|
56930
|
56982
| 56997