Create element and view when diagram is created [message #150110] |
Tue, 11 September 2007 11:33  |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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());
}
|
|
|
Powered by
FUDForum. Page generated in 0.06910 seconds