How to run Java code from a Sirius diagram ? [message #1780722] |
Fri, 26 January 2018 10:00 |
Matthieu Durot Messages: 10 Registered: February 2017 |
Junior Member |
|
|
Hello,
I'm new to sirius and still learning possiblities that it offers to us.
I've made a small java service to, basically, display a dialog from a popup menu.
public class TestService implements IExternalJavaAction {
@Override
public void execute(Collection<? extends EObject> arg0, Map<String, Object> arg1) {
JOptionPane.showMessageDialog(null, "Test Java Action Call.");
}
@Override
public boolean canExecute(Collection<? extends EObject> arg0) {
// TODO Auto-generated method stub
return true;
}
}
My problem is that I can't find how to call/execute it from my popup.
I've created an operation action and in the "begin" operation I've created an external java action call but I can't manage to make it work !
Btw, I'm using sirius 4.1.8 on mars.2.
Thank you for your help,
Matthieu
[Updated on: Fri, 26 January 2018 15:13] Report message to a moderator
|
|
|
|
|
Re: How to run Java code from a Sirius diagram ? [message #1780761 is a reply to message #1780751] |
Fri, 26 January 2018 16:49 |
|
Hi.
IExternalJavaAction and what we call "Java services" are actually two very different things. See my previous answer to a similar question here.
You probably don't want to use IExternalJavaAction, it's an older mechanism, harder to use and less flexible than Java services. If you have used the "Viewpoint Specification Project" creation wizard, you should already have almost everything setup, with a Services.java class ready, where you can add your custom services. In your case something like:
public EObject showMessage(EObject self, String text) {
MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "My Service", text);
return self;
}
Note that this uses JFace/SWT. Your example uses JOptionPane which comes from Swing and will not work (or not well) inside Eclipse (but this has nothing to do with Sirius).
To invoke the service from a tool, inside the "Begin" operation of the tool add a "Change Context" operation with an expression like this:
aql:self.showMessage('My message')
"Change Context" is normally designed to navigate inside the model and change the "current element" on which the next operations apply. Here we use it only for it's side effect, as the service returns the "self" element it got passed (but it could return something else, depending on whatever the service method does).
See the documentation for more details. The Advanced Tutorial also shows how to define and use Java services.
Regards,
Pierre-Charles David - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
[Updated on: Fri, 26 January 2018 16:50] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.04449 seconds