use of com.archimatetool.model.IArchimateModel 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.IArchimateModel in project archi by archimatetool.
the class CreateEmptyModelProviderTests method runCreatesEmptyModel.
@Test
public void runCreatesEmptyModel() throws Exception {
CommandLineState.setModel(null);
CommandLine commandLine = mock(CommandLine.class);
when(commandLine.hasOption(CreateEmptyModelProvider.OPTION_CREATE_EMPTY_MODEL)).thenReturn(true);
provider.run(commandLine);
IArchimateModel model = CommandLineState.getModel();
assertNotNull(model);
assertNotNull(model.getAdapter(IArchiveManager.class));
assertNotNull(model.getAdapter(CommandStack.class));
}
use of com.archimatetool.model.IArchimateModel in project archi by archimatetool.
the class LoadModelFromFileProviderTests method runCreatesEmptyModel.
@Test
public void runCreatesEmptyModel() throws Exception {
CommandLineState.setModel(null);
CommandLine commandLine = mock(CommandLine.class);
when(commandLine.hasOption(LoadModelFromFileProvider.OPTION_LOAD_FILE_MODEL)).thenReturn(true);
String filePath = TestData.TEST_MODEL_FILE_ARCHISURANCE.getAbsolutePath();
when(commandLine.getOptionValue(LoadModelFromFileProvider.OPTION_LOAD_FILE_MODEL)).thenReturn(filePath);
provider.run(commandLine);
IArchimateModel model = CommandLineState.getModel();
assertNotNull(model);
assertNotNull(model.getAdapter(IArchiveManager.class));
assertNotNull(model.getAdapter(CommandStack.class));
assertEquals(TestData.TEST_MODEL_FILE_ARCHISURANCE, model.getFile());
}
use of com.archimatetool.model.IArchimateModel in project archi by archimatetool.
the class MyImporter method doImport.
@Override
public void doImport() throws IOException {
File file = askOpenFile();
if (file == null) {
return;
}
// Load in the file and get its information here.
// Assuming you load in the data in some way, perhaps with JDOM, or a SAX Parser ot text reader then you will
// have a representation of it in memory that you need to map to Archi elements.
// Here is some example raw data in String format. This is a very simple example so the data
// is not in the best format. There is no error checking either.
// Elements
String[] elements = { // Type, Name, ID
"BusinessActor", "Actor", "elementID1", "BusinessRole", "Client", "elementID2", "BusinessFunction", "My Function", "elementID3" };
// Relationships
String[] relations = { // Type, Name, ID, sourceID, targetID
"AssignmentRelationship", "Assigned to", "relID1", "elementID1", "elementID2", "UsedByRelationship", "", "relID2", "elementID1", "elementID3", "AssociationRelationship", "", "relID3", "elementID2", "elementID3" };
// Views
String[] views = { // Name, ID
"A View", "view1", "Another View", "view2" };
// View elements
String[] viewElements = { // ID of parent View, ID of referenced element, x, y, width, height
"view1", "elementID1", "10", "10", "-1", "-1", "view1", "elementID2", "310", "10", "-1", "-1", "view1", "elementID3", "310", "110", "-1", "-1", "view2", "elementID2", "10", "10", "-1", "-1", "view2", "elementID3", "10", "110", "-1", "-1" };
// View connections
String[] viewConnections = { // ID of parent View, ID of relationship
"view1", "relID1", "view1", "relID2", "view2", "relID3" };
// Create the model...
// Create a new Archimate Model and set its defaults
IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
model.setDefaults();
model.setName("My Model");
// Create and add elements matching imported data
// If an ID is not provided for an element then a unique ID will be generated when the model element is added to a parent
// model element, otherwise you can use your own IDs provided in the input data.
// Let's use an ID -> EObject mapping table for convenience
idLookup = new HashMap<String, EObject>();
// Create and add model elements
for (int i = 0; i < elements.length; ) {
String type = elements[i++];
String name = elements[i++];
String id = elements[i++];
createAndAddArchimateElement(model, (EClass) IArchimatePackage.eINSTANCE.getEClassifier(type), name, id);
}
// Create and add model relationships and set source and target elements
for (int i = 0; i < relations.length; ) {
String type = relations[i++];
String name = relations[i++];
String id = relations[i++];
String sourceID = relations[i++];
String targetID = relations[i++];
IArchimateRelationship relationship = createAndAddArchimateRelationship(model, (EClass) IArchimatePackage.eINSTANCE.getEClassifier(type), name, id);
// Find source and target elements from their IDs in the lookup table
IArchimateElement source = (IArchimateElement) idLookup.get(sourceID);
IArchimateElement target = (IArchimateElement) idLookup.get(targetID);
relationship.setSource(source);
relationship.setTarget(target);
}
// Create and add diagram views
for (int i = 0; i < views.length; ) {
String name = views[i++];
String id = views[i++];
createAndAddView(model, name, id);
}
// Add diagram elements to views
for (int i = 0; i < viewElements.length; ) {
String viewID = viewElements[i++];
String refID = viewElements[i++];
int x = Integer.parseInt(viewElements[i++]);
int y = Integer.parseInt(viewElements[i++]);
int width = Integer.parseInt(viewElements[i++]);
int height = Integer.parseInt(viewElements[i++]);
IDiagramModel diagramModel = (IDiagramModel) idLookup.get(viewID);
IArchimateElement element = (IArchimateElement) idLookup.get(refID);
createAndAddElementToView(diagramModel, element, x, y, width, height);
}
// Add diagram connections to views
for (int i = 0; i < viewConnections.length; ) {
String viewID = viewConnections[i++];
String relationshipID = viewConnections[i++];
IDiagramModel diagramModel = (IDiagramModel) idLookup.get(viewID);
IArchimateRelationship relationship = (IArchimateRelationship) idLookup.get(relationshipID);
createAndAddConnectionsToView(diagramModel, relationship);
}
// And open the Model in the Editor
IEditorModelManager.INSTANCE.openModel(model);
}
use of com.archimatetool.model.IArchimateModel in project archi by archimatetool.
the class SaveAsTemplateHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IArchimateModel model = getActiveArchimateModel();
if (model != null) {
WizardDialog dialog = new ExtendedWizardDialog(workbenchWindow.getShell(), new SaveArchimateModelAsTemplateWizard(model), // $NON-NLS-1$
"SaveModelAsTemplateWizard");
dialog.open();
}
return null;
}
Aggregations