Adding menu options when I right click on my diagram [message #1841409] |
Fri, 14 May 2021 17:40  |
Eclipse User |
|
|
|
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 #1841479 is a reply to message #1841477] |
Tue, 18 May 2021 15:11   |
Eclipse User |
|
|
|
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 #1841486 is a reply to message #1841483] |
Tue, 18 May 2021 20:08   |
Eclipse User |
|
|
|
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 #1841509 is a reply to message #1841497] |
Wed, 19 May 2021 14:27   |
Eclipse User |
|
|
|
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] by Moderator 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   |
Eclipse User |
|
|
|
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")
|
|
|
|
Powered by
FUDForum. Page generated in 0.06135 seconds