Search in sources :

Example 36 with IDiagramModelArchimateConnection

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

the class DeleteNestedConnectionsCommand method createDeleteCommands.

/**
 * Child Objects that have connections
 */
void createDeleteCommands() {
    for (IDiagramModelArchimateObject child : fChildObjects) {
        for (IDiagramModelConnection connection : child.getTargetConnections()) {
            if (connection instanceof IDiagramModelArchimateConnection && DiagramModelUtils.shouldBeHiddenConnection((IDiagramModelArchimateConnection) connection)) {
                for (IDiagramModelConnection subconnection : connection.getTargetConnections()) {
                    Command cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand(subconnection);
                    add(cmd);
                }
                for (IDiagramModelConnection subconnection : connection.getSourceConnections()) {
                    Command cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand(subconnection);
                    add(cmd);
                }
            }
        }
    }
}
Also used : Command(org.eclipse.gef.commands.Command) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject)

Example 37 with IDiagramModelArchimateConnection

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

the class ArchimateDiagramConnectionPolicy method createArchimateReconnectCommand.

private Command createArchimateReconnectCommand(IDiagramModelArchimateConnection connection, IDiagramModelArchimateComponent dmc, boolean isSourceCommand) {
    IArchimateRelationship relationship = connection.getArchimateRelationship();
    IArchimateConcept newConcept = dmc.getArchimateConcept();
    CompoundCommand cmd = new CompoundCommand() {

        boolean affectsOtherViews = false;

        @Override
        public void execute() {
            // Lazily create commands
            createCommands();
            super.execute();
            // Show message that it affected other Viewss
            if (affectsOtherViews && ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.SHOW_WARNING_ON_RECONNECT)) {
                boolean answer = MessageDialog.openQuestion(Display.getDefault().getActiveShell(), Messages.ArchimateDiagramConnectionPolicy_0, Messages.ArchimateDiagramConnectionPolicy_1 + // $NON-NLS-1$
                "\n\n" + Messages.ArchimateDiagramConnectionPolicy_2);
                if (!answer) {
                    // We have to call undo() later in the thread as the Command is not yet on the CommandStack
                    Display.getDefault().asyncExec(() -> ((CommandStack) connection.getAdapter(CommandStack.class)).undo());
                }
            }
        }

        @Override
        public boolean canExecute() {
            // Can't reconnect to the same dmc
            return isSourceCommand ? connection.getSource() != dmc : connection.getTarget() != dmc;
        }

        // Add commands for all instances of diagram connections
        private void createCommands() {
            for (IDiagramModelArchimateConnection matchingConnection : relationship.getReferencingDiagramConnections()) {
                // The same diagram
                if (matchingConnection.getDiagramModel() == connection.getDiagramModel()) {
                    // If we are reconnecting to a dmc with a different concept then reconnect all instances on this diagram
                    if (isNewConnection(matchingConnection, dmc, isSourceCommand)) {
                        add(createReconnectCommand(matchingConnection, dmc, isSourceCommand));
                    } else // Else if we are reconnecting to a dmc with the same concept then reconnect only this one instance of the connection
                    if (connection == matchingConnection) {
                        add(createReconnectCommand(matchingConnection, dmc, isSourceCommand));
                    }
                } else // A different diagram
                {
                    // Does the new target concept exist on the diagram?
                    List<IDiagramModelArchimateComponent> list = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(matchingConnection.getDiagramModel(), newConcept);
                    // Yes, so reconnect to it *if* it is different than the existing concept
                    if (!list.isEmpty()) {
                        // Get the first instance of the new component
                        IDiagramModelArchimateComponent newComponent = list.get(0);
                        // If the instance's concept is different than the original concept then reconnect
                        if (isNewConnection(matchingConnection, newComponent, isSourceCommand)) {
                            Command cmd = createReconnectCommand(matchingConnection, newComponent, isSourceCommand);
                            if (cmd.canExecute()) {
                                affectsOtherViews = true;
                                add(cmd);
                            }
                        }
                    } else // No, so delete the matching connection
                    {
                        add(DiagramCommandFactory.createDeleteDiagramConnectionCommand(matchingConnection));
                        affectsOtherViews = true;
                    }
                }
            }
        }
    };
    return cmd;
}
Also used : CreateDiagramConnectionCommand(com.archimatetool.editor.diagram.commands.CreateDiagramConnectionCommand) ReconnectDiagramConnectionCommand(com.archimatetool.editor.diagram.commands.ReconnectDiagramConnectionCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) CreateDiagramArchimateConnectionWithDialogCommand(com.archimatetool.editor.diagram.commands.CreateDiagramArchimateConnectionWithDialogCommand) Command(org.eclipse.gef.commands.Command) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 38 with IDiagramModelArchimateConnection

use of com.archimatetool.model.IDiagramModelArchimateConnection 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 39 with IDiagramModelArchimateConnection

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

the class GenerateViewCommand method createDiagramModel.

