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/EditorReference.java (-1 / +14 lines)
Lines 33-38 Link Here
33
import org.eclipse.ui.IWorkbenchPage;
33
import org.eclipse.ui.IWorkbenchPage;
34
import org.eclipse.ui.IWorkbenchPart;
34
import org.eclipse.ui.IWorkbenchPart;
35
import org.eclipse.ui.IWorkbenchPart2;
35
import org.eclipse.ui.IWorkbenchPart2;
36
import org.eclipse.ui.IWorkbenchPart3;
36
import org.eclipse.ui.IWorkbenchPartConstants;
37
import org.eclipse.ui.IWorkbenchPartConstants;
37
import org.eclipse.ui.PartInitException;
38
import org.eclipse.ui.PartInitException;
38
import org.eclipse.ui.PlatformUI;
39
import org.eclipse.ui.PlatformUI;
Lines 140-146 Link Here
140
        String partName = memento
141
        String partName = memento
141
                .getString(IWorkbenchConstants.TAG_PART_NAME);
142
                .getString(IWorkbenchConstants.TAG_PART_NAME);
142
143
143
        // For compatibility set the part name to the title if not found
144
        IMemento propBag = memento.getChild(IWorkbenchConstants.TAG_PROPERTIES);
145
		if (propBag != null) {
146
			IMemento[] props = propBag
147
					.getChildren(IWorkbenchConstants.TAG_PROPERTY);
148
			for (int i = 0; i < props.length; i++) {
149
				propertyCache.put(props[i].getID(), props[i].getTextData());
150
			}
151
		}
152
153
		// For compatibility set the part name to the title if not found
144
        if (partName == null) {
154
        if (partName == null) {
145
            partName = title;
155
            partName = title;
146
        }
156
        }
Lines 592-597 Link Here
592
    					multiEditorChildren = manager.openMultiEditor(this,
602
    					multiEditorChildren = manager.openMultiEditor(this,
593
    						(MultiEditor) part, (MultiEditorInput) editorInput);
603
    						(MultiEditor) part, (MultiEditorInput) editorInput);
594
    				}
604
    				}
605
                    if (part instanceof IWorkbenchPart3) {
606
                    	createPartProperties((IWorkbenchPart3)part);
607
                    }
595
                } finally {
608
                } finally {
596
                    UIStats.end(UIStats.CREATE_PART, this, editorID);
609
                    UIStats.end(UIStats.CREATE_PART, this, editorID);
597
                }
610
                }
(-)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/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/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 (+12 lines)
Lines 27-32 Link Here
27
import org.eclipse.ui.IWorkbenchPage;
27
import org.eclipse.ui.IWorkbenchPage;
28
import org.eclipse.ui.IWorkbenchPart;
28
import org.eclipse.ui.IWorkbenchPart;
29
import org.eclipse.ui.IWorkbenchPart2;
29
import org.eclipse.ui.IWorkbenchPart2;
30
import org.eclipse.ui.IWorkbenchPart3;
30
import org.eclipse.ui.PartInitException;
31
import org.eclipse.ui.PartInitException;
31
import org.eclipse.ui.PlatformUI;
32
import org.eclipse.ui.PlatformUI;
32
import org.eclipse.ui.internal.misc.StatusUtil;
33
import org.eclipse.ui.internal.misc.StatusUtil;
Lines 67-72 Link Here
67
68
68
		if (memento != null) {
69
		if (memento != null) {
69
			name = memento.getString(IWorkbenchConstants.TAG_PART_NAME);
70
			name = memento.getString(IWorkbenchConstants.TAG_PART_NAME);
71
			IMemento propBag = memento.getChild(IWorkbenchConstants.TAG_PROPERTIES);
72
			if (propBag != null) {
73
				IMemento[] props = propBag
74
						.getChildren(IWorkbenchConstants.TAG_PROPERTY);
75
				for (int i = 0; i < props.length; i++) {
76
					propertyCache.put(props[i].getID(), props[i].getTextData());
77
				}
78
			}
70
		}
79
		}
71
		if (name == null) {
80
		if (name == null) {
72
			name = title;
81
			name = title;
Lines 307-312 Link Here
307
				UIStats.end(UIStats.CREATE_PART, view, label);
316
				UIStats.end(UIStats.CREATE_PART, view, label);
308
			}
317
			}
