Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Immediate execution Tool(How to create a tool that runs immidiately (without selecting its target))
Immediate execution Tool [message #1583858] Sun, 25 January 2015 11:51 Go to next message
Marcin Trycz is currently offline Marcin TryczFriend
Messages: 12
Registered: August 2014
Junior Member
Hello, and first of all thank you for this great framework.

I'm trying to add a tool that can be executed instantly, without the user having to click on the diagram.

The scenario is this:
We have a model of a reaction inside a biological cell, with nodes being genes that interact with eachother. Each gene can be active or inactive. The next state of the system is deterministically defined by the current state.
I'd like to have a tool to "compute next state" of the system. The context of this operation is fixed (the base element of the model).
Currently I need to click on the tool, then click on the diagram to execute the action. It gets tedious when I want to compute several steps.

Currently the next state is computed in an External Java Action, but since it's quite simple I think it could be defined in a simple tool with "if" and "for" elements etc.

Thanks in advance.


I'm just a user.

[Updated on: Sun, 25 January 2015 12:54]

Report message to a moderator

Re: Immediate execution Tool [message #1584136 is a reply to message #1583858] Sun, 25 January 2015 15:40 Go to previous message
Marcin Trycz is currently offline Marcin TryczFriend
Messages: 12
Registered: August 2014
Junior Member
I was able to add this functionality, but not through the "tools" interface of Sirius, but through a simple org.eclipse.ui.actionSets button.

Unfortunately I can't post links to external guides that I used for this, but I'll add useful google phrases.

I added a simple plugin to my project (the Hello World template, actually).
It's really rudimental and needs some fixing and proofing, but here's the idea:
0. Setup an additional button for your plugin project (Google: vogella plugin tutorial)
1. Get a reference to the active editor; if it's a Sirius editor, then go on.
2. Get the domain object from the editor.
3. EMF modifications need to run inside a transaction (advices found here: Google: techblog Making your EMF model transactional) so get a Transactional Domain for editing
4. Execute the transformation logic inside a Command in the TransactionalDomain.
5. Refresh the diagram, just in case.

Pierre-Charles David set me on track with this solution (www.eclipse.org/forums/index.php/m/1405511/#msg_1405511) some months ago, but I didn't get to fix this earlier.
Thank you Pierre-Charles!

Here's the code for the new button logic (it's ugly and dirty, but it's working)
(Note that DummySimulation has this strange interface, because it's actually an ExternalJavaAction)

	public void run(IAction action) {
		IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
		if(editor instanceof DDiagramEditorImpl) {
			DDiagramEditorImpl diagEditor = (DDiagramEditorImpl) editor;
			final DSemanticDiagramSpec spec = (DSemanticDiagramSpec) diagEditor.getDiagram().getElement();
			DSemanticDiagramSpec diagram = (DSemanticDiagramSpec) spec;	
			GeneChartSirius genechart = (GeneChartSirius) diagram.getTarget();
			final Collection collection = new ArrayList();
			collection.add(genechart);

			TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(genechart);
			ted.getCommandStack().execute(new RecordingCommand(ted) {

				@Override
				protected void doExecute() {
					DummySimulation sim = new DummySimulation();
					sim.execute(collection, null);
					spec.refresh();
				}
			});
		}
	}



As a cool bonus, this solution supports "undo" logic.

Hope that helps somebody too.
Still, if you know of a simpler way to add this logic to a Sirius Tool, let me know.

Cheers.


I'm just a user.
Previous Topic:Containers inside containers
Next Topic:Create a sirius diagram programmatically
Goto Forum:
  


Current Time: Thu Apr 25 16:00:13 GMT 2024

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

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

Back to the top