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

Commit

Permalink
[importer] Code refactoring and fix model folders order
Browse files Browse the repository at this point in the history
  • Loading branch information
jbsarrodie committed Mar 24, 2015
1 parent 0c9b80a commit 768abf1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 14 deletions.
3 changes: 2 additions & 1 deletion org.archicontribs.grafico/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
com.archimatetool.editor
com.archimatetool.editor,
org.eclipse.emf.common
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class Messages extends NLS {

public static String MyExporter_4;

public static String MyImporter_0;

static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.XMLResource;
Expand All @@ -35,7 +34,6 @@
import com.archimatetool.model.IDiagramModelArchimateObject;
import com.archimatetool.model.IDiagramModelReference;
import com.archimatetool.model.IFolder;
import com.archimatetool.model.IFolderContainer;
import com.archimatetool.model.IIdentifier;
import com.archimatetool.model.IRelationship;

Expand Down Expand Up @@ -77,7 +75,7 @@ public void doImport() throws IOException {
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMLResourceFactoryImpl()); //$NON-NLS-1$

// Load the Model from files (it will contain unresolved proxies)
IArchimateModel model = (IArchimateModel) loadFolder(modelFolder);
IArchimateModel model = (IArchimateModel) loadModel(modelFolder);

// Resolve proxies
resolveProxies(model);
Expand Down Expand Up @@ -178,25 +176,55 @@ private EObject resolve(IIdentifier object) {
}
}

private IArchimateModel loadModel(File folder) {
IArchimateModel model = (IArchimateModel) loadElement(new File(folder, "folder.xml")); //$NON-NLS-1$
IFolder tmpFolder;

if (model != null) {
if ((tmpFolder = loadFolder(new File(folder, "business"))) != null) //$NON-NLS-1$
model.getFolders().add(tmpFolder);
if ((tmpFolder = loadFolder(new File(folder, "application"))) != null) //$NON-NLS-1$
model.getFolders().add(tmpFolder);
if ((tmpFolder = loadFolder(new File(folder, "technology"))) != null) //$NON-NLS-1$
model.getFolders().add(tmpFolder);
if ((tmpFolder = loadFolder(new File(folder, "motivation"))) != null) //$NON-NLS-1$
model.getFolders().add(tmpFolder);
if ((tmpFolder = loadFolder(new File(folder, "implementation_migration"))) != null) //$NON-NLS-1$
model.getFolders().add(tmpFolder);
if ((tmpFolder = loadFolder(new File(folder, "connectors"))) != null) //$NON-NLS-1$
model.getFolders().add(tmpFolder);
if ((tmpFolder = loadFolder(new File(folder, "relations"))) != null) //$NON-NLS-1$
model.getFolders().add(tmpFolder);
if ((tmpFolder = loadFolder(new File(folder, "derived"))) != null) //$NON-NLS-1$
model.getFolders().add(tmpFolder);
if ((tmpFolder = loadFolder(new File(folder, "diagrams"))) != null) //$NON-NLS-1$
model.getFolders().add(tmpFolder);
}

return model;
}

/**
* Load each XML file to recreate original object
*
* @param folder
* @return
*/
private IFolderContainer loadFolder(File folder) {
private IFolder loadFolder(File folder) {
if (!folder.isDirectory() | !(new File(folder, "folder.xml")).isFile()) { //$NON-NLS-1$
return null;
}

// Load folder object itself
IFolderContainer currentFolder = (IFolderContainer) loadElement(new File(folder, "folder.xml")); //$NON-NLS-1$
IFolder currentFolder = (IFolder) loadElement(new File(folder, "folder.xml")); //$NON-NLS-1$

// Load each elements (except folder.xml) and add them to folder
for (File fileOrFolder: folder.listFiles()) {
if(!fileOrFolder.getName().equals("folder.xml")) { //$NON-NLS-1$
if (fileOrFolder.isFile() & currentFolder instanceof IFolder) {
((IFolder) currentFolder).getElements().add(loadElement(fileOrFolder));
} else {
currentFolder.getFolders().add((IFolder) loadFolder(fileOrFolder));
}
}
if (fileOrFolder.isFile() & !fileOrFolder.getName().equals("folder.xml")) { //$NON-NLS-1$
currentFolder.getElements().add(loadElement(fileOrFolder));
} else {
currentFolder.getFolders().add(loadFolder(fileOrFolder));
}
}

return currentFolder;
Expand Down Expand Up @@ -226,7 +254,7 @@ private EObject loadElement(File file) {
private File askOpenFolder() {
DirectoryDialog dialog = new DirectoryDialog(Display.getCurrent().getActiveShell());
dialog.setText(Messages.MyExporter_0);
dialog.setMessage("Choose a folder from which to import the model.");
dialog.setMessage(Messages.MyImporter_0);
String path = dialog.open();
return (path == null)? null : new File(path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ MyExporter_0=Export Model
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.

0 comments on commit 768abf1

Please sign in to comment.