Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Adding an action to context menu(Adding an action to context menu, on selection of any pictogram element in graphiti modeler)
Adding an action to context menu [message #635223] Tue, 26 October 2010 05:07
Ashwani Kr Sharma is currently offline Ashwani Kr SharmaFriend
Messages: 119
Registered: July 2009
Location: Bangalore, India
Senior Member

Hi,

I need to implement a Open action on an element in Graphiti Modeler. The action should appear in context menu on the model element.
I found two ways to do that:
1) Create a OpenFeature. In ToolBehaviorProvider override getContextMenu to return a context menu for a feature. E.g.

public IContextMenuEntry[] getContextMenu(ICustomContext context) {
	List<ContextMenuEntry> subMenuList = new ArrayList<ContextMenuEntry>();
		
	// create a menu-entry only for auto layout custom feature
	if (context instanceof ICustomContext) {
		ICustomContext customContext = (ICustomContext) context;
		ICustomFeature[] customFeatures =
                         getFeatureProvider().getCustomFeatures(customContext);
		for (ICustomFeature customFeature : customFeatures) {
			if (customFeature instanceof OpenFeature) { 
			ContextMenuEntry subMenu;
			subMenu = new ContextMenuEntry(customFeature, context);
			subMenu.setText( ((AbstractCustomFeature) customFeature).getName());  			      subMenu.setDescription(((AbstractCustomFeature) customFeature).getName()); 
			subMenu.setSubmenu(true);
			subMenuList.add(subMenu);
				}
			}
		}
		
		return subMenuList.toArray(new ContextMenuEntry[subMenuList.size()]);
	}


2)
a. Extend Diagram Editor
b. Override createContextMenuProvider() and return a instance of class extending DiagramEditorContextMenuProvider
c. In the class extending DiagramEditorContextMenuProvider, interrupt context menu creation process to add my actions
d. My actions can be initialized in init of my DiagramEditor extension

I think approach 1 is preferable. Because it was doing everything via commands internally. What is the recommended approach ?
But I am stuck in an issue now, when Open action is clicked the command is added to command stack and Diagram Editor becomes dirty. This command is kind of read-only commad. It is not changing anything in the diagram. How can i solve this ?

Regards,
Ashwani Kr Sharma

[Updated on: Tue, 26 October 2010 06:25]

Report message to a moderator

Previous Topic:label for a shape
Next Topic:How to create relationships such as eSuperTypes
Goto Forum:
  


Current Time: Thu Mar 28 19:15:59 GMT 2024

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

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

Back to the top