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 #635221] Tue, 26 October 2010 05:02 Go to next message
Ashwani Kr Sharma is currently offline Ashwani Kr SharmaFriend
Messages: 119
Registered: July 2009
Location: Bangalore, India
Senior Member

This message got saved twice. Chrome error.
Plase ignore this. Original message is here:
http://www.eclipse.org/forums/index.php?t=msg&th=199134& amp;start=0&S=9859670c14cd923de1278b1af524961d

[Updated on: Tue, 26 October 2010 05:12]

Report message to a moderator

Re: Adding an action to context menu [message #635249 is a reply to message #635221] Tue, 26 October 2010 07:42 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hi Ashwani,

yes, option 1) is indeed the preferred one. See the method getContextMenu in
TutorialToolBehaviorProvider in the Graphiti tutorial.

To avoid that the editor gets dirty you might override hasDoneChanges and
return false in your feature.But ensure that there are really no changes
done to any model when the feature executes!

Regrads,
Michael


"Ashwani Kr Sharma" <ashw.kumar@gmail.com> wrote in message
news:ia5ng6$coh$1@news.eclipse.org...
> 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. How can i solve
> this ?
>
> Regards,
> Ashwani Kr Sharma
>
>
Re: Adding an action to context menu [message #635265 is a reply to message #635249] Tue, 26 October 2010 08:41 Go to previous messageGo to next message
Ashwani Kr Sharma is currently offline Ashwani Kr SharmaFriend
Messages: 119
Registered: July 2009
Location: Bangalore, India
Senior Member

Hi,

It does not work because: internally graphiti creates a org.eclipse.graphiti.internal.command.CommandContainer and in GFCommandStack (line143), gefCommandWrapper.getCommand() does not return a FeatureCommand and hence hasdoneChanges is never called.
if (gefCommand instanceof GefCommandWrapper) {
			GefCommandWrapper gefCommandWrapper = (GefCommandWrapper) gefCommand;
			ICommand command = gefCommandWrapper.getCommand();
			if (command instanceof FeatureCommand) {


Hence, editor still becomes dirty. Am i missing anything ?

About the second approach i mentioned: One benefit there is if i create a Open,OpenWith action group, i can re-use it at many places like explorer, editor, views etc. But graphiti features will be restricted to grphiti modeler only.

Regards.
Ashwani Kr Sharma

[Updated on: Tue, 26 October 2010 09:52]

Report message to a moderator

Re: Adding an action to context menu [message #635514 is a reply to message #635265] Wed, 27 October 2010 07:33 Go to previous message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Right, there is alread a bugzilla for hasDoneChanges not being called in
that scenario, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=327756 .

The action group approach is of course more flexible if you want to use it
outside of Graphiti. Onthe other hand you might also use the feature inside
Graphiti and wrap it for outside usage in an action and action group.

Michael


"Ashwani Kr Sharma" <ashw.kumar@gmail.com> wrote in message
news:ia6426$v3p$1@news.eclipse.org...
> Hi,
>
> It does not work because: internally graphiti creates a
> org.eclipse.graphiti.internal.command.CommandContainer and in
> GFCommandStack (line143), gefCommandWrapper.getCommand() does return a
> FeatureCommand and hence hasdoneChanges is never called.
>
> if (gefCommand instanceof GefCommandWrapper) {
> GefCommandWrapper gefCommandWrapper = (GefCommandWrapper) gefCommand;
> ICommand command = gefCommandWrapper.getCommand();
> if (command instanceof FeatureCommand) {
>
> Hence, editor still becomes dirty. Am i missing anything ?
>
> About the second approach i mentioned: One benefit there is if i create a
> Open,OpenWith action group, i can re-use it at many places like explorer,
> editor, views etc. But graphiti features will be restricted to grphiti
> modeler only.
>
> Regards.
> Ashwani Kr Sharma
Previous Topic:How to create relationships such as eSuperTypes
Next Topic:filled ellipse renders with small gap
Goto Forum:
  


Current Time: Wed Apr 24 22:07:42 GMT 2024

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

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

Back to the top