Search in sources :

Example 6 with IDiagramModelReference

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

the class SketchEditPartFactoryTests method testSketchDiagramModelReferenceEditPart.

@Test
public void testSketchDiagramModelReferenceEditPart() {
    IDiagramModelReference ref = IArchimateFactory.eINSTANCE.createDiagramModelReference();
    EditPart editPart = editPartFactory.createEditPart(null, ref);
    assertTrue(editPart instanceof SketchDiagramModelReferenceEditPart);
    assertEquals(ref, editPart.getModel());
}
Also used : IDiagramModelReference(com.archimatetool.model.IDiagramModelReference) DiagramConnectionEditPart(com.archimatetool.editor.diagram.editparts.DiagramConnectionEditPart) EditPart(org.eclipse.gef.EditPart) EmptyEditPart(com.archimatetool.editor.diagram.editparts.diagram.EmptyEditPart) Test(org.junit.Test)

Example 7 with IDiagramModelReference

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

the class CopySnapshotTests method testCanPasteToDiagram_DifferentModelDiagramReference.

@Test
public void testCanPasteToDiagram_DifferentModelDiagramReference() throws IOException {
    loadTestModel1();
    // Test can't paste IDiagramModelReference to another Archimate model
    // Source model
    IDiagramModelReference reference = IArchimateFactory.eINSTANCE.createDiagramModelReference();
    reference.setReferencedModel(model.getDiagramModels().get(0));
    sourceDiagramModel.getChildren().add(reference);
    // Target model
    IArchimateModel model2 = IArchimateFactory.eINSTANCE.createArchimateModel();
    IArchimateDiagramModel targetDiagramModel2 = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
    model2.getDefaultFolderForObject(targetDiagramModel2).getElements().add(targetDiagramModel2);
    List<IDiagramModelComponent> selected = new ArrayList<IDiagramModelComponent>();
    selected.add(reference);
    CopySnapshot snapshot = new CopySnapshot(selected);
    assertFalse(snapshot.canPasteToDiagram(targetDiagramModel2));
    // Should be OK if other objects added
    selected.addAll(sourceDiagramModel.getChildren());
    snapshot = new CopySnapshot(selected);
    assertTrue(snapshot.canPasteToDiagram(targetDiagramModel2));
}
Also used : IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) IDiagramModelReference(com.archimatetool.model.IDiagramModelReference) ArrayList(java.util.ArrayList) IArchimateModel(com.archimatetool.model.IArchimateModel) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel) Test(org.junit.Test)

Example 8 with IDiagramModelReference

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

the class DiagramModelReferenceUIProviderTests method testGetImageInstance.

@Override
public void testGetImageInstance() {
    IDiagramModelReference ref = (IDiagramModelReference) IArchimateFactory.eINSTANCE.create(expectedClass);
    ref.setReferencedModel(IArchimateFactory.eINSTANCE.createArchimateDiagramModel());
    provider.setInstance(ref);
    Image image = provider.getImage();
    assertNotNull(image);
    ref.setReferencedModel(IArchimateFactory.eINSTANCE.createSketchModel());
    image = provider.getImage();
    assertNotNull(image);
}
Also used : IDiagramModelReference(com.archimatetool.model.IDiagramModelReference) Image(org.eclipse.swt.graphics.Image)

Example 9 with IDiagramModelReference

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

the class ArchimateDiagramConnectionPolicy method isValidConnection.

/**
 * @param source
 * @param target
 * @param relationshipType
 * @return True if valid connection source/target for connection type
 */
