Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 89834 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/presentations/PresentablePart.java (-3 / +47 lines)
Lines 13-18 Link Here
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
import java.util.List;
14
import java.util.List;
15
15
16
import org.eclipse.core.runtime.ListenerList;
17
import org.eclipse.jface.util.IPropertyChangeListener;
18
import org.eclipse.jface.util.PropertyChangeEvent;
16
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.swt.graphics.Image;
17
import org.eclipse.swt.graphics.Point;
20
import org.eclipse.swt.graphics.Point;
18
import org.eclipse.swt.graphics.Rectangle;
21
import org.eclipse.swt.graphics.Rectangle;
Lines 46-51 Link Here
46
49
47
    // Lazily initialized. Use getPropertyListenerProxy() to access.
50
    // Lazily initialized. Use getPropertyListenerProxy() to access.
48
    private IPropertyListener lazyPropertyListenerProxy;
51
    private IPropertyListener lazyPropertyListenerProxy;
52
    
53
    private ListenerList partPropertyChangeListeners = new ListenerList();
54
    
55
    private IPropertyChangeListener lazyPartPropertyChangeListener;
49
56
50
    // Lazily initialized. Use getMenu() to access 
57
    // Lazily initialized. Use getMenu() to access 
51
    private IPartMenu viewMenu;
58
    private IPartMenu viewMenu;
Lines 75-80 Link Here
75
    public PresentablePart(PartPane part, Composite parent) {
82
    public PresentablePart(PartPane part, Composite parent) {
76
        this.part = part;
83
        this.part = part;
77
        getPane().addPropertyListener(getPropertyListenerProxy());
84
        getPane().addPropertyListener(getPropertyListenerProxy());
85
        getPane().addPartPropertyListener(getPartPropertyListenerProxy());
78
    }
86
    }
79
87
80
    public PartPane getPane() {
88
    public PartPane getPane() {
Lines 92-110 Link Here
92
100
93
        return lazyPropertyListenerProxy;
101
        return lazyPropertyListenerProxy;
94
    }
102
    }
103
    
104
    private IPropertyChangeListener getPartPropertyListenerProxy() {
105
		if (lazyPartPropertyChangeListener == null) {
106
			lazyPartPropertyChangeListener = new IPropertyChangeListener() {
107
				public void propertyChange(PropertyChangeEvent event) {
108
					firePartPropertyChange(event);
109
				}
110
			};
111
		}
112
		return lazyPartPropertyChangeListener;
113
	}
95
114
96
    /**
115
    /**
97
     * Detach this PresentablePart from the real part. No further methods should be invoked
116
	 * Detach this PresentablePart from the real part. No further methods should
98
     * on this object.
117
	 * be invoked on this object.
99
     */
118
	 */
100
    public void dispose() {
119
    public void dispose() {
101
        // Ensure that the property listener is detached (necessary to prevent leaks)
120
        // Ensure that the property listener is detached (necessary to prevent leaks)
102
        getPane().removePropertyListener(getPropertyListenerProxy());
121
        getPane().removePropertyListener(getPropertyListenerProxy());
122
        getPane().removePartPropertyListener(getPartPropertyListenerProxy());
103
123
104
        // Null out the various fields to ease garbage collection (optional)
124
        // Null out the various fields to ease garbage collection (optional)
105
        part = null;
125
        part = null;
106
        listeners.clear();
126
        listeners.clear();
107
        listeners = null;
127
        listeners = null;
128
        partPropertyChangeListeners.clear();
129
        partPropertyChangeListeners = null;
108
    }
130
    }
109
131
110
    public void firePropertyChange(int propertyId) {
132
    public void firePropertyChange(int propertyId) {
Lines 121-126 Link Here
121
        listeners.remove(listener);
143
        listeners.remove(listener);
122
    }
144
    }
123
145
146
    protected void firePartPropertyChange(PropertyChangeEvent event) {
147
		Object[] l = partPropertyChangeListeners.getListeners();
148
		for (int i = 0; i < l.length; i++) {
149
			((IPropertyChangeListener) l[i]).propertyChange(event);
150
		}
151
	}
152
    
153
    public void addPartPropertyListener(IPropertyChangeListener listener) {
154
    	partPropertyChangeListeners.add(listener);
155
    }
156
    
157
    public void removePartPropertyListener(IPropertyChangeListener listener) {
158
    	partPropertyChangeListeners.remove(listener);
159
    }
160
    
124
    /* (non-Javadoc)
161
    /* (non-Javadoc)
125
     * @see org.eclipse.ui.presentations.IPresentablePart#setBounds(org.eclipse.swt.graphics.Rectangle)
162
     * @see org.eclipse.ui.presentations.IPresentablePart#setBounds(org.eclipse.swt.graphics.Rectangle)
126
     */
163
     */
Lines 351-354 Link Here
351
        }
388
        }
352
    }
389
    }
353
390
391
	/* (non-Javadoc)
392
	 * @see org.eclipse.ui.presentations.IPresentablePart#getPartProperty(java.lang.String)
393
	 */
394
	public String getPartProperty(String key) {
395
		return getPartReference().getPartProperty(key);
396
	}
397
354
}
398
}
(-)Eclipse UI/org/eclipse/ui/internal/PartPane.java (-2 / +30 lines)
Lines 12-17 Link Here
12
12
13
import org.eclipse.core.runtime.ListenerList;
13
import org.eclipse.core.runtime.ListenerList;
14
import org.eclipse.jface.action.MenuManager;
14
import org.eclipse.jface.action.MenuManager;
15
import org.eclipse.jface.util.IPropertyChangeListener;
16
import org.eclipse.jface.util.PropertyChangeEvent;
15
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.events.FocusAdapter;
18
import org.eclipse.swt.events.FocusAdapter;
17
import org.eclipse.swt.events.FocusEvent;
19
import org.eclipse.swt.events.FocusEvent;
Lines 50-56 Link Here
50
 * LayoutPart and downcasting. The getPresentablePart() method only applies to PartPanes, and
