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());
}
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));
}
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);
}
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;
}
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;
}
Aggregations