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 262891
Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/WorkingSetComparator.java (-26 / +39 lines)
Lines 24-31 Link Here
24
	 * Static instance of this class.
24
	 * Static instance of this class.
25
	 * @since 3.2
25
	 * @since 3.2
26
	 */
26
	 */
27
	public static WorkingSetComparator INSTANCE = new WorkingSetComparator();
27
	public static WorkingSetComparator INSTANCE_NAMES_ONLY = new WorkingSetComparator(false);
28
	
28
	
29
	public static WorkingSetComparator INSTANCE_LABELS_NAMES = new WorkingSetComparator();
30
31
	private boolean useLabels;
32
	
33
	public WorkingSetComparator(){
34
		this(true);
35
	}
36
	
37
	public WorkingSetComparator(boolean useLabels){
38
		this.useLabels=useLabels;
39
	}
29
    private Collator fCollator = Collator.getInstance();
40
    private Collator fCollator = Collator.getInstance();
30
41
31
    /**
42
    /**
Lines 34-62 Link Here
34
     * @see Comparator#compare(Object, Object)
45
     * @see Comparator#compare(Object, Object)
35
     */
46
     */
36
    public int compare(Object o1, Object o2) {
47
    public int compare(Object o1, Object o2) {
37
		String name1 = null;
48
    	String name1 = null;
38
		String name2 = null;
49
    	String name2 = null;
39
50
    	int result = 0;
40
		if (o1 instanceof IWorkingSet) {
51
    	if(useLabels){
41
			name1 = ((IWorkingSet) o1).getLabel();
52
    		if (o1 instanceof IWorkingSet) {
42
		}
53
    			name1 = ((IWorkingSet) o1).getLabel();
43
54
    		}
44
		if (o2 instanceof IWorkingSet) {
55
45
			name2 = ((IWorkingSet) o2).getLabel();
56
    		if (o2 instanceof IWorkingSet) {
46
		}
57
    			name2 = ((IWorkingSet) o2).getLabel();
47
58
    		}
48
		int result = fCollator.compare(name1, name2);
59
49
		if (result == 0) { // okay, same name - now try the unique id
60
    		result = fCollator.compare(name1, name2);
50
61
    	}
51
			if (o1 instanceof IWorkingSet) {
62
    	if (result == 0) { // okay, same name - now try the unique id
52
				name1 = ((IWorkingSet) o1).getName();
63
53
			}
64
    		if (o1 instanceof IWorkingSet) {
54
65
    			name1 = ((IWorkingSet) o1).getName();
55
			if (o2 instanceof IWorkingSet) {
66
    		}
56
				name2 = ((IWorkingSet) o2).getName();
67
57
			}
68
    		if (o2 instanceof IWorkingSet) {
58
			result = name1.compareTo(name2);
69
    			name2 = ((IWorkingSet) o2).getName();
59
		}
70
    		}
60
		return result;
71
    		result = name1.compareTo(name2);
61
	}
72
    	}
73
    	return result;
74
    }
62
}
75
}
(-)Eclipse UI/org/eclipse/ui/internal/AbstractWorkingSetManager.java (-3 / +6 lines)
Lines 15-20 Link Here
15
import java.io.IOException;
15
import java.io.IOException;
16
import java.io.OutputStreamWriter;
16
import java.io.OutputStreamWriter;
17
import java.util.ArrayList;
17
import java.util.ArrayList;
18
import java.util.Arrays;
18
import java.util.HashMap;
19
import java.util.HashMap;
19
import java.util.Iterator;
20
import java.util.Iterator;
20
import java.util.List;
21
import java.util.List;
Lines 91-97 Link Here
91
					StatusUtil.newStatus(PlatformUI.PLUGIN_ID, exception));
92
					StatusUtil.newStatus(PlatformUI.PLUGIN_ID, exception));
92
		}
93
		}
93
	}
94
	}
94
    private SortedSet workingSets = new TreeSet(WorkingSetComparator.INSTANCE);
95
    private SortedSet workingSets = new TreeSet(WorkingSetComparator.INSTANCE_NAMES_ONLY);
95
    
96
    
96
    /**
97
    /**
97
     * Size of the list of most recently used working sets.
98
     * Size of the list of most recently used working sets.
Lines 258-264 Link Here
258
     * @see org.eclipse.ui.IWorkingSetManager
259
     * @see org.eclipse.ui.IWorkingSetManager
259
     */