52
 * LayoutPart and downcasting. The getPresentablePart() method only applies to PartPanes, and
51
 * should be removed from LayoutPart.
53
 * should be removed from LayoutPart.
52
 */
54
 */
53
public abstract class PartPane extends LayoutPart implements IPropertyListener, Listener {
55
public abstract class PartPane extends LayoutPart implements IPropertyListener,
56
		Listener, IPropertyChangeListener {
54
57
55
    public static final String PROP_ZOOMED = "zoomed"; //$NON-NLS-1$
58
    public static final String PROP_ZOOMED = "zoomed"; //$NON-NLS-1$
56
59
Lines 58-63 Link Here
58
61
59
    private MenuManager paneMenuManager;
62
    private MenuManager paneMenuManager;
60
    private ListenerList listeners = new ListenerList();
63
    private ListenerList listeners = new ListenerList();
64
    private ListenerList partListeners = new ListenerList();
61
65
62
    protected IWorkbenchPartReference partReference;
66
    protected IWorkbenchPartReference partReference;
63
67
Lines 135-140 Link Here
135
		}
139
		}
136
140
137
        partReference.addPropertyListener(this);
141
        partReference.addPropertyListener(this);
142
        partReference.addPartPropertyListener(this);
138
        // Create view form.	
143
        // Create view form.	
139
        control = new Composite(parent, SWT.NONE);
144
        control = new Composite(parent, SWT.NONE);
140
        control.setLayout(new FillLayout());
145
        control.setLayout(new FillLayout());
Lines 176-181 Link Here
176
        }
181
        }
177
        
182
        
178
        partReference.removePropertyListener(this);
183
        partReference.removePropertyListener(this);
184
        partReference.removePartPropertyListener(this);
179
    }
185
    }
180
186
181
    /**
187
    /**
Lines 600-607 Link Here
600
            ((IPropertyListener) listeners[i]).propertyChanged(this, propertyId);
606
            ((IPropertyListener) listeners[i]).propertyChanged(this, propertyId);
601
        }
607
        }
602
    }
608
    }
603
609
    
604
    public void propertyChanged(Object source, int propId) {
610
    public void propertyChanged(Object source, int propId) {
605
        firePropertyChange(propId);
611
        firePropertyChange(propId);
606
    }
612
    }
613
    
614
    public void addPartPropertyListener(IPropertyChangeListener listener) {
615
    	partListeners.add(listener);
616
    }
617
    
618
    public void removePartPropertyListener(IPropertyChangeListener listener) {
619
    	partListeners.remove(listener);
620
    }
621
    
622
    public void firePartPropertyChange(PropertyChangeEvent event) {
623
    	Object[] l = partListeners.getListeners();
624
    	for (int i = 0; i < l.length; i++) {
625
			((IPropertyChangeListener)l[i]).propertyChange(event);
626
		}
627
    }
628
    
629
    /* (non-Javadoc)
630
     * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
631
     */
632
    public void propertyChange(PropertyChangeEvent event) {
633
    	firePartPropertyChange(event);
634
    }
607
}
635
}
(-)Eclipse UI/org/eclipse/ui/internal/ViewFactory.java (-2 / +29 lines)
Lines 11-22 Link Here
11
package org.eclipse.ui.internal;
11
package org.eclipse.ui.internal;
12
12
13
import java.util.HashMap;
13
import java.util.HashMap;
14
import java.util.Iterator;
14
import java.util.List;
15
import java.util.List;
16
import java.util.Map;
15
17
16
import org.eclipse.core.runtime.IExtension;
18
import org.eclipse.core.runtime.IExtension;
17
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.MultiStatus;
20
import org.eclipse.core.runtime.MultiStatus;
19
import org.eclipse.core.runtime.Platform;
21
import org.eclipse.core.runtime.SafeRunner;
20
import org.eclipse.core.runtime.Status;
22
import org.eclipse.core.runtime.Status;
21
import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler;
23
import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler;
22
import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
24
import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
Lines 25-30 Link Here
25
import org.eclipse.ui.IMemento;
27
import org.eclipse.ui.IMemento;
26
import org.eclipse.ui.IViewPart;
28
import org.eclipse.ui.IViewPart;
27
import org.eclipse.ui.IViewReference;
29
import org.eclipse.ui.IViewReference;
30
import org.eclipse.ui.IWorkbenchPart3;
28
import org.eclipse.ui.PartInitException;
31
import org.eclipse.ui.PartInitException;
29
import org.eclipse.ui.PlatformUI;
32
import org.eclipse.ui.PlatformUI;
30
import org.eclipse.ui.views.IViewDescriptor;
33
import org.eclipse.ui.views.IViewDescriptor;
Lines 301-308 Link Here
301
        final IViewReference viewRef = ref;
304
        final IViewReference viewRef = ref;
302
        final IViewPart view = (IViewPart) ref.getPart(false);
305
        final IViewPart view = (IViewPart) ref.getPart(false);
