Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Multiple Sort Contributions (or Comparators) in Outline(How to implement multiple contributions sorting the outline differently)
Multiple Sort Contributions (or Comparators) in Outline [message #1770617] Tue, 15 August 2017 04:17 Go to next message
Eclipse UserFriend
Hi,

I want to add a contribution to the outline view sorting the elements of the outline differently from the default alphabetic sort.

The following classes are involved in the implementation:

  • org.eclipse.xtext.ui.editor.outline.actions.SortOutlineContribution
  • org.eclipse.xtext.ui.editor.outline.impl.OutlineFilterAndSorter.IComparator
  • my.language.UIModule: binding or configuring the contributions or comparators

I have already written some filter contributions, they are all implemented by subclassing
org.eclipse.xtext.ui.editor.outline.actions.AbstractFilterOutlineContribution. But how to I add a new sort contribution, based on the SortOutlineContribution?

Ideally I want to only write a new comparator. I already did that and using
@Override
public Class<? extends IComparator> bindOutlineFilterAndSorter$IComparator() {
	return MyComparator.class;
}

I can replace the default (pure lexicographic) comparator. But I don't want to replace it, I want to add it.

Apparently I need to write a new contribution, since a text, description and icon are required not provided by the comparator only. Unfortunately the SortOutlineContribution doesn't look like being designed for re-use.

For filter contributions, I need to bind them as follows in the UIModule:
public void configureMyFilterOutlineContribution(Binder binder) {
	binder.bind(IOutlineContribution.class).annotatedWith(
		Names.named("MyFilterOutlineContribution")
	).to(MyFilterOutlineContribution.class);
}

Is there something similar for sorting? But where do the text and icon come from then?

What do you recommend?

Cheers,
Jens


Re: Multiple Sort Contributions (or Comparators) in Outline [message #1770618 is a reply to message #1770617] Tue, 15 August 2017 04:33 Go to previous messageGo to next message
Eclipse UserFriend
the data comes from org.eclipse.xtext.ui.editor.outline.actions.SortOutlineContribution.configureAction(Action)

so copy&paste / subclass should work + adding an artificial binding with an artifical named key should do the trick
Re: Multiple Sort Contributions (or Comparators) in Outline [message #1770619 is a reply to message #1770618] Tue, 15 August 2017 04:39 Go to previous messageGo to next message
Eclipse UserFriend
Unfortunately it is not that easy: The multiple sort contributions need to be aware of the other. That is, only one of them must be active at a time. Seems as if the framework is not prepared for that, is it?
Re: Multiple Sort Contributions (or Comparators) in Outline [message #1770621 is a reply to message #1770619] Tue, 15 August 2017 04:48 Go to previous messageGo to next message
Eclipse UserFriend
Seems so.
Re: Multiple Sort Contributions (or Comparators) in Outline [message #1770622 is a reply to message #1770619] Tue, 15 August 2017 04:49 Go to previous messageGo to next message
Eclipse UserFriend
Actually, the framework does not support multiple comparators, cf org.eclipse.xtext.ui.editor.outline.impl.OutlineFilterAndSorter:

It is possible to add (or remove) filters (plural!), but only one comparator can be set.

So it may be possible to write a special comparator that can be configured by multiple contributions, but I'm not sure its worth the effort (at least for me). So I will stick to simply replacing the original comparator.

But if someone has a better (or already working solution), I would be very interested in that.

Cheers,
Jens

Re: Multiple Sort Contributions (or Comparators) in Outline [message #1770623 is a reply to message #1770622] Tue, 15 August 2017 04:59 Go to previous messageGo to next message
Eclipse UserFriend
can you file an enhancement request for that.
Re: Multiple Sort Contributions (or Comparators) in Outline [message #1770624 is a reply to message #1770623] Tue, 15 August 2017 05:03 Go to previous messageGo to next message
Eclipse UserFriend
Christian Dietrich wrote on Tue, 15 August 2017 10:59
can you file an enhancement request for that.


Well, there are so many other much more sever issues open, that I'm reluctant to add an enhancement request for something that rather unimportant ;-)
Re: Multiple Sort Contributions (or Comparators) in Outline [message #1770625 is a reply to message #1770624] Tue, 15 August 2017 05:04 Go to previous messageGo to next message
Eclipse UserFriend
yes but this is something a beginner could easily work on
Re: Multiple Sort Contributions (or Comparators) in Outline [message #1770628 is a reply to message #1770625] Tue, 15 August 2017 05:21 Go to previous message
Eclipse UserFriend
Good point. Created issue: https://github.com/eclipse/xtext-core/issues/423
Previous Topic:XText 2.12 blocking issues with Large Grammars
Next Topic:How to use EOL to grammar
Goto Forum:
  


Current Time: Sun Jul 27 09:38:43 EDT 2025

Powered by FUDForum. Page generated in 0.05291 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top