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