Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Drag and Drop a view onto another
Drag and Drop a view onto another [message #734718] Sun, 09 October 2011 13:44 Go to next message
Simon Schwichtenberg is currently offline Simon SchwichtenbergFriend
Messages: 126
Registered: September 2011
Senior Member
hi,

i tried very hard at this, but i could not get it to work. hope someone could help:

in my ecore model there is a top level node "Goal" and a top level node "Agent" which consists of "Operation" nodes (realized as compartment). Node "Operation" consists of "Operationalization" nodes, which has references to "Goal".

i want to support drag and drop of "Operations" onto "Goals". After the "Operation" is dropped, then a command shall be called, which creates a new "Operationalization" node and set its reference to "Goal".

i installed an editpolicy in "Goal". The canExecute() method of OperationAddOperationalizationCommand is called, which returns true, but the command is never executed. i would be thankful for every hint.

i should also note that i get an
java.lang.NullPointerException
at org.eclipse.gmf.runtime.diagram.ui.editpolicies.XYLayoutEditPolicy.getConstraintFor(XYLayoutEditPolicy.java:229)
when i try to drag the "Operation" off the "Agent"s compartment. maybe someone has some hints for that.

		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE,
				new DragDropEditPolicy(){
			public Command getDropObjectsCommand(
					DropObjectsRequest dropRequest) {
				List viewDescriptors = new ArrayList();
				Operation bla=null;
				for (Iterator it = dropRequest.getObjects().iterator(); it
						.hasNext();) {
					Object nextObject = (Object) it.next();
					
					if(nextObject instanceof Operation){
						bla = (Operation) nextObject;
					}
					if (false == nextObject instanceof EObject) {
						continue;
					}

				}
				
				Command c = new ICommandProxy(new OperationAddOperationalizationCommand(getEditingDomain(),(View) getModel(),bla , ((View) getHost().getModel()).getElement()));
				

				return c;
			}
			
		});


public class OperationAddOperationalizationCommand extends AbstractTransactionalCommand {
	
	public OperationAddOperationalizationCommand(TransactionalEditingDomain editingDomain, View parentView , EObject source, EObject target) {
		super(editingDomain, "heiho", getWorkspaceFiles(parentView));
		this.target = target;
		this.source = source;
	}

	EObject target;
	EObject source;
		

	public boolean canExecute(){
		if(source == null || false == source instanceof Operation){
			return false;
		}
		
		if(target == null || false == target instanceof Goal){
			return false;
		}
		
		if(getSource().getOperationalizations().contains(target)){
			return false;
		}
		
		return true;
	}
	
	protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
			IAdaptable info) throws ExecutionException {
		
		
		if(getTarget()!=null && getSource()!=null){
			
			Operationalization opz = XkaosFactory.eINSTANCE.createOperationalization();
			opz.setGoal(getTarget());
			getSource().getOperationalizations().add(opz);
		}
		
		return CommandResult.newOKCommandResult();
	}
Re: Drag and Drop a view onto another [message #737012 is a reply to message #734718] Fri, 14 October 2011 15:16 Go to previous message
Simon Schwichtenberg is currently offline Simon SchwichtenbergFriend
Messages: 126
Registered: September 2011
Senior Member
ok, "solved". the code above is fine, but you should not set a breakpoint at a wrong position...
Previous Topic:Could anybody help me with this?
Next Topic:Drag and dropping ports into tasks
Goto Forum:
  


Current Time: Thu Dec 18 10:44:11 GMT 2014

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

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