309
318
319
			if (view instanceof IWorkbenchPart3) {
320
				createPartProperties((IWorkbenchPart3)view);
321
			}
310
			// Create site
322
			// Create site
311
			site = new ViewSite(this, view, factory.page, desc);
323
			site = new ViewSite(this, view, factory.page, desc);
312
			actionBars = new ViewActionBars(factory.page.getActionBars(), site,
324
			actionBars = new ViewActionBars(factory.page.getActionBars(), site,
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchPartReference.java (+75 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.Iterator;
16
import java.util.Map;
14
17
15
import org.eclipse.core.runtime.Assert;
18
import org.eclipse.core.runtime.Assert;
16
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.ListenerList;
20
import org.eclipse.core.runtime.ListenerList;
18
import org.eclipse.jface.resource.ImageDescriptor;
21
import org.eclipse.jface.resource.ImageDescriptor;
19
import org.eclipse.jface.resource.JFaceResources;
22
import org.eclipse.jface.resource.JFaceResources;
23
import org.eclipse.jface.util.IPropertyChangeListener;
24
import org.eclipse.jface.util.PropertyChangeEvent;
20
import org.eclipse.osgi.util.NLS;
25
import org.eclipse.osgi.util.NLS;
21
import org.eclipse.swt.events.DisposeEvent;
26
import org.eclipse.swt.events.DisposeEvent;
22
import org.eclipse.swt.events.DisposeListener;
27
import org.eclipse.swt.events.DisposeListener;
Lines 29-34 Link Here
29
import org.eclipse.ui.ISharedImages;
34
import org.eclipse.ui.ISharedImages;
30
import org.eclipse.ui.IWorkbenchPart;
35
import org.eclipse.ui.IWorkbenchPart;
31
import org.eclipse.ui.IWorkbenchPart2;
36
import org.eclipse.ui.IWorkbenchPart2;
37
import org.eclipse.ui.IWorkbenchPart3;
32
import org.eclipse.ui.IWorkbenchPartConstants;
38
import org.eclipse.ui.IWorkbenchPartConstants;
33
import org.eclipse.ui.IWorkbenchPartReference;
39
import org.eclipse.ui.IWorkbenchPartReference;
34
import org.eclipse.ui.IWorkbenchPartSite;
40
import org.eclipse.ui.IWorkbenchPartSite;
Lines 137-146 Link Here
137
     */
143
     */
138
    private ListenerList internalPropChangeListeners = new ListenerList();
144
    private ListenerList internalPropChangeListeners = new ListenerList();
139
    
145
    
146
    private ListenerList partChangeListeners = new ListenerList();
147
    
140
    private String partName;
148
    private String partName;
141
149
142
    private String contentDescription;
150
    private String contentDescription;
143
    
151
    
152
    protected Map propertyCache = new HashMap();
153
    
144
    /**
154
    /**
145
     * Used to remember which events have been queued.
155
     * Used to remember which events have been queued.
146
     */
156
     */
Lines 163-168 Link Here
163
        }
173
        }
164
    };
174
    };
165
    
175
    
176
    private IPropertyChangeListener partPropertyChangeListener = new IPropertyChangeListener() {
177
		public void propertyChange(PropertyChangeEvent event) {
178
			partPropertyChanged(event);
179
		}
180
    };
181
    
166
    public WorkbenchPartReference() {
182
    public WorkbenchPartReference() {
167
        //no-op
183
        //no-op
168
    }
184
    }
Lines 283-288 Link Here
283
        	}
299
        	}
284
        }
300
        }
285
    }
301
    }
302
    
303
    protected void partPropertyChanged(PropertyChangeEvent event) {
304
    	firePartPropertyChange(event);
305
    }
