[solved]How get and set features values on drag and drop ? [message #790209] |
Sat, 04 February 2012 00:02 |
Missing name Mising name Messages: 9 Registered: April 2011 |
Junior Member |
|
|
I'm trying alter some eClass features value when some node drop on a diferent compartment. But when I try alter the feature value on my destiny node, this node became invalid, no one another node can be droped there.
I register my DragDropEditPolicy, in EditPart, overriding de getDropCommand as below:
protected Command getDropCommand(ChangeBoundsRequest request) {
FolderEditPart folder = (FolderEditPart)getTargetEditPart(request).getParent();
Folder eFolder = (Folder)folder.resolveSemanticElement();
EStructuralFeature esf = eFolder.eClass().getEStructuralFeature("files");
File file = FolderFactory.eINSTANCE.createFile();
file.setName("newFile");
eFolder.eSet(esf, file); // here is the problem, I cant set the new value
return super.getDropCommand(request);
}
My duvid is, how can I set and get feature values on drag and drop events using the gmf?
obs: the feature that I want change is many-valued.
[Updated on: Sun, 05 February 2012 03:48] Report message to a moderator
|
|
|
Re: How get and set features values on drag and drop ? [message #790469 is a reply to message #790209] |
Sat, 04 February 2012 09:32 |
Ed Merks Messages: 33137 Registered: July 2009 |
Senior Member |
|
|
Comments below.
On 04/02/2012 1:02 AM, Missing name Mising name wrote:
> I'm trying alter some eClass features value when some node drop on a
> diferent compartment. But when I try alter the feature value on my
> destiny node, this node became invalid, no one another node can be
> droped there.
>
> I register my DragDropEditPolicy, in EditPart, overriding de
> getDropCommand as below:
>
>
> protected Command getDropCommand(ChangeBoundsRequest request) {
> FolderEditPart folder =
> (FolderEditPart)getTargetEditPart(request).getParent();
> Folder eFolder = (Folder)folder.resolveSemanticElement();
> EStructuralFeature esf =
> eFolder.eClass().getEStructuralFeature("files");
> File file = FolderFactory.eINSTANCE.createFile();
> file.setName("newFile");
>
> eFolder.eSet(esf, file); // here is the problem, I cant set the
> new value
Given this method is returning a command, any changes you make to the
model need to be done as part of executing a command, not as part of
creating the command. I'm also not sure why you'd be doing this
reflectively rather than doing eFolder.getFiles().add().
> return super.getDropCommand(request);
> }
>
>
> My duvid is, how I can set and get feature values on drag and drop
> events using the gmf?
>
> obs: the feature that I want change is many-valued.
It's clear then that calling eSet will require the argument to be a list
so you'll be getting a class cast exception. Haven't you used the
debugger to track what's happening? You'd better look at what super
does and understand how to create commands. No doubt you'll need to
compose a command (CompoundCommand) for adding a file to the folder with
the command you're getting back from super...
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Re: How get and set features values on drag and drop ? [message #791038 is a reply to message #790955] |
Sun, 05 February 2012 06:56 |
Ed Merks Messages: 33137 Registered: July 2009 |
Senior Member |
|
|
Comments below.
On 05/02/2012 4:47 AM, Missing name Mising name wrote:
> I solve my problem with this:
>
>
> protected Command getDropCommand(ChangeBoundsRequest request) {
>
> FolderImpl folder = (FolderImpl)getHostObject();
Why cast to an Impl? Aren't all the methods you need available on the
interface?
> folder.eSetDeliver(false); // permite get/set EObjects
>
> List l = request.getEditParts();
>
> File f = null;
> for (Object obj : l) {
> if(obj instanceof FileEditPart) {
> FileEditPart fileEditPart = ((FileEditPart)obj);
>
> f = ((File)fileEditPart.resolveSemanticElement());
> }
> } if(!folder.getFiles().contains(f))
> folder.getFiles().add(f); // apenas um EObject e setado no
> destino
Keep in mind that this can't be undone and that the command stack
assumes the state of the model is only ever changed by virtue of
executing, undo, and redoing commands. You really should do this as a
command...
>
> ChangeBoundsRequest req = new ChangeBoundsRequest(REQ_ADD);
> req.setEditParts(request.getEditParts());
> req.setMoveDelta(request.getMoveDelta());
> req.setSizeDelta(request.getSizeDelta());
> req.setLocation(request.getLocation());
> req.setResizeDirection(request.getResizeDirection());
> Command cmd = getHost().getCommand(req);
>
> if (cmd == null || !cmd.canExecute()) {
> return super.getDropCommand(request);
> }
>
>
> return cmd;
>
> }
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03076 seconds