Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Context menu, connection between two items
Context menu, connection between two items [message #170919] Thu, 31 January 2008 10:32 Go to next message
Eclipse UserFriend
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);
}
});
}
}
Re: Context menu, connection between two items [message #171318 is a reply to message #170919] Mon, 04 February 2008 04:36 Go to previous message
Eclipse UserFriend
Originally posted by: marsha.rohrer.swisscom.com

Anyone who could help me for my context menu?

Documentation about creating requests and commands is really poor...

Thanks
Marsha
Previous Topic:Custom figures and two figures for one editpart
Next Topic:How to use New Element Spec in a Feature Seq Initializer
Goto Forum:
  


Current Time: Tue Jul 22 02:37:50 EDT 2025

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

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

Back to the top