Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Adding a connection using a context menu action
Adding a connection using a context menu action [message #225263] Thu, 09 April 2009 12:51 Go to next message
Robert Wloch is currently offline Robert WlochFriend
Messages: 109
Registered: July 2009
Senior Member
Hi,

I'm trying to add a figure and a connection to an already existing figure
using a context menu action on the existing figure. So far, I get the new
figure created by creating a CreateUnspecifiedTypeRequest (that's creating
an internal CreateViewAndElementRequest):

CreateUnspecifiedTypeRequest unspecifiedTypeRequest = new
CreateUnspecifiedTypeRequest(
elementTypes, getPreferencesHint());
request = unspecifiedTypeRequest.getRequestForType(elementType);
setRequestLocation(reqest, contextEP);

The request is send to my DiagramEditPart to get the command which is
executed (wrapped in an ICommandProxy and CompoundCommand). It does work
well for my figure Node.

Trying to create a connection the same way fails for some reason, although
I create a CreateUnspecifiedTypeConnectionRequest (that's creating an
internal CreateConnectionViewAndElementRequest):

CreateUnspecifiedTypeConnectionRequest unspecifiedTypeRequest = new
CreateUnspecifiedTypeConnectionRequest(
elementTypes, false, getPreferencesHint());
request = unspecifiedTypeRequest.getRequestForType(elementType);
if (request instanceof CreateConnectionViewAndElementRequest) {
CreateConnectionViewAndElementRequest req =
(CreateConnectionViewAndElementRequest) request;
req.setSourceEditPart(sourceEP);
req.setTargetEditPart(targetEP);
req.setSuppressibleUI(true);
req.setType(RequestConstants.REQ_CONNECTION_END);
}

Again, the request is send to my DiagramEditPart to get the command which
is executed (wrapped in an ICommandProxy and CompoundCommand) but nothing
happens. I get no error log message or alike.

Debugging the command execution revealed that the respective create
connection command is checking if it's executable but a deeply wrapped
CompoundCommand inbetween two ToggleCanonicalModeCommands returns false
upon its ICommandProxy's PromptForConnectAndEndCommand trying to open some
Dialog:

public boolean canExecute() {
return createPopupMenu() != null;
}

I thought by setting req.setSuppressibleUI(true) the command wouldn't
attempt to interact with the user? What did I miss or do wrong?

Cheers,
Rob
Re: Adding a connection using a context menu action [message #225739 is a reply to message #225263] Tue, 14 April 2009 07:46 Go to previous messageGo to next message
Robert Wloch is currently offline Robert WlochFriend
Messages: 109
Registered: July 2009
Senior Member
I did some extended debugging and figured that the semantic connection
element gets created. It's just the view element not being created by
programmatically creating and executing the create connection command.

As far as I understood from the TargetingTool and
UnspecifiedTypeConnectionTool I do the same steps to create the create
request. I just do it in one method:

private Command myGetCommand(EditPart targetEP, EditPart sourceEP) {
...
CreateUnspecifiedTypeConnectionRequest unspecifiedTypeRequest = new
CreateUnspecifiedTypeConnectionRequest(
elementTypes, false, getPreferencesHint());
CreateRequest request =
unspecifiedTypeRequest.getRequestForType(elementType);
if (request instanceof CreateConnectionViewAndElementRequest) {
CreateConnectionViewAndElementRequest req =
(CreateConnectionViewAndElementRequest) request;
req.setSourceEditPart(sourceEP);
req.setTargetEditPart(targetEP);
req.setType(RequestConstants.REQ_CONNECTION_END);
}

Command cmd = targetEP.getCommand(request)
return cmd;
}

That command is then executed on the DiagramEditor's CommandStack.

What I don't get is, why there's no view element being created, although I
use a CreateConnectionViewAndElementRequest to get the create command.

What did I miss?
Re: Adding a connection using a context menu action [message #225833 is a reply to message #225739] Tue, 14 April 2009 13:00 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Robert,

Try following code:

request.setType(RequestConstants.REQ_CONNECTION_START);
request.setSourceEditPart(sourceEditPart);
sourceEditPart.getCommand(request);
request.setTargetEditPart(targetEditPart);
request.setType(RequestConstants.REQ_CONNECTION_END);
Command cmd = targetEditPart.getCommand(request);
if (cmd != null && cmd.canExecute()) {
executeCommand(cmd);
}

-----------------
Alex Shatalin
Re: Adding a connection using a context menu action [message #226076 is a reply to message #225833] Wed, 15 April 2009 07:48 Go to previous message
Robert Wloch is currently offline Robert WlochFriend
Messages: 109
Registered: July 2009
Senior Member
Alex, thanks a lot! That snippet did it. I'd never thought of
CreateUnspecifiedTypeConnectionRequest being some kind of state machine.
:o)
Previous Topic:How to refesh the diagram in the GMF editor by interval?
Next Topic:[Announce] GMF 2.2.0 I200904141928 is available
Goto Forum:
  


Current Time: Tue Apr 23 16:38:16 GMT 2024

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

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

Back to the top