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

(-)src/org/eclipse/ui/views/properties/IPropertySourceProvider.java (-8 / +13 lines)
Lines 11-27 Link Here
11
package org.eclipse.ui.views.properties;
11
package org.eclipse.ui.views.properties;
12
12
13
/**
13
/**
14
 * Interface used by <code>PropertySheetRoot</code> to obtain an 
14
 * Interface used by {@link org.eclipse.ui.views.properties.PropertySheetEntry}
15
 * <code>IPropertySource</code> for a given object.
15
 * to obtain an {@link org.eclipse.ui.views.properties.IPropertySource} for a
16
 * given object.
16
 * <p>
17
 * <p>
17
 * This interface may be implemented by clients.
18
 * This interface may be implemented by clients.
18
 * </p>
19
 * </p>
19
 */
20
 */
20
public interface IPropertySourceProvider {
21
public interface IPropertySourceProvider {
21
    /**
22
	
22
     * Returns a property source for the given object.
23
	/**
23
     *
24
	 * Returns a property source for the given object.
24
     * @param object the object
25
	 * 
25
     */
26
	 * @param object
26
    public IPropertySource getPropertySource(Object object);
27
	 *            the object
28
	 * @return the property source for the object passed in (maybe
29
	 *         <code>null</code>)
30
	 */
31
	public IPropertySource getPropertySource(Object object);
27
}
32
}
(-)src/org/eclipse/ui/views/properties/PropertySheetEntry.java (-22 / +3 lines)
Lines 12-25 Link Here
12
12
13
package org.eclipse.ui.views.properties;
13
package org.eclipse.ui.views.properties;
14
14
15
import java.text.Collator;
16
import java.util.ArrayList;
15
import java.util.ArrayList;
17
import java.util.Arrays;
16
import java.util.Arrays;
18
import java.util.Collections;
19
import java.util.Comparator;
20
import java.util.HashMap;
17
import java.util.HashMap;
21
import java.util.List;
18
import java.util.List;
22
import java.util.Locale;
23
import java.util.Map;
19
import java.util.Map;
24
20
25
import org.eclipse.core.runtime.IAdaptable;
21
import org.eclipse.core.runtime.IAdaptable;
Lines 151-157 Link Here
151
    }
147
    }
152
148
153
    /**
149
    /**
154
     * Return the sorted intersection of all the <code>IPropertyDescriptor</code>s 
150
     * Return the unsorted intersection of all the <code>IPropertyDescriptor</code>s 
155
     * for the objects.
151
     * for the objects.
156
     * @return List
152
     * @return List
157
     */
153
     */
Lines 189-211 Link Here
189
            }
185
            }
190
        }
186
        }
191
187
192
        // Sort the descriptors	
188
        // sorting is handled in the PropertySheetViewer, return unsorted
193
        List descriptors = new ArrayList(intersection.values());
189
        return new ArrayList(intersection.values());
194
        Collections.sort(descriptors, new Comparator() {
195
            Collator coll = Collator.getInstance(Locale.getDefault());
196
197
            public int compare(Object a, Object b) {
198
                IPropertyDescriptor d1, d2;
199
                String dname1, dname2;
200
                d1 = (IPropertyDescriptor) a;
201
                dname1 = d1.getDisplayName();
202
                d2 = (IPropertyDescriptor) b;
203
                dname2 = d2.getDisplayName();
204
                return coll.compare(dname1, dname2);
205
            }
206
        });
207
208
        return descriptors;
209
    }
190
    }
