Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Command#canExecute is false, why ?
Command#canExecute is false, why ? [message #535900] Wed, 26 May 2010 09:32
Ralf is currently offline RalfFriend
Messages: 25
Registered: March 2010
Junior Member
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: Sat May 18 04:12:43 GMT 2024

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

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

Back to the top