260
     */
260
    public IWorkingSet[] getWorkingSets() {
261
    public IWorkingSet[] getWorkingSets() {
261
    		SortedSet visibleSubset = new TreeSet(WorkingSetComparator.INSTANCE);
262
    		SortedSet visibleSubset = new TreeSet(WorkingSetComparator.INSTANCE_LABELS_NAMES);
262
    		for (Iterator i = workingSets.iterator(); i.hasNext();) {
263
    		for (Iterator i = workingSets.iterator(); i.hasNext();) {
263
				IWorkingSet workingSet = (IWorkingSet) i.next();
264
				IWorkingSet workingSet = (IWorkingSet) i.next();
264
				if (workingSet.isVisible()) {
265
				if (workingSet.isVisible()) {
Lines 269-275 Link Here
269
    }
270
    }
270
    
271
    
271
    public IWorkingSet[] getAllWorkingSets() {
272
    public IWorkingSet[] getAllWorkingSets() {
272
    		return (IWorkingSet[]) workingSets.toArray(new IWorkingSet[workingSets.size()]);
273
    	IWorkingSet[] wSets= (IWorkingSet[]) workingSets.toArray(new IWorkingSet[workingSets.size()]);
274
    	Arrays.sort(wSets,WorkingSetComparator.INSTANCE_LABELS_NAMES);
275
    	return wSets;
273
    }
276
    }
274
277
275
    /* (non-Javadoc)
278
    /* (non-Javadoc)
(-)Eclipse UI Tests/org/eclipse/ui/tests/api/IWorkingSetTest.java (-2 / +32 lines)
Lines 99-105 Link Here
99
        fWorkingSet.setId(null);
99
        fWorkingSet.setId(null);
100
        assertEquals(null, fWorkingSet.getId());
100
        assertEquals(null, fWorkingSet.getId());
101
    }
101
    }
102
102
    public void testNoDuplicateWorkingSetNamesDifferentLabels()
103
    throws Throwable {
104
    	/* get workingSetManager */
105
    	IWorkingSetManager workingSetManager = fWorkbench
106
    	.getWorkingSetManager();
107
    	/*
108
    	 * check that initially workingSetManager contains "fWorkingSet"
109
    	 */
110
    	assertTrue(ArrayUtil.equals(new IWorkingSet[] { fWorkingSet },
111
    			workingSetManager.getWorkingSets()));
112
113
    	String sameName = fWorkingSet.getName();
114
    	IWorkingSet wSet = workingSetManager.createWorkingSet(sameName,
115
    			new IAdaptable[] {});
116
    	wSet.setLabel(WORKING_SET_NAME_2);
117
118
    	/*
119
    	 * Expected to throw an error as the wSet has the same name as
120
    	 * fWorkingSet
121
    	 */
122
    	boolean exceptionThrown = false;
123
    	try {
124
    		workingSetManager.addWorkingSet(wSet);
125
    		/* Test failed, restore state */
126
    		workingSetManager.removeWorkingSet(wSet);
127
    	} catch (RuntimeException exception) {
128
    		exceptionThrown = true;
129
    	}
130
    	assertTrue(exceptionThrown);
131
    }
132
    
103
    public void testSetName() throws Throwable {
133
    public void testSetName() throws Throwable {
104
        boolean exceptionThrown = false;
134
        boolean exceptionThrown = false;
105
135
Lines 131-137 Link Here
131
		assertFalse(fWorkingSet.isEmpty());
161
		assertFalse(fWorkingSet.isEmpty());
132
	}
162
	}
133
    
163
    
134
    
164
   
135
    public void testApplicableTo_ResourceWorkingSet() {
165
    public void testApplicableTo_ResourceWorkingSet() {
136
		fWorkingSet.setId("org.eclipse.ui.resourceWorkingSetPage");
166
		fWorkingSet.setId("org.eclipse.ui.resourceWorkingSetPage");
137
		assertEquals("org.eclipse.ui.resourceWorkingSetPage", fWorkingSet
167
		assertEquals("org.eclipse.ui.resourceWorkingSetPage", fWorkingSet

Return to bug 262891