210
191
211
    /**
192
    /**
(-)src/org/eclipse/ui/views/properties/PropertySheetPage.java (-1 / +25 lines)
Lines 85-90 Link Here
85
    public static final String HELP_CONTEXT_PROPERTY_SHEET_PAGE = "org.eclipse.ui.property_sheet_page_help_context"; //$NON-NLS-1$
85
    public static final String HELP_CONTEXT_PROPERTY_SHEET_PAGE = "org.eclipse.ui.property_sheet_page_help_context"; //$NON-NLS-1$
86
86
87
    private PropertySheetViewer viewer;
87
    private PropertySheetViewer viewer;
88
    
89
    private PropertySheetSorter sorter;
88
90
89
    private IPropertySheetEntry rootEntry;
91
    private IPropertySheetEntry rootEntry;
90
92
Lines 117-123 Link Here
117
    public void createControl(Composite parent) {
119
    public void createControl(Composite parent) {
118
        // create a new viewer
120
        // create a new viewer
119
        viewer = new PropertySheetViewer(parent);
121
        viewer = new PropertySheetViewer(parent);
120
122
        viewer.setSorter(sorter);
123
        
121
        // set the model for the viewer
124
        // set the model for the viewer
122
        if (rootEntry == null) {
125
        if (rootEntry == null) {
123
            // create a new root
126
            // create a new root
Lines 461-464 Link Here
461
            // the following will trigger an update
464
            // the following will trigger an update
462
            viewer.setRootEntry(rootEntry);
465
            viewer.setRootEntry(rootEntry);
463
    }
466
    }
467
468
    /**
469
	 * Sets the sorter used for sorting categories and entries in the viewer
470
	 * of this page.
471
	 * <p>
472
	 * The default sorter sorts categories and entries alphabetically. 
473
	 * </p>
474
	 * @param sorter the sorter to set (<code>null</code> will reset to the
475
	 * default sorter)
476
	 */
477
	public void setSorter(PropertySheetSorter sorter) {
478
		this.sorter = sorter;
479
        if (viewer != null) {
480
        	viewer.setSorter(sorter);
481
        	
482
        	// the following will trigger an update
483
        	if(null != viewer.getRootEntry())
484
        		viewer.setRootEntry(rootEntry);
485
        }
486
	}
487
464
}
488
}
(-)src/org/eclipse/ui/views/properties/PropertySheetViewer.java (-32 / +47 lines)
Lines 11-26 Link Here
11
11
12
package org.eclipse.ui.views.properties;
12
package org.eclipse.ui.views.properties;
13
13
14
import java.text.Collator;
15
import java.util.ArrayList;
14
import java.util.ArrayList;
16
import java.util.Arrays;
15
import java.util.Arrays;
17
import java.util.Collections;
16
import java.util.Collection;
18
import java.util.Comparator;
19
import java.util.HashMap;
17
import java.util.HashMap;
20
import java.util.HashSet;
18
import java.util.HashSet;
21
import java.util.Iterator;
19
import java.util.Iterator;
22
import java.util.List;
20
import java.util.List;
23
import java.util.Locale;
24
import java.util.Map;
21
import java.util.Map;
25
import java.util.Set;
22
import java.util.Set;
26
23
Lines 105-110 Link Here
105
102
106
    // Cell editor activation listeners
103
    // Cell editor activation listeners
107
    private ListenerList activationListeners = new ListenerList(3);
104
    private ListenerList activationListeners = new ListenerList(3);
105
    
106
    // the property sheet sorter
107
    private PropertySheetSorter sorter = new PropertySheetSorter();
108
108
109
    /**
109
    /**
110
     * Creates a property sheet viewer on a newly-created tree control
110
     * Creates a property sheet viewer on a newly-created tree control
Lines 491-497 Link Here
491
    }
491
    }
492
    
492
    
493
    /**
493
    /**
494
     * Returns the children of the given category or entry
494
     * Returns the sorted children of the given category or entry
495
     *
495
     *
496
     * @param node a category or entry
496
     * @param node a category or entry
497
     * @return the children of the given category or entry
497
     * @return the children of the given category or entry
Lines 536-543 Link Here
536
                return Arrays.asList(categories);
536
                return Arrays.asList(categories);
537
        }
537
        }
538
538
539
        // return the filtered child entries
539
        // return the sorted & filtered child entries
540
        return getFilteredEntries(entry.getChildEntries());
540
        return getSortedEntries(getFilteredEntries(entry.getChildEntries()));
541
    }
541
    }
542
542
543
    /**
543
    /**
Lines 549-555 Link Here
549
     *         <code>IPropertySheetEntry</code>)
549
     *         <code>IPropertySheetEntry</code>)
550
     */
550
     */
551
    private List getChildren(PropertySheetCategory category) {
551
    private List getChildren(PropertySheetCategory category) {
552
        return getFilteredEntries(category.getChildEntries());
552
        return getSortedEntries(getFilteredEntries(category.getChildEntries()));
553
    }
553
    }