303
        if (view != null) {
306
        if (view != null) {
304
            Platform.run(new SafeRunnable() {
307
            SafeRunner.run(new SafeRunnable() {
305
                public void run() {
308
                public void run() {
309
                	if (view instanceof IWorkbenchPart3) {
310
						Map properties = ((IWorkbenchPart3) view)
311
								.getPartProperties();
312
						if (!properties.isEmpty()) {
313
							IMemento propBag = viewMemento
314
									.createChild(IWorkbenchConstants.TAG_PROPERTIES);
315
							Iterator i = properties.entrySet().iterator();
316
							while (i.hasNext()) {
317
								Map.Entry entry = (Map.Entry) i.next();
318
								IMemento p = propBag.createChild(
319
										IWorkbenchConstants.TAG_PROPERTY,
320
										(String) entry.getKey());
321
								p.putTextData((String) entry.getValue());
322
							}
323
						}
324
					}
306
                    view.saveState(viewMemento
325
                    view.saveState(viewMemento
307
                            .createChild(IWorkbenchConstants.TAG_VIEW_STATE));
326
                            .createChild(IWorkbenchConstants.TAG_VIEW_STATE));
308
                }
327
                }
Lines 319-324 Link Here
319
            });
338
            });
320
        } else {
339
        } else {
321
        	IMemento mem = null;
340
        	IMemento mem = null;
341
        	IMemento props = null;
322
        	
342
        	
323
        	// if we've created the reference once, any previous workbench
343
        	// if we've created the reference once, any previous workbench
324
        	// state memento is there.  After once, there is no previous
344
        	// state memento is there.  After once, there is no previous
Lines 326-334 Link Here
326
			if (ref instanceof ViewReference) {
346
			if (ref instanceof ViewReference) {
327
				mem = ((ViewReference) ref).getMemento();
347
				mem = ((ViewReference) ref).getMemento();
328
				if (mem!=null) {
348
				if (mem!=null) {
349
					props = mem.getChild(IWorkbenchConstants.TAG_PROPERTIES);
350
				}
351
				if (mem!=null) {
329
					mem = mem.getChild(IWorkbenchConstants.TAG_VIEW_STATE);
352
					mem = mem.getChild(IWorkbenchConstants.TAG_VIEW_STATE);
330
				}
353
				}
331
			}
354
			}
355
			if (props != null) {
356
				viewMemento.createChild(IWorkbenchConstants.TAG_PROPERTIES)
357
						.putMemento(props);
358
			}
332
			if (mem != null) {
359
			if (mem != null) {
333
				IMemento child = viewMemento
360
				IMemento child = viewMemento
334
						.createChild(IWorkbenchConstants.TAG_VIEW_STATE);
361
						.createChild(IWorkbenchConstants.TAG_VIEW_STATE);
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchPartReference.java (+66 lines)
Lines 11-22 Link Here
11
package org.eclipse.ui.internal;
11
package org.eclipse.ui.internal;
12
12
13
import java.util.BitSet;
13
import java.util.BitSet;
14
import java.util.HashMap;
15
import java.util.Map;
14
16
15
import org.eclipse.core.runtime.Assert;
17
import org.eclipse.core.runtime.Assert;
16
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.ListenerList;
19
import org.eclipse.core.runtime.ListenerList;
18
import org.eclipse.jface.resource.ImageDescriptor;
20
import org.eclipse.jface.resource.ImageDescriptor;
19
import org.eclipse.jface.resource.JFaceResources;
21
import org.eclipse.jface.resource.JFaceResources;
22
import org.eclipse.jface.util.IPropertyChangeListener;
23
import org.eclipse.jface.util.PropertyChangeEvent;
20
import org.eclipse.osgi.util.NLS;
24
import org.eclipse.osgi.util.NLS;
21
import org.eclipse.swt.events.DisposeEvent;
25
import org.eclipse.swt.events.DisposeEvent;
22
import org.eclipse.swt.events.DisposeListener;
26
import org.eclipse.swt.events.DisposeListener;
Lines 29-34 Link Here
29
import org.eclipse.ui.ISharedImages;
33
import org.eclipse.ui.ISharedImages;
30
import org.eclipse.ui.IWorkbenchPart;
34
import org.eclipse.ui.IWorkbenchPart;
31
import org.eclipse.ui.IWorkbenchPart2;
35
import org.eclipse.ui.IWorkbenchPart2;
36
import org.eclipse.ui.IWorkbenchPart3;
32
import org.eclipse.ui.IWorkbenchPartConstants;
37
import org.eclipse.ui.IWorkbenchPartConstants;
33
import org.eclipse.ui.IWorkbenchPartReference;
38
import org.eclipse.ui.IWorkbenchPartReference;
34
import org.eclipse.ui.IWorkbenchPartSite;
39
import org.eclipse.ui.IWorkbenchPartSite;
Lines 137-146 Link Here
137
     */
142
     */
138
    private ListenerList internalPropChangeListeners = new ListenerList();
143
    private ListenerList internalPropChangeListeners = new ListenerList();
139
    
144
    
145
    private ListenerList partChangeListeners = new ListenerList();
146
    
140
    private String partName;
147
    private String partName;
141
148
142
    private String contentDescription;
149
    private String contentDescription;
143
    
150
    
151
    protected Map propertyCache = new HashMap();
152
    
144
    /**
153
    /**
145
     * Used to remember which events have been queued.
154
     * Used to remember which events have been queued.
146
     */
155
     */
Lines 163-168 Link Here
163
        }
172
        }
164
    };
173
    };
165
    
174
    
175
    private IPropertyChangeListener partPropertyChangeListener = new IPropertyChangeListener() {
176
		public void propertyChange(PropertyChangeEvent event) {
177
			partPropertyChanged(event);
178
		}
179
    };
180
    
166
    public WorkbenchPartReference() {
181
    public WorkbenchPartReference() {
167
        //no-op
182
        //no-op
168
    }
183
    }
Lines 283-288 Link Here
283
        	}
298
        	}
284
        }
299
        }
285
    }
300
    }
301
    
