|
Re: Adding an action to context menu [message #635249 is a reply to message #635221] |
Tue, 26 October 2010 07:42 |
Michael Wenz 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 |
|
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 |
Michael Wenz 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
|
|
|
Powered by
FUDForum. Page generated in 0.04580 seconds