554
554
555
    /*
555
    /*
Lines 589-601 Link Here
589
        }
589
        }
590
        return filteredEntries;
590
        return filteredEntries;
591
    }
591
    }
592
    
593
    /**
594
	 * Returns a sorted list of <code>IPropertySheetEntry</code> entries.
595
	 * 
596
	 * @param unsortedEntries
597
	 *            unsorted list of <code>IPropertySheetEntry</code>
598
	 * @return a sorted list of the specified entries
599
	 */
600
	private List getSortedEntries(List unsortedEntries) {
601
		IPropertySheetEntry[] propertySheetEntries = (IPropertySheetEntry[]) unsortedEntries
602
				.toArray(new IPropertySheetEntry[unsortedEntries.size()]);
603
		sorter.sort(propertySheetEntries);
604
		return Arrays.asList(propertySheetEntries);
605
	}
606
    
592
607
593
    /**
608
    /**
594
     * The <code>PropertySheetViewer</code> implementation of this method
609
	 * The <code>PropertySheetViewer</code> implementation of this method
595
     * declared on <code>IInputProvider</code> returns the objects for which
610
	 * declared on <code>IInputProvider</code> returns the objects for which
596
     * the viewer is currently showing properties. It returns an
611
	 * the viewer is currently showing properties. It returns an
597
     * <code>Object[]</code> or <code>null</code>.
612
	 * <code>Object[]</code> or <code>null</code>.
598
     */
613
	 */
599
    public Object getInput() {
614
    public Object getInput() {
600
        return input;
615
        return input;
601
    }
616
    }
Lines 910-915 Link Here
910
    }
925
    }
911
926
912
    /**
927
    /**
928
	 * Sets the sorter for this viewer.
929
	 * <p>
930
	 * The default sorter sorts categories and entries alphabetically. 
931
	 * A viewer update needs to be triggered after the sorter has changed.
932
	 * </p>
933
	 * @param sorter the sorter to set (<code>null</code> will reset to the
934
	 * default sorter)
935
	 */
936
	public void setSorter(PropertySheetSorter sorter) {
937
		if (null == sorter)
938
			sorter = new PropertySheetSorter();
939
		this.sorter = sorter;
940
	}
941
942
    /**
913
     * Sets the status line manager this view will use to show messages.
943
     * Sets the status line manager this view will use to show messages.
914
     * 
944
     * 
915
     * @param manager
945
     * @param manager
Lines 997-1021 Link Here
997
            categoryCache.put(MISCELLANEOUS_CATEGORY_NAME, misc);
1027
            categoryCache.put(MISCELLANEOUS_CATEGORY_NAME, misc);
998
1028
999
        // Sort the categories
1029
        // Sort the categories
1000
        List list = new ArrayList(categoryCache.values());
1030
        Collection categoryCacheValues = categoryCache.values();
1001
        for (int i = 0; i < categoriesToRemove.size(); i++)
1031
        categories = (PropertySheetCategory[]) categoryCacheValues
1002
            list.remove(categoriesToRemove.get(i));
1032
        	.toArray(new PropertySheetCategory[categoryCacheValues.size()]);
1003
        Collections.sort(list, new Comparator() {
1033
        sorter.sort(categories);
1004
            Collator coll = Collator.getInstance(Locale.getDefault());
1005
1006
            public int compare(Object a, Object b) {
1007
                PropertySheetCategory c1, c2;
1008
                String dname1, dname2;
1009
                c1 = (PropertySheetCategory) a;
1010
                dname1 = c1.getCategoryName();
1011
                c2 = (PropertySheetCategory) b;
1012
                dname2 = c2.getCategoryName();
1013
                return coll.compare(dname1, dname2);
1014
            }
1015
        });
1016
1017
        categories = (PropertySheetCategory[]) list
1018
                .toArray(new PropertySheetCategory[list.size()]);
1019
    }
1034
    }
1020
1035
1021
    /**
1036
    /**
(-)src/org/eclipse/ui/views/properties/PropertySheetSorter.java (+142 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 Gunnar Wagenknecht 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
 *    Gunnar Wagenknecht - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.views.properties;
12
13
import java.text.Collator;
14
import java.util.Arrays;
15
import java.util.Comparator;
16
17
import org.eclipse.jface.viewers.ViewerSorter;
18
19
/**
20
 * Class used by {@link org.eclipse.ui.views.properties.PropertySheetPage} to
21
 * sort properties.
22
 * <p>
23
 * The default implementation sorts alphabetically. Subclasses may overwrite to
24
 * implement custom sorting.
25
 * </p>
26
 */
