Search in sources :

Example 6 with IDiagramModelContainer

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

the class DiagramModelUtils method shouldBeHiddenConnection.

/**
 * @param connection The connection to check
 * @return true if a connection should be hidden when its source (parent) element contains its target (child) element
 */
public static boolean shouldBeHiddenConnection(IDiagramModelArchimateConnection connection) {
    if (!ConnectionPreferences.useNestedConnections()) {
        return false;
    }
    // Only if the connection's source and target are both ArchiMate concepts
    if (!(connection.getSource() instanceof IDiagramModelArchimateComponent) && !(connection.getTarget() instanceof IDiagramModelArchimateComponent)) {
        return false;
    }
    IDiagramModelArchimateComponent source = (IDiagramModelArchimateComponent) connection.getSource();
    IDiagramModelArchimateComponent target = (IDiagramModelArchimateComponent) connection.getTarget();
    // If the connection's source element contains the target element, or the connection's target element contains the source element
    if (source instanceof IDiagramModelArchimateObject && target instanceof IDiagramModelArchimateObject) {
        if (((IDiagramModelContainer) source).getChildren().contains((IDiagramModelArchimateObject) target) || ((IDiagramModelContainer) target).getChildren().contains((IDiagramModelArchimateObject) source)) {
            // And it's a relationship type we have chosen to hide
            for (EClass eClass : ConnectionPreferences.getRelationsClassesForHiding()) {
                if (connection.getArchimateRelationship().eClass() == eClass) {
                    return true;
                }
            }
        }
    }
    // If connection's source is an element and target is a connection
    if (source instanceof IDiagramModelArchimateObject && target instanceof IDiagramModelArchimateConnection) {
        IDiagramModelArchimateObject parent = (IDiagramModelArchimateObject) source;
        IConnectable connectionSource = ((IDiagramModelArchimateConnection) target).getSource();
        IConnectable connectionTarget = ((IDiagramModelArchimateConnection) target).getTarget();
        if (parent.getChildren().contains(connectionSource) && parent.getChildren().contains(connectionTarget)) {
            // And it's a relationship type we have chosen to hide
            for (EClass eClass : ConnectionPreferences.getRelationsClassesForHiding()) {
                if (connection.getArchimateRelationship().eClass() == eClass) {
                    return true;
                }
            }
        }
    }
    // TODO: Not sure if this directionality should be allowed
    if (target instanceof IDiagramModelArchimateObject && source instanceof IDiagramModelArchimateConnection) {
        IDiagramModelArchimateObject parent = (IDiagramModelArchimateObject) target;
        IConnectable connectionSource = ((IDiagramModelArchimateConnection) source).getSource();
        IConnectable connectionTarget = ((IDiagramModelArchimateConnection) source).getTarget();
        if (parent.getChildren().contains(connectionSource) && parent.getChildren().contains(connectionTarget)) {
            // And it's a relationship type we have chosen to hide
            for (EClass eClass : ConnectionPreferences.getRelationsClassesForHiding()) {
                if (connection.getArchimateRelationship().eClass() == eClass) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IConnectable(com.archimatetool.model.IConnectable) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer)

Example 7 with IDiagramModelContainer

use of com.archimatetool.model.IDiagramModelContainer 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 8 with IDiagramModelContainer

use of com.archimatetool.model.IDiagramModelContainer 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 9 with IDiagramModelContainer

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

the class SendBackwardAction method createCommand.

private Command createCommand(List<?> selection) {
    GraphicalViewer viewer = getWorkbenchPart().getAdapter(GraphicalViewer.class);
    CompoundCommand result = new CompoundCommand(TEXT);
    for (Object object : selection) {
        if (object instanceof GraphicalEditPart) {
            GraphicalEditPart editPart = (GraphicalEditPart) object;
            Object model = editPart.getModel();
            // This can happen if we do things wrong
            if (viewer != editPart.getViewer()) {
                // $NON-NLS-1$
                System.err.println("Wrong selection for Viewer in " + getClass());
            }
            // Locked
            if (model instanceof ILockable && ((ILockable) model).isLocked()) {
                continue;
            }
            if (model instanceof IDiagramModelObject) {
                IDiagramModelObject diagramObject = (IDiagramModelObject) model;
                IDiagramModelContainer parent = (IDiagramModelContainer) diagramObject.eContainer();
                /*
                     * Parent can be null when objects are selected (with marquee tool) and transferred from one container
                     * to another and the Diagram Editor updates the enablement state of Actions.
                     */
                if (parent == null) {
                    continue;
                }
                int originalPos = parent.getChildren().indexOf(diagramObject);
                if (originalPos > 0) {
                    result.add(new SendBackwardCommand(parent, originalPos));
                }
            }
        }
    }
    return result.unwrap();
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) ILockable(com.archimatetool.model.ILockable)

Example 10 with IDiagramModelContainer

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

the class HTMLReportExporter method addNewBounds.

/**
 * Add new bounds for each diagram object in relation to its parent offset x,y
 */
private void addNewBounds(IDiagramModelObject dmo, int offsetX, int offsetY) {
    // Add new bounds caled to device zoom
    BoundsWithAbsolutePosition newBounds = new BoundsWithAbsolutePosition(dmo.getBounds(), ImageFactory.getDeviceZoom() / 100);
    // Add offset
    newBounds.setOffset(offsetX, offsetY);
    childBoundsMap.put(dmo.getId(), newBounds);
    // Children
    if (dmo instanceof IDiagramModelArchimateObject || dmo instanceof IDiagramModelGroup) {
        for (IDiagramModelObject child : ((IDiagramModelContainer) dmo).getChildren()) {
            addNewBounds(child, newBounds.getX1(), newBounds.getY1());
        }
    }
}
Also used : IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelGroup(com.archimatetool.model.IDiagramModelGroup) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer)

Aggregations

IDiagramModelContainer (com.archimatetool.model.IDiagramModelContainer)15 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)13 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)6 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)4 IArchimateElement (com.archimatetool.model.IArchimateElement)3 ArrayList (java.util.ArrayList)3 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)3 IBounds (com.archimatetool.model.IBounds)2 IDiagramModel (com.archimatetool.model.IDiagramModel)2 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)2 ILockable (com.archimatetool.model.ILockable)2 EObject (org.eclipse.emf.ecore.EObject)2 GraphicalViewer (org.eclipse.gef.GraphicalViewer)2 CreateDiagramArchimateConnectionWithDialogCommand (com.archimatetool.editor.diagram.commands.CreateDiagramArchimateConnectionWithDialogCommand)1 AbstractBaseEditPart (com.archimatetool.editor.diagram.editparts.AbstractBaseEditPart)1 GroupEditPart (com.archimatetool.editor.diagram.editparts.diagram.GroupEditPart)1 IContainerFigure (com.archimatetool.editor.diagram.figures.IContainerFigure)1 IConnectable (com.archimatetool.model.IConnectable)1 IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)1 IDiagramModelComponent (com.archimatetool.model.IDiagramModelComponent)1