302
    protected void partPropertyChanged(PropertyChangeEvent event) {
303
    	firePartPropertyChange(event);
304
    }
286
305
287
    /**
306
    /**
288
     * Refreshes all cached values with the values from the real part 
307
     * Refreshes all cached values with the values from the real part 
Lines 571-576 Link Here
571
                    // object that should dispose this control, and it will remove the listener before it does so.
590
                    // object that should dispose this control, and it will remove the listener before it does so.
572
                    getPane().getControl().addDisposeListener(prematureDisposeListener);
591
                    getPane().getControl().addDisposeListener(prematureDisposeListener);
573
                    part.addPropertyListener(propertyChangeListener);
592
                    part.addPropertyListener(propertyChangeListener);
593
                    if (part instanceof IWorkbenchPart3) {
594
                    	((IWorkbenchPart3)part).addPartPropertyListener(partPropertyChangeListener);
595
                    }
574
596
575
                    refreshFromPart();
597
                    refreshFromPart();
576
                    releaseReferences();
598
                    releaseReferences();
Lines 646-651 Link Here
646
        }
668
        }
647
        
669
        
648
        clearListenerList(internalPropChangeListeners);
670
        clearListenerList(internalPropChangeListeners);
671
        clearListenerList(partChangeListeners);
649
        Image oldImage = image;
672
        Image oldImage = image;
650
        ImageDescriptor oldDescriptor = imageDescriptor;
673
        ImageDescriptor oldDescriptor = imageDescriptor;
651
        image = null;
674
        image = null;
Lines 684-689 Link Here
684
            // Don't let exceptions in client code bring us down. Log them and continue.
707
            // Don't let exceptions in client code bring us down. Log them and continue.
685
            try {
708
            try {
686
                part.removePropertyListener(propertyChangeListener);
709
                part.removePropertyListener(propertyChangeListener);
710
                if (part instanceof IWorkbenchPart3) {
711
                	((IWorkbenchPart3)part).removePartPropertyListener(partPropertyChangeListener);
712
                }
687
                part.dispose();
713
                part.dispose();
688
            } catch (Exception e) {
714
            } catch (Exception e) {
689
                WorkbenchPlugin.log(e);
715
                WorkbenchPlugin.log(e);
Lines 712-715 Link Here
712
        return pinned;
738
        return pinned;
713
    }
739
    }
714
740
741
    /* (non-Javadoc)
742
     * @see org.eclipse.ui.IWorkbenchPartReference#getPartProperty(java.lang.String)
743
     */
744
    public String getPartProperty(String key) {
745
		if (part != null) {
746
			if (part instanceof IWorkbenchPart3) {
747
				return ((IWorkbenchPart3) part).getPartProperty(key);
748
			}
749
		} else {
750
			return (String)propertyCache.get(key);
751
		}
752
		return null;
753
	}
754
    
755
    /* (non-Javadoc)
756
     * @see org.eclipse.ui.IWorkbenchPartReference#addPartPropertyListener(org.eclipse.jface.util.IPropertyChangeListener)
757
     */
758
    public void addPartPropertyListener(IPropertyChangeListener listener) {
759
    	if (isDisposed()) {
760
    		return;
761
    	}
762
    	partChangeListeners.add(listener);
763
    }
764
    
765
    /* (non-Javadoc)
766
     * @see org.eclipse.ui.IWorkbenchPartReference#removePartPropertyListener(org.eclipse.jface.util.IPropertyChangeListener)
767
     */
768
    public void removePartPropertyListener(IPropertyChangeListener listener) {
769
    	if (isDisposed()) {
770
    		return;
771
    	}
772
    	partChangeListeners.remove(listener);
773
    }
774
    
775
    protected void firePartPropertyChange(PropertyChangeEvent event) {
776
		Object[] l = partChangeListeners.getListeners();
777
		for (int i = 0; i < l.length; i++) {
778
			((IPropertyChangeListener) l[i]).propertyChange(event);
779
		}
780
	}
715
}
781
}
(-)Eclipse UI/org/eclipse/ui/internal/IWorkbenchConstants.java (+4 lines)
Lines 120-125 Link Here
120
120
121
    public static final String TAG_PART_NAME = "partName"; //$NON-NLS-1$
121
    public static final String TAG_PART_NAME = "partName"; //$NON-NLS-1$
122
122
123
	public static final String TAG_PROPERTIES = "properties"; //$NON-NLS-1$
124
	
125
    public static final String TAG_PROPERTY = "property"; //$NON-NLS-1$
126
123
    public static final String TAG_PART_TRIMSTATE = "inTrim"; //$NON-NLS-1$
127
    public static final String TAG_PART_TRIMSTATE = "inTrim"; //$NON-NLS-1$
124
128
125
    public static final String TAG_RELATIVE = "relative"; //$NON-NLS-1$
129
    public static final String TAG_RELATIVE = "relative"; //$NON-NLS-1$
(-)Eclipse UI/org/eclipse/ui/internal/EditorManager.java (+18 lines)
Lines 77-82 Link Here
77
import org.eclipse.ui.IViewPart;
77
import org.eclipse.ui.IViewPart;
78
import org.eclipse.ui.IWorkbenchPage;
78
import org.eclipse.ui.IWorkbenchPage;
79
import org.eclipse.ui.IWorkbenchPart;
79
import org.eclipse.ui.IWorkbenchPart;
80
import org.eclipse.ui.IWorkbenchPart3;
80
import org.eclipse.ui.IWorkbenchPartReference;
81
import org.eclipse.ui.IWorkbenchPartReference;
81
import org.eclipse.ui.IWorkbenchWindow;
82
import org.eclipse.ui.IWorkbenchWindow;
82
import org.eclipse.ui.PartInitException;
83
import org.eclipse.ui.PartInitException;
Lines 1600-1605 Link Here
1600
1601
1601
				editorMem.putString(IWorkbenchConstants.TAG_PART_NAME,
1602
				editorMem.putString(IWorkbenchConstants.TAG_PART_NAME,
1602
						editorRef.getPartName());
1603
						editorRef.getPartName());
