Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Sort actions in menu
Sort actions in menu [message #932575] Thu, 04 October 2012 08:26 Go to next message
Linus Pettersson is currently offline Linus PetterssonFriend
Messages: 8
Registered: October 2012
Junior Member
Hi!

I have a tree editor generated by EMF. When right clicking in the editr I can create children and siblings. The problem is that these seem to be in random order. Now I want to sort them (the children and siblings) alphabetically.

I have some issues with this though.

My thought was to edit/override the populateMenuManager method and sort the actions there.

	protected void populateManager(IContributionManager manager, Collection<? extends IAction> actions, String contributionID) {
		if (actions != null) {
                       // Sort actions here....
			for (IAction action : actions) {
				if (contributionID != null) {
					manager.insertBefore(contributionID, action);
				}
				else {
					manager.add(action);
				}
			}
		}
	}


Is there any built in, effective, method to sort this?
Re: Sort actions in menu [message #932589 is a reply to message #932575] Thu, 04 October 2012 08:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26235
Registered: July 2009
Senior Member
Linus,

Comments below.

On 04/10/2012 10:26 AM, Linus Pettersson wrote:
> Hi!
>
> I have a tree editor generated by EMF. When right clicking in the
> editr I can create children and siblings. The problem is that these
> seem to be in random order.
They're not in a random order. The features are ordered as they appear
in the class's all features, and for each feature, they're ordered as
the types are ordered in the package. I.e., the generator will produce
results in that order.

> Now I want to sort them (the children and siblings) alphabetically.
You might want to try sorting your classifiers in the package
alphabetically first...

Failing that, keep in mind that the order you see will follow the order
returned by the item provider's getNewChildDescriptors.
>
> I have some issues with this though.
>
> My thought was to edit/override the populateMenuManager method and
> sort the actions there.
>
>
> protected void populateManager(IContributionManager manager,
> Collection<? extends IAction> actions, String contributionID) {
> if (actions != null) {
> // Sort actions here....
> for (IAction action : actions) {
> if (contributionID != null) {
> manager.insertBefore(contributionID, action);
> }
> else {
> manager.add(action);
> }
> }
> }
> }
>
>
> Is there any built in, effective, method to sort this?
Another place to consider sorting is in a derived version of
org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain.getNewChildDescriptors(Object,
Object). The instances are typically CommandParameter instances where
you can get at the getFeature and the getValue and define a Comparator
for those. Or you could specialize the item providers themselves to do
sorting in
org.eclipse.emf.edit.provider.ItemProviderAdapter.getNewChildDescriptors(Object,
EditingDomain, Object) with the same approach. You could make use of
the GenModel's Provider Root Extends Class to specify an extended
version of ItemProviderAdapter that all your generated item provider
adapters will extend so you can put the logic in just one place; that
probably the cleanest approach.
Re: Sort actions in menu [message #932607 is a reply to message #932589] Thu, 04 October 2012 09:00 Go to previous message
Linus Pettersson is currently offline Linus PetterssonFriend
Messages: 8
Registered: October 2012
Junior Member
Thank you!

For now I just sorted it using a TreeMap... Not the cleanest way, but it works for now. Will try your suggestions later on!
Previous Topic:[CDO] Implement an alternative store
Next Topic:One Model editor with derived models
Goto Forum:
  


Current Time: Thu Nov 27 21:21:33 GMT 2014

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

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