use of com.archimatetool.model.IIdentifier in project archi by archimatetool.
the class TreeStateHelper method saveStateOnApplicationClose.
/**
* Save expanded state of tree elements on Application close
* @param memento
*/
void saveStateOnApplicationClose(IMemento memento) {
Hashtable<File, String> map = new Hashtable<File, String>();
IMemento expandedMem = memento.createChild(MEMENTO_EXPANDED);
for (Object element : fTreeViewer.getVisibleExpandedElements()) {
if (element instanceof IIdentifier && element instanceof IArchimateModelObject) {
// Only store if saved in a file
File file = ((IArchimateModelObject) element).getArchimateModel().getFile();
if (file != null) {
String id = ((IIdentifier) element).getId();
String string = map.get(file);
if (string == null) {
string = id;
} else {
string += ELEMENT_SEP_CHAR + id;
}
map.put(file, string);
}
}
}
for (File file : map.keySet()) {
IMemento elementMem = expandedMem.createChild(MEMENTO_MODEL);
elementMem.putString(MEMENTO_FILE, file.getAbsolutePath());
elementMem.putString(MEMENTO_ELEMENTS, map.get(file));
}
}
use of com.archimatetool.model.IIdentifier in project archi-modelrepository-plugin by archi-contribs.
the class GraficoModelImporter method importAsModel.
/**
* Import the grafico XML files as a IArchimateModel
* @throws IOException
*/
public IArchimateModel importAsModel() throws IOException {
// Create folders for model and images
File modelFolder = new File(fLocalRepoFolder, IGraficoConstants.MODEL_FOLDER);
modelFolder.mkdirs();
File imagesFolder = new File(fLocalRepoFolder, IGraficoConstants.IMAGES_FOLDER);
imagesFolder.mkdirs();
// If the top folder.xml does not exist then there is nothing to import, so return null
if (!(new File(modelFolder, IGraficoConstants.FOLDER_XML)).isFile()) {
return null;
}
// Create ResourceSet
fResourceSet = new ResourceSetImpl();
// $NON-NLS-1$
fResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMLResourceFactoryImpl());
// Reset the ID -> Object lookup table
fIDLookup = new HashMap<String, IIdentifier>();
// Load the Model from files (it will contain unresolved proxies)
fModel = loadModel(modelFolder);
// Remove model from its resource (needed to save it back to a .archimate file)
fResourceSet.getResource(URI.createFileURI((new File(modelFolder, IGraficoConstants.FOLDER_XML)).getAbsolutePath()), true).getContents().remove(fModel);
// Resolve proxies
fUnresolvedObjects = null;
resolveProxies();
// Load images
loadImages(imagesFolder);
return fModel;
}
use of com.archimatetool.model.IIdentifier in project archi-modelrepository-plugin by archi-contribs.
the class GraficoModelImporter method resolve.
/**
* Check if 'object' is a proxy. if yes, replace it with real object from mapping table.
*/
private EObject resolve(IIdentifier object, IIdentifier parent) {
if (object != null && object.eIsProxy()) {
URI objectURI = EcoreUtil.getURI(object);
String objectID = EcoreUtil.getURI(object).fragment();
// Get proxy object
IIdentifier newObject = fIDLookup.get(objectID);
// If proxy has not been resolved
if (newObject == null) {
// Add to list
if (fUnresolvedObjects == null) {
fUnresolvedObjects = new ArrayList<UnresolvedObject>();
}
fUnresolvedObjects.add(new UnresolvedObject(objectURI, parent));
}
return newObject == null ? object : newObject;
} else {
return object;
}
}
use of com.archimatetool.model.IIdentifier in project archi-modelrepository-plugin by archi-contribs.
the class GraficoModelLoader method restoreProblemObjects.
/**
* Find the problem object xml files from the commit history and restore them
* @param unresolvedObjects
* @return
* @throws IOException
*/
private IArchimateModel restoreProblemObjects(List<UnresolvedObject> unresolvedObjects) throws IOException {
fRestoredObjects = new ArrayList<IIdentifier>();
List<String> restoredIdentifiers = new ArrayList<String>();
try (Repository repository = Git.open(fRepository.getLocalRepositoryFolder()).getRepository()) {
try (RevWalk revWalk = new RevWalk(repository)) {
for (UnresolvedObject unresolved : unresolvedObjects) {
String missingFileName = unresolved.missingObjectURI.lastSegment();
String missingObjectID = unresolved.missingObjectURI.fragment();
// Already got this one
if (restoredIdentifiers.contains(missingObjectID)) {
continue;
}
boolean found = false;
// Reset RevWalk
revWalk.reset();
ObjectId id = repository.resolve(IGraficoConstants.REFS_HEADS_MASTER);
if (id != null) {
revWalk.markStart(revWalk.parseCommit(id));
}
// Iterate all commits
for (RevCommit commit : revWalk) {
try (TreeWalk treeWalk = new TreeWalk(repository)) {
treeWalk.addTree(commit.getTree());
treeWalk.setRecursive(true);
// We can't use a PathFilter for the file name as its path is not correct
while (!found && treeWalk.next()) {
// File is found
if (treeWalk.getPathString().endsWith(missingFileName)) {
// Save file
ObjectId objectId = treeWalk.getObjectId(0);
ObjectLoader loader = repository.open(objectId);
File file = new File(fRepository.getLocalRepositoryFolder(), treeWalk.getPathString());
file.getParentFile().mkdirs();
GraficoUtils.writeObjectToFileWithSystemLineEndings(file, loader);
restoredIdentifiers.add(missingObjectID);
found = true;
}
}
}
if (found) {
break;
}
}
}
revWalk.dispose();
}
}
// Then re-import
GraficoModelImporter importer = new GraficoModelImporter(fRepository.getLocalRepositoryFolder());
IArchimateModel graficoModel = importer.importAsModel();
// do this again
graficoModel.setFile(fRepository.getTempModelFile());
// Collect restored objects
for (Iterator<EObject> iter = graficoModel.eAllContents(); iter.hasNext(); ) {
EObject element = iter.next();
for (String id : restoredIdentifiers) {
if (element instanceof IIdentifier && id.equals(((IIdentifier) element).getId())) {
fRestoredObjects.add((IIdentifier) element);
}
}
}
return graficoModel;
}
use of com.archimatetool.model.IIdentifier in project archi-modelrepository-plugin by archi-contribs.
the class GraficoModelLoader method getRestoredObjectsAsString.
/**
* @return The list of resolved objects as a message string or null
*/
public String getRestoredObjectsAsString() {
if (fRestoredObjects == null) {
return null;
}
String s = Messages.GraficoModelLoader_0;
for (IIdentifier id : fRestoredObjects) {
if (id instanceof INameable) {
String name = ((INameable) id).getName();
String className = id.eClass().getName();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
s += "\n" + (StringUtils.isSet(name) ? name + " (" + className + ")" : className);
}
}
return s;
}
Aggregations