|
Re: Inserting nodes in a compartment [message #218916 is a reply to message #217333] |
Mon, 16 February 2009 10:58 |
Marcel Bootsma 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);
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.02597 seconds