Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Inserting nodes in a compartment
Inserting nodes in a compartment [message #217333] Thu, 05 February 2009 09:03 Go to next message
Marcel Bootsma is currently offline Marcel BootsmaFriend
Messages: 11
Registered: July 2009
Junior Member
Hello,

I am tying to insert nodes in a compartment at a specific place.
I implemented the Add children recipe
(http://wiki.eclipse.org/GMF/Recipes) on a small test editor. In this
editor I can add 'Attributes' to 'Elements'.

Adding the Attributes at a specific place in the commpartment of an
Element works perfectly but when I save the diagram and have a look at the
model file the added Attributes are still appended at the end.

It seems that the CompartmentChildCreateCommand works only on the
notational model but not on the semantic model.

Did I forget something? It seems that nobody else is having this problem.

I would realy appreciate some help in this because I'am still far from GMF
guru..

Marcel
Re: Inserting nodes in a compartment [message #218916 is a reply to message #217333] Mon, 16 February 2009 10:58 Go to previous message
Marcel Bootsma is currently offline Marcel BootsmaFriend
Messages: 11
Registered: July 2009
Junior Member
I investigated the problem and found the following solution:

The CreateCommand inserts the new view at the correct position in the
notational but appends it in the semantical model. This means that it
should be moved to the correct postions in the semantical model.
I added the following lines to my CustomCompartmentChildCreateCommand an
now it works.


if (index > -1) {
EList nodes = (EList)
getContainerView().getElement().eGet(UMLPackage.Literals.INT ERFACE__OWNED_ATTRIBUTE);
nodes.add(index, nodes.remove(nodes.size() - 1));
}

Note: UMLPackage.Literals.INTERFACE__OWNED_ATTRIBUTE is the
EStructuralFeature of the the EList containing the nodes to be moved, in
my case the attributes of an UML interface. It is the same feature as used
in the Reorder children GMF/Recipe. You have to replace this with your own
lists EStructuralFeature.


The whole listing of my CustomCompartmentChildCreateCommand:

package com.thalesgroup.o2.layouteditor.custom.commands;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
import org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand;
import
org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewReques t.ViewDescriptor;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.uml2.uml.UMLPackage;

public class CustomCompartmentChildCreateCommand extends CreateCommand {

int index;

public CustomCompartmentChildCreateCommand (
TransactionalEditingDomain editingDomain,
ViewDescriptor viewDescriptor,
View containerView,
int index) {
super(editingDomain, viewDescriptor, containerView);
this.index = index;
}

@Override
protected CommandResult doExecuteWithResult(
IProgressMonitor progressMonitor, IAdaptable info) throws
ExecutionException {

View view =
ViewService.getInstance().createView(
viewDescriptor.getViewKind(),
viewDescriptor.getElementAdapter(),
containerView,
viewDescriptor.getSemanticHint(),
index,
viewDescriptor.isPersisted(),
viewDescriptor.getPreferencesHint());
viewDescriptor.setView(view);

if (index > -1) {
EList nodes = (EList)
getContainerView().getElement().eGet(UMLPackage.Literals.INT ERFACE__OWNED_ATTRIBUTE);
nodes.add(index, nodes.remove(nodes.size() - 1));

}

return CommandResult.newOKCommandResult(viewDescriptor);
}

}
Previous Topic:How I can add graphical elements to my file
Next Topic:GMF/Recipes: Reorder...
Goto Forum:
  


Current Time: Sat Mar 06 03:26:07 GMT 2021

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

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

Back to the top