Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » New child menu entry for EMap and custom dialog
New child menu entry for EMap and custom dialog [message #896093] Tue, 17 July 2012 09:02 Go to next message
John M. is currently offline John M.Friend
Messages: 198
Registered: July 2010
Senior Member
Hello,

I have modelled a StringToIntegerMap and trying to add a menu item for creating an entry.

My idea was to edit the generated method collectNewChildDescriptors and add following:

newChildDescriptors.add(createChildParameter(Package.Literals.STRING_TO_INTEGER_MAP__VALUE, Factory.eINSTANCE.create(Package.Literals.STRING_TO_INTEGER_MAP)));


But I get a NPE in the ActionBarContributor.

Can I add on that way an item?

[Updated on: Tue, 17 July 2012 15:29]

Report message to a moderator

Re: New child entry for map [message #896136 is a reply to message #896093] Tue, 17 July 2012 11:53 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Comments below.

On 17/07/2012 11:02 AM, Missing name Mising name wrote:
> Hello,
>
> I have modelled a StringToIntegerMap and trying to add a menu item for
> creating an entry.
>
> My idea was to edit the generated method collectNewChildDescriptors
> and add following:
I'd expect such an entry generated for you. E.g., in
EAnnotationItemProvider it generates the following for the details
feature (the map) of the EAnnotation.

newChildDescriptors.add
(createChildParameter
(EcorePackage.Literals.EANNOTATION__DETAILS,
EcoreFactory.eINSTANCE.create(EcorePackage.Literals.ESTRING_TO_STRING_MAP_ENTRY)));


>
> newChildDescriptors.add(createChildParameter(Package.Literals.STRING_TO_INTEGER_MAP__VALUE,
> Factory.eINSTANCE.create(Package.Literals.STRING_TO_INTEGER_MAP)));
Where did you add this? The feature looks wrong. You're not trying to
create a map entry as the value for a map entry.
>
> But I get a NPE in the ActionBarContributor.
>
> Can I add on that way an item?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: New child menu entry for EMap [message #896149 is a reply to message #896093] Tue, 17 July 2012 12:21 Go to previous messageGo to next message
John M. is currently offline John M.Friend
Messages: 198
Registered: July 2010
Senior Member
I am sorry, there is no generated literal with ending MAP_ENTRY.
I had found a message here, where do you say the same, but I can't figure out, how I get the literal.
Re: New child menu entry for EMap [message #896159 is a reply to message #896149] Tue, 17 July 2012 12:43 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Given you've provided no information about your model, I can't tell you
the names. I can suggest you look at EcorePackage.Literals to see how
EAnnotation's details map looks there.

On 17/07/2012 2:21 PM, Missing name Mising name wrote:
> I am sorry, there is no generated literal with ending MAP_ENTRY.
> I had found a message here, where do you say the same, but I can't
> figure out, how I get the literal.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: New child menu entry for EMap [message #896169 is a reply to message #896093] Tue, 17 July 2012 13:39 Go to previous messageGo to next message
John M. is currently offline John M.Friend
Messages: 198
Registered: July 2010
Senior Member
Thanks.

I found my mistake. I had forgotten to activate child creation in the genmodel for the map.
How can I overwrite the new child add command with an own implementation? I want to shown a own dialog for the creation.

For editing of the property view I can implement my own PropertyDescriptor, which opens a InputDialog in the createPropertyEditor method.
But how can I open it automatically?
Re: New child menu entry for EMap [message #896175 is a reply to message #896169] Tue, 17 July 2012 13:48 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Comments below.

On 17/07/2012 3:39 PM, Missing name Mising name wrote:
> Thanks.
>
> I found my mistake. I had forgotten to activate child creation in the
> genmodel for the map.
> How can I overwrite the new child add command with an own
> implementation? I want to shown a own dialog for the creation.
EMF Commands aren't intended to show dialogs. You'll need to design
your own Action.
>
> For editing of the property view I can implement my own
> PropertyDescriptor, which opens a InputDialog in the
> createPropertyEditor method.
Yes, like in the EMF Recipe for that.
> But how can I open it automatically?
It must be launched as a cell editor.

Doesn't creating the entry and using the cell editors do the trick. It's
certainly sufficient, though you might want something fancier.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: New child menu entry for EMap [message #896195 is a reply to message #896093] Tue, 17 July 2012 14:27 Go to previous messageGo to next message
John M. is currently offline John M.Friend
Messages: 198
Registered: July 2010
Senior Member
I think I figured out, how to create the command. Overwriting in the ItemProvider the method createCreateChildCommand and return an own implementation of a class which extends CommandWrapper and implements CommandActionDelegate. (regarding http://www.eclipse.org/forums/index.php/mv/msg/126669/389299/#msg_389299)

But I don't understand your hit:
>> But how can I open it automatically?
> It must be launched as a cell editor.
> Doesn't creating the entry and using the cell editors do the trick. It's
> certainly sufficient, though you might want something fancier.
Re: New child menu entry for EMap [message #896196 is a reply to message #896195] Tue, 17 July 2012 14:30 Go to previous messageGo to next message
John M. is currently offline John M.Friend
Messages: 198
Registered: July 2010
Senior Member
I found another forum post (http://www.eclipse.org/forums/index.php/mv/msg/300043/808869/#msg_808869) where you refer the class EGenericItemProvider, but I can't find it and Google doesn't really help.
Re: New child menu entry for EMap [message #896209 is a reply to message #896196] Tue, 17 July 2012 15:01 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
It's in org.eclipse.emf.ecore.edit. If you open the Plug-ins View, you
can select them all and using Add to Java Search so that Ctrl-Shift-T
will find it.

On 17/07/2012 4:30 PM, Missing name Mising name wrote:
> I found another forum post
> (http://www.eclipse.org/forums/index.php/mv/msg/300043/808869/#msg_808869)
> where you refer the class EGenericItemProvider, but I can't find it
> and Google doesn't really help.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: New child menu entry for EMap [message #896212 is a reply to message #896209] Tue, 17 July 2012 15:11 Go to previous messageGo to next message
John M. is currently offline John M.Friend
Messages: 198
Registered: July 2010
Senior Member
Thanks, but I can't find EGenericItemProvider only EGenericTypeItemProvider.
I don't know if that is the right one.

But please tell me if my approach is right (http://www.eclipse.org/forums/index.php/mv/msg/367617/896195/#msg_896195).
Re: New child menu entry for EMap [message #896213 is a reply to message #896212] Tue, 17 July 2012 15:16 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Oops, typo. Yes, that's the right one.

On 17/07/2012 5:11 PM, Missing name Mising name wrote:
> Thanks, but I can't find EGenericItemProvider only
> EGenericTypeItemProvider.
> I don't know if that is the right one.
>
> But please tell me if my approach is right
> (http://www.eclipse.org/forums/index.php/mv/msg/367617/896195/#msg_896195).


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: New child menu entry for EMap and custom dialog [message #896216 is a reply to message #896093] Tue, 17 July 2012 15:31 Go to previous messageGo to next message
John M. is currently offline John M.Friend
Messages: 198
Registered: July 2010
Senior Member
My command implementation with the InputDialog looks like following:

import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CommandWrapper;
import org.eclipse.emf.edit.command.CommandActionDelegate;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.ui.PlatformUI;

public class DefinitionCreateCommand extends CommandWrapper implements CommandActionDelegate {
	public DefinitionCreateCommand(Command command) {
		super(command);
	}

	@Override
	public void execute() {
		InputDialog dialog = new InputDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "test",
				"test message", "", null);
		dialog.open();
	}

	@Override
	public Object getImage() {
		return ((CommandActionDelegate) super.command).getImage();
	}

	@Override
	public String getText() {
		return ((CommandActionDelegate) super.command).getText();
	}

	@Override
	public String getToolTipText() {
		return ((CommandActionDelegate) super.command).getToolTipText();
	}
}


I have overwritten the method createCreateChildCommand with following content:
return new DefinitionCreateCommand(super.createCreateChildCommand(domain, owner, feature, value, index, collection));


It works so long, but how can I pass the result back?
Re: New child menu entry for EMap and custom dialog [message #896340 is a reply to message #896216] Wed, 18 July 2012 06:51 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Command.getResult generally does the trick, after the command has been
executed.


On 17/07/2012 5:31 PM, Missing name Mising name wrote:
> My command implementation with the InputDialog looks like following:
>
> import org.eclipse.emf.common.command.Command;
> import org.eclipse.emf.common.command.CommandWrapper;
> import org.eclipse.emf.edit.command.CommandActionDelegate;
> import org.eclipse.jface.dialogs.InputDialog;
> import org.eclipse.ui.PlatformUI;
>
> public class DefinitionCreateCommand extends CommandWrapper implements
> CommandActionDelegate {
> public DefinitionCreateCommand(Command command) {
> super(command);
> }
>
> @Override
> public void execute() {
> InputDialog dialog = new
> InputDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
> "test",
> "test message", "", null);
> dialog.open();
> }
>
> @Override
> public Object getImage() {
> return ((CommandActionDelegate) super.command).getImage();
> }
>
> @Override
> public String getText() {
> return ((CommandActionDelegate) super.command).getText();
> }
>
> @Override
> public String getToolTipText() {
> return ((CommandActionDelegate) super.command).getToolTipText();
> }
> }
>
> I have overwritten the method createCreateChildCommand with following
> content:
> return new
> DefinitionCreateCommand(super.createCreateChildCommand(domain, owner,
> feature, value, index, collection));
>
> It works so long, but how can I pass the result back?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: New child menu entry for EMap and custom dialog [message #896404 is a reply to message #896340] Wed, 18 July 2012 10:00 Go to previous messageGo to next message
John M. is currently offline John M.Friend
Messages: 198
Registered: July 2010
Senior Member
Thanks for the advice, but it is never called in my implementation. I think I have missed something out.
I observed the AddCommand's and SetCommand's getResult and doGetResult, too and there happens nothing.
Re: New child menu entry for EMap and custom dialog [message #896408 is a reply to message #896404] Wed, 18 July 2012 10:16 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
CreateChildCommand is like this:

@Override
public Collection<?> getResult()
{
Collection<?> result = helper.getCreateChildResult(child);
return result == null ? Collections.EMPTY_LIST : result;
}

So I'd expect it to return the created child. Not all commands create
things so many return an empty list.

On 18/07/2012 12:00 PM, Missing name Mising name wrote:
> Thanks for the advice, but it is never called in my implementation. I
> think I have missed something out.
> I observed the AddCommand's and SetCommand's getResult and
> doGetResult, too and there happens nothing.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: New child menu entry for EMap and custom dialog [message #896436 is a reply to message #896408] Wed, 18 July 2012 11:55 Go to previous messageGo to next message
John M. is currently offline John M.Friend
Messages: 198
Registered: July 2010
Senior Member
But it isn't called neither.
I added that method to my observed methods, but nothing happens.
I am a little bit confused. Smile
Re: New child menu entry for EMap and custom dialog [message #896445 is a reply to message #896436] Wed, 18 July 2012 12:16 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
I was assuming you wanted to call it yourself. I.e., it was my answer
for "how can I pass the result back? " but now I'm not sure I understand
that question at all. You'll need to elaborate it.


On 18/07/2012 1:55 PM, Missing name Mising name wrote:
> But it isn't called neither.
> I added that method to my observed methods, but nothing happens.
> I am a little bit confused. :)


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: New child menu entry for EMap and custom dialog [message #896454 is a reply to message #896445] Wed, 18 July 2012 12:30 Go to previous messageGo to next message
John M. is currently offline John M.Friend
Messages: 198
Registered: July 2010
Senior Member
Okay, I will try it. Smile
I want a dialog for the child creation, so I overwrote createCreateChildCommand and create my own instance of my own command (see http://www.eclipse.org/forums/index.php/mv/msg/367617/896216/#msg_896216).
It opens the InputDialog and takes the data, but I don't know how to pass it back.

I have investigated the method getResult, but it seems that it is never called in my case.
I just try to put the data of the InputDialog into the AddCommand.

The method createCreateChildCommand has the argument Object value. Perhaps I have to use it, but I can only imagine a way with chained commands and don't know if it is the right way. So that I overwrite the createCommand method, execute my own dialog command and after that create the AddCommand with the super implementation and chain it.
Re: New child menu entry for EMap and custom dialog [message #896459 is a reply to message #896454] Wed, 18 July 2012 12:42 Go to previous messageGo to next message
John M. is currently offline John M.Friend
Messages: 198
Registered: July 2010
Senior Member
Okay I think I found a solution. Following code works for me, but it is the right way?

@Override
public void execute() {
	super.execute();
	
	dialog = new InputDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "test",
			"test message", "", null);
	dialog.open();
	Collection<?> affectedObjects = getCommand().getAffectedObjects();
	for (Iterator iterator = affectedObjects.iterator(); iterator.hasNext();) {
		Object object = iterator.next();
		
		if (object instanceof StringToIntegerMapImpl) {
			((StringToIntegerMapImpl) object).setKey("test");
			((StringToIntegerMapImpl) object).setValue(2);
		}
	}
}
Re: New child menu entry for EMap and custom dialog [message #896460 is a reply to message #896454] Wed, 18 July 2012 12:51 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Comments below.

On 18/07/2012 2:30 PM, Missing name Mising name wrote:
> Okay, I will try it. :)
> I want a dialog for the child creation, so I overwrote
> createCreateChildCommand and create my own instance of my own command
> (see
> http://www.eclipse.org/forums/index.php/mv/msg/367617/896216/#msg_896216).
Yes.
> It opens the InputDialog and takes the data, but I don't know how to
> pass it back.
I thought I mentioned already that opening a dialog in a command is not
a good idea. After all, what should happen if the dialog is canceled.
I suppose you could throw an exception...
>
> I have investigated the method getResult, but it seems that it is
> never called in my case.
You mentioned that.
> I just try to put the data of the InputDialog into the AddCommand.
But you've already called super.execute so the child is already added.
>
> The method createCreateChildCommand has the argument Object value.
> Perhaps I have to use it, but I can only imagine a way with chained
> commands and don't know if it is the right way. So that I overwrite
> the createCommand method, execute my own dialog command and after that
> create the AddCommand with the super implementation and chain it.
I think you should modify the generated action bar contributor to create
your own specialized action which will launch a dialog and will only
invoke a command to add the result to the model if the user hits okay.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: New child menu entry for EMap and custom dialog [message #896466 is a reply to message #896460] Wed, 18 July 2012 13:15 Go to previous messageGo to next message
John M. is currently offline John M.Friend
Messages: 198
Registered: July 2010
Senior Member
>> I just try to put the data of the InputDialog into the AddCommand.
> But you've already called super.execute so the child is already added.
I found no other way to get the affected children.

> I think you should modify the generated action bar contributor to create
> your own specialized action which will launch a dialog and will only
> invoke a command to add the result to the model if the user hits okay.
I can't do that, because I have a derived model and that action is part of the extending model.
Can I use the org.eclipse.ui.editorActions extension point?
Re: New child menu entry for EMap and custom dialog [message #896501 is a reply to message #896093] Wed, 18 July 2012 14:54 Go to previous messageGo to next message
John M. is currently offline John M.Friend
Messages: 198
Registered: July 2010
Senior Member
In general, is it a praticable way to create my own extension point for such an idea?
I would create one and integrate it into the contributor class, so I can add my own action for special new child actions.
Re: New child menu entry for EMap and custom dialog [message #896505 is a reply to message #896501] Wed, 18 July 2012 14:59 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Yes, that seems practical.

On 18/07/2012 4:54 PM, Missing name Mising name wrote:
> In general, is it a praticable way to create my own extension point
> for such an idea?
> I would create one and integrate it into the contributor class, so I
> can add my own action for special new child actions.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[xcore] not serialize a specific property
Next Topic:Strategies for handling dangling references?
Goto Forum:
  


Current Time: Thu Mar 28 12:55:59 GMT 2024

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

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

Back to the top