use of com.archimatetool.model.IArchimateModel in project archi by archimatetool.
the class DiagramModelExtraTests method testDiagramModelArchimateConnection_eInverseAdd_Relationship_getReferencingDiagramObjects.
/**
* See {@link DiagramModelArchimateConnection#eInverseAdd(org.eclipse.emf.ecore.InternalEObject, int, Class, org.eclipse.emf.common.notify.NotificationChain)}
* See {@link DiagramModelArchimateConnection#eInverseRemove(org.eclipse.emf.ecore.InternalEObject, int, Class, org.eclipse.emf.common.notify.NotificationChain)}
*/
@Test
public void testDiagramModelArchimateConnection_eInverseAdd_Relationship_getReferencingDiagramObjects() {
IArchimateElement element1 = IArchimateFactory.eINSTANCE.createBusinessActor();
IArchimateElement element2 = IArchimateFactory.eINSTANCE.createBusinessActor();
IArchimateElement element3 = IArchimateFactory.eINSTANCE.createBusinessActor();
IArchimateElement element4 = IArchimateFactory.eINSTANCE.createBusinessActor();
IArchimateRelationship relation1 = IArchimateFactory.eINSTANCE.createAssociationRelationship();
IArchimateRelationship relation2 = IArchimateFactory.eINSTANCE.createAssociationRelationship();
IArchimateRelationship relation3 = IArchimateFactory.eINSTANCE.createAssociationRelationship();
relation1.setSource(element1);
relation1.setTarget(element2);
relation2.setSource(element2);
relation2.setTarget(element3);
relation3.setSource(element3);
relation3.setTarget(element4);
IDiagramModelArchimateObject dmo1 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
IDiagramModelArchimateObject dmo2 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
IDiagramModelArchimateObject dmo3 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
IDiagramModelArchimateObject dmo4 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
dmo1.setArchimateElement(element1);
dmo2.setArchimateElement(element2);
dmo3.setArchimateElement(element3);
dmo4.setArchimateElement(element4);
IDiagramModelArchimateConnection conn1 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
IDiagramModelArchimateConnection conn2 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
IDiagramModelArchimateConnection conn3 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
// conn3a shares a relationship with conn3
IDiagramModelArchimateConnection conn3a = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
conn1.setArchimateRelationship(relation1);
conn2.setArchimateRelationship(relation2);
conn3.setArchimateRelationship(relation3);
// same
conn3a.setArchimateRelationship(relation3);
// Set up model and diagram model
IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
model.setDefaults();
IDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
model.getDefaultFolderForObject(dm).getElements().add(dm);
// Add some parents
IDiagramModelGroup parent1 = IArchimateFactory.eINSTANCE.createDiagramModelGroup();
dm.getChildren().add(parent1);
IDiagramModelArchimateObject parent2 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
parent1.getChildren().add(parent2);
// Add the dmos
dm.getChildren().add(dmo1);
parent1.getChildren().add(dmo2);
parent2.getChildren().add(dmo3);
dm.getChildren().add(dmo4);
// Starts at sizes
assertEquals(1, conn1.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(1, conn2.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(2, conn3.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(2, conn3a.getArchimateRelationship().getReferencingDiagramConnections().size());
// Connect
conn1.connect(dmo1, dmo2);
assertEquals(1, conn1.getArchimateRelationship().getReferencingDiagramConnections().size());
conn2.connect(dmo2, dmo3);
assertEquals(1, conn2.getArchimateRelationship().getReferencingDiagramConnections().size());
conn3.connect(dmo3, dmo4);
assertEquals(1, conn2.getArchimateRelationship().getReferencingDiagramConnections().size());
conn3a.connect(dmo3, dmo4);
assertEquals(2, conn3.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(2, conn3a.getArchimateRelationship().getReferencingDiagramConnections().size());
// Remove diagram model, should be the same
((IFolder) dm.eContainer()).getElements().remove(dm);
assertEquals(1, conn1.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(1, conn2.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(2, conn3.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(2, conn3a.getArchimateRelationship().getReferencingDiagramConnections().size());
// Add diagram model back again
model.getDefaultFolderForObject(dm).getElements().add(dm);
assertEquals(1, conn1.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(1, conn2.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(2, conn3.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(2, conn3a.getArchimateRelationship().getReferencingDiagramConnections().size());
// Disconnect
conn1.disconnect();
conn2.disconnect();
conn3.disconnect();
conn3a.disconnect();
assertEquals(0, conn1.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(0, conn2.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(0, conn3.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(0, conn3a.getArchimateRelationship().getReferencingDiagramConnections().size());
}
use of com.archimatetool.model.IArchimateModel in project archi by archimatetool.
the class NewCanvasFromTemplateWizard method createNewCanvasFromTemplate.
private void createNewCanvasFromTemplate(File file) throws IncompatibleModelException, IOException {
// Ascertain if this is a zip file
boolean isArchiveFormat = IArchiveManager.FACTORY.isArchiveFile(file);
Resource resource = ArchimateResourceFactory.createNewResource(isArchiveFormat ? IArchiveManager.FACTORY.createArchiveModelURI(file) : URI.createFileURI(file.getAbsolutePath()));
// Check model compatibility
ModelCompatibility modelCompatibility = new ModelCompatibility(resource);
// Wrap in try/catch to load as much as possible
try {
resource.load(null);
} catch (IOException ex) {
// Error occured loading model. Was it a disaster?
try {
modelCompatibility.checkErrors();
}// Incompatible
catch (IncompatibleModelException ex1) {
fErrorMessage = NLS.bind(Messages.NewCanvasFromTemplateWizard_4, file) + "\n" + // $NON-NLS-1$
ex1.getMessage();
throw ex1;
}
}
// And then fix any backward compatibility issues
try {
modelCompatibility.fixCompatibility();
} catch (CompatibilityHandlerException ex) {
}
// Pull out the Canvas model
IArchimateModel templateModel = (IArchimateModel) resource.getContents().get(0);
IFolder folderViews = templateModel.getFolder(FolderType.DIAGRAMS);
ICanvasModel canvasModel = (ICanvasModel) folderViews.getElements().get(0);
// Create New UUIDs for elements...
TemplateUtils.generateNewUUIDs(canvasModel);
// Load the images from the template model's file now
if (isArchiveFormat) {
IArchiveManager archiveManager = (IArchiveManager) fFolder.getAdapter(IArchiveManager.class);
archiveManager.loadImagesFromModelFile(file);
}
Command cmd = new NewDiagramCommand(fFolder, canvasModel, Messages.NewCanvasFromTemplateWizard_5);
CommandStack commandStack = (CommandStack) fFolder.getAdapter(CommandStack.class);
commandStack.execute(cmd);
}
use of com.archimatetool.model.IArchimateModel in project archi by archimatetool.
the class SaveCanvasAsTemplateWizard method saveModelToTempFile.
private File saveModelToTempFile() throws IOException {
// $NON-NLS-1$
File tmpFile = File.createTempFile("architemplate", null);
tmpFile.deleteOnExit();
// Create a new container Archimate model
IArchimateModel tempModel = IArchimateFactory.eINSTANCE.createArchimateModel();
tempModel.setDefaults();
// Remove this after default folders have been added, as we'll generate our own IDs
tempModel.eAdapters().clear();
tempModel.setId(EcoreUtil.generateUUID());
tempModel.setFile(tmpFile);
tempModel.setVersion(ModelVersion.VERSION);
tempModel.setName(Messages.SaveCanvasAsTemplateWizard_4);
// Get the Canvas copy
ICanvasModel copyCanvas = EcoreUtil.copy(fCanvasModel);
// Remove any unsupported elements
for (Iterator<EObject> iter = copyCanvas.eAllContents(); iter.hasNext(); ) {
EObject eObject = iter.next();
if (eObject instanceof IDiagramModelReference) {
EcoreUtil.delete(eObject);
}
}
// Generate new IDs
TemplateUtils.generateNewUUIDs(copyCanvas);
// Add the canvas copy to a new Views folder
IFolder folder = tempModel.getDefaultFolderForObject(copyCanvas);
folder.getElements().add(copyCanvas);
// Use an Archive Manager to save it
IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(tempModel);
archiveManager.saveModel();
archiveManager.dispose();
return tmpFile;
}
use of com.archimatetool.model.IArchimateModel in project archi by archimatetool.
the class CreateEmptyModelProvider method createEmptyModel.
private IArchimateModel createEmptyModel() {
IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
model.setDefaults();
// Add an Archive Manager
IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(model);
model.setAdapter(IArchiveManager.class, archiveManager);
// Add a Command Stack
CommandStack cmdStack = new CommandStack();
model.setAdapter(CommandStack.class, cmdStack);
logMessage(Messages.CreateEmptyModelProvider_7);
return model;
}
use of com.archimatetool.model.IArchimateModel in project archi by archimatetool.
the class LoadModelFromFileProvider method run.
public void run(CommandLine commandLine) throws Exception {
if (commandLine.hasOption(OPTION_LOAD_FILE_MODEL)) {
String filePath = commandLine.getOptionValue(OPTION_LOAD_FILE_MODEL);
File file = new File(filePath);
IArchimateModel model = loadModel(file);
if (model == null) {
throw new IOException(Messages.LoadModelFromFileProvider_3);
}
CommandLineState.setModel(model);
logMessage(NLS.bind(Messages.LoadModelFromFileProvider_4, model.getName()));
}
}
Aggregations