Search in sources :

Example 11 with IDiagramModelConnection

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

the class ArchimateDiagramConnectionPolicy method getReconnectCommand.

/**
 * Create a ReconnectCommand
 */
protected Command getReconnectCommand(ReconnectRequest request, boolean isSourceCommand) {
    IDiagramModelConnection connection = (IDiagramModelConnection) request.getConnectionEditPart().getModel();
    // The re-connected object
    IConnectable newObject = (IConnectable) getHost().getModel();
    // Get the type of connection (plain) or relationship (if archimate connection) and check if it is valid
    EClass type = connection.eClass();
    if (connection instanceof IDiagramModelArchimateConnection) {
        type = ((IDiagramModelArchimateConnection) connection).getArchimateRelationship().eClass();
    }
    if (isSourceCommand) {
        if (!isValidConnection(newObject, connection.getTarget(), type)) {
            return null;
        }
    } else {
        if (!isValidConnection(connection.getSource(), newObject, type)) {
            return null;
        }
    }
    /*
         * Re-connect ArchiMate Connection to Archimate Component
         * In this case we have to check for matching occurences on all diagrams
         */
    if (connection instanceof IDiagramModelArchimateConnection && newObject instanceof IDiagramModelArchimateComponent) {
        IArchimateRelationship relationship = ((IDiagramModelArchimateConnection) connection).getArchimateRelationship();
        IArchimateConcept newConcept = ((IDiagramModelArchimateComponent) newObject).getArchimateConcept();
        // Compound Command
        CompoundCommand result = new CompoundCommand();
        // Check for matching connections in this and other diagrams
        for (IDiagramModel diagramModel : newConcept.getArchimateModel().getDiagramModels()) {
            for (IDiagramModelArchimateConnection matchingConnection : DiagramModelUtils.findDiagramModelConnectionsForRelation(diagramModel, relationship)) {
                IDiagramModelArchimateComponent matchingComponent = null;
                // Same Diagram so use the new target
                if (newObject.getDiagramModel() == diagramModel) {
                    matchingComponent = (IDiagramModelArchimateComponent) newObject;
                } else // Different Diagram so find a match
                {
                    List<IDiagramModelArchimateComponent> list = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(diagramModel, newConcept);
                    if (!list.isEmpty()) {
                        matchingComponent = list.get(0);
                    }
                }
                // Does the new object exist on the diagram? Yes, reconnect
                if (matchingComponent != null) {
                    ReconnectDiagramConnectionCommand cmd = new ReconnectDiagramConnectionCommand(matchingConnection);
                    if (isSourceCommand) {
                        cmd.setNewSource(matchingComponent);
                    } else {
                        cmd.setNewTarget(matchingComponent);
                    }
                    result.add(cmd);
                } else // No, so delete the matching connection
                {
                    result.add(DiagramCommandFactory.createDeleteDiagramConnectionCommand(matchingConnection));
                }
            }
        }
        return result.unwrap();
    } else // Re-connect other cases
    {
        ReconnectDiagramConnectionCommand cmd = new ReconnectDiagramConnectionCommand(connection);
        if (isSourceCommand) {
            cmd.setNewSource(newObject);
        } else {
            cmd.setNewTarget(newObject);
        }
        return cmd;
    }
}
Also used : IConnectable(com.archimatetool.model.IConnectable) EClass(org.eclipse.emf.ecore.EClass) ReconnectDiagramConnectionCommand(com.archimatetool.editor.diagram.commands.ReconnectDiagramConnectionCommand) IDiagramModel(com.archimatetool.model.IDiagramModel) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 12 with IDiagramModelConnection

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

the class BasicConnectionPolicy method getReconnectSourceCommand.

@Override
protected Command getReconnectSourceCommand(ReconnectRequest request) {
    ReconnectDiagramConnectionCommand cmd = null;
    IDiagramModelConnection connection = (IDiagramModelConnection) request.getConnectionEditPart().getModel();
    IDiagramModelObject newSource = (IDiagramModelObject) getHost().getModel();
    if (isValidConnectionSource(newSource, connection.eClass())) {
        cmd = new ReconnectDiagramConnectionCommand(connection);
        cmd.setNewSource(newSource);
    }
    return cmd;
}
Also used : ReconnectDiagramConnectionCommand(com.archimatetool.editor.diagram.commands.ReconnectDiagramConnectionCommand) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject)

Example 13 with IDiagramModelConnection

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

