Edit entities with context menu via parameterized commands [message #1038186] |
Wed, 10 April 2013 10:19  |
Eclipse User |
|
|
|
Hello everybody,
I have the following use case: I have JFace tree with some nodes which represents my structured set of data. Now I want to edit these entities by right-clicking one node and selecting the "Edit" item from the context menu, which opens a separate dialog to edit the entity.
My idea to achieve this was using a parameterized command and an appropriate handler class like the following, but this didn't work for me. As you can see, I changed the String type of the parameter to any arbitrary Object, but I didn't figure out how to assign a parameter of the general object type to a command.
@Execute
public void execute(@Named("com.example.e4.rcp.todo.commandparameter.input") Object myObject) {
System.out.println(param);
}
I currently haven't figured out how this works in a "beautiful way", so I constructed an ugly work-around: Every time the selection of my JFace tree changes, I use the event broker to post the selected entity. Any handler which subscribes to this post initializes itself with this entity. Now when the command is executed by clicking on a menu item, the corresponding (and already initialized) handler is executed.
private Person person;
@Inject
private IEventBroker broker;
@Inject
@Optional
public void initialize(@UIEventTopic("person_changed") Person person) {
this.person = person;
}
@CanExecute
public boolean canExecute() {
if (person!= null) {
return true;
}
return false;
}
@Execute
public void execute(Shell parent) {...}
Can anybody provide me a more beautiful way to achieve this functionality wihout using the event broker?
Thanks in advance
Regards, Andreas
|
|
|
|
|
|
|
Re: Edit entities with context menu via parameterized commands [message #1039499 is a reply to message #1039483] |
Fri, 12 April 2013 04:28  |
Eclipse User |
|
|
|
Sopot Cela wrote on Fri, 12 April 2013 10:08Why don't you propagate and then inject the specific domain object? DI is type sensitive so you would only get the method called if it is of the right type and would skip those 3.x style type checks.
Sorry ... now I get it. You probably mean:
@CanExecute
public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection) {
if (selection == null) {
return false;
} else if (selection.isEmpty()) {
return false;
}
... test that selection has the right type ...
}
|
|
|
Powered by
FUDForum. Page generated in 1.13160 seconds