private IArchimateDiagramModel createDiagramModel() {
    // New Diagram
    IArchimateDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
    dm.setName(fViewName);
    dm.setViewpoint(fViewpoint.getID());
    fParentFolder = fSelectedElements.get(0).getArchimateModel().getDefaultFolderForObject(dm);
    fParentFolder.getElements().add(dm);
    int x = 20;
    int y = 20;
    getElementsToAdd();
    for (IArchimateElement element : fSelectedElements) {
        createDiagramNode(element, dm, x, y);
        y += 100;
    }
    x = 170;
    y = 20;
    for (IArchimateElement element : fAddedElements) {
        if (!fSelectedElements.contains(element)) {
            createDiagramNode(element, dm, x, y);
            y += 80;
            if (y > 700) {
                y = 20;
                x += 150;
            }
        }
    }
    // Add connections between elements first
    for (IDiagramModelObject dmoSource : dm.getChildren()) {
        IArchimateElement elementSource = ((IDiagramModelArchimateObject) dmoSource).getArchimateElement();
        for (IArchimateRelationship relation : List.copyOf(elementSource.getSourceRelationships())) {
            // work on a copy of the list
            for (IDiagramModelObject dmoTarget : dm.getChildren()) {
                IArchimateElement elementTarget = ((IDiagramModelArchimateObject) dmoTarget).getArchimateElement();
                // Don't add connections that are not connected to the main elements if option is set
                if (!fAddAllConnections && !(fSelectedElements.contains(elementSource)) && !(fSelectedElements.contains(elementTarget))) {
                    continue;
                }
                if (relation.getTarget() == elementTarget) {
                    // Create connection
                    IDiagramModelArchimateConnection newConnection = ArchimateDiagramModelFactory.createDiagramModelArchimateConnection(relation);
                    newConnection.connect(dmoSource, dmoTarget);
                }
            }
        }
    }
    // Add connections to connections
    for (Iterator<EObject> iter1 = dm.eAllContents(); iter1.hasNext(); ) {
        EObject eObject1 = iter1.next();
        if (eObject1 instanceof IDiagramModelArchimateConnection) {
            IDiagramModelArchimateConnection connection = (IDiagramModelArchimateConnection) eObject1;
            for (IDiagramModelObject dmo : dm.getChildren()) {
                IArchimateElement element = ((IDiagramModelArchimateObject) dmo).getArchimateElement();
                for (IArchimateRelationship relation : List.copyOf(connection.getArchimateRelationship().getSourceRelationships())) {
                    // work on a copy of the list
                    if (relation.getTarget() == element) {
                        IDiagramModelArchimateConnection newConnection = ArchimateDiagramModelFactory.createDiagramModelArchimateConnection(relation);
                        newConnection.connect(connection, dmo);
                    }
                }
                for (IArchimateRelationship relation : List.copyOf(connection.getArchimateRelationship().getTargetRelationships())) {
                    // work on a copy of the list
                    if (relation.getSource() == element) {
                        IDiagramModelArchimateConnection newConnection = ArchimateDiagramModelFactory.createDiagramModelArchimateConnection(relation);
                        newConnection.connect(dmo, connection);
                    }
                }
            }
        }
    }
    return dm;
}
Also used : IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) EObject(org.eclipse.emf.ecore.EObject) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IViewpoint(com.archimatetool.model.viewpoints.IViewpoint) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel)

Example 40 with IDiagramModelArchimateConnection

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

the class AbstractModelView method getElementsToUpdateFromNotification.

/**
 * @return All the tree element nodes that may need updating when a change occurs
 */
protected Set<Object> getElementsToUpdateFromNotification(Notification msg) {
    Set<Object> list = new HashSet<Object>();
    // If notifier is a folder ignore
    if (msg.getNotifier() instanceof IFolder) {
        return list;
    }
    int type = msg.getEventType();
    Object element = null;
    if (type == Notification.REMOVE) {
        element = msg.getOldValue();
    } else if (type == Notification.ADD) {
        element = msg.getNewValue();
    } else if (type == Notification.SET) {
        element = msg.getNotifier();
    }
    // If it's a diagram object or a diagram dig in and treat it separately
    if (element instanceof IDiagramModelContainer) {
        getDiagramElementsToUpdate(list, (IDiagramModelContainer) element);
        return list;
    }
    // If it's a diagram connection get the relationship
    if (element instanceof IDiagramModelArchimateConnection) {
        element = ((IDiagramModelArchimateConnection) element).getArchimateRelationship();
    }
    // Got either a folder, a relationship or an element
    if (element != null) {
        list.add(element);
        // If an element, also add any attached relationships
        if (element instanceof IArchimateElement) {
            getRelationshipsToUpdate(list, (IArchimateElement) element);
        }
    }
    return list;
}
Also used : IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) EObject(org.eclipse.emf.ecore.EObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer) HashSet(java.util.HashSet) IFolder(com.archimatetool.model.IFolder)

Aggregations

IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)59 Test (org.junit.Test)31 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)29 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)27 IArchimateElement (com.archimatetool.model.IArchimateElement)20 IDiagramModel (com.archimatetool.model.IDiagramModel)10 IArchimateConcept (com.archimatetool.model.IArchimateConcept)9 IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)9 IArchimateModel (com.archimatetool.model.IArchimateModel)8 IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)8 ArrayList (java.util.ArrayList)8 EObject (org.eclipse.emf.ecore.EObject)8 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)7 IAssignmentRelationship (com.archimatetool.model.IAssignmentRelationship)6 IConnectable (com.archimatetool.model.IConnectable)6 Command (org.eclipse.gef.commands.Command)6 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)6 ArchimateTestModel (com.archimatetool.testingtools.ArchimateTestModel)5 EClass (org.eclipse.emf.ecore.EClass)4 NoteEditPart (com.archimatetool.editor.diagram.editparts.diagram.NoteEditPart)3