Using the DeferredCreateConnectionViewAndElementCommand [message #158705] |
Wed, 07 November 2007 11:25  |
Eclipse User |
|
|
|
I am trying to use the DeferredCreateConnectionViewAndElementCommand and
getting nowhere.
This is a typical boxes with pins scenario. I have elements named
ProcessReference with children InputPin. There are other elements named
ValueObject. I connect the relation InboundDataFlow from the ValueObject
element to the InputPin child of a ProcessReference element. That works
fine. I can drag a InboundDataFlow connection from a ValueObject to an
InputPin, no problem.
Now I want to automatically create a new InputPin child on the
ProcessReference when the user drags a InboundDataFlow onto the
ProcessReference. Seems like a common enough problem.
I tried using the code shown in
http://wiki.eclipse.org/GMF_Tutorial_Part_3, but with no luck.
Question 1. Where should the overwrite occur? I put in the
ProcessReference semantic edit policy. Is that right?
public class ProcessReferenceItemSemanticEditPolicy extends
XyzBaseItemSemanticEditPolicy {
protected Command getCreateRelationshipCommand(CreateRelationshipRequest
req) {
if (XyzElementTypes.InboundDataFlow_3002 == req.getElementType()){
if (req.getTarget() == null)
return null;
return getCreateCompleteIncomingInboundDataFlow3002Command(req);
}
return super.getCreateRelationshipCommand(req);
}
/**
* Creates a compound command that creates the pin and
* creates the connection to the pin. The second step must be a deferred
* because it depends on completion of the first step.
*
*/
protected Command getCreateCompleteIncomingInboundDataFlow3002Command(
CreateRelationshipRequest req) {
CompoundCommand compoundCmd = new CompoundCommand("Create Pin and
Inbound Data Flow Connector");
// create pin command
ProcessReferenceEditPart targetPart =
(ProcessReferenceEditPart)this.getHost();
CreateViewAndElementRequest pinReq = new CreateViewAndElementRequest(
XyzElementTypes.InputPin_2005,
targetPart.getDiagramPreferencesHint());
Command createPinCmd = targetPart.getCommand(pinReq);
compoundCmd.add(createPinCmd);
// create defered relationship
Object newObj = pinReq.getNewObject();// have adapter for new pin results
IAdaptable pinViewAdapter = (IAdaptable) ((List) newObj).get(0);
IAdaptable sourceViewAdapter = new EObjectAdapter(req.getSource());
ContainerEditPart parent = (ContainerEditPart)targetPart.getParent();
CreateConnectionViewAndElementRequest connectorReq =
new CreateConnectionViewAndElementRequest(
XyzElementTypes.InboundDataFlow_3002,
((IHintedType)XyzElementTypes.InboundDataFlow_3002).getSeman ticHint(),
parent.getDiagramPreferencesHint());
ICommand createConnectorCmd = new
DeferredCreateConnectionViewAndElementCommand(
connectorReq,
sourceViewAdapter,
pinViewAdapter,
parent.getViewer());
compoundCmd.add(new ICommandProxy(createConnectorCmd));
return compoundCmd;
}
}
The method gets called, twice, but does nothing. I would expect that the
deferred command would forward to the InputPin element's semantic edit
policy to complete the process, but it never gets called.
Question 2. Do I have the right semantic hints set?
Question 3. Should I create a new request for the deferred command (as I
have done) or am I supposed to forward the create relationship request
past to the method?
I appreciate the help.
|
|
|
Re: Using the DeferredCreateConnectionViewAndElementCommand [message #158809 is a reply to message #158705] |
Thu, 08 November 2007 05:11  |
Eclipse User |
|
|
|
Hello Jeffrey,
In GMF CreateUnspecifiedTypeRequest used to create all the diagram nodes,
so you can see how to handle this request (create appropriate CreateViewAndElementRequest)
in this class. I think first you should make sure InputPin is created correctly
and then start working with link to it. I suggest you to debug command returned
by your edit policy to see why corresponding composed command is returning
"false" from corresponding "canExecute" method.
-----------------
Alex Shatalin
|
|
|
Powered by
FUDForum. Page generated in 0.03744 seconds