Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Adding menu options when I right click on my diagram
Adding menu options when I right click on my diagram [message #1841409] Fri, 14 May 2021 17:40 Go to next message
Thomas Chiang is currently offline Thomas ChiangFriend
Messages: 106
Registered: March 2020
Senior Member
Hello,

I have been looking around and I haven't found a helpful answer to this question yet. I am trying to create a new menu item so that when I right click on an element within my diagram I can browse the menu and look for custom options such as highlighting my selected element, asking the editor about what else my element is connected to etc. Ideally this would be to perform a transitive closure from a selected element but before I even get there I need to know how to create the menu option and how to connect it to a java action call , aql script, OCL, or EOL.

Any help with this?
Re: Adding menu options when I right click on my diagram [message #1841457 is a reply to message #1841409] Mon, 17 May 2021 15:51 Go to previous messageGo to next message
Laurent Redor is currently offline Laurent RedorFriend
Messages: 300
Registered: July 2009
Senior Member
Hi Thomas,
I think that popup menu and group menu are what you looking for.
Regards,
Laurent


Laurent Redor - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Adding menu options when I right click on my diagram [message #1841462 is a reply to message #1841457] Mon, 17 May 2021 19:37 Go to previous messageGo to next message
Thomas Chiang is currently offline Thomas ChiangFriend
Messages: 106
Registered: March 2020
Senior Member
I have been trying to get my menu labels to appear when I right click in my diagram by following the example but it's not working no matter how much I play with it and follow the example. I am very lost at the moment trying to figure this out as I seem to be doing exactly what the example says to do.

I have my pop up menu defined and there is a group menu option in there defined as well so that it shows up at the root of the popup menu when I right click without any context:
index.php/fa/40500/0/

And then when I go ahead and right click on my diagram editor there isn't anything that shows up. I also checked the tree editor but nothing shows up there either.
index.php/fa/40501/0/
index.php/fa/40502/0/

There is this line in the page that you sent me: Note: If your VSM is in the runtime environment workspace to do dynamic development of your VSM, the changes are not systematically reflected in the menu. A selection change may be necessary (to rebuild the menu).

I am working in a runtime environment for the development of my editor so I have been refreshing the project, closing and opening it again as well as simply creating new models and nothing seems to change in the menu. Are there any other troubleshooting steps I can take to figure out why the example isn't working? Is there some sort of extension that I need to add to my runtime VSM to allow for the creation of these menus??

[Updated on: Mon, 17 May 2021 19:55]

Report message to a moderator

Re: Adding menu options when I right click on my diagram [message #1841477 is a reply to message #1841462] Tue, 18 May 2021 12:46 Go to previous messageGo to next message
Laurent Redor is currently offline Laurent RedorFriend
Messages: 300
Registered: July 2009
Senior Member
Hi,
I think that the group is visible only if there is a content; an "Operation Action" for example.
The class PopupMenuTest tests this feature. You can have a look on the VSM used for this test to have some examples.
Regards,
Laurent


Laurent Redor - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Adding menu options when I right click on my diagram [message #1841479 is a reply to message #1841477] Tue, 18 May 2021 15:11 Go to previous messageGo to next message
Thomas Chiang is currently offline Thomas ChiangFriend
Messages: 106
Registered: March 2020
Senior Member
This example has been very helpful thank you!

Now I have one more question. I'm trying to get a hello world example to run from the menu options that I have created but it doesn't seem to be running anything when I click on the menu option that I have added. Here is the code for the external action call:

/**
 * 
 */
package WFP.design;

import java.util.Collection;
import java.util.Map;
import org.eclipse.core.commands.*;
import org.eclipse.ui.handlers.*;
import java.io.*;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.sirius.business.api.action.AbstractExternalJavaAction;
import org.eclipse.sirius.business.api.session.SessionManager;
import org.eclipse.sirius.viewpoint.DSemanticDecorator;
import org.eclipse.ui.PlatformUI;

/**
 * @author sirch
 *
 */
public class myAction extends AbstractExternalJavaAction{

	@Override
	public boolean canExecute(Collection<? extends EObject> arg0) {
		// TODO Auto-generated method stub
		System.out.println("Hello world");
		return true;
	}

	@Override
	public void execute(Collection<? extends EObject> arg0, Map<String, Object> arg1) {
		// TODO Auto-generated method stub
		System.out.println("Hello world");
	}

}


Not sure why I can't print anything out from this call. How can I troubleshoot my menu items and action calls?
Re: Adding menu options when I right click on my diagram [message #1841483 is a reply to message #1841479] Tue, 18 May 2021 17:00 Go to previous messageGo to next message
Laurent Redor is currently offline Laurent RedorFriend
Messages: 300
Registered: July 2009
Senior Member
I'm not sure where is displayed this message in this context.
You can replace your sysout by something like :
org.eclipse.jface.dialogs.MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "My dialog", "Hello world");


Laurent Redor - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Adding menu options when I right click on my diagram [message #1841486 is a reply to message #1841483] Tue, 18 May 2021 20:08 Go to previous messageGo to next message
Thomas Chiang is currently offline Thomas ChiangFriend
Messages: 106
Registered: March 2020
Senior Member
Hi Laurent,

I managed to figure out how to get around the issue of not being able to sysout. I imported the VSM into my Eclipse IDE instead of having it in development mode (in the runtime application) according to the documentation for popup menus.

I do have another question that has popped up now though. As I create the java service to perform actions on the elements within my model I want to be able to check it against my metamodel instead of against the metamodel for Sirius. Any idea how I can do this or what packages I can import to enable this?
Re: Adding menu options when I right click on my diagram [message #1841497 is a reply to message #1841486] Wed, 19 May 2021 06:53 Go to previous messageGo to next message
Laurent Redor is currently offline Laurent RedorFriend
Messages: 300
Registered: July 2009
Senior Member
I'm not sure to understand what you really need. But from an instance of the Sirius metamodel, ie a DSemanticDecorator, you can access to an instance of "your metamodel" through the target feature.

Laurent Redor - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Adding menu options when I right click on my diagram [message #1841509 is a reply to message #1841497] Wed, 19 May 2021 14:27 Go to previous messageGo to next message
Thomas Chiang is currently offline Thomas ChiangFriend
Messages: 106
Registered: March 2020
Senior Member
Ok if that's the case I think my question is how do I actually get to that class? I've been trying to work based off of what has been discussed in this post but I don't really understand how they specified the context for which they want to run their java calls.
https://www.eclipse.org/forums/index.php/t/1089628/

In my canExecute() method I have a simple check to make sure that I can't access the java call if I right click on the blank space in the diagram:
public boolean canExecute(Collection<? extends EObject> arg0) {
		// TODO Auto-generated method stub
		Iterator it = arg0.iterator();
		while (it.hasNext()) {
			EObject next = (EObject) it.next();
			if (next.eClass().getName().contentEquals("DSemanticDiagram")){
				//System.out.println("Object name is " + next.eClass().getName());
				return false;
			}
		}
		return true;
	}


Ultimately I aim trying to further specify what my call can run on based on what type of class it is based upon what I have specified in my metamodel. And then later on when I want to specify the execute() method I will need to be able to check what model elements I am working on so that I can perform different actions on them like changing colors, sizes, deletion/creation etc.

[Updated on: Wed, 19 May 2021 15:09]

Report message to a moderator

Re: Adding menu options when I right click on my diagram [message #1841599 is a reply to message #1841509] Fri, 21 May 2021 13:12 Go to previous messageGo to next message
Laurent Redor is currently offline Laurent RedorFriend
Messages: 300
Registered: July 2009
Senior Member
The plug-in containing your java services, must depends of Sirius MM plug-in and also of your MM plug-in if you want to "manipulate" them.
For example "org.eclipse.sirius" and "org.eclipse.sirius.diagram".

And for information, the code
next instanceof DSemanticDiagram

is better than
next.eClass().getName().contentEquals("DSemanticDiagram")


Laurent Redor - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Adding menu options when I right click on my diagram [message #1841605 is a reply to message #1841599] Fri, 21 May 2021 18:45 Go to previous message
Thomas Chiang is currently offline Thomas ChiangFriend
Messages: 106
Registered: March 2020
Senior Member
No Message Body

[Updated on: Fri, 21 May 2021 19:30]

Report message to a moderator

Previous Topic:Adding metamodel plug-in problem
Next Topic:Sirius Web UML Sequence Diagram
Goto Forum:
  


Current Time: Thu Dec 12 17:23:20 GMT 2024

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

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

Back to the top