Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » [solved]How get and set features values on drag and drop ?
[solved]How get and set features values on drag and drop ? [message #790209] Sat, 04 February 2012 00:02 Go to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
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 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
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 #790955 is a reply to message #790209] Sun, 05 February 2012 03:47 Go to previous messageGo to next message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 9
Registered: April 2011
Junior Member
I solve my problem with this:

protected Command getDropCommand(ChangeBoundsRequest request) {
		
	FolderImpl folder = (FolderImpl)getHostObject();
	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
						
	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;
	
}
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 Go to previous message
Ed Merks is currently offline Ed MerksFriend
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/
Previous Topic:[SOLVED] Create child nodes automatically when parent is created
Next Topic:Some duvids about GMF model format
Goto Forum:
  


Current Time: Sat Apr 20 03:47:10 GMT 2024

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

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

Back to the top