1604
				
1605
				if (editor instanceof IWorkbenchPart3) {
1606
					Map properties = ((IWorkbenchPart3) editor)
1607
							.getPartProperties();
1608
					if (!properties.isEmpty()) {
1609
						IMemento propBag = editorMem
1610
								.createChild(IWorkbenchConstants.TAG_PROPERTIES);
1611
						Iterator i = properties.entrySet().iterator();
1612
						while (i.hasNext()) {
1613
							Map.Entry entry = (Map.Entry) i.next();
1614
							IMemento p = propBag.createChild(
1615
									IWorkbenchConstants.TAG_PROPERTY,
1616
									(String) entry.getKey());
1617
							p.putTextData((String) entry.getValue());
1618
						}
1619
					}
1620
				}
1603
1621
1604
				if (editorRef.isPinned()) {
1622
				if (editorRef.isPinned()) {
1605
					editorMem.putString(IWorkbenchConstants.TAG_PINNED, "true"); //$NON-NLS-1$
1623
					editorMem.putString(IWorkbenchConstants.TAG_PINNED, "true"); //$NON-NLS-1$
(-)Eclipse UI/org/eclipse/ui/internal/ViewReference.java (+8 lines)
Lines 67-72 Link Here
67
67
68
		if (memento != null) {
68
		if (memento != null) {
69
			name = memento.getString(IWorkbenchConstants.TAG_PART_NAME);
69
			name = memento.getString(IWorkbenchConstants.TAG_PART_NAME);
70
			IMemento propBag = memento.getChild(IWorkbenchConstants.TAG_PROPERTIES);
71
			if (propBag != null) {
72
				IMemento[] props = propBag
73
						.getChildren(IWorkbenchConstants.TAG_PROPERTY);
74
				for (int i = 0; i < props.length; i++) {
75
					propertyCache.put(props[i].getID(), props[i].getTextData());
76
				}
77
			}
70
		}
78
		}
71
		if (name == null) {
79
		if (name == null) {
72
			name = title;
80
			name = title;
(-)Eclipse UI/org/eclipse/ui/internal/EditorReference.java (-1 / +10 lines)
Lines 140-146 Link Here
140
        String partName = memento
140
        String partName = memento
141
                .getString(IWorkbenchConstants.TAG_PART_NAME);
141
                .getString(IWorkbenchConstants.TAG_PART_NAME);
142
142
143
        // For compatibility set the part name to the title if not found
143
        IMemento propBag = memento.getChild(IWorkbenchConstants.TAG_PROPERTIES);
144
		if (propBag != null) {
145
			IMemento[] props = propBag
146
					.getChildren(IWorkbenchConstants.TAG_PROPERTY);
147
			for (int i = 0; i < props.length; i++) {
148
				propertyCache.put(props[i].getID(), props[i].getTextData());
149
			}
150
		}
151
152
		// For compatibility set the part name to the title if not found
144
        if (partName == null) {
153
        if (partName == null) {
145
            partName = title;
154
            partName = title;
146
        }
155
        }
(-)Eclipse UI/org/eclipse/ui/presentations/IPresentablePart.java (+40 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.presentations;
11
package org.eclipse.ui.presentations;
12
12
13
import org.eclipse.jface.util.IPropertyChangeListener;
13
import org.eclipse.swt.graphics.Image;
14
import org.eclipse.swt.graphics.Image;
14
import org.eclipse.swt.graphics.Rectangle;
15
import org.eclipse.swt.graphics.Rectangle;
15
import org.eclipse.swt.widgets.Control;
16
import org.eclipse.swt.widgets.Control;
Lines 226-229 Link Here
226
     */
227
     */
227
    public Control getControl();
228
    public Control getControl();
228
229
230
    /**
231
	 * Get a property from the part's arbitrary property set.
232
	 * <p>
233
	 * <b>Note:</b> this is a different set of properties than the ones covered
234
	 * by the PROP_* constants.
235
	 * </p>
236
	 * 
237
	 * @param key
238
	 *            The property key to retrieve. Must not be <code>null</code>.
239
	 * @return the property, or <code>null</code> if that property is not set.
240
	 * @since 3.3
241
	 */
242
	public String getPartProperty(String key);
243
	
244
	/**
245
	 * Add a listener for changes in the arbitrary properties set.
246
	 * <p>
247
	 * <b>Note:</b> this is a different set of properties than the ones covered
248
	 * by the PROP_* constants.
249
	 * </p>
250
	 * 
251
	 * @param listener
252
	 *            Must not be <code>null</code>.
253
	 * @since 3.3
254
	 */
255
	public void addPartPropertyListener(IPropertyChangeListener listener);
256
	
257
	/**
258
	 * Remove a change listener from the arbitrary properties set.
259
	 * <p>
260
	 * <b>Note:</b> this is a different set of properties than the ones covered
261
	 * by the PROP_* constants.
262
	 * </p>
263
	 * 
264
	 * @param listener
265
	 *            Must not be <code>null</code>.
266
	 * @since 3.3
267
	 */
268
	public void removePartPropertyListener(IPropertyChangeListener listener);
229
}
269
}
(-)Eclipse UI/org/eclipse/ui/IWorkbenchPartReference.java (+31 lines)
Lines 11-16 Link Here
11
11
12
package org.eclipse.ui;
12
package org.eclipse.ui;
13
13
14
import org.eclipse.jface.util.IPropertyChangeListener;
14
import org.eclipse.swt.graphics.Image;
15
import org.eclipse.swt.graphics.Image;
15
16
16
/**
17
/**
Lines 93-96 Link Here
93
     */
94
     */
94
    public boolean isDirty();
95
    public boolean isDirty();
95
    
96
    
97
    /**
98
	 * Return an arbitrary property from the reference. If the part has been
99
	 * instantiated, it just delegates to the part. If not, then it looks in its
100
	 * own cache of properties. If the property is not available or the part has
101
	 * never been instantiated, it can return <code>null</code>.
102
	 * 
103
	 * @param key
104
	 *            The property to return. Must not be <code>null</code>.
105
	 * @return The String property, or <code>null</code>.
106
	 * @since 3.3
107
	 */
108
    public String getPartProperty(String key);
109
    
110
    /**
111
	 * Add a listener for changes in the arbitrary properties set.
112
	 * 
113
	 * @param listener
114
	 *            Must not be <code>null</code>.
115
	 * @since 3.3
116
	 */
117
    public void addPartPropertyListener(IPropertyChangeListener listener);
118
    
119
    /**
120
	 * Remove a listener for changes in the arbitrary properties set.
121
	 * 
122
	 * @param listener
123
	 *            Must not be <code>null</code>.
124
	 * @since 3.3
125
	 */
126
    public void removePartPropertyListener(IPropertyChangeListener listener);
96
}
127
}
(-)Eclipse UI/org/eclipse/ui/part/WorkbenchPart.java (-3 / +67 lines)
Lines 10-31 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.part;
11
package org.eclipse.ui.part;
12
12
13
import com.ibm.icu.text.MessageFormat;
13
import java.util.Collections;
14
import java.util.HashMap;
15
import java.util.Map;
14
16
15
import org.eclipse.core.commands.common.EventManager;
17
import org.eclipse.core.commands.common.EventManager;
16
import org.eclipse.core.runtime.Assert;
18
import org.eclipse.core.runtime.Assert;
17
import org.eclipse.core.runtime.IConfigurationElement;
19
import org.eclipse.core.runtime.IConfigurationElement;
18
import org.eclipse.core.runtime.IExecutableExtension;
20
import org.eclipse.core.runtime.IExecutableExtension;
21
import org.eclipse.core.runtime.ListenerList;
19
import org.eclipse.core.runtime.Platform;
22
import org.eclipse.core.runtime.Platform;
20
import org.eclipse.jface.resource.ImageDescriptor;
23
import org.eclipse.jface.resource.ImageDescriptor;
21
import org.eclipse.jface.resource.JFaceResources;
24
import org.eclipse.jface.resource.JFaceResources;
25
import org.eclipse.jface.util.IPropertyChangeListener;
26
import org.eclipse.jface.util.PropertyChangeEvent;
22
import org.eclipse.jface.window.Window;
27
import org.eclipse.jface.window.Window;
23
import org.eclipse.swt.graphics.Image;
28
import org.eclipse.swt.graphics.Image;
24
import org.eclipse.swt.widgets.Composite;
29
import org.eclipse.swt.widgets.Composite;
25
import org.eclipse.ui.IPropertyListener;
30
import org.eclipse.ui.IPropertyListener;
26
import org.eclipse.ui.ISharedImages;
31
import org.eclipse.ui.ISharedImages;
27
import org.eclipse.ui.IWorkbenchPart;
32
import org.eclipse.ui.IWorkbenchPart;
28
import org.eclipse.ui.IWorkbenchPart2;
33
import org.eclipse.ui.IWorkbenchPart3;
29
import org.eclipse.ui.IWorkbenchPartConstants;
34
import org.eclipse.ui.IWorkbenchPartConstants;
30
import org.eclipse.ui.IWorkbenchPartSite;
35
import org.eclipse.ui.IWorkbenchPartSite;
31
import org.eclipse.ui.PlatformUI;
36
import org.eclipse.ui.PlatformUI;
Lines 34-39 Link Here
34
import org.eclipse.ui.internal.util.Util;
39
import org.eclipse.ui.internal.util.Util;
35
import org.eclipse.ui.plugin.AbstractUIPlugin;
40
import org.eclipse.ui.plugin.AbstractUIPlugin;
36
41
42
import com.ibm.icu.text.MessageFormat;
43
37
/**
44
/**
38
 * Abstract base implementation of all workbench parts.
45
 * Abstract base implementation of all workbench parts.
39
 * <p>
46
 * <p>
Lines 46-52 Link Here
46
 * @see org.eclipse.ui.part.EditorPart
53
 * @see org.eclipse.ui.part.EditorPart
47
 */
54
 */
48
public abstract class WorkbenchPart extends EventManager implements
55
public abstract class WorkbenchPart extends EventManager implements
49
		IWorkbenchPart2, IExecutableExtension, IWorkbenchPartOrientation {
56
		IWorkbenchPart3, IExecutableExtension, IWorkbenchPartOrientation {
50
    private String title = ""; //$NON-NLS-1$
57
    private String title = ""; //$NON-NLS-1$
51
58
52
    private ImageDescriptor imageDescriptor;
59
    private ImageDescriptor imageDescriptor;
Lines 62-67 Link Here
62
    private String partName = ""; //$NON-NLS-1$
69
    private String partName = ""; //$NON-NLS-1$
63
70
64
    private String contentDescription = ""; //$NON-NLS-1$
71
    private String contentDescription = ""; //$NON-NLS-1$
72
    
73
    private ListenerList partChangeListeners = new ListenerList();
65
74
66
    /**
75
    /**
67
     * Creates a new workbench part.
76
     * Creates a new workbench part.
Lines 103-108 Link Here
103
        // should not be notifying anyone after the part
112
        // should not be notifying anyone after the part
104
        // has been disposed.
113
        // has been disposed.
105
        clearListeners();
114
        clearListeners();
115
        partChangeListeners.clear();
106
    }
116
    }
107
117
108
    /**
118
    /**
Lines 462-465 Link Here
462
    	return Window.getDefaultOrientation();
472
    	return Window.getDefaultOrientation();
463
    }
473
    }
464
474
475
    /* (non-Javadoc)
476
     * @see org.eclipse.ui.IWorkbenchPart3#addPartPropertyListener(org.eclipse.jface.util.IPropertyChangeListener)
477
     */
478
    public void addPartPropertyListener(IPropertyChangeListener listener) {
479
    	partChangeListeners.add(listener);
480
    }
481
    
482
    /* (non-Javadoc)
483
     * @see org.eclipse.ui.IWorkbenchPart3#removePartPropertyListener(org.eclipse.jface.util.IPropertyChangeListener)
484
     */
485
    public void removePartPropertyListener(IPropertyChangeListener listener) {
486
    	partChangeListeners.remove(listener);
487
    }
488
    
489
    protected void firePartPropertyChanged(String key, String oldValue, String newValue) {
490
    	final PropertyChangeEvent event = new PropertyChangeEvent(this, key, oldValue, newValue);
491
    	Object[] l = partChangeListeners.getListeners();
492
    	for (int i = 0; i < l.length; i++) {
493
			try {
494
				((IPropertyChangeListener)l[i]).propertyChange(event);
495
			} catch (RuntimeException e) {
496
				WorkbenchPlugin.log(e);
497
			}
498
		}
499
    }
500
    
501
    private Map partProperties = new HashMap();
502
    
503
    /* (non-Javadoc)
504
     * @see org.eclipse.ui.IWorkbenchPart3#setPartProperty(java.lang.String, java.lang.String)
505
     */
506
    public void setPartProperty(String key, String value) {
507
    	String oldValue = (String) partProperties.get(key);
508
    	if (value==null) {
509
    		partProperties.remove(key);
510
    	} else {
511
    		partProperties.put(key, value);
512
    	}
513
    	firePartPropertyChanged(key, oldValue, value);
514
    }
515
    
516
    /* (non-Javadoc)
517
     * @see org.eclipse.ui.IWorkbenchPart3#getPartProperty(java.lang.String)
518
     */
519
    public String getPartProperty(String key) {
520
    	return (String)partProperties.get(key);
521
    }
522
    
523
    /* (non-Javadoc)
524
     * @see org.eclipse.ui.IWorkbenchPart3#getPartProperties()
525
     */
526
    public Map getPartProperties() {
527
    	return Collections.unmodifiableMap(partProperties);
528
    }
465
}
529
}
(-)Eclipse (+85 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.ui;
13
14
import java.util.Map;
15
16
import org.eclipse.jface.util.IPropertyChangeListener;
17
18
/**
19
 * A part can provide arbitrary properties. The properties will be persisted
20
 * between sessions by the part reference, and will be available from the part
21
 * reference as well as the part. The properties can only be set on a part, not
22
 * on the reference. The properties will be available to the IPresentablePart.
23
 * <p>
24
 * Setting a property must fire a PropertyChangeEvent.
25
 * </p>
26
 * 
27
 * @since 3.3
28
 */
29
public interface IWorkbenchPart3 extends IWorkbenchPart2 {
30
	/**
31
	 * Add a listener for changes in the arbitrary properties set.
32
	 * <p>
33
	 * <b>Note:</b> this is a different set of properties than the ones covered
34
	 * by the IWorkbenchPartConstants.PROP_* constants.
35
	 * </p>
36
	 * 
37
	 * @param listener
38
	 *            Must not be <code>null</code>.
39
	 */
40
	public void addPartPropertyListener(IPropertyChangeListener listener);
41
42
	/**
43
	 * Remove a change listener from the arbitrary properties set.
44
	 * <p>
45
	 * <b>Note:</b> this is a different set of properties than the ones covered
46
	 * by the IWorkbenchPartConstants.PROP_* constants.
47
	 * </p>
48
	 * 
49
	 * @param listener
50
	 *            Must not be <code>null</code>.
51
	 */
52
	public void removePartPropertyListener(IPropertyChangeListener listener);
53
54
	/**
55
	 * Return the value for the arbitrary property key, or <code>null</code>.
56
	 * 
57
	 * @param key
58
	 *            the arbitrary property. Must not be <code>null</code>.
59
	 * @return the property value, or <code>null</code>.
60
	 */
61
	public String getPartProperty(String key);
62
63
	/**
64
	 * Set an arbitrary property on the part. It is the implementor's
65
	 * responsibility to fire the corresponding PropertyChangeEvent.
66
	 * <p>
67
	 * A default implementation has been added to WorkbenchPart.
68
	 * </p>
69
	 * 
70
	 * @param key
71
	 *            the arbitrary property. Must not be <code>null</code>.
72
	 * @param value
73
	 *            the property value. A <code>null</code> value will remove
74
	 *            that property.
75
	 */
76
	public void setPartProperty(String key, String value);
77
78
	/**
79
	 * Return an unmodifiable map of the arbitrary properties. This method can
80
	 * be used to save the properties during workbench save/restore.
81
	 * 
82
	 * @return A Map of the properties. Must not be <code>null</code>.
83
	 */
84
	public Map getPartProperties();
85
}
(-)src/org/eclipse/ui/tests/performance/presentations/TestPresentablePart.java (+29 lines)
Lines 11-18 Link Here
11
package org.eclipse.ui.tests.performance.presentations;
11
package org.eclipse.ui.tests.performance.presentations;
12
12
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
import java.util.HashMap;
14
import java.util.List;
15
import java.util.List;
16
import java.util.Map;
15
17
18
import org.eclipse.core.runtime.ListenerList;
19
import org.eclipse.jface.util.IPropertyChangeListener;
16
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.events.DisposeEvent;
21
import org.eclipse.swt.events.DisposeEvent;
18
import org.eclipse.swt.events.DisposeListener;
22
import org.eclipse.swt.events.DisposeListener;
Lines 175-179 Link Here
175
        toRemove.dispose();
179
        toRemove.dispose();
176
        firePropertyChange(IPresentablePart.PROP_TOOLBAR);
180
        firePropertyChange(IPresentablePart.PROP_TOOLBAR);
177
    }
181
    }
