Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 08:17 Go to next message
Jens von Pilgrim is currently offline Jens von PilgrimFriend
Messages: 313
Registered: July 2009
Senior Member
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 08:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12229
Registered: July 2009
Senior Member
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


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Multiple Sort Contributions (or Comparators) in Outline [message #1770619 is a reply to message #1770618] Tue, 15 August 2017 08:39 Go to previous messageGo to next message
Jens von Pilgrim is currently offline Jens von PilgrimFriend
Messages: 313
Registered: July 2009
Senior Member
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 08:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12229
Registered: July 2009
Senior Member
Seems so.

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Multiple Sort Contributions (or Comparators) in Outline [message #1770622 is a reply to message #1770619] Tue, 15 August 2017 08:49 Go to previous messageGo to next message
Jens von Pilgrim is currently offline Jens von PilgrimFriend
Messages: 313
Registered: July 2009
Senior Member
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 08:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12229
Registered: July 2009
Senior Member
can you file an enhancement request for that.


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Multiple Sort Contributions (or Comparators) in Outline [message #1770624 is a reply to message #1770623] Tue, 15 August 2017 09:03 Go to previous messageGo to next message
Jens von Pilgrim is currently offline Jens von PilgrimFriend
Messages: 313
Registered: July 2009
Senior Member
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 09:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12229
Registered: July 2009
Senior Member
yes but this is something a beginner could easily work on

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Multiple Sort Contributions (or Comparators) in Outline [message #1770628 is a reply to message #1770625] Tue, 15 August 2017 09:21 Go to previous message
Jens von Pilgrim is currently offline Jens von PilgrimFriend
Messages: 313
Registered: July 2009
Senior Member
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: Thu Sep 20 01:11:39 GMT 2018

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

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

Back to the top