Adding an action to context menu [message #635223] |
Tue, 26 October 2010 05:07 |
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.02323 seconds