Drag and Drop a view onto another [message #734718] |
Sun, 09 October 2011 13:44 |
Simon Schwichtenberg Messages: 127 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();
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.02894 seconds