View | Details | Raw Unified | Return to bug 37183
Collapse All | Expand All

(-)Eclipse UI Tests/org/eclipse/ui/tests/api/IWorkingSetTest.java (-1 / +41 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Benjamin Muskalla - bug 37183 (need "oldValue" forIWorkingSet PropertyChangeEvent)
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui.tests.api;
12
package org.eclipse.ui.tests.api;
12
13
Lines 15-21 Link Here
15
import org.eclipse.core.resources.IWorkspace;
16
import org.eclipse.core.resources.IWorkspace;
16
import org.eclipse.core.resources.IWorkspaceRoot;
17
import org.eclipse.core.resources.IWorkspaceRoot;
17
import org.eclipse.core.resources.ResourcesPlugin;
18
import org.eclipse.core.resources.ResourcesPlugin;
19
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IAdaptable;
20
import org.eclipse.core.runtime.IAdaptable;
21
import org.eclipse.jface.util.IPropertyChangeListener;
22
import org.eclipse.jface.util.PropertyChangeEvent;
19
import org.eclipse.ui.IWorkingSet;
23
import org.eclipse.ui.IWorkingSet;
20
import org.eclipse.ui.IWorkingSetManager;
24
import org.eclipse.ui.IWorkingSetManager;
21
import org.eclipse.ui.tests.harness.util.ArrayUtil;
25
import org.eclipse.ui.tests.harness.util.ArrayUtil;
Lines 34-39 Link Here
34
38
35
    IWorkingSet fWorkingSet;
39
    IWorkingSet fWorkingSet;
36
40
41
	public String fChangeProperty;
42
43
	public IWorkingSet fChangeNewValue;
44
45
	public IWorkingSet fChangeOldValue;
46
37
    public IWorkingSetTest(String testName) {
47
    public IWorkingSetTest(String testName) {
38
        super(testName);
48
        super(testName);
39
    }
49
    }
Lines 117-122 Link Here
117
        assertEquals(" ", fWorkingSet.getName());
127
        assertEquals(" ", fWorkingSet.getName());
118
    }
128
    }
119
    
129
    
130
    public void testBug37183() throws CoreException {
131
    	class TestPropertyChangeListener implements IPropertyChangeListener {
132
            public void propertyChange(PropertyChangeEvent event) {
133
                fChangeProperty = event.getProperty();
134
                fChangeNewValue = (IWorkingSet) event.getNewValue();
135
                fChangeOldValue = (IWorkingSet) event.getOldValue();
136
            }
137
        }
138
    	IPropertyChangeListener workingSetListener = new TestPropertyChangeListener();
139
    	fWorkbench.getWorkingSetManager().addPropertyChangeListener(workingSetListener);
140
    			
141
    	final String newLabel = "new foo label";
142
		fWorkingSet.setLabel(newLabel);
143
		assertNotNull(fChangeOldValue);
144
		assertEquals(WORKING_SET_NAME_1, fChangeOldValue.getLabel());
145
		
146
    	fWorkingSet.setName(WORKING_SET_NAME_2);
147
    	assertNotNull(fChangeOldValue);
148
		assertEquals(WORKING_SET_NAME_1, fChangeOldValue.getName());
149
    	
150
        IProject p1 = FileUtil.createProject("TP1");
151
        IFile f1 = FileUtil.createFile("f1.txt", p1);
152
        IAdaptable[] elements = new IAdaptable[] { f1, p1 };
153
        fWorkingSet.setElements(elements);
154
        assertNotNull(fChangeOldValue);
155
		assertEquals(1, fChangeOldValue.getElements().length);
156
        
157
        fWorkbench.getWorkingSetManager().removePropertyChangeListener(workingSetListener);
158
    }
159
    