static boolean isValidConnection(IConnectable source, IConnectable target, EClass relationshipType) {
    /*
         * Diagram Connection from/to notes/groups/diagram refs.
         * Allowed between notes, visual groups, diagram refs and ArchiMate components
         */
    if (relationshipType == IArchimatePackage.eINSTANCE.getDiagramModelConnection()) {
        // Not circular
        if (source == target) {
            return false;
        }
        // Notes
        if (source instanceof IDiagramModelNote || target instanceof IDiagramModelNote) {
            return true;
        }
        // Groups
        if (source instanceof IDiagramModelGroup || target instanceof IDiagramModelGroup) {
            return !(source instanceof IDiagramModelArchimateComponent) && !(target instanceof IDiagramModelArchimateComponent);
        }
        // Diagram Refs
        if (source instanceof IDiagramModelReference || target instanceof IDiagramModelReference) {
            return !(source instanceof IDiagramModelArchimateComponent) && !(target instanceof IDiagramModelArchimateComponent);
        }
        return false;
    }
    // Connection from Archimate concept to Archimate concept (but not from relation to relation)
    if ((source instanceof IDiagramModelArchimateComponent && target instanceof IDiagramModelArchimateComponent) && !(source instanceof IDiagramModelArchimateConnection && target instanceof IDiagramModelArchimateConnection)) {
        // Special case if relationshipType == null. Means that the Magic connector is being used
        if (relationshipType == null) {
            return true;
        }
        IArchimateConcept sourceConcept = ((IDiagramModelArchimateComponent) source).getArchimateConcept();
        IArchimateConcept targetConcept = ((IDiagramModelArchimateComponent) target).getArchimateConcept();
        return ArchimateModelUtils.isValidRelationship(sourceConcept, targetConcept, relationshipType);
    }
    return false;
}
Also used : IDiagramModelReference(com.archimatetool.model.IDiagramModelReference) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IDiagramModelGroup(com.archimatetool.model.IDiagramModelGroup) IDiagramModelNote(com.archimatetool.model.IDiagramModelNote)

Example 10 with IDiagramModelReference

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

the class SketchEditPartFactory method createEditPart.

public EditPart createEditPart(EditPart context, Object model) {
    if (model == null) {
        return null;
    }
    EditPart child = null;
    IObjectUIProvider provider = null;
    // Exceptions to the rule...
    if (model instanceof IDiagramModelReference) {
        child = new SketchDiagramModelReferenceEditPart();
    } else if (model instanceof IDiagramModelGroup) {
        child = new SketchGroupEditPart();
    } else if (model instanceof EObject) {
        provider = ObjectUIFactory.INSTANCE.getProviderForClass(((EObject) model).eClass());
        if (provider != null) {
            child = provider.createEditPart();
        }
    }
    /*
         * It's better to return an Empty Edit Part in case of a corrupt model.
         * Returning null is disastrous and means the Diagram View won't open.
         */
    if (child == null) {
        // $NON-NLS-1$
        Logger.logError("Could not create EditPart for: " + model);
        child = new EmptyEditPart();
    }
    // Set the Model in the Edit part
    child.setModel(model);
    return child;
}
Also used : IDiagramModelReference(com.archimatetool.model.IDiagramModelReference) EObject(org.eclipse.emf.ecore.EObject) EditPart(org.eclipse.gef.EditPart) EmptyEditPart(com.archimatetool.editor.diagram.editparts.diagram.EmptyEditPart) IDiagramModelGroup(com.archimatetool.model.IDiagramModelGroup) EmptyEditPart(com.archimatetool.editor.diagram.editparts.diagram.EmptyEditPart) IObjectUIProvider(com.archimatetool.editor.ui.factory.IObjectUIProvider)

Aggregations

IDiagramModelReference (com.archimatetool.model.IDiagramModelReference)17 IDiagramModel (com.archimatetool.model.IDiagramModel)7 Test (org.junit.Test)7 EObject (org.eclipse.emf.ecore.EObject)5 EmptyEditPart (com.archimatetool.editor.diagram.editparts.diagram.EmptyEditPart)4 EditPart (org.eclipse.gef.EditPart)4 IArchimateModel (com.archimatetool.model.IArchimateModel)3 IDiagramModelGroup (com.archimatetool.model.IDiagramModelGroup)3 DiagramConnectionEditPart (com.archimatetool.editor.diagram.editparts.DiagramConnectionEditPart)2 IObjectUIProvider (com.archimatetool.editor.ui.factory.IObjectUIProvider)2 IArchimateConcept (com.archimatetool.model.IArchimateConcept)2 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)2 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)2 IDiagramModelComponent (com.archimatetool.model.IDiagramModelComponent)2 IDiagramModelNote (com.archimatetool.model.IDiagramModelNote)2 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)2 ArrayList (java.util.ArrayList)2 ICanvasModel (com.archimatetool.canvas.model.ICanvasModel)1 DiagramImageEditPart (com.archimatetool.editor.diagram.editparts.diagram.DiagramImageEditPart)1 IArchiveManager (com.archimatetool.editor.model.IArchiveManager)1