Skip to main content



      Home
Home » Modeling » EMF » Sort actions in menu
Sort actions in menu [message #932575] Thu, 04 October 2012 04:26 Go to next message
Eclipse UserFriend
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 04:44 Go to previous messageGo to next message
Eclipse UserFriend
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 05:00 Go to previous message
Eclipse UserFriend
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 Jul 10 09:30:26 EDT 2025

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

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

Back to the top