Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 17897 Details for
Bug 1883
[PropertiesView] property view sorting (1G956Q4)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Patch that adds sorting to PropertySheetPage
patch-1883-org.eclipse.ui.views.txt (text/plain), 15.59 KB, created by
Gunnar Wagenknecht
on 2005-02-12 10:14:06 EST
(
hide
)
Description:
Patch that adds sorting to PropertySheetPage
Filename:
MIME Type:
Creator:
Gunnar Wagenknecht
Created:
2005-02-12 10:14:06 EST
Size:
15.59 KB
patch
obsolete
>Index: src/org/eclipse/ui/views/properties/IPropertySourceProvider.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.views/src/org/eclipse/ui/views/properties/IPropertySourceProvider.java,v >retrieving revision 1.4 >diff -u -r1.4 IPropertySourceProvider.java >--- src/org/eclipse/ui/views/properties/IPropertySourceProvider.java 8 Jul 2004 20:07:12 -0000 1.4 >+++ src/org/eclipse/ui/views/properties/IPropertySourceProvider.java 12 Feb 2005 14:59:25 -0000 >@@ -11,17 +11,22 @@ > package org.eclipse.ui.views.properties; > > /** >- * Interface used by <code>PropertySheetRoot</code> to obtain an >- * <code>IPropertySource</code> for a given object. >+ * Interface used by {@link org.eclipse.ui.views.properties.PropertySheetEntry} >+ * to obtain an {@link org.eclipse.ui.views.properties.IPropertySource} for a >+ * given object. > * <p> > * This interface may be implemented by clients. > * </p> > */ > public interface IPropertySourceProvider { >- /** >- * Returns a property source for the given object. >- * >- * @param object the object >- */ >- public IPropertySource getPropertySource(Object object); >+ >+ /** >+ * Returns a property source for the given object. >+ * >+ * @param object >+ * the object >+ * @return the property source for the object passed in (maybe >+ * <code>null</code>) >+ */ >+ public IPropertySource getPropertySource(Object object); > } >Index: src/org/eclipse/ui/views/properties/PropertySheetEntry.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.views/src/org/eclipse/ui/views/properties/PropertySheetEntry.java,v >retrieving revision 1.11 >diff -u -r1.11 PropertySheetEntry.java >--- src/org/eclipse/ui/views/properties/PropertySheetEntry.java 19 Aug 2004 20:37:02 -0000 1.11 >+++ src/org/eclipse/ui/views/properties/PropertySheetEntry.java 12 Feb 2005 14:59:26 -0000 >@@ -12,14 +12,10 @@ > > package org.eclipse.ui.views.properties; > >-import java.text.Collator; > import java.util.ArrayList; > import java.util.Arrays; >-import java.util.Collections; >-import java.util.Comparator; > import java.util.HashMap; > import java.util.List; >-import java.util.Locale; > import java.util.Map; > > import org.eclipse.core.runtime.IAdaptable; >@@ -151,7 +147,7 @@ > } > > /** >- * Return the sorted intersection of all the <code>IPropertyDescriptor</code>s >+ * Return the unsorted intersection of all the <code>IPropertyDescriptor</code>s > * for the objects. > * @return List > */ >@@ -189,23 +185,8 @@ > } > } > >- // Sort the descriptors >- List descriptors = new ArrayList(intersection.values()); >- Collections.sort(descriptors, new Comparator() { >- Collator coll = Collator.getInstance(Locale.getDefault()); >- >- public int compare(Object a, Object b) { >- IPropertyDescriptor d1, d2; >- String dname1, dname2; >- d1 = (IPropertyDescriptor) a; >- dname1 = d1.getDisplayName(); >- d2 = (IPropertyDescriptor) b; >- dname2 = d2.getDisplayName(); >- return coll.compare(dname1, dname2); >- } >- }); >- >- return descriptors; >+ // sorting is handled in the PropertySheetViewer, return unsorted >+ return new ArrayList(intersection.values()); > } > > /** >Index: src/org/eclipse/ui/views/properties/PropertySheetPage.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.views/src/org/eclipse/ui/views/properties/PropertySheetPage.java,v >retrieving revision 1.20 >diff -u -r1.20 PropertySheetPage.java >--- src/org/eclipse/ui/views/properties/PropertySheetPage.java 25 Jan 2005 21:27:32 -0000 1.20 >+++ src/org/eclipse/ui/views/properties/PropertySheetPage.java 12 Feb 2005 14:59:26 -0000 >@@ -85,6 +85,8 @@ > public static final String HELP_CONTEXT_PROPERTY_SHEET_PAGE = "org.eclipse.ui.property_sheet_page_help_context"; //$NON-NLS-1$ > > private PropertySheetViewer viewer; >+ >+ private PropertySheetSorter sorter; > > private IPropertySheetEntry rootEntry; > >@@ -117,7 +119,8 @@ > public void createControl(Composite parent) { > // create a new viewer > viewer = new PropertySheetViewer(parent); >- >+ viewer.setSorter(sorter); >+ > // set the model for the viewer > if (rootEntry == null) { > // create a new root >@@ -461,4 +464,25 @@ > // the following will trigger an update > viewer.setRootEntry(rootEntry); > } >+ >+ /** >+ * Sets the sorter used for sorting categories and entries in the viewer >+ * of this page. >+ * <p> >+ * The default sorter sorts categories and entries alphabetically. >+ * </p> >+ * @param sorter the sorter to set (<code>null</code> will reset to the >+ * default sorter) >+ */ >+ public void setSorter(PropertySheetSorter sorter) { >+ this.sorter = sorter; >+ if (viewer != null) { >+ viewer.setSorter(sorter); >+ >+ // the following will trigger an update >+ if(null != viewer.getRootEntry()) >+ viewer.setRootEntry(rootEntry); >+ } >+ } >+ > } >Index: src/org/eclipse/ui/views/properties/PropertySheetViewer.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.views/src/org/eclipse/ui/views/properties/PropertySheetViewer.java,v >retrieving revision 1.14 >diff -u -r1.14 PropertySheetViewer.java >--- src/org/eclipse/ui/views/properties/PropertySheetViewer.java 12 Feb 2005 02:19:08 -0000 1.14 >+++ src/org/eclipse/ui/views/properties/PropertySheetViewer.java 12 Feb 2005 14:59:27 -0000 >@@ -11,16 +11,13 @@ > > package org.eclipse.ui.views.properties; > >-import java.text.Collator; > import java.util.ArrayList; > import java.util.Arrays; >-import java.util.Collections; >-import java.util.Comparator; >+import java.util.Collection; > import java.util.HashMap; > import java.util.HashSet; > import java.util.Iterator; > import java.util.List; >-import java.util.Locale; > import java.util.Map; > import java.util.Set; > >@@ -105,6 +102,9 @@ > > // Cell editor activation listeners > private ListenerList activationListeners = new ListenerList(3); >+ >+ // the property sheet sorter >+ private PropertySheetSorter sorter = new PropertySheetSorter(); > > /** > * Creates a property sheet viewer on a newly-created tree control >@@ -491,7 +491,7 @@ > } > > /** >- * Returns the children of the given category or entry >+ * Returns the sorted children of the given category or entry > * > * @param node a category or entry > * @return the children of the given category or entry >@@ -536,8 +536,8 @@ > return Arrays.asList(categories); > } > >- // return the filtered child entries >- return getFilteredEntries(entry.getChildEntries()); >+ // return the sorted & filtered child entries >+ return getSortedEntries(getFilteredEntries(entry.getChildEntries())); > } > > /** >@@ -549,7 +549,7 @@ > * <code>IPropertySheetEntry</code>) > */ > private List getChildren(PropertySheetCategory category) { >- return getFilteredEntries(category.getChildEntries()); >+ return getSortedEntries(getFilteredEntries(category.getChildEntries())); > } > > /* >@@ -589,13 +589,28 @@ > } > return filteredEntries; > } >+ >+ /** >+ * Returns a sorted list of <code>IPropertySheetEntry</code> entries. >+ * >+ * @param unsortedEntries >+ * unsorted list of <code>IPropertySheetEntry</code> >+ * @return a sorted list of the specified entries >+ */ >+ private List getSortedEntries(List unsortedEntries) { >+ IPropertySheetEntry[] propertySheetEntries = (IPropertySheetEntry[]) unsortedEntries >+ .toArray(new IPropertySheetEntry[unsortedEntries.size()]); >+ sorter.sort(propertySheetEntries); >+ return Arrays.asList(propertySheetEntries); >+ } >+ > > /** >- * The <code>PropertySheetViewer</code> implementation of this method >- * declared on <code>IInputProvider</code> returns the objects for which >- * the viewer is currently showing properties. It returns an >- * <code>Object[]</code> or <code>null</code>. >- */ >+ * The <code>PropertySheetViewer</code> implementation of this method >+ * declared on <code>IInputProvider</code> returns the objects for which >+ * the viewer is currently showing properties. It returns an >+ * <code>Object[]</code> or <code>null</code>. >+ */ > public Object getInput() { > return input; > } >@@ -910,6 +925,21 @@ > } > > /** >+ * Sets the sorter for this viewer. >+ * <p> >+ * The default sorter sorts categories and entries alphabetically. >+ * A viewer update needs to be triggered after the sorter has changed. >+ * </p> >+ * @param sorter the sorter to set (<code>null</code> will reset to the >+ * default sorter) >+ */ >+ public void setSorter(PropertySheetSorter sorter) { >+ if (null == sorter) >+ sorter = new PropertySheetSorter(); >+ this.sorter = sorter; >+ } >+ >+ /** > * Sets the status line manager this view will use to show messages. > * > * @param manager >@@ -997,25 +1027,10 @@ > categoryCache.put(MISCELLANEOUS_CATEGORY_NAME, misc); > > // Sort the categories >- List list = new ArrayList(categoryCache.values()); >- for (int i = 0; i < categoriesToRemove.size(); i++) >- list.remove(categoriesToRemove.get(i)); >- Collections.sort(list, new Comparator() { >- Collator coll = Collator.getInstance(Locale.getDefault()); >- >- public int compare(Object a, Object b) { >- PropertySheetCategory c1, c2; >- String dname1, dname2; >- c1 = (PropertySheetCategory) a; >- dname1 = c1.getCategoryName(); >- c2 = (PropertySheetCategory) b; >- dname2 = c2.getCategoryName(); >- return coll.compare(dname1, dname2); >- } >- }); >- >- categories = (PropertySheetCategory[]) list >- .toArray(new PropertySheetCategory[list.size()]); >+ Collection categoryCacheValues = categoryCache.values(); >+ categories = (PropertySheetCategory[]) categoryCacheValues >+ .toArray(new PropertySheetCategory[categoryCacheValues.size()]); >+ sorter.sort(categories); > } > > /** >Index: src/org/eclipse/ui/views/properties/PropertySheetSorter.java >=================================================================== >RCS file: src/org/eclipse/ui/views/properties/PropertySheetSorter.java >diff -N src/org/eclipse/ui/views/properties/PropertySheetSorter.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/ui/views/properties/PropertySheetSorter.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,142 @@ >+/******************************************************************************* >+ * Copyright (c) 2005 Gunnar Wagenknecht and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Gunnar Wagenknecht - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.ui.views.properties; >+ >+import java.text.Collator; >+import java.util.Arrays; >+import java.util.Comparator; >+ >+import org.eclipse.jface.viewers.ViewerSorter; >+ >+/** >+ * Class used by {@link org.eclipse.ui.views.properties.PropertySheetPage} to >+ * sort properties. >+ * <p> >+ * The default implementation sorts alphabetically. Subclasses may overwrite to >+ * implement custom sorting. >+ * </p> >+ */ >+public class PropertySheetSorter extends ViewerSorter { >+ >+ /** >+ * The collator used to sort strings. >+ */ >+ private Collator collator; >+ >+ /** >+ * Creates a new sorter, which uses the default collator to sort strings. >+ */ >+ public PropertySheetSorter() { >+ this(Collator.getInstance()); >+ } >+ >+ /** >+ * Creates a new sorter, which uses the given collator to sort strings. >+ * >+ * @param collator >+ * the collator to use to sort strings >+ */ >+ public PropertySheetSorter(Collator collator) { >+ this.collator = collator; >+ } >+ >+ /** >+ * Returns a negative, zero, or positive number depending on whether the >+ * first element is less than, equal to, or greater than the second element. >+ * <p> >+ * The default implementation of this method is based on a case insensitive >+ * compare of the display names. Subclasses may override. >+ * </p> >+ * >+ * @param entryA >+ * the first element >+ * @param entryB >+ * the second element >+ * @return a negative number if the first element is less than the second >+ * element; the value <code>0</code> if the first element is equal >+ * to the second element; and a positive number if the first element >+ * is greater than the second element >+ */ >+ public int compare(IPropertySheetEntry entryA, IPropertySheetEntry entryB) { >+ return getCollator().compare(entryA.getDisplayName(), >+ entryB.getDisplayName()); >+ } >+ >+ /** >+ * Returns a negative, zero, or positive number depending on whether the >+ * first element is less than, equal to, or greater than the second element. >+ * <p> >+ * The default implementation of this method is based on a case insensitive >+ * compare of the strings. Subclasses may override. >+ * </p> >+ * >+ * @param categoryA >+ * the first element >+ * @param categoryB >+ * the second element >+ * @return a negative number if the first element is less than the second >+ * element; the value <code>0</code> if the first element is equal >+ * to the second element; and a positive number if the first element >+ * is greater than the second element >+ */ >+ public int compareCategories(String categoryA, String categoryB) { >+ return getCollator().compare(categoryA, categoryB); >+ } >+ >+ /** >+ * Returns the collator used to sort strings. >+ * >+ * @return the collator used to sort strings >+ */ >+ public Collator getCollator() { >+ return collator; >+ } >+ >+ /** >+ * Sorts the given elements in-place, modifying the given array. >+ * <p> >+ * The default implementation of this method uses the java.util.Arrays#sort >+ * algorithm on the given array, calling <code>compare</code> to compare >+ * elements. >+ * </p> >+ * <p> >+ * Subclasses may reimplement this method to provide a more optimized >+ * implementation. >+ * </p> >+ * >+ * @param entries >+ * the elements to sort >+ */ >+ public void sort(IPropertySheetEntry[] entries) { >+ Arrays.sort(entries, new Comparator() { >+ public int compare(Object a, Object b) { >+ return PropertySheetSorter.this.compare( >+ (IPropertySheetEntry) a, (IPropertySheetEntry) b); >+ } >+ }); >+ } >+ >+ /** >+ * Sorts the given categories in-place, modifying the given array. >+ * >+ * @param categories >+ * the categories to sort >+ */ >+ void sort(PropertySheetCategory[] categories) { >+ Arrays.sort(categories, new Comparator() { >+ public int compare(Object a, Object b) { >+ return PropertySheetSorter.this.compareCategories( >+ ((PropertySheetCategory) a).getCategoryName(), >+ ((PropertySheetCategory) b).getCategoryName()); >+ } >+ }); >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 1883
:
13943
| 17897