Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » How to run Java code from a Sirius diagram ?(Java Action Call)
How to run Java code from a Sirius diagram ? [message #1780722] Fri, 26 January 2018 10:00 Go to next message
Matthieu Durot is currently offline Matthieu DurotFriend
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: Java Action Call [message #1780747 is a reply to message #1780722] Fri, 26 January 2018 15:11 Go to previous messageGo to next message
Matthieu Durot is currently offline Matthieu DurotFriend
Messages: 10
Registered: February 2017
Junior Member
It may not be possible, do anyone know about it ?
Re: How to run Java code from a Sirius diagram ? [message #1780751 is a reply to message #1780722] Fri, 26 January 2018 15:30 Go to previous messageGo to next message
David CHARLET is currently offline David CHARLETFriend
Messages: 12
Registered: January 2018
Junior Member
I am facing the same issue and have no clue how to solve it.
Re: How to run Java code from a Sirius diagram ? [message #1780761 is a reply to message #1780751] Fri, 26 January 2018 16:49 Go to previous messageGo to next message
Pierre-Charles David is currently offline Pierre-Charles DavidFriend
Messages: 703
Registered: July 2009
Senior Member
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

Re: How to run Java code from a Sirius diagram ? [message #1781008 is a reply to message #1780761] Wed, 31 January 2018 13:51 Go to previous message
Matthieu Durot is currently offline Matthieu DurotFriend
Messages: 10
Registered: February 2017
Junior Member
Hello Pierre-Charles,

Thanks for the quick answer !
It helped a lot thank you.

Matthieu
Previous Topic:Open Diagram programmatically
Next Topic:SVG references not working
Goto Forum:
  


Current Time: Sat Apr 20 02:26:35 GMT 2024

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

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

Back to the top