the class BasicConnectionPolicy method getReconnectTargetCommand.

@Override
protected Command getReconnectTargetCommand(ReconnectRequest request) {
    ReconnectDiagramConnectionCommand cmd = null;
    IDiagramModelConnection connection = (IDiagramModelConnection) request.getConnectionEditPart().getModel();
    IDiagramModelObject newTarget = (IDiagramModelObject) getHost().getModel();
    if (isValidConnectionTarget(newTarget, connection.eClass())) {
        cmd = new ReconnectDiagramConnectionCommand(connection);
        cmd.setNewTarget(newTarget);
    }
    return cmd;
}
Also used : ReconnectDiagramConnectionCommand(com.archimatetool.editor.diagram.commands.ReconnectDiagramConnectionCommand) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject)

Example 14 with IDiagramModelConnection

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

the class FormatPainterTool method createCommand.

protected CompoundCommand createCommand(PaintFormat pf, IDiagramModelComponent targetComponent) {
    CompoundCommand result = new CompoundCommand(Messages.FormatPainterTool_0);
    // IFontAttribute
    if (pf.getSourceComponent() instanceof IFontAttribute && targetComponent instanceof IFontAttribute) {
        IFontAttribute source = (IFontAttribute) pf.getSourceComponent();
        IFontAttribute target = (IFontAttribute) targetComponent;
        Command cmd = new FontStyleCommand(target, source.getFont());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        cmd = new FontColorCommand(target, source.getFontColor());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // ILineObject
    if (pf.getSourceComponent() instanceof ILineObject && targetComponent instanceof ILineObject) {
        ILineObject source = (ILineObject) pf.getSourceComponent();
        ILineObject target = (ILineObject) targetComponent;
        Command cmd = new LineColorCommand(target, source.getLineColor());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        cmd = new LineWidthCommand(target, source.getLineWidth());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // IBorderObject
    if (pf.getSourceComponent() instanceof IBorderObject && targetComponent instanceof IBorderObject) {
        IBorderObject source = (IBorderObject) pf.getSourceComponent();
        IBorderObject target = (IBorderObject) targetComponent;
        Command cmd = new BorderColorCommand(target, source.getBorderColor());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // ITextPosition
    if (pf.getSourceComponent() instanceof ITextPosition && targetComponent instanceof ITextPosition) {
        ITextPosition source = (ITextPosition) pf.getSourceComponent();
        ITextPosition target = (ITextPosition) targetComponent;
        Command cmd = new TextPositionCommand(target, source.getTextPosition());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // ITextAlignment
    if (pf.getSourceComponent() instanceof ITextAlignment && targetComponent instanceof ITextAlignment) {
        ITextAlignment source = (ITextAlignment) pf.getSourceComponent();
        ITextAlignment target = (ITextAlignment) targetComponent;
        Command cmd = new TextAlignmentCommand(target, source.getTextAlignment());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // IDiagramModelObject
    if (pf.getSourceComponent() instanceof IDiagramModelObject && targetComponent instanceof IDiagramModelObject) {
        IDiagramModelObject source = (IDiagramModelObject) pf.getSourceComponent();
        IDiagramModelObject target = (IDiagramModelObject) targetComponent;
        // Source fill colour is null which is "default"
        String fillColorString = source.getFillColor();
        if (fillColorString == null) {
            fillColorString = ColorFactory.convertColorToString(ColorFactory.getDefaultFillColor(source));
        }
        Command cmd = new FillColorCommand(target, fillColorString);
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        // Alpha opacity
        cmd = new DiagramModelObjectAlphaCommand(target, source.getAlpha());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // IDiagramModelConnection
    if (pf.getSourceComponent() instanceof IDiagramModelConnection && targetComponent instanceof IDiagramModelConnection) {
        IDiagramModelConnection source = (IDiagramModelConnection) pf.getSourceComponent();
        IDiagramModelConnection target = (IDiagramModelConnection) targetComponent;
        // Connection text position
        Command cmd = new ConnectionTextPositionCommand(target, source.getTextPosition());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    return result;
}
Also used : TextAlignmentCommand(com.archimatetool.editor.diagram.commands.TextAlignmentCommand) LineColorCommand(com.archimatetool.editor.diagram.commands.LineColorCommand) ITextPosition(com.archimatetool.model.ITextPosition) FillColorCommand(com.archimatetool.editor.diagram.commands.FillColorCommand) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) DiagramModelObjectAlphaCommand(com.archimatetool.editor.diagram.commands.DiagramModelObjectAlphaCommand) ILineObject(com.archimatetool.model.ILineObject) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) BorderColorCommand(com.archimatetool.editor.diagram.commands.BorderColorCommand) IBorderObject(com.archimatetool.model.IBorderObject) FontColorCommand(com.archimatetool.editor.diagram.commands.FontColorCommand) ITextAlignment(com.archimatetool.model.ITextAlignment) FontStyleCommand(com.archimatetool.editor.diagram.commands.FontStyleCommand) DiagramModelObjectAlphaCommand(com.archimatetool.editor.diagram.commands.DiagramModelObjectAlphaCommand) ConnectionTextPositionCommand(com.archimatetool.editor.diagram.commands.ConnectionTextPositionCommand) BorderColorCommand(com.archimatetool.editor.diagram.commands.BorderColorCommand) TextPositionCommand(com.archimatetool.editor.diagram.commands.TextPositionCommand) LineWidthCommand(com.archimatetool.editor.diagram.commands.LineWidthCommand) FontColorCommand(com.archimatetool.editor.diagram.commands.FontColorCommand) TextAlignmentCommand(com.archimatetool.editor.diagram.commands.TextAlignmentCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) FillColorCommand(com.archimatetool.editor.diagram.commands.FillColorCommand) LineColorCommand(com.archimatetool.editor.diagram.commands.LineColorCommand) Command(org.eclipse.gef.commands.Command) IFontAttribute(com.archimatetool.model.IFontAttribute) ConnectionTextPositionCommand(com.archimatetool.editor.diagram.commands.ConnectionTextPositionCommand) TextPositionCommand(com.archimatetool.editor.diagram.commands.TextPositionCommand) LineWidthCommand(com.archimatetool.editor.diagram.commands.LineWidthCommand) FontStyleCommand(com.archimatetool.editor.diagram.commands.FontStyleCommand) ConnectionTextPositionCommand(com.archimatetool.editor.diagram.commands.ConnectionTextPositionCommand)

Example 15 with IDiagramModelConnection

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

the class CanvasModelEditPartFactoryTests method testCanvasConnectionEditPart.

@Test
public void testCanvasConnectionEditPart() {
    IDiagramModelConnection conn = ICanvasFactory.eINSTANCE.createCanvasModelConnection();
    EditPart editPart = editPartFactory.createEditPart(null, conn);
    assertTrue(editPart instanceof DiagramConnectionEditPart);
    assertEquals(conn, editPart.getModel());
}
Also used : IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) DiagramImageEditPart(com.archimatetool.editor.diagram.editparts.diagram.DiagramImageEditPart) DiagramConnectionEditPart(com.archimatetool.editor.diagram.editparts.DiagramConnectionEditPart) EditPart(org.eclipse.gef.EditPart) EmptyEditPart(com.archimatetool.editor.diagram.editparts.diagram.EmptyEditPart) DiagramConnectionEditPart(com.archimatetool.editor.diagram.editparts.DiagramConnectionEditPart) Test(org.junit.Test)

Aggregations

IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)34 Test (org.junit.Test)15 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)10 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)7 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)6 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)6 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)5 Command (org.eclipse.gef.commands.Command)5 IArchimateElement (com.archimatetool.model.IArchimateElement)4 IConnectable (com.archimatetool.model.IConnectable)4 IDiagramModel (com.archimatetool.model.IDiagramModel)4 EditPart (org.eclipse.gef.EditPart)4 ReconnectDiagramConnectionCommand (com.archimatetool.editor.diagram.commands.ReconnectDiagramConnectionCommand)3 EmptyEditPart (com.archimatetool.editor.diagram.editparts.diagram.EmptyEditPart)3 ArrayList (java.util.ArrayList)3 ConnectionTextPositionCommand (com.archimatetool.editor.diagram.commands.ConnectionTextPositionCommand)2 LineWidthCommand (com.archimatetool.editor.diagram.commands.LineWidthCommand)2 DiagramConnectionEditPart (com.archimatetool.editor.diagram.editparts.DiagramConnectionEditPart)2 DeleteArchimateElementCommand (com.archimatetool.editor.model.commands.DeleteArchimateElementCommand)2 DeleteArchimateRelationshipCommand (com.archimatetool.editor.model.commands.DeleteArchimateRelationshipCommand)2