Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
[Importer] Now show an error message when some files are missing.
Browse files Browse the repository at this point in the history
This is seen as non resolved proxies.
  • Loading branch information
jbsarrodie committed Nov 12, 2016
1 parent eca3843 commit ff75297
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ public class Messages extends NLS {

public static String MyImporter_0;

public static String MyImporter_1;

public static String MyImporter_2;

public static String MyImporter_3;

public static String MyImporter_4;

static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.InternalEObject;
Expand Down Expand Up @@ -55,6 +58,7 @@
public class MyImporter implements IModelImporter {
// ID -> Object lookup table
Map<String, IIdentifier> idLookup = new HashMap<String, IIdentifier>();
MultiStatus resolveErrors;

ResourceSet resourceSet;

Expand All @@ -81,9 +85,10 @@ public void doImport() throws IOException {
// Load the Model from files (it will contain unresolved proxies)
IArchimateModel model = (IArchimateModel) loadModel(modelFolder);
// Remove model from its resource (needed to save it back to a .archimate file)
resourceSet.getResource(URI.createFileURI((new File(modelFolder, "folder.xml")).getAbsolutePath()), true).getContents().remove(model);
resourceSet.getResource(URI.createFileURI((new File(modelFolder, "folder.xml")).getAbsolutePath()), true).getContents().remove(model); //$NON-NLS-1$

// Resolve proxies
resolveErrors = null;
resolveProxies(model);

// Load images in a dummy .archimate file and assign it to model
Expand All @@ -92,6 +97,14 @@ public void doImport() throws IOException {
IEditorModelManager.INSTANCE.openModel(model);
// Clean up file reference
model.setFile(null);

// Show warnings and errors (if any)
if (resolveErrors != null)
org.eclipse.jface.dialogs.ErrorDialog.openError(
Display.getCurrent().getActiveShell(),
Messages.MyImporter_1,
Messages.MyImporter_2,
resolveErrors);
}

/**
Expand Down Expand Up @@ -145,24 +158,24 @@ private void resolveProxies(EObject object) {
if(eObject instanceof IArchimateRelationship) {
// Resolve proxies for Relations
IArchimateRelationship relation = (IArchimateRelationship) eObject;
relation.setSource((IArchimateConcept) resolve(relation.getSource()));
relation.setTarget((IArchimateConcept) resolve(relation.getTarget()));
relation.setSource((IArchimateConcept) resolve(relation.getSource(), relation));
relation.setTarget((IArchimateConcept) resolve(relation.getTarget(), relation));
} else if(eObject instanceof IDiagramModelArchimateObject) {
// Resolve proxies for Elements
IDiagramModelArchimateObject element = (IDiagramModelArchimateObject) eObject;
element.setArchimateElement((IArchimateElement) resolve(element.getArchimateElement()));
element.setArchimateElement((IArchimateElement) resolve(element.getArchimateElement(), element));
// Update cross-references
element.getArchimateElement().getReferencingDiagramObjects().add(element);
} else if(eObject instanceof IDiagramModelArchimateConnection) {
// Resolve proxies for Connections
IDiagramModelArchimateConnection archiConnection = (IDiagramModelArchimateConnection) eObject;
archiConnection.setArchimateRelationship((IArchimateRelationship) resolve(archiConnection.getArchimateRelationship()));
archiConnection.setArchimateRelationship((IArchimateRelationship) resolve(archiConnection.getArchimateRelationship(), archiConnection));
// Update cross-reference
archiConnection.getArchimateRelationship().getReferencingDiagramConnections().add(archiConnection);
} else if (eObject instanceof IDiagramModelReference) {
// Resolve proxies for Model References
IDiagramModelReference element = (IDiagramModelReference) eObject;
element.setReferencedModel((IDiagramModel) resolve(element.getReferencedModel()));
element.setReferencedModel((IDiagramModel) resolve(element.getReferencedModel(), element));
}
}
}
Expand All @@ -173,9 +186,19 @@ private void resolveProxies(EObject object) {
* @param object
* @return
*/
private EObject resolve(IIdentifier object) {
private EObject resolve(IIdentifier object, IIdentifier parent) {
if (object != null & object.eIsProxy()) {
IIdentifier newObject = idLookup.get(((InternalEObject) object).eProxyURI().fragment());
// Log errors if proxy has not been resolved
if (newObject == null) {
String message = String.format(Messages.MyImporter_3, ((InternalEObject) object).eProxyURI().fragment(), parent.getClass().getSimpleName(), parent.getId());
System.out.println(message);
// Create resolveError the first time
if (resolveErrors == null)
resolveErrors = new MultiStatus("org.archicontribs.grafico", IStatus.ERROR, Messages.MyImporter_4, null); //$NON-NLS-1$
// Add an error to the list
resolveErrors.add(new Status(IStatus.ERROR, "org.archicontribs.grafico", message)); //$NON-NLS-1$
}
return newObject == null ? object : newObject;
} else {
return object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ MyExporter_1=''{0}'' already exists. Are you sure you want to overwrite it?
MyExporter_3=Choose a folder in which to export the model.
MyExporter_4=''{0}'' is not empty. Are you sure you want to overwrite it?
MyImporter_0=Choose a folder from which to import the model.
MyImporter_1=GRAFICO Import
MyImporter_2=Errors happened during import
MyImporter_3=Unable to resolve proxy for concept with Id=%s (parent is %s with Id=%s)
MyImporter_4=Missing concept(s)

0 comments on commit ff75297

Please sign in to comment.