Eclipse PDE - How to Sort Properties in the Propecia Standard View



I am developing an Eclipse 3.6 plugin and have a view containing a TreeViewer . When an item from this TreeViewer selected, its properties are displayed in the standard property view. Properties are currently sorted alphabetically by default.
I would like to order these properties in different ways.

It seems that someone also had this problem:
http://www.eclipse.org/forums/index.php/m/393029/

Properties in the property view of the default editor are sorted alphabetically. I would like to ask how to change and arrange them in different orders.

Proposed Solution:

Your editor should provide the PropertySheetPage from the getAdapter (class). If it does not provide one property sheet, it will use the PropertySheetPage property by default, which uses the standard one to create sort order. Your getAdapter () method should provide a specialized subclass of PropertySheetPage that sets you the sorter.

So I need to subclass PropertySheetPage , override the setSorter method, and everything should be fine.

Two questions arise:

  • Why does he write in the documentation that:

    This class can be created; it is not intended to be a subclass.

  • Where can I make a connection between the presentation of standard properties and a subclass of PropertySheetPage ?
    I do not use the editor in my case, but just have a TreeViewer that when selecting an item, it provides properties.

    Any support is appreciated!
+4
source share
1 answer

I came across the same and found a solution.

What I did was add the sort sequence prefix to the identifier of the property pages that I entered (basically a three-digit number) and create a ContributionComparator that took the first 3 digits of the identifier and made the main appearance.

The code looks something like this:

 @Override public int compare(IComparableContribution c1, IComparableContribution c2) { int result = super.compare(c1, c2); IPluginContribution pc1 = (IPluginContribution)c1; IPluginContribution pc2 = (IPluginContribution)c2; String id1 = pc1.getLocalId().substring(0,3); String id2 = pc2.getLocalId().substring(0,3); result = id1.compareTo(id2); return result; } 

Then, in WorkbenchAdvisor , I overridden getComparitorFor to create an instance of ContributionComparator, which I created if the contribType property was:

 @Override public ContributionComparator getComparatorFor(String contributionType) { ContributionComparator cc; if (contributionType.equals(IContributionService.TYPE_PROPERTY)) { cc = new MyContributionComparator(); } else { cc = super.getComparatorFor(contributionType); } return cc; } 

Now the property pages are displayed in the order I want them.

+3
source

Source: https://habr.com/ru/post/1495965/


All Articles