182
183
    private ListenerList partPropertyListeners = new ListenerList();
184
    
185
    private Map partProperties = new HashMap();
186
    
187
	/* (non-Javadoc)
188
	 * @see org.eclipse.ui.presentations.IPresentablePart#addPartPropertyListener(org.eclipse.jface.util.IPropertyChangeListener)
189
	 */
190
	public void addPartPropertyListener(IPropertyChangeListener listener) {
191
		partPropertyListeners.add(listener);
192
	}
193
194
	/* (non-Javadoc)
195
	 * @see org.eclipse.ui.presentations.IPresentablePart#getPartProperty(java.lang.String)
196
	 */
197
	public String getPartProperty(String key) {
198
		return (String) partProperties.get(key);
199
	}
200
201
	/* (non-Javadoc)
202
	 * @see org.eclipse.ui.presentations.IPresentablePart#removePartPropertyListener(org.eclipse.jface.util.IPropertyChangeListener)
203
	 */
204
	public void removePartPropertyListener(IPropertyChangeListener listener) {
205
		partPropertyListeners.remove(listener);
206
	}
178
    
207
    
179
}
208
}
(-)Eclipse UI Tests/org/eclipse/ui/tests/api/ApiTestSuite.java (+2 lines)
Lines 13-18 Link Here
13
import junit.framework.Test;
13
import junit.framework.Test;
14
import junit.framework.TestSuite;
14
import junit.framework.TestSuite;
15
15
16
import org.eclipse.ui.tests.api.workbenchpart.ArbitraryPropertyTest;
16
import org.eclipse.ui.tests.api.workbenchpart.OverriddenTitleTest;
17
import org.eclipse.ui.tests.api.workbenchpart.OverriddenTitleTest;
17
import org.eclipse.ui.tests.api.workbenchpart.RawIViewPartTest;
18
import org.eclipse.ui.tests.api.workbenchpart.RawIViewPartTest;
18
import org.eclipse.ui.tests.api.workbenchpart.ViewPartTitleTest;
19
import org.eclipse.ui.tests.api.workbenchpart.ViewPartTitleTest;
Lines 76-80 Link Here
76
        addTest(new TestSuite(XMLMementoTest.class));
