|
Re: Sort actions in menu [message #932589 is a reply to message #932575] |
Thu, 04 October 2012 08:44 |
Ed Merks Messages: 33137 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.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.01333 seconds