Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » adding an node to a connection
adding an node to a connection [message #188358] Wed, 21 May 2008 21:27 Go to next message
Brian Jakubik is currently offline Brian JakubikFriend
Messages: 140
Registered: July 2009
Senior Member
Is it possible to drop a node on a connection, and have it redo the
connections to insert the node in between them?

Example
node1 -----------------> node2
^
node* dropped here

resulting in
node1 ------->node*------> node2

Any guidance would be appreciated if it is possible

Thanks
Brian Jakubik
Re: adding an node to a connection [message #189669 is a reply to message #188358] Wed, 28 May 2008 09:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tobk42.gmx.de

Hello,

I am currently investigating an Action doing the same thing for my
editor, however currently I am stuck with reconnecting the orginal
connection to the new edit part. An alternative way would be to create a
new connection and to copy the several values to its underlying EObject.
However, reconnecting the old connection would be the 'cleaner'
solution. I would appreciate any help and will share the resulting
action once its done.

Tobias



Brian Jakubik schrieb:
> Is it possible to drop a node on a connection, and have it redo the
> connections to insert the node in between them?
>
> Example
> node1 -----------------> node2
> ^
> node* dropped here
>
> resulting in
> node1 ------->node*------> node2
>
> Any guidance would be appreciated if it is possible
>
> Thanks
> Brian Jakubik
Re: adding an node to a connection [message #189810 is a reply to message #189669] Wed, 28 May 2008 15:41 Go to previous message
Eclipse UserFriend
Originally posted by: tobk42.gmx.de

Did it. Well, with a workaround, not really reconnecting the edge but
drawing a new one and copying the attributes one by one. See the code
below. I'm posting only the doRun method of the IObjectDelegate. The
action is made available in the contextmenu as in the GMF Tutorial, Part
III. Tell me if you find out how to integrate this in the palette or the
ModellingAssistant or how to use the ReconnectCommand here.

--- BEGIN CODE ---

public void run(IAction action) {
//this compound command will hold the various partial commands
CompoundCommand cc= new CompoundCommand(getCommandName());
LaneLaneCompartmentEditPart laneCompEditPart=
(LaneLaneCompartmentEditPart) seqFlowEditPart.getSource().getParent();
// Create Node Command
CreateViewRequest nodeRequest =
CreateViewRequestFactory.getCreateShapeRequest(getElementTyp e(),
laneCompEditPart.getDiagramPreferencesHint());
Point p= seqFlowEditPart.getFigure().getBounds().getCenter();
p.translate(-20, -20);
laneCompEditPart.getFigure().translateToAbsolute(p);
nodeRequest.setLocation(p);
Command creatNodeCmd = laneCompEditPart.getCommand(nodeRequest);
cc.add(creatNodeCmd);
IAdaptable nodeViewAdapter = (IAdaptable) ((List)
nodeRequest.getNewObject()).get(0);
// Create Sequence Flow Command
CreateConnectionViewAndElementRequest seqFlowRequest= new
CreateConnectionViewAndElementRequest(
VsdtElementTypes.SequenceFlow_3001,
((IHintedType)
VsdtElementTypes.SequenceFlow_3001).getSemanticHint(),
seqFlowEditPart.getDiagramPreferencesHint());
ICommand createSequenceFlowCmd = new
DeferredCreateConnectionViewAndElementCommand(
seqFlowRequest,
nodeViewAdapter,
new EObjectAdapter((EObject)
seqFlowEditPart.getTarget().getModel()),
seqFlowEditPart.getViewer());
cc.add(new ICommandProxy(createSequenceFlowCmd));

// Reconnect original Sequence Flow
// ReconnectRequest reconnectRequest= new ReconnectRequest();
// reconnectRequest.setConnectionEditPart(seqFlowEditPart);
// reconnectRequest.setTargetEditPart(seqFlowEditPart.getSource ());
// Command reconnectCommand=
seqFlowEditPart.getCommand(reconnectRequest);
// cc.add(reconnectCommand);

// reconnecting doesn't work yet; workaround: create new connection
//XXX BEGIN WORKAROUND
// Create Sequence Flow Command
seqFlowRequest= new CreateConnectionViewAndElementRequest(
VsdtElementTypes.SequenceFlow_3001,
((IHintedType)
VsdtElementTypes.SequenceFlow_3001).getSemanticHint(),
seqFlowEditPart.getDiagramPreferencesHint());
createSequenceFlowCmd = new
DeferredCreateConnectionViewAndElementCommand(
seqFlowRequest,
new EObjectAdapter((EObject)
seqFlowEditPart.getSource().getModel()),
nodeViewAdapter,
seqFlowEditPart.getViewer());
cc.add(new ICommandProxy(createSequenceFlowCmd));

IAdaptable newSeqFlowViewAdapter = (IAdaptable)
seqFlowRequest.getNewObject();
// put stuff together
cc.add(new ICommandProxy(new
CopySeqFlowAttCommand(laneCompEditPart.getViewer(),
seqFlowEditPart.getCastedModel(), newSeqFlowViewAdapter)));

//delete old connection (edge first, then model element)
DeleteCommand delCommand= new DeleteCommand((View)
seqFlowEditPart.getModel());
cc.add(new ICommandProxy(delCommand));
DestroyElementRequest destroyRequest= new
DestroyElementRequest(seqFlowEditPart.getCastedModel(), false);
destroyRequest.setEditingDomain(laneCompEditPart.getEditingD omain());
DestroyElementCommand destroyCommand= new
DestroyElementCommand(destroyRequest);
cc.add(new ICommandProxy(destroyCommand));
// XXX END WORKAROUND

// execute commands

laneCompEditPart.getDiagramEditDomain().getDiagramCommandSta ck().execute(cc);

// put the new node in edit mode
final EditPartViewer viewer = laneCompEditPart.getViewer();
final EditPart elementPart = (EditPart)
viewer.getEditPartRegistry().get(nodeViewAdapter.getAdapter( View.class));
if (elementPart != null) {
Display.getCurrent().asyncExec(new Runnable() {
public void run() {
viewer.setSelection(new StructuredSelection(elementPart));
Request der = new Request(RequestConstants.REQ_DIRECT_EDIT);
elementPart.performRequest(der);
}
});
}
}

protected class CopySeqFlowAttCommand extends
AbstractTransactionalCommand {
SequenceFlow oldSeqFlow;
EditPartViewer viewer;
IAdaptable newSeqFlowViewAdapter;
public CopySeqFlowAttCommand(EditPartViewer editPartViewer,
SequenceFlow sequenceFlow, IAdaptable adaptable) {
super(TransactionUtil.getEditingDomain(sequenceFlow), "Copy
SequenceFlow Attributes", Collections

..singletonList(WorkspaceSynchronizer.getFile(sequenceFlow.e Resource())));
this.viewer= editPartViewer;
this.oldSeqFlow= sequenceFlow;
this.newSeqFlowViewAdapter= adaptable;
}
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor
monitor, IAdaptable adaptable) throws ExecutionException {
EditPart editPart = (EditPart)
viewer.getEditPartRegistry().get(newSeqFlowViewAdapter.getAd apter(View.class));
if (editPart instanceof SequenceFlowEditPart) {
SequenceFlowEditPart newSeqFlowEditPart =
(SequenceFlowEditPart) editPart;
SequenceFlow newSeqFlow= newSeqFlowEditPart.getCastedModel();
if (oldSeqFlow != null && newSeqFlow != null) {

newSeqFlow.setConditionExpression(oldSeqFlow.getConditionExp ression());
...
return CommandResult.newOKCommandResult();
}
}
return null;
}
}

--- END CODE ---



Tobias schrieb:
> Hello,
>
> I am currently investigating an Action doing the same thing for my
> editor, however currently I am stuck with reconnecting the orginal
> connection to the new edit part. An alternative way would be to create a
> new connection and to copy the several values to its underlying EObject.
> However, reconnecting the old connection would be the 'cleaner'
> solution. I would appreciate any help and will share the resulting
> action once its done.
>
> Tobias
>
>
>
> Brian Jakubik schrieb:
>> Is it possible to drop a node on a connection, and have it redo the
>> connections to insert the node in between them?
>>
>> Example
>> node1 -----------------> node2
>> ^
>> node* dropped here
>>
>> resulting in
>> node1 ------->node*------> node2
>>
>> Any guidance would be appreciated if it is possible
>>
>> Thanks
>> Brian Jakubik
Previous Topic:Connections between nodes aren't always well displayed
Next Topic:to extend the copy/paste function
Goto Forum:
  


Current Time: Fri Apr 26 10:43:19 GMT 2024

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

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

Back to the top