27
public class PropertySheetSorter extends ViewerSorter {
28
29
	/**
30
	 * The collator used to sort strings.
31
	 */
32
	private Collator collator;
33
34
	/**
35
	 * Creates a new sorter, which uses the default collator to sort strings.
36
	 */
37
	public PropertySheetSorter() {
38
		this(Collator.getInstance());
39
	}
40
41
	/**
42
	 * Creates a new sorter, which uses the given collator to sort strings.
43
	 * 
44
	 * @param collator
45
	 *            the collator to use to sort strings
46
	 */
47
	public PropertySheetSorter(Collator collator) {
48
		this.collator = collator;
49
	}
50
51
	/**
52
	 * Returns a negative, zero, or positive number depending on whether the
53
	 * first element is less than, equal to, or greater than the second element.
54
	 * <p>
55
	 * The default implementation of this method is based on a case insensitive
56
	 * compare of the display names. Subclasses may override.
57
	 * </p>
58
	 * 
59
	 * @param entryA
60
	 *            the first element
61
	 * @param entryB
62
	 *            the second element
63
	 * @return a negative number if the first element is less than the second
64
	 *         element; the value <code>0</code> if the first element is equal
65
	 *         to the second element; and a positive number if the first element
66
	 *         is greater than the second element
67
	 */
68
	public int compare(IPropertySheetEntry entryA, IPropertySheetEntry entryB) {
69
		return getCollator().compare(entryA.getDisplayName(),
70
				entryB.getDisplayName());
71
	}
72
73
	/**
74
	 * Returns a negative, zero, or positive number depending on whether the
75
	 * first element is less than, equal to, or greater than the second element.
76
	 * <p>
77
	 * The default implementation of this method is based on a case insensitive
78
	 * compare of the strings. Subclasses may override.
79
	 * </p>
80
	 * 
81
	 * @param categoryA
82
	 *            the first element
83
	 * @param categoryB
84
	 *            the second element
85
	 * @return a negative number if the first element is less than the second
86
	 *         element; the value <code>0</code> if the first element is equal
87
	 *         to the second element; and a positive number if the first element
88
	 *         is greater than the second element
89
	 */
90
	public int compareCategories(String categoryA, String categoryB) {
91
		return getCollator().compare(categoryA, categoryB);
92
	}
93
94
	/**
95
	 * Returns the collator used to sort strings.
96
	 * 
97
	 * @return the collator used to sort strings
98
	 */
99
	public Collator getCollator() {
100
		return collator;
101
	}
102
103
	/**
104
	 * Sorts the given elements in-place, modifying the given array.
105
	 * <p>
106
	 * The default implementation of this method uses the java.util.Arrays#sort
107
	 * algorithm on the given array, calling <code>compare</code> to compare
108
	 * elements.
109
	 * </p>
110
	 * <p>
111
	 * Subclasses may reimplement this method to provide a more optimized
112
	 * implementation.
113
	 * </p>
114
	 * 
115
	 * @param entries
116
	 *            the elements to sort
117
	 */
118
	public void sort(IPropertySheetEntry[] entries) {
119
		Arrays.sort(entries, new Comparator() {
120
			public int compare(Object a, Object b) {
121
				return PropertySheetSorter.this.compare(
122
						(IPropertySheetEntry) a, (IPropertySheetEntry) b);
123
			}
124
		});
125
	}
126
127
	/**
128
	 * Sorts the given categories in-place, modifying the given array.
129
	 * 
130
	 * @param categories
131
	 *            the categories to sort
132
	 */
133
	void sort(PropertySheetCategory[] categories) {
134
		Arrays.sort(categories, new Comparator() {
135
			public int compare(Object a, Object b) {
136
				return PropertySheetSorter.this.compareCategories(
137
						((PropertySheetCategory) a).getCategoryName(),
138
						((PropertySheetCategory) b).getCategoryName());
139
			}
140
		});
141
	}
142
}

Return to bug 1883