Context menu, connection between two items [message #170919] |
Thu, 31 January 2008 10:32  |
Eclipse User |
|
|
|
Originally posted by: marsha.rohrer.swisscom.com
Hi,
In my diagram I have a rectangle, a circle and a connecton that links a
rectangle with a circle.
What I want now is add a new circle with a link to the rectangle through
the context menu. i.e. if I click on "insert circle" a circle will be
added with the link to the rectangle from which I opened the context menu.
I copied the example in the mindmap tutorial 3
( http://wiki.eclipse.org/index.php/GMF_Tutorial_Part_3#Custom _Actions). Up
to now I am able to make the circle appear but something goes wrong with
the link. As far as I found out the CreateConnectionViewAndElementRequest
isn't created properly. Find the run method of my action below.
Do you have a hint for me?
Thank you.
Marsha
public void run(IAction action) {
CompoundCommand cc = new CompoundCommand("Create Start Condition and
Link");
// Create the new start condition for the step.
CreateViewRequest startCondRequest = CreateViewRequestFactory
.getCreateShapeRequest(GameElementTypes.StartCondition_1003,
selectedElement.getDiagramPreferencesHint());
Point p =
selectedElement.getFigure().getBounds().getTopRight().getCop y();
selectedElement.getFigure().translateToAbsolute(p);
int edgeCount =
selectedElement.getNotationView().getSourceEdges().size();
// A quick hack to get subtopics to layout to the right, from top to
// bottom
int offset = (edgeCount * 50) - 100;
startCondRequest.setLocation(p.translate(100, offset));
GAMEContextEditPart gameEditPart = (GAMEContextEditPart) selectedElement
.getParent();
Command createTopicCmd = gameEditPart.getCommand(startCondRequest);
IAdaptable stepViewAdapter = (IAdaptable) ((List) startCondRequest
.getNewObject()).get(0);
cc.add(createTopicCmd);
// create the start condition link
ICommand createLinkStartCondCmd = new
DeferredCreateConnectionViewAndElementCommand(
new CreateConnectionViewAndElementRequest(
GameElementTypes.StartConditionStep_3004,
((IHintedType) GameElementTypes.StartConditionStep_3004)
.getSemanticHint(), selectedElement
.getDiagramPreferencesHint()),
new EObjectAdapter((EObject) selectedElement.getModel()),
stepViewAdapter, selectedElement.getViewer());
cc.add(new ICommandProxy(createLinkStartCondCmd));
selectedElement.getDiagramEditDomain().getDiagramCommandStac k()
.execute(cc);
// put the new topic in edit mode
final EditPartViewer viewer = selectedElement.getViewer();
final EditPart elementPart = (EditPart) viewer.getEditPartRegistry()
.get(stepViewAdapter.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);
}
});
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.24865 seconds