Search in sources :

Example 26 with IDiagramModelObject

use of com.archimatetool.model.IDiagramModelObject in project archi by archimatetool.

the class CopySnapshot method getMinimumPoint.

// Find leftmost and topmost origin of top level objects
private Point getMinimumPoint(Set<IConnectable> selectedObjects) {
    // flag values
    int xOrigin = 99999, yOrigin = 99999;
    for (IConnectable object : selectedObjects) {
        if (object instanceof IDiagramModelObject) {
            IDiagramModelObject dmo = (IDiagramModelObject) object;
            Point pt = new Point(dmo.getBounds().getX(), dmo.getBounds().getY());
            translateToAbsolute(dmo, pt);
            // If this object has a parent that is also selected, ignore it
            if (dmo.eContainer() instanceof IDiagramModelObject && selectedObjects.contains(dmo.eContainer())) {
                continue;
            }
            if (pt.x < xOrigin) {
                xOrigin = pt.x;
            }
            if (pt.y < yOrigin) {
                yOrigin = pt.y;
            }
        }
    }
    return (xOrigin == 99999 || yOrigin == 99999) ? null : new Point(xOrigin, yOrigin);
}
Also used : IConnectable(com.archimatetool.model.IConnectable) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point)

Example 27 with IDiagramModelObject

use of com.archimatetool.model.IDiagramModelObject in project archi by archimatetool.

the class CopySnapshot method createPasteObject.

private IDiagramModelObject createPasteObject(IDiagramModelContainer container, IDiagramModelObject snapshotObject) {
    // Don't paste invalid objects
    if (!isValidPasteComponent(fTargetDiagramModel, snapshotObject)) {
        return null;
    }
    IDiagramModelObject pasteObject = (IDiagramModelObject) snapshotObject.getCopy();
    createID(pasteObject);
    // Offset top level objects if container is diagram
    if (container instanceof IDiagramModel) {
        IDiagramModelObject originalObject = (IDiagramModelObject) fOriginalToSnapshotComponentsMapping.getKey(snapshotObject);
        IBounds bounds = originalObject.getBounds().getCopy();
        Point pt = new Point(bounds.getX(), bounds.getY());
        translateToAbsolute(originalObject, pt);
        bounds.setX(pt.x + fXOffSet);
        bounds.setY(pt.y + fYOffSet);
        pasteObject.setBounds(bounds);
    }
    // If Archimate object
    if (pasteObject instanceof IDiagramModelArchimateObject) {
        IDiagramModelArchimateObject dmo = (IDiagramModelArchimateObject) pasteObject;
        // Re-use original ArchiMate components
        if (!fDoCreateNewArchimateComponents) {
            IDiagramModelArchimateObject originalDiagramObject = (IDiagramModelArchimateObject) fOriginalToSnapshotComponentsMapping.getKey(snapshotObject);
            IArchimateElement element = originalDiagramObject.getArchimateElement();
            dmo.setArchimateElement(element);
        }
        // Provide new names if required
        if (fDoCreateNewArchimateComponents && isSourceAndTargetArchiMateModelSame()) {
            String name = dmo.getArchimateElement().getName();
            // $NON-NLS-1$
            dmo.getArchimateElement().setName(name + " " + Messages.CopySnapshot_1);
        }
    }
    // Add to Mapping
    fSnapshotToNewComponentMapping.put(snapshotObject, pasteObject);
    // Object is Container, so recurse
    if (snapshotObject instanceof IDiagramModelContainer) {
        for (IDiagramModelObject child : ((IDiagramModelContainer) snapshotObject).getChildren()) {
            IDiagramModelObject dmo = createPasteObject((IDiagramModelContainer) pasteObject, child);
            if (dmo != null) {
                ((IDiagramModelContainer) pasteObject).getChildren().add(dmo);
            }
        }
    }
    return pasteObject;
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) IBounds(com.archimatetool.model.IBounds) IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) Point(org.eclipse.draw2d.geometry.Point) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer)

Example 28 with IDiagramModelObject

use of com.archimatetool.model.IDiagramModelObject in project archi by archimatetool.

the class CopySnapshot method getTopLevelObjectsToCopy.

/*
     * Create a list of topmost objects to copy.
     * This will eliminate duplicate selected children and give us only the top level objects to copy.
     */
