Search in sources :

Example 1 with RepositionEObjectCommand

use of org.eclipse.gmf.runtime.emf.commands.core.commands.RepositionEObjectCommand in project statecharts by Yakindu.

the class CompartmentLayoutEditPolicy method createMoveChildCommand.

@Override
@SuppressWarnings("rawtypes")
protected Command createMoveChildCommand(EditPart child, EditPart after) {
    int newIndex;
    int displacement;
    int childIndex = getHost().getChildren().indexOf(child);
    int afterIndex = getHost().getChildren().indexOf(after);
    if (afterIndex == -1) {
        newIndex = getHost().getChildren().size() - 1;
        displacement = newIndex - childIndex;
    } else {
        newIndex = afterIndex;
        displacement = afterIndex - childIndex;
        if (childIndex <= afterIndex) {
            newIndex--;
            displacement--;
        }
    }
    TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
    RepositionEObjectCommand command = new CompartmentRepositionEObjectCommand(child, editingDomain, "", (EList) ((View) child.getParent().getModel()).getElement().eGet(feature), ((View) child.getModel()).getElement(), displacement, newIndex);
    eraseLayoutTargetFeedback(null);
    return new ICommandProxy(command);
}
Also used : IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) ICommandProxy(org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) CompartmentRepositionEObjectCommand(org.yakindu.base.gmf.runtime.commands.CompartmentRepositionEObjectCommand) RepositionEObjectCommand(org.eclipse.gmf.runtime.emf.commands.core.commands.RepositionEObjectCommand) CompartmentRepositionEObjectCommand(org.yakindu.base.gmf.runtime.commands.CompartmentRepositionEObjectCommand)

Aggregations

TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)1 ICommandProxy (org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy)1 IGraphicalEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart)1 RepositionEObjectCommand (org.eclipse.gmf.runtime.emf.commands.core.commands.RepositionEObjectCommand)1 CompartmentRepositionEObjectCommand (org.yakindu.base.gmf.runtime.commands.CompartmentRepositionEObjectCommand)1