Search in sources :

Example 21 with IArchimateModel

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

the class EditorModelManager method loadModel.

@Override
public IArchimateModel loadModel(File file) {
    if (file == null || !file.exists()) {
        return null;
    }
    // If it is already loaded return it
    IArchimateModel model = locateLoadedModel(file);
    if (model != null) {
        return model;
    }
    // Ascertain if this is an archive file
    boolean useArchiveFormat = IArchiveManager.FACTORY.isArchiveFile(file);
    // Create the Resource
    Resource resource = ArchimateResourceFactory.createNewResource(useArchiveFormat ? IArchiveManager.FACTORY.createArchiveModelURI(file) : URI.createFileURI(file.getAbsolutePath()));
    // Check model compatibility
    ModelCompatibility modelCompatibility = new ModelCompatibility(resource);
    // Load the model file
    try {
        resource.load(null);
    } catch (IOException ex) {
        // Error occured loading model.
        try {
            modelCompatibility.checkErrors();
        } catch (IncompatibleModelException ex1) {
            // Was it a disaster?
            MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.EditorModelManager_2, NLS.bind(Messages.EditorModelManager_3, file) + "\n" + // $NON-NLS-1$
            ex1.getMessage());
            return null;
        }
    }
    model = (IArchimateModel) resource.getContents().get(0);
    // Once loaded - check for later model version
    boolean isLaterModelVersion = modelCompatibility.isLaterModelVersion(ModelVersion.VERSION);
    if (isLaterModelVersion) {
        boolean answer = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), Messages.EditorModelManager_4, NLS.bind(Messages.EditorModelManager_5, file, model.getVersion()));
        if (!answer) {
            return null;
        }
    } else // Check for unknown model features which might be OK to load
    {
        List<Diagnostic> exceptions = modelCompatibility.getAcceptableExceptions();
        if (!exceptions.isEmpty()) {
            // $NON-NLS-1$
            String message = "";
            for (int i = 0; i < exceptions.size(); i++) {
                if (i == 3) {
                    // $NON-NLS-1$
                    message += (exceptions.size() - 3) + " " + Messages.EditorModelManager_12;
                    break;
                }
                // $NON-NLS-1$
                message += exceptions.get(i).getMessage() + "\n";
            }
            boolean answer = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), Messages.EditorModelManager_4, NLS.bind(Messages.EditorModelManager_13, file) + "\n\n" + // $NON-NLS-1$
            message);
            if (!answer) {
                return null;
            }
        }
    }
    // And then fix any backward compatibility issues
    try {
        modelCompatibility.fixCompatibility();
    } catch (CompatibilityHandlerException ex) {
    }
    model.setFile(file);
    model.setDefaults();
    getModels().add(model);
    model.eAdapters().add(new ECoreAdapter());
    // New Command Stack
    createNewCommandStack(model);
    // New Archive Manager
    createNewArchiveManager(model);
    // Initiate all diagram models to be marked as "saved" - this is for the editor view persistence
    markDiagramModelsAsSaved(model);
    // This last
    firePropertyChange(this, PROPERTY_MODEL_LOADED, null, model);
    return model;
}
Also used : ModelCompatibility(com.archimatetool.editor.model.compatibility.ModelCompatibility) Resource(org.eclipse.emf.ecore.resource.Resource) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) CompatibilityHandlerException(com.archimatetool.editor.model.compatibility.CompatibilityHandlerException) IOException(java.io.IOException) IArchimateModel(com.archimatetool.model.IArchimateModel) IncompatibleModelException(com.archimatetool.editor.model.compatibility.IncompatibleModelException)

Example 22 with IArchimateModel

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

the class AbstractECorePropertySection method getFilteredObjects.

/**
 * Filter selected objects.
 * Also ensure that selected objects are from only one model.
 * We don't support selections from more than one model due to each model having its own command stack.
 *
 * @return A list of filtered adaptable objects according to type
 */