77
        addTest(new TestSuite(XMLMementoTest.class));
77
        addTest(new TestSuite(TrimLayoutTest.class));
78
        addTest(new TestSuite(TrimLayoutTest.class));
78
        addTest(new TestSuite(IWorkbenchPartTestableTests.class));
79
        addTest(new TestSuite(IWorkbenchPartTestableTests.class));
80
        addTest(new TestSuite(ArbitraryPropertyTest.class));
79
    }
81
    }
80
}
82
}
(-)Eclipse (+67 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.tests.api.workbenchpart;
12
13
import org.eclipse.jface.util.IPropertyChangeListener;
14
import org.eclipse.jface.util.PropertyChangeEvent;
15
import org.eclipse.ui.internal.WorkbenchPage;
16
import org.eclipse.ui.internal.WorkbenchWindow;
17
import org.eclipse.ui.tests.harness.util.UITestCase;
18
19
/**
20
 * @since 3.0
21
 */
22
public class ArbitraryPropertyTest extends UITestCase {
23
	final static String VIEW_ID = "org.eclipse.ui.tests.workbenchpart.OverriddenTitleView";
24
25
	/**
26
	 * @param testName
27
	 */
28
	public ArbitraryPropertyTest(String testName) {
29
		super(testName);
30
	}
31
32
	WorkbenchWindow window;
33
34
	WorkbenchPage page;
35
36
	/*
37
	 * (non-Javadoc)
38
	 * 
39
	 * @see org.eclipse.ui.tests.harness.util.UITestCase#doSetUp()
40
	 */
41
	protected void doSetUp() throws Exception {
42
		super.doSetUp();
43
		window = (WorkbenchWindow) openTestWindow();
44
		page = (WorkbenchPage) window.getActivePage();
45
	}
46
47
	/*
48
	 * (non-Javadoc)
49
	 * 
50
	 * @see org.eclipse.ui.tests.util.UITestCase#doTearDown()
51
	 */
52
	protected void doTearDown() throws Exception {
53
		super.doTearDown();
54
	}
55
56
	public void testViewProperties() throws Exception {
57
		OverriddenTitleView view = (OverriddenTitleView) page.showView(VIEW_ID);
58
		IPropertyChangeListener viewListener = new IPropertyChangeListener() {
59
			public void propertyChange(PropertyChangeEvent event) {
60
				System.err.println(event.getProperty());
61
			}
62
		};
63
		view.addPartPropertyListener(viewListener);
64
		view.setPartProperty("org.eclipse.ui.test.user", "pwebster");
65
		view.removePartPropertyListener(viewListener);
66
	}
67
}

Return to bug 89834