private List<IDiagramModelObject> getTopLevelObjectsToCopy(List<IDiagramModelComponent> selected) {
    List<IDiagramModelObject> objects = new ArrayList<IDiagramModelObject>();
    for (IDiagramModelComponent component : selected) {
        if (component instanceof IDiagramModelObject) {
            if (!hasAncestorSelected((IDiagramModelObject) component, selected)) {
                // if an ancestor is selected don't add that
                objects.add((IDiagramModelObject) component);
            }
        }
    }
    /*
         * Restore the relative Z-Order in this new list by original Z-order in original model
         * If each has the same container parent
         */
    Collections.sort(objects, new Comparator<Object>() {

        public int compare(Object o1, Object o2) {
            if (o1 instanceof IDiagramModelObject && o2 instanceof IDiagramModelObject) {
                IDiagramModelContainer parent1 = (IDiagramModelContainer) ((IDiagramModelObject) o1).eContainer();
                IDiagramModelContainer parent2 = (IDiagramModelContainer) ((IDiagramModelObject) o2).eContainer();
                if (parent1 == parent2) {
                    int index1 = parent1.getChildren().indexOf(o1);
                    int index2 = parent2.getChildren().indexOf(o2);
                    return index1 - index2;
                }
            }
            return 0;
        }
    });
    return objects;
}
Also used : IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) ArrayList(java.util.ArrayList) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) EObject(org.eclipse.emf.ecore.EObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer)

Example 29 with IDiagramModelObject

use of com.archimatetool.model.IDiagramModelObject in project archi by archimatetool.

the class CutAction method run.

@Override
public void run() {
    // Copy and then Delete Selected objects
    super.run();
    BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {

        public void run() {
            CompoundCommand result = new CompoundCommand(Messages.CutAction_1);
            for (Object object : getSelectedObjects()) {
                if (object instanceof EditPart) {
                    Object model = ((EditPart) object).getModel();
                    if (model instanceof IDiagramModelObject) {
                        Command cmd = DiagramCommandFactory.createDeleteDiagramObjectCommand((IDiagramModelObject) model);
                        result.add(cmd);
                    }
                }
            }
            // Don't use unwrap because we want the "Cut" label
            execute(result);
        }
    });
}
Also used : Command(org.eclipse.gef.commands.Command) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) EditPart(org.eclipse.gef.EditPart) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 30 with IDiagramModelObject

use of com.archimatetool.model.IDiagramModelObject in project archi by archimatetool.

the class DefaultEditPartSizeAction method createDefaultSizeCommand.

private Command createDefaultSizeCommand(List<?> objects) {
    CompoundCommand command = new CompoundCommand();
    for (Object object : objects) {
        if (object instanceof GraphicalEditPart) {
            GraphicalEditPart part = (GraphicalEditPart) object;
            if (part.getModel() instanceof IDiagramModelObject) {
                IDiagramModelObject model = (IDiagramModelObject) part.getModel();
                if (model instanceof ILockable && ((ILockable) model).isLocked()) {
                    continue;
                }
                IFigure figure = part.getFigure();
                if (figure instanceof IDiagramModelObjectFigure) {
                    Dimension defaultSize = ((IDiagramModelObjectFigure) figure).getDefaultSize();
                    IBounds bounds = model.getBounds().getCopy();
                    if (bounds.getWidth() != defaultSize.width || bounds.getHeight() != defaultSize.height) {
                        bounds.setWidth(defaultSize.width);
                        bounds.setHeight(defaultSize.height);
                        Command cmd = new SetConstraintObjectCommand(model, bounds);
                        command.add(cmd);
                    }
                }
            }
        }
    }
    return command.unwrap();
}
Also used : SetConstraintObjectCommand(com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand) SetConstraintObjectCommand(com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) IBounds(com.archimatetool.model.IBounds) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelObjectFigure(com.archimatetool.editor.diagram.figures.IDiagramModelObjectFigure) Dimension(org.eclipse.draw2d.geometry.Dimension) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) ILockable(com.archimatetool.model.ILockable) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)51 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)12 IDiagramModelContainer (com.archimatetool.model.IDiagramModelContainer)12 IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)10 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)10 Test (org.junit.Test)10 IArchimateElement (com.archimatetool.model.IArchimateElement)9 Dimension (org.eclipse.draw2d.geometry.Dimension)9 IDiagramModel (com.archimatetool.model.IDiagramModel)8 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)7 IBounds (com.archimatetool.model.IBounds)6 Command (org.eclipse.gef.commands.Command)6 ILockable (com.archimatetool.model.ILockable)5 ArrayList (java.util.ArrayList)5 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)4 EObject (org.eclipse.emf.ecore.EObject)4 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)4 IArchimateModel (com.archimatetool.model.IArchimateModel)3 IDiagramModelGroup (com.archimatetool.model.IDiagramModelGroup)3 ILineObject (com.archimatetool.model.ILineObject)3