Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Dynamic command handlers for diagram-selections
Dynamic command handlers for diagram-selections [message #1804784] Mon, 01 April 2019 08:54 Go to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 301
Registered: December 2015
Senior Member
Hi,

I think this is a common issue, so not sure if Sirius has already a solution:

I have an org.eclipse.core.command that's enabled on a given domain element type. I want to be able to execute the command also when a diagram element that maps to that type is selected.

The current way is that handlers are just coupled to sirius:
1. their enablement must work for diagram elements with the corredt target type
2. the handler code itself must first translate the diagram selection to the domain selection

Whenever I face this, I hate it, and wonder if there's a better way, and maybe someone tried already? Maybe this could work:

If I have a list of command ids, I could dynamically register a handler for these commands that

1. is active, by checking if another handler for that command is active while replacing the selection of diagram elements with the selection of domain elements.

2. executes that other handler, again, replacing the selection

Yes, I would need to know the commands that should be treated that way, e.g. via extension, but still better than having to deal with 2 kinds of selections all the time no?
Re: Dynamic command handlers for diagram-selections [message #1804798 is a reply to message #1804784] Mon, 01 April 2019 12:48 Go to previous messageGo to next message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 249
Registered: June 2017
Senior Member
Hi Felix,

Sirius has no mechanism to avoid handling both cases. Regarding your solution I d'ont have any thoughts on it because I am not familiar with the command framework for anything other than simple cases. The idea seems nice if you are doing a lot of commands in this case at different moments.

Regards,


Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Dynamic command handlers for diagram-selections [message #1804845 is a reply to message #1804798] Tue, 02 April 2019 08:42 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 301
Registered: December 2015
Senior Member
Maybe it's even easier: If using 'adapt' in the enablement expressions, It is probably just a question of registering the right (eclipse) adapter factories for my domain types. This is possible since EditPart implements IAdaptable and delegates its getAdapter() factory to the platform adapter manager.. I'll come back if I have something.
Re: Dynamic command handlers for diagram-selections [message #1804855 is a reply to message #1804845] Tue, 02 April 2019 11:37 Go to previous message
Felix Dorner is currently offline Felix DornerFriend
Messages: 301
Registered: December 2015
Senior Member
Hi, yes, I will just add an adapter factory for the type IDiagramElementEditPart to the root type of the domain model type hierarchy and use 'adapt' in the handler expressions. The handler code must adapt the selection again but I can live with that.


public class IDiagramElementEditPartAdapterFactory implements IAdapterFactory {

  @SuppressWarnings("unchecked")
  @Override
  public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
    if (adapterType == MyDomainElement.class) {
      Object model = ((IDiagramElementEditPart) adaptableObject).getModel();
      if (model instanceof View) {
        Object element = ((View)model).getElement();
        if (element instanceof DSemanticDecorator && adapterType.isInstance(((DSemanticDecorator)element).getTarget())) {
          return (T) ((DSemanticDecorator)element).getTarget();
        }
      }
    }
    return null;
  }

  @Override
  public Class<?>[] getAdapterList() {
    return new Class[] {
        MyDomainElement.class
    };
  }

}
Previous Topic:Avoid properties to store like prototype
Next Topic:Creating diagram for transient EObject
Goto Forum:
  


Current Time: Mon Aug 19 14:04:38 GMT 2019

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

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

Back to the top