Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Command#canExecute is false, why ?
Command#canExecute is false, why ? [message #535900] Wed, 26 May 2010 05:32
Eclipse UserFriend
I created a simple DropEditPolicy which always inserts the same basic node (Activity_2003), but the created CompoundCommand always is not executable (canExecute() == false). Can anyone give me a clue where's the problem ?

public class DropObjectEditPolicy extends GraphicalEditPolicy implements EditPolicy {

	public Command getCommand(Request request) {
		if (RequestConstants.REQ_DROP_OBJECTS.equals(request.getType())) {
			DropObjectsRequest dndRequest = (DropObjectsRequest) request;
			return getDropCommand(dndRequest);
		}
		return null;
	}

	private Command getDropCommand(DropObjectsRequest dndRequest) {

		ProcessEditPart editor = (ProcessEditPart) getHost();
		IElementType type = ProcessElementTypes.Activity_2003; // Basic node, can be placed anywhere
		ViewAndElementDescriptor viewDescriptor = new ViewAndElementDescriptor(
				new CreateElementRequestAdapter(new CreateElementRequest(type)),
				Node.class,
				((IHintedType) type).getSemanticHint(),
				editor.getDiagramPreferencesHint());

		CreateViewAndElementRequest req = new CreateViewAndElementRequest(viewDescriptor);
		
		CompoundCommand cmd = new CompoundCommand("Drop new activity");
		cmd.add(editor.getCommand(req));
		System.out.println(">>>>>> DropObjectEditPolicy.getDropCommand() canExecute()=" + cmd.canExecute());
		
		return cmd;
	}

	public boolean understandsRequest(Request request) {
		return RequestConstants.REQ_DROP_OBJECTS.equals(request.getType()) && request instanceof DropObjectsRequest;
	}
}
Previous Topic:Disable Note attachment completly
Next Topic:EConstraint in Ecore Model
Goto Forum:
  


Current Time: Fri Jun 13 04:19:42 EDT 2025

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

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

Back to the top