Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Create element and view when diagram is created
Create element and view when diagram is created [message #150110] Tue, 11 September 2007 11:33 Go to next message
Eclipse UserFriend
When a user creates a new diagram, I want to be able to add an element and
a view for that element to the root model element. It would also be nice
if I could place this element on the diagram at specific coordinates.
Does anyone have a code example to create an element and its view and to
place it on the diagram at a specific location. Where should I put this
code?
Re: Create element and view when diagram is created [message #150344 is a reply to message #150110] Wed, 12 September 2007 06:19 Go to previous message
Eclipse UserFriend
I was able to solve this by overriding the decorateView method on the root
view factory (the one that extends the DiagramViewFactory):

protected void decorateView(View view,
org.eclipse.core.runtime.IAdaptable semanticAdapter,
String diagramKind) {
super.decorateView(view, semanticAdapter, diagramKind);

// Automatically create a start step when a new diagram is created
// This method is only be called when a diagram is created not loaded.
this.createStartStep(view);
}

I had to manually add the element that I wanted and create a Node for the
model notation as follows:

protected void createStartStep(View view) {
// Root model element
Component component;

// Model element to create
StartStep startStep;

// Create a new child model element
startStep = StepFactory.eINSTANCE.createStartStep();

// Get the root model element
component = (Component) view.getElement();

// Add my new model element to the root element
component.getSteps().add(startStep);

// Create the notation element (node) providing the model
// element that the node will be mapped to
Node aNode = getViewService().createNode(view,
startStep,
MyVisualIDRegistry.getType(StartStepEditPart.VISUAL_ID),
getPreferencesHint());
}
Previous Topic:Get coordinates
Next Topic:Custom Figure with dependable backgroundcolors
Goto Forum:
  


Current Time: Thu Jul 17 20:37:54 EDT 2025

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

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

Back to the top