286
306
287
    /**
307
    /**
288
     * Refreshes all cached values with the values from the real part 
308
     * 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.
591
                    // object that should dispose this control, and it will remove the listener before it does so.
572
                    getPane().getControl().addDisposeListener(prematureDisposeListener);
592
                    getPane().getControl().addDisposeListener(prematureDisposeListener);
573
                    part.addPropertyListener(propertyChangeListener);
593
                    part.addPropertyListener(propertyChangeListener);
594
                    if (part instanceof IWorkbenchPart3) {
595
                    	((IWorkbenchPart3)part).addPartPropertyListener(partPropertyChangeListener);
596
                    }
574
597
575
                    refreshFromPart();
598
                    refreshFromPart();
576
                    releaseReferences();
599
                    releaseReferences();
Lines 646-651 Link Here
646
        }
669
        }
647
        
670
        
648
        clearListenerList(internalPropChangeListeners);
671
        clearListenerList(internalPropChangeListeners);
672
        clearListenerList(partChangeListeners);
649
        Image oldImage = image;
673
        Image oldImage = image;
650
        ImageDescriptor oldDescriptor = imageDescriptor;
674
        ImageDescriptor oldDescriptor = imageDescriptor;
651
        image = null;
675
        image = null;
Lines 684-689 Link Here
684
            // Don't let exceptions in client code bring us down. Log them and continue.
708
            // Don't let exceptions in client code bring us down. Log them and continue.
685
            try {
709
            try {
686
                part.removePropertyListener(propertyChangeListener);
710
                part.removePropertyListener(propertyChangeListener);
711
                if (part instanceof IWorkbenchPart3) {
712
                	((IWorkbenchPart3)part).removePartPropertyListener(partPropertyChangeListener);
713
                }
687
                part.dispose();
714
                part.dispose();
688
            } catch (Exception e) {
715
            } catch (Exception e) {
689
                WorkbenchPlugin.log(e);
716
                WorkbenchPlugin.log(e);
Lines 712-715 Link Here
712
        return pinned;
739
        return pinned;
713
    }
740
    }
714
741
742
    /* (non-Javadoc)
743
     * @see org.eclipse.ui.IWorkbenchPartReference#getPartProperty(java.lang.String)
744
     */
745
    public String getPartProperty(String key) {
746
		if (part != null) {
747
			if (part instanceof IWorkbenchPart3) {
748
				return ((IWorkbenchPart3) part).getPartProperty(key);
749
			}
750
		} else {
751
			return (String)propertyCache.get(key);
752
		}
753
		return null;
754
	}
755
    
756
    /* (non-Javadoc)
757
     * @see org.eclipse.ui.IWorkbenchPartReference#addPartPropertyListener(org.eclipse.jface.util.IPropertyChangeListener)
758
     */
759
    public void addPartPropertyListener(IPropertyChangeListener listener) {
760
    	if (isDisposed()) {
761
    		return;
762
    	}
763
    	partChangeListeners.add(listener);
764
    }
765
    
766
    /* (non-Javadoc)
767
     * @see org.eclipse.ui.IWorkbenchPartReference#removePartPropertyListener(org.eclipse.jface.util.IPropertyChangeListener)
768
     */
769
    public void removePartPropertyListener(IPropertyChangeListener listener) {
770
    	if (isDisposed()) {
771
    		return;
772
    	}
773
    	partChangeListeners.remove(listener);
774
    }
775
    
776
    protected void firePartPropertyChange(PropertyChangeEvent event) {
777
		Object[] l = partChangeListeners.getListeners();
778
		for (int i = 0; i < l.length; i++) {
779
			((IPropertyChangeListener) l[i]).propertyChange(event);
780
		}
781
	}
782
    
783
    protected void createPartProperties(IWorkbenchPart3 workbenchPart) {
784
		Iterator i = propertyCache.entrySet().iterator();
785
		while (i.hasNext()) {
786
			Map.Entry e = (Map.Entry) i.next();
787
			workbenchPart.setPartProperty((String) e.getKey(), (String) e.getValue());
788
		}
789
	}
715
}
790
}
(-)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/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 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/internal/presentations/PresentablePart.java (-3 / +49 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
					PropertyChangeEvent e = new PropertyChangeEvent(this,
109
							event.getProperty(), event.getOldValue(), event.getNewValue());
110
					firePartPropertyChange(e);
111
				}
112
			};
113
		}
114
		return lazyPartPropertyChangeListener;
115
	}
95
116
96
    /**
117
    /**
97
     * Detach this PresentablePart from the real part. No further methods should be invoked
118
	 * Detach this PresentablePart from the real part. No further methods should
98
     * on this object.
119
	 * be invoked on this object.
99
     */
120
	 */
100
    public void dispose() {
121
    public void dispose() {
101
        // Ensure that the property listener is detached (necessary to prevent leaks)
122
        // Ensure that the property listener is detached (necessary to prevent leaks)
102
        getPane().removePropertyListener(getPropertyListenerProxy());
123
        getPane().removePropertyListener(getPropertyListenerProxy());
124
        getPane().removePartPropertyListener(getPartPropertyListenerProxy());
103
125
104
        // Null out the various fields to ease garbage collection (optional)
126
        // Null out the various fields to ease garbage collection (optional)
105
        part = null;
127
        part = null;
106
        listeners.clear();
128
        listeners.clear();
107
        listeners = null;
129
        listeners = null;
130
        partPropertyChangeListeners.clear();
131
        partPropertyChangeListeners = null;
108
    }
132
    }
109
133
110
    public void firePropertyChange(int propertyId) {
134
    public void firePropertyChange(int propertyId) {
Lines 121-126 Link Here
121
        listeners.remove(listener);
145
        listeners.remove(listener);
122
    }
146
    }
123
147
148
    protected void firePartPropertyChange(PropertyChangeEvent event) {
149
		Object[] l = partPropertyChangeListeners.getListeners();
150
		for (int i = 0; i < l.length; i++) {
151
			((IPropertyChangeListener) l[i]).propertyChange(event);
152
		}
153
	}
154
    
155
    public void addPartPropertyListener(IPropertyChangeListener listener) {
156
    	partPropertyChangeListeners.add(listener);
157
    }
158
    
159
    public void removePartPropertyListener(IPropertyChangeListener listener) {
160
    	partPropertyChangeListeners.remove(listener);
161
    }
162
    
124
    /* (non-Javadoc)
163
    /* (non-Javadoc)
125
     * @see org.eclipse.ui.presentations.IPresentablePart#setBounds(org.eclipse.swt.graphics.Rectangle)
164
     * @see org.eclipse.ui.presentations.IPresentablePart#setBounds(org.eclipse.swt.graphics.Rectangle)
126
     */
165
     */
Lines 351-354 Link Here
351
        }
390
        }
352
    }
391
    }
353
392
393
	/* (non-Javadoc)
394
	 * @see org.eclipse.ui.presentations.IPresentablePart#getPartProperty(java.lang.String)
395
	 */
396
	public String getPartProperty(String key) {
397
		return getPartReference().getPartProperty(key);
398
	}
399
354
}
400
}
(-)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 (+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
}
(-)UI-Session Tests.launch (-2 / +2 lines)
Lines 16-28 Link Here
16
<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/pde-junit"/>
16
<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/pde-junit"/>
17
<booleanAttribute key="clearws" value="true"/>
17
<booleanAttribute key="clearws" value="true"/>
18
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.ui.tests.session.SessionTests"/>
18
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.ui.tests.session.SessionTests"/>
19
<stringAttribute key="pde.version" value="3.2a"/>
19
<stringAttribute key="pde.version" value="3.3"/>
20
<stringAttribute key="templateConfig" value=""/>
20
<stringAttribute key="templateConfig" value=""/>
21
<booleanAttribute key="default" value="true"/>
21
<booleanAttribute key="default" value="true"/>
22
<booleanAttribute key="clearConfig" value="true"/>
22
<booleanAttribute key="clearConfig" value="true"/>
23
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
23
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
24
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
25
<booleanAttribute key="useDefaultConfigArea" value="false"/>
24
<booleanAttribute key="useDefaultConfigArea" value="false"/>
25
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
26
<booleanAttribute key="useDefaultConfig" value="true"/>
26
<booleanAttribute key="useDefaultConfig" value="true"/>
27
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
27
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
28
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.ui.tests"/>
28
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.ui.tests"/>
(-)Eclipse UI Tests/org/eclipse/ui/tests/session/SessionTests.java (-8 / +12 lines)
Lines 29-36 Link Here
29
	 * 
29
	 * 
30
	 */
30
	 */
31
	public SessionTests() {
31
	public SessionTests() {
32
		addHandlerStateTests();
32
//		addHandlerStateTests();
33
		addIntroTests();
33
//		addIntroTests();
34
		addEditorTests();
34
		addEditorTests();
35
		addViewStateTests();
35
		addViewStateTests();
36
	}
36
	}
Lines 39-48 Link Here
39
	 * Add editor tests that involve starting and stopping sessions.
39
	 * Add editor tests that involve starting and stopping sessions.
40
	 */
40
	 */
41
	private void addEditorTests() {
41
	private void addEditorTests() {
42
//		addTest(new WorkbenchSessionTest("editorSessionTests",
43
//				Bug95357Test.class));
44
//		addTest(new WorkbenchSessionTest("editorSessionTests",
45
//				EditorWithStateTest.class));
42
		addTest(new WorkbenchSessionTest("editorSessionTests",
46
		addTest(new WorkbenchSessionTest("editorSessionTests",
43
				Bug95357Test.class));
47
				ArbitraryPropertiesEditorTest.class));
44
		addTest(new WorkbenchSessionTest("editorSessionTests",
45
				EditorWithStateTest.class));
46
	}
48
	}
47
49
48
	/**
50
	/**
Lines 70-78 Link Here
70
	 * workspace for these particular session tests.
72
	 * workspace for these particular session tests.
71
	 */
73
	 */
72
	private void addViewStateTests() {
74
	private void addViewStateTests() {
75
//		addTest(new WorkbenchSessionTest("editorSessionTests",
76
//				Bug98800Test.class));
77
//		addTest(new WorkbenchSessionTest("editorSessionTests",
78
//				Bug108033Test.class));
73
		addTest(new WorkbenchSessionTest("editorSessionTests",
79
		addTest(new WorkbenchSessionTest("editorSessionTests",
74
				Bug98800Test.class));
80
				ArbitraryPropertiesViewTest.class));
75
		addTest(new WorkbenchSessionTest("editorSessionTests",
76
				Bug108033Test.class));
77
	}
81
	}
78
}
82
}
(-)Eclipse (+141 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2005 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.session;
12
13
import junit.framework.TestCase;
14
import junit.framework.TestSuite;
15
16
import org.eclipse.jface.util.IPropertyChangeListener;
17
import org.eclipse.jface.util.PropertyChangeEvent;
18
import org.eclipse.ui.IViewPart;
19
import org.eclipse.ui.IViewReference;
20
import org.eclipse.ui.IWorkbench;
21
import org.eclipse.ui.IWorkbenchPage;
22
import org.eclipse.ui.IWorkbenchPart3;
23
import org.eclipse.ui.PlatformUI;
24
25
/**
26
 * If a view is not activated during a session, it's part is not instantiated.
27
 * This tests that case, and the outcome should be the view has it's last
28
 * session state when it is finally instantiated in the workbench.
29
 * 
30
 * @since 3.3
31
 */
32
public class ArbitraryPropertiesViewTest extends TestCase {
33
	/**
34
	 * 
35
	 */
36
	private static final String USER_PROP = "org.eclipse.ui.tests.users";
37
38
	private static final String PROBLEM_VIEW_ID = "org.eclipse.ui.views.ProblemView";
39
40
	private static final String VIEW_WITH_STATE_ID = "org.eclipse.ui.tests.session.ViewWithState";
41
42
	public static TestSuite suite() {
43
		return new TestSuite(ArbitraryPropertiesViewTest.class);
44
	}
45
46
	public ArbitraryPropertiesViewTest(String testName) {
47
		super(testName);
48
	}
49
50
	/**
51
	 * This is the first part of a 3 part tests. First instantiate a view and
52
	 * set a state.
53
	 * 
54
	 * @throws Throwable
55
	 */
56
	public void testActivateView() throws Throwable {
57
		final IWorkbench workbench = PlatformUI.getWorkbench();
58
		final IWorkbenchPage page = workbench.getActiveWorkbenchWindow()
59
				.getActivePage();
60
61
		IViewPart v = page.showView(VIEW_WITH_STATE_ID);
62
63
		// put another view in front of our view
64
		page.showView(PROBLEM_VIEW_ID);
65
66
		IWorkbenchPart3 wp = (IWorkbenchPart3) v;
67
		wp.setPartProperty(USER_PROP, "pwebster");
68
	}
69
70
	/**
71
	 * The second session doesn't activate the view, so it should not be
72
	 * instantiated.
73
	 * 
74
	 * @throws Throwable
75
	 */
76
	public void testSecondOpening() throws Throwable {
77
		final IWorkbench workbench = PlatformUI.getWorkbench();
78
		final IWorkbenchPage page = workbench.getActiveWorkbenchWindow()
79
				.getActivePage();
80
81
		IViewReference[] views = page.getViewReferences();
82
		for (int i = 0; i < views.length; i++) {
83
			IViewReference ref = views[i];
84
			if (ref.getId().equals(VIEW_WITH_STATE_ID)) {
85
				assertNull("The view should not be instantiated", ref
86
						.getPart(false));
87
				assertEquals("pwebster", ref.getPartProperty(USER_PROP));
88
			}
89
		}
90
	}
91
92
	static class PropListener implements IPropertyChangeListener {
93
		public int count = 0;
94
95
		/*
96
		 * (non-Javadoc)
97
		 * 
98
		 * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
99
		 */
100
		public void propertyChange(PropertyChangeEvent event) {
101
			count++;
102
		}
103
	};
104
105
	/**
106
	 * Activate the view and it's state should re-appear.
107
	 * 
108
	 * @throws Throwable
109
	 */
110
	public void testPartInstantiation() throws Throwable {
111
		final IWorkbench workbench = PlatformUI.getWorkbench();
112
		final IWorkbenchPage page = workbench.getActiveWorkbenchWindow()
113
				.getActivePage();
114
		
115
		IViewReference[] views = page.getViewReferences();
116
		for (int i = 0; i < views.length; i++) {
117
			System.err.println("views: " + views[i].getId());
118
		}
119
120
		IViewReference ref = page.findViewReference(VIEW_WITH_STATE_ID);
121
		assertEquals("pwebster", ref.getPartProperty(USER_PROP));
122
		PropListener listener = new PropListener();
123
		ref.addPartPropertyListener(listener);
124
125
		IViewPart v = null;
126
		try {
127
			v = page.showView(VIEW_WITH_STATE_ID);
128
			IWorkbenchPart3 wp = (IWorkbenchPart3) v;
129
			assertEquals("pwebster", wp.getPartProperty(USER_PROP));
130
			assertEquals(0, listener.count);
131
		} finally {
132
			ref.removePartPropertyListener(listener);
133
		}
134
		// the state should not be saved between a close and
135
		// an open in the same session
136
		page.hideView(v);
137
		v = page.showView(VIEW_WITH_STATE_ID);
138
		IWorkbenchPart3 wp = (IWorkbenchPart3) v;
139
		assertNull(wp.getPartProperty(USER_PROP));
140
	}
141
}
(-)Eclipse (+154 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2005 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.session;
12
13
import junit.framework.TestCase;
14
import junit.framework.TestSuite;
15
16
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.resources.IProject;
18
import org.eclipse.jface.util.IPropertyChangeListener;
19
import org.eclipse.jface.util.PropertyChangeEvent;
20
import org.eclipse.ui.IEditorInput;
21
import org.eclipse.ui.IEditorPart;
22
import org.eclipse.ui.IEditorReference;
23
import org.eclipse.ui.IWorkbench;
24
import org.eclipse.ui.IWorkbenchPage;
25
import org.eclipse.ui.IWorkbenchPart3;
26
import org.eclipse.ui.PlatformUI;
27
import org.eclipse.ui.ide.IDE;
28
import org.eclipse.ui.part.FileEditorInput;
29
import org.eclipse.ui.tests.api.workbenchpart.TitleTestEditor;
30
import org.eclipse.ui.tests.harness.util.FileUtil;
31
32
/**
33
 * If a view is not activated during a session, it's part is not instantiated.
34
 * This tests that case, and the outcome should be the view has it's last
35
 * session state when it is finally instantiated in the workbench.
36
 * 
37
 * @since 3.3
38
 */
39
public class ArbitraryPropertiesEditorTest extends TestCase {
40
	/**
41
	 * 
42
	 */
43
	private static final String USER_PROP = "org.eclipse.ui.tests.users";
44
45
	private static final String EDITOR_ID = "org.eclipse.ui.tests.TitleTestEditor";
46
47
	public static TestSuite suite() {
48
		return new TestSuite(ArbitraryPropertiesEditorTest.class);
49
	}
50
51
	public ArbitraryPropertiesEditorTest(String testName) {
52
		super(testName);
53
	}
54
55
	/**
56
	 * This is the first part of a 3 part tests. First instantiate a view and
57
	 * set a state.
58
	 * 
59
	 * @throws Throwable
60
	 */
61
	public void testOpenEditor() throws Throwable {
62
		final IWorkbench workbench = PlatformUI.getWorkbench();
63
		final IWorkbenchPage page = workbench.getActiveWorkbenchWindow()
64
				.getActivePage();
65
66
		IProject proj = FileUtil.createProject("EditorSessionTest");
67
		IFile file = FileUtil.createFile("state.txt", proj);
68
69
		TitleTestEditor editor = (TitleTestEditor) page.openEditor(
70
				new FileEditorInput(file), EDITOR_ID);
71
72
		// this makes the second file active on the first
73
		file = FileUtil.createFile("state_active.txt", proj);
74
		IDE.openEditor(page, file);
75
76
		editor.setPartProperty(USER_PROP, "pwebster");
77
	}
78
79
	/**
80
	 * The second session doesn't activate the view, so it should not be
81
	 * instantiated.
82
	 * 
83
	 * @throws Throwable
84
	 */
85
	public void testSecondOpening() throws Throwable {
86
		final IWorkbench workbench = PlatformUI.getWorkbench();
87
		final IWorkbenchPage page = workbench.getActiveWorkbenchWindow()
88
				.getActivePage();
89
		IEditorReference[] editors = page.getEditorReferences();
90
		for (int i = 0; i < editors.length; i++) {
91
			IEditorReference ref = editors[i];
92
			if (ref.getEditorInput().getName().equals("state.txt")) {
93
				assertNull("The editor should not be instantiated", ref
94
						.getPart(false));
95
				assertEquals("pwebster", ref.getPartProperty(USER_PROP));
96
			}
97
		}
98
	}
99
100
	static class PropListener implements IPropertyChangeListener {
101
		public int count = 0;
102
103
		/*
104
		 * (non-Javadoc)
105
		 * 
106
		 * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
107
		 */
108
		public void propertyChange(PropertyChangeEvent event) {
109
			count++;
110
		}
111
	};
112
113
	/**
114
	 * Activate the view and it's state should re-appear.
115
	 * 
116
	 * @throws Throwable
117
	 */
118
	public void testPartInstantiation() throws Throwable {
119
		final IWorkbench workbench = PlatformUI.getWorkbench();
120
		final IWorkbenchPage page = workbench.getActiveWorkbenchWindow()
121
				.getActivePage();
122
123
		IEditorReference ref = null;
124
		IEditorReference[] editors = page.getEditorReferences();
125
		for (int i = 0; i < editors.length; i++) {
126
			if (editors[i].getEditorInput().getName().equals("state.txt")) {
127
				ref = editors[i];
128
			}
129
		}
130
131
		assertEquals("pwebster", ref.getPartProperty(USER_PROP));
132
		PropListener listener = new PropListener();
133
		ref.addPartPropertyListener(listener);
134
135
		try {
136
137
			IWorkbenchPart3 wp = (IWorkbenchPart3) ref.getPart(true);
138
			assertEquals("pwebster", wp.getPartProperty(USER_PROP));
139
			assertEquals(0, listener.count);
140
		} finally {
141
			ref.removePartPropertyListener(listener);
142
		}
143
144
		IEditorInput input = ref.getEditorInput();
145
146
		// the state should not be saved between a close and
147
		// an open in the same session
148
		page.closeEditor((IEditorPart) ref.getPart(true), false);
149
150
		TitleTestEditor editor = (TitleTestEditor) page.openEditor(input,
151
				EDITOR_ID);
152
		assertNull(editor.getPartProperty(USER_PROP));
153
	}
154
}
(-)Eclipse (+176 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.core.resources.IFile;
14
import org.eclipse.core.resources.IStorage;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.jface.resource.ImageDescriptor;
17
import org.eclipse.jface.util.IPropertyChangeListener;
18
import org.eclipse.jface.util.PropertyChangeEvent;
19
import org.eclipse.ui.IEditorReference;
20
import org.eclipse.ui.IFileEditorInput;
21
import org.eclipse.ui.IPersistableElement;
22
import org.eclipse.ui.IViewReference;
23
import org.eclipse.ui.internal.WorkbenchPage;
24
import org.eclipse.ui.internal.WorkbenchWindow;
25
import org.eclipse.ui.tests.harness.util.UITestCase;
26
27
/**
28
 * @since 3.0
29
 */
30
public class ArbitraryPropertyTest extends UITestCase {
31
	/**
32
	 * 
33
	 */
34
	private static final String EDITOR_ID = "org.eclipse.ui.tests.TitleTestEditor";
35
36
	/**
37
	 * 
38
	 */
39
	private static final String USER_PROP = "org.eclipse.ui.test.user";
40
41
	final static String VIEW_ID = "org.eclipse.ui.tests.workbenchpart.OverriddenTitleView";
42
43
	/**
44
	 * @param testName
45
	 */
46
	public ArbitraryPropertyTest(String testName) {
47
		super(testName);
48
	}
49
50
	WorkbenchWindow window;
51
52
	WorkbenchPage page;
53
54
	/*
55
	 * (non-Javadoc)
56
	 * 
57
	 * @see org.eclipse.ui.tests.harness.util.UITestCase#doSetUp()
58
	 */
59
	protected void doSetUp() throws Exception {
60
		super.doSetUp();
61
		window = (WorkbenchWindow) openTestWindow();
62
		page = (WorkbenchPage) window.getActivePage();
63
	}
64
65
	/*
66
	 * (non-Javadoc)
67
	 * 
68
	 * @see org.eclipse.ui.tests.util.UITestCase#doTearDown()
69
	 */
70
	protected void doTearDown() throws Exception {
71
		super.doTearDown();
72
	}
73
74
	static class PropListener implements IPropertyChangeListener {
75
		String firedProp = null;
76
77
		String firedOV = null;
78
79
		String firedNV = null;
80
81
		public void propertyChange(PropertyChangeEvent event) {
82
			firedProp = event.getProperty();
83
			firedOV = (String) event.getOldValue();
84
			firedNV = (String) event.getNewValue();
85
		}
86
	};
87
88
	public void testViewProperties() throws Exception {
89
		OverriddenTitleView view = (OverriddenTitleView) page.showView(VIEW_ID);
90
		IViewReference ref = (IViewReference) page.getReference(view);
91
92
		PropListener viewListener = new PropListener();
93
		view.addPartPropertyListener(viewListener);
94
		PropListener refListener = new PropListener();
95
		ref.addPartPropertyListener(refListener);
96
97
		view.setPartProperty(USER_PROP, "pwebster");
98
99
		try {
100
			assertEquals("pwebster", view.getPartProperty(USER_PROP));
101
			assertEquals("pwebster", ref.getPartProperty(USER_PROP));
102
103
			assertEquals(USER_PROP, viewListener.firedProp);
104
			assertNull(viewListener.firedOV);
105
			assertEquals("pwebster", viewListener.firedNV);
106
			assertEquals(USER_PROP, refListener.firedProp);
107
			assertNull(refListener.firedOV);
108
			assertEquals("pwebster", refListener.firedNV);
109
		} finally {
110
			view.removePartPropertyListener(viewListener);
111
			ref.removePartPropertyListener(refListener);
112
		}
113
	}
114
115
	public void testEditorProperties() throws Exception {
116
		IFileEditorInput input = new IFileEditorInput() {
117
			public boolean exists() {
118
				return true;
119
			}
120
121
			public ImageDescriptor getImageDescriptor() {
122
				return null;
123
			}
124
125
			public String getName() {
126
				return "MyInputFile";
127
			}
128
129
			public IPersistableElement getPersistable() {
130
				return null;
131
			}
132
133
			public String getToolTipText() {
134
				return "My Input File";
135
			}
136
137
			public Object getAdapter(Class adapter) {
138
				return null;
139
			}
140
141
			public IFile getFile() {
142
				return null;
143
			}
144
145
			public IStorage getStorage() throws CoreException {
146
				if (false) throw new CoreException(null);
147
				return null;
148
			}
149
		};
150
		TitleTestEditor editor = (TitleTestEditor) page.openEditor(input,
151
				EDITOR_ID);
152
		IEditorReference ref = (IEditorReference) page.getReference(editor);
153
154
		PropListener editorListener = new PropListener();
155
		editor.addPartPropertyListener(editorListener);
156
		PropListener refListener = new PropListener();
157
		ref.addPartPropertyListener(refListener);
158
159
		editor.setPartProperty(USER_PROP, "pwebster");
160
161
		try {
162
			assertEquals("pwebster", editor.getPartProperty(USER_PROP));
163
			assertEquals("pwebster", ref.getPartProperty(USER_PROP));
164
165
			assertEquals(USER_PROP, editorListener.firedProp);
166
			assertNull(editorListener.firedOV);
167
			assertEquals("pwebster", editorListener.firedNV);
168
			assertEquals(USER_PROP, refListener.firedProp);
169
			assertNull(refListener.firedOV);
170
			assertEquals("pwebster", refListener.firedNV);
171
		} finally {
172
			editor.removePartPropertyListener(editorListener);
173
			ref.removePartPropertyListener(refListener);
174
		}
175
	}
176
}

Return to bug 89834