120
    public void testIsEmpty() {
160
    public void testIsEmpty() {
121
		fWorkingSet.setElements(new IAdaptable[] {});
161
		fWorkingSet.setElements(new IAdaptable[] {});
122
		assertTrue(fWorkingSet.isEmpty());
162
		assertTrue(fWorkingSet.isEmpty());
(-)Eclipse UI Tests/org/eclipse/ui/tests/api/IWorkingSetManagerTest.java (-3 / +3 lines)
Lines 131-149 Link Here
131
													// label property
131
													// label property
132
		assertEquals(IWorkingSetManager.CHANGE_WORKING_SET_LABEL_CHANGE,
132
		assertEquals(IWorkingSetManager.CHANGE_WORKING_SET_LABEL_CHANGE,
133
				fChangeProperty);
133
				fChangeProperty);
134
		assertEquals(null, fChangeOldValue);
134
		assertNotNull(fChangeOldValue);
135
		assertEquals(fWorkingSet, fChangeNewValue);
135
		assertEquals(fWorkingSet, fChangeNewValue);
136
		fWorkingSet.setName(WORKING_SET_NAME_2);
136
		fWorkingSet.setName(WORKING_SET_NAME_2);
137
		assertEquals(IWorkingSetManager.CHANGE_WORKING_SET_NAME_CHANGE,
137
		assertEquals(IWorkingSetManager.CHANGE_WORKING_SET_NAME_CHANGE,
138
				fChangeProperty);
138
				fChangeProperty);
139
		assertEquals(null, fChangeOldValue);
139
		assertNotNull(fChangeOldValue);
140
		assertEquals(fWorkingSet, fChangeNewValue);
140
		assertEquals(fWorkingSet, fChangeNewValue);
141
141
142
        resetChangeData();
142
        resetChangeData();
143
        fWorkingSet.setElements(new IAdaptable[] {});
143
        fWorkingSet.setElements(new IAdaptable[] {});
144
        assertEquals(IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE,
144
        assertEquals(IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE,
145
                fChangeProperty);
145
                fChangeProperty);
146
        assertEquals(null, fChangeOldValue);
146
        assertNotNull(fChangeOldValue);
147
        assertEquals(fWorkingSet, fChangeNewValue);
147
        assertEquals(fWorkingSet, fChangeNewValue);
148
    }
148
    }
149
149
(-)Eclipse UI/org/eclipse/ui/IWorkingSet.java (-1 / +2 lines)
Lines 24-31 Link Here
24
 * @since 2.0 initial version
24
 * @since 2.0 initial version
25
 * @since 3.0 now extends {@link org.eclipse.ui.IPersistableElement}
25
 * @since 3.0 now extends {@link org.eclipse.ui.IPersistableElement}
26
 * @since 3.2 now extends {@link org.eclipse.core.runtime.IAdaptable}
26
 * @since 3.2 now extends {@link org.eclipse.core.runtime.IAdaptable}
27
 * @since 3.4 now extends {@link Cloneable}
27
 */
28
 */