private List<EObject> getFilteredObjects(List<?> objects) {
    ArrayList<EObject> list = new ArrayList<EObject>();
    IObjectFilter filter = getFilter();
    // Get underlying object if a Filter is applied
    for (Object object : objects) {
        if (filter != null) {
            object = filter.adaptObject(object);
        }
        if (object instanceof EObject) {
            list.add((EObject) object);
        }
    }
    // Only use the objects that are in *one* model - the model in the first selected object
    if (!list.isEmpty()) {
        IArchimateModel firstModel = ((IArchimateModelObject) list.get(0)).getArchimateModel();
        // Remove objects with different parent models
        for (int i = list.size() - 1; i >= 1; i--) {
            IArchimateModelObject eObject = (IArchimateModelObject) list.get(i);
            if (eObject.getArchimateModel() != firstModel) {
                list.remove(eObject);
            }
        }
    }
    return list;
}
Also used : IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) EObject(org.eclipse.emf.ecore.EObject) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 23 with IArchimateModel

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

the class DiagramEditorInputFactory method createElement.

@Override
public IAdaptable createElement(IMemento memento) {
    String viewID = memento.getString(TAG_VIEW_ID);
    String fileName = memento.getString(TAG_VIEW_FILE);
    String viewName = memento.getString(TAG_VIEW_NAME);
    if (viewID != null && fileName != null) {
        File file = new File(fileName);
        for (IArchimateModel model : IEditorModelManager.INSTANCE.getModels()) {
            if (file.equals(model.getFile())) {
                for (IDiagramModel diagramModel : model.getDiagramModels()) {
                    if (viewID.equals(diagramModel.getId())) {
                        return new DiagramEditorInput(diagramModel);
                    }
                }
            }
        }
    }
    // Cannot find it, must have been removed from file
    return new NullDiagramEditorInput(fileName, viewName);
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) File(java.io.File) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 24 with IArchimateModel

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

the class IArchiveManagerTests method testFactory_createArchiveManager.

@Test
public void testFactory_createArchiveManager() throws IOException {
    ArchimateTestModel tm = new ArchimateTestModel(TestData.TEST_MODEL_FILE_ARCHISURANCE);
    IArchimateModel model = tm.loadModel();
    IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(model);
    assertNotNull(archiveManager);
}
Also used : IArchimateModel(com.archimatetool.model.IArchimateModel) ArchimateTestModel(com.archimatetool.testingtools.ArchimateTestModel) Test(org.junit.Test)

Example 25 with IArchimateModel

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

the class ModelCheckerTests method checkAll.

@Test
public void checkAll() {
    File file = TestData.TEST_MODEL_FILE_ARCHISURANCE;
    IArchimateModel model = new EditorModelManager().loadModel(file);
    assertNotNull(model);
    ModelChecker modelChecker = new ModelChecker(model);
    assertTrue(modelChecker.checkAll());
}
Also used : EditorModelManager(com.archimatetool.editor.model.impl.EditorModelManager) File(java.io.File) IArchimateModel(com.archimatetool.model.IArchimateModel) Test(org.junit.Test)

Aggregations

IArchimateModel (com.archimatetool.model.IArchimateModel)124 Test (org.junit.Test)51 File (java.io.File)35 IOException (java.io.IOException)22 IArchimateElement (com.archimatetool.model.IArchimateElement)14 EObject (org.eclipse.emf.ecore.EObject)14 IArchiveManager (com.archimatetool.editor.model.IArchiveManager)13 ArchimateTestModel (com.archimatetool.testingtools.ArchimateTestModel)13 IDiagramModel (com.archimatetool.model.IDiagramModel)12 CommandStack (org.eclipse.gef.commands.CommandStack)11 IFolder (com.archimatetool.model.IFolder)10 ArrayList (java.util.ArrayList)10 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)9 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)9 IArchimateModelObject (com.archimatetool.model.IArchimateModelObject)7 IArchimateDiagramModel (com.archimatetool.model.IArchimateDiagramModel)6 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)6 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)5 IIdentifier (com.archimatetool.model.IIdentifier)5 GraficoModelLoader (org.archicontribs.modelrepository.grafico.GraficoModelLoader)5