28
public interface IWorkingSet extends IPersistableElement, IAdaptable {
29
public interface IWorkingSet extends IPersistableElement, IAdaptable, Cloneable {
29
    /**
30
    /**
30
     * Returns the elements that are contained in this working set.
31
     * Returns the elements that are contained in this working set.
31
     * 
32
     * 
(-)Eclipse UI/org/eclipse/ui/IWorkingSetManager.java (-7 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Benjamin Muskalla - bug 37183 (need "oldValue" forIWorkingSet PropertyChangeEvent)
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui;
12
package org.eclipse.ui;
12
13
Lines 55-61 Link Here
55
    /**
56
    /**
56
     * Change event id when the working set contents changed
57
     * Change event id when the working set contents changed
57
     * newValue of the PropertyChangeEvent will be the changed working set.
58
     * newValue of the PropertyChangeEvent will be the changed working set.
58
     * oldValue will be null.
59
     *
59
     *
60
     * @see IPropertyChangeListener
60
     * @see IPropertyChangeListener
61
     */
61
     */
Lines 64-70 Link Here
64
    /**
64
    /**
65
     * Change event id when the working set name changed.
65
     * Change event id when the working set name changed.
66
     * newValue of the PropertyChangeEvent will be the changed working set.
66
     * newValue of the PropertyChangeEvent will be the changed working set.
67
     * oldValue will be null.
68
     *
67
     *
69
     * @see IPropertyChangeListener
68
     * @see IPropertyChangeListener
70
     */
69
     */
Lines 73-79 Link Here
73
    /**
72
    /**
74
     * Change event id when the working set label changed.
73
     * Change event id when the working set label changed.
75
     * newValue of the PropertyChangeEvent will be the changed working set.
74
     * newValue of the PropertyChangeEvent will be the changed working set.
76
     * oldValue will be null.
77
     *
75
     *
78
     * @see IPropertyChangeListener
76
     * @see IPropertyChangeListener
79
     * @since 3.2
77
     * @since 3.2
Lines 83-97 Link Here
83
    /**
81
    /**
84
     * Change event id when a working set updater got installed.
82
     * Change event id when a working set updater got installed.
85
     * NewValue of the PropertyChangeEvent will be the installed updater.
83
     * NewValue of the PropertyChangeEvent will be the installed updater.
86
     * OldValue will be <code>null</code>
84
     * oldValue will be <code>null</code>
87
     * @since 3.1
85
     * @since 3.1
88
     */
86
     */
89
    public static final String CHANGE_WORKING_SET_UPDATER_INSTALLED = "workingSetUpdaterInstalled"; //$NON-NLS-1$
87
    public static final String CHANGE_WORKING_SET_UPDATER_INSTALLED = "workingSetUpdaterInstalled"; //$NON-NLS-1$
90
    
88
    
91
    /**
89
    /**
92
     * Change event id when a working set updater got uninstalled.
90
     * Change event id when a working set updater got uninstalled.
93
     * NewValue will be <code>null</code>
91
     * newValue will be <code>null</code>
94
     * OldValue of the PropertyChangeEvent will be the uninstalled updater.
92
     * oldValue of the PropertyChangeEvent will be the uninstalled updater.
95
     * @since 3.3
93
     * @since 3.3
96
     */
94
     */
97
    public static final String CHANGE_WORKING_SET_UPDATER_UNINSTALLED = "workingSetUpdaterUninstalled"; //$NON-NLS-1$
95
    public static final String CHANGE_WORKING_SET_UPDATER_UNINSTALLED = "workingSetUpdaterUninstalled"; //$NON-NLS-1$
(-)Eclipse UI/org/eclipse/ui/internal/AbstractWorkingSet.java (-5 / +34 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2006 IBM Corporation and others.
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Benjamin Muskalla - bug 37183 (need "oldValue" forIWorkingSet PropertyChangeEvent)
10
 *******************************************************************************/
11
 *******************************************************************************/
11
12
12
package org.eclipse.ui.internal;
13
package org.eclipse.ui.internal;
Lines 86-101 Link Here
86
	public void setName(String newName) {
87
	public void setName(String newName) {
87
	    Assert.isNotNull(newName, "Working set name must not be null"); //$NON-NLS-1$
88
	    Assert.isNotNull(newName, "Working set name must not be null"); //$NON-NLS-1$
88
	    
89
	    
90
	    IWorkingSet oldInstance = getCurrentStateObject();
91
	    
89
	    name = newName;
92
	    name = newName;
90
	    fireWorkingSetChanged(IWorkingSetManager.CHANGE_WORKING_SET_NAME_CHANGE, null);
93
	    fireWorkingSetChanged(IWorkingSetManager.CHANGE_WORKING_SET_NAME_CHANGE, oldInstance);
91
	    
94
	    
92
	    if (labelBoundToName) {
95
	    if (labelBoundToName) {
96
	    		oldInstance = getCurrentStateObject();
93
	    		label = newName;
97
	    		label = newName;
94
	    		fireWorkingSetChanged(IWorkingSetManager.CHANGE_WORKING_SET_LABEL_CHANGE, null);
98
	    		fireWorkingSetChanged(IWorkingSetManager.CHANGE_WORKING_SET_LABEL_CHANGE, oldInstance);
95
	    }
99
	    }
96
	}
100
	}
97
101
98
	/**
102
	/**
103
	 * Returns a clone of the current working set
104
	 * 
105
	 * @return {@link IWorkingSet} the working set
106
	 */
107
	protected IWorkingSet getCurrentStateObject() {
108
		IWorkingSet oldInstance = null;
109
	    try {
110
			oldInstance = (IWorkingSet) this.clone();
111
		} catch (CloneNotSupportedException e) {
112
			e.printStackTrace();
113
		}
114
		return oldInstance;
115
	}
116
117
	/**
99
	 * Connect this working set to a manger. 
118
	 * Connect this working set to a manger. 
100
	 * 
119
	 * 
101
	 * @param manager the manager to connect to
120
	 * @param manager the manager to connect to
Lines 106-112 Link Here
106
	}
125
	}
107
126
108
	/**
127
	/**
109
	 * Disconnet this working set from its manager, if any.
128
	 * Disconnect this working set from its manager, if any.
110
	 */
129
	 */
111
	public void disconnect() {
130
	public void disconnect() {
112
		this.manager= null;
131
		this.manager= null;
Lines 169-179 Link Here
169
	}
188
	}
170
189
171
	public void setLabel(String label) {
190
	public void setLabel(String label) {
191
		IWorkingSet oldInstance = getCurrentStateObject();
172
		this.label = label == null ? getName() : label;
192
		this.label = label == null ? getName() : label;
173
		labelBoundToName = Util.equals(label, name);  // rebind the label to the name
193
		labelBoundToName = Util.equals(label, name);  // rebind the label to the name
174
		
194
		
175
		fireWorkingSetChanged(
195
		fireWorkingSetChanged(
176
				IWorkingSetManager.CHANGE_WORKING_SET_LABEL_CHANGE, null);
196
				IWorkingSetManager.CHANGE_WORKING_SET_LABEL_CHANGE, oldInstance);
177
	}
197
	}
178
	
198
	
179
	public boolean isEmpty() {
199
	public boolean isEmpty() {
Lines 187-190 Link Here
187
    public final ImageDescriptor getImage() {
207
    public final ImageDescriptor getImage() {
188
        return getImageDescriptor();
208
        return getImageDescriptor();
189
    }
209
    }
210
    
211
    /* (non-Javadoc)
212
     * @see java.lang.Object#clone()
213
     */
214
    protected Object clone() throws CloneNotSupportedException {
215
    	AbstractWorkingSet clone = (AbstractWorkingSet) super.clone();
216
    	clone.disconnect();
217
    	return clone;
218
    }
190
}
219
}
(-)Eclipse UI/org/eclipse/ui/internal/WorkingSet.java (-1 / +3 lines)
Lines 19-24 Link Here
19
import org.eclipse.ui.IElementFactory;
19
import org.eclipse.ui.IElementFactory;
20
import org.eclipse.ui.IMemento;
20
import org.eclipse.ui.IMemento;
21
import org.eclipse.ui.IPersistableElement;
21
import org.eclipse.ui.IPersistableElement;
22
import org.eclipse.ui.IWorkingSet;
22
import org.eclipse.ui.IWorkingSetManager;
23
import org.eclipse.ui.IWorkingSetManager;
23
import org.eclipse.ui.PlatformUI;
24
import org.eclipse.ui.PlatformUI;
24
import org.eclipse.ui.internal.misc.Policy;
25
import org.eclipse.ui.internal.misc.Policy;
Lines 213-221 Link Here
213
	 * @see org.eclipse.ui.IWorkingSet
214
	 * @see org.eclipse.ui.IWorkingSet
214
	 */
215
	 */
215
	public void setElements(IAdaptable[] newElements) {
216
	public void setElements(IAdaptable[] newElements) {
217
		IWorkingSet oldInstance = getCurrentStateObject();
216
		internalSetElements(newElements);
218
		internalSetElements(newElements);
217
		fireWorkingSetChanged(
219
		fireWorkingSetChanged(
218
				IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE, null);
220
				IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE, oldInstance);
219
	}
221
	}
220
222
221
	/*
223
	/*

Return to bug 37183