use of com.archimatetool.model.IIdentifier in project archi by archimatetool.
the class FieldDataFactory method getFieldValue.
public static Object getFieldValue(Object dataElement, String fieldName) {
if ("this".equals(fieldName)) {
// $NON-NLS-1$
return dataElement;
}
if ("id".equals(fieldName) && dataElement instanceof IIdentifier) {
// $NON-NLS-1$
return ((IIdentifier) dataElement).getId();
}
if ("name".equals(fieldName) && dataElement instanceof INameable) {
// $NON-NLS-1$
String name = ((INameable) dataElement).getName();
if (name == null || "".equals(name)) {
// $NON-NLS-1$
name = ArchiLabelProvider.INSTANCE.getDefaultName(((EObject) dataElement).eClass());
}
return name;
}
if ("type".equals(fieldName) && dataElement instanceof EObject) {
// $NON-NLS-1$
return ArchiLabelProvider.INSTANCE.getDefaultName(((EObject) dataElement).eClass());
}
if ("documentation".equals(fieldName) && dataElement instanceof IDocumentable) {
// $NON-NLS-1$
String s = ((IDocumentable) dataElement).getDocumentation();
return StringUtils.isSet(s) ? s : null;
}
if ("purpose".equals(fieldName) && dataElement instanceof IArchimateModel) {
// $NON-NLS-1$
String s = ((IArchimateModel) dataElement).getPurpose();
return StringUtils.isSet(s) ? s : null;
}
if ("relation_source".equals(fieldName) && dataElement instanceof IArchimateRelationship) {
// $NON-NLS-1$
IArchimateRelationship relation = (IArchimateRelationship) dataElement;
IArchimateConcept source = relation.getSource();
String s = source.getName();
return StringUtils.isSet(s) ? s : null;
}
if ("relation_target".equals(fieldName) && dataElement instanceof IArchimateRelationship) {
// $NON-NLS-1$
IArchimateRelationship relation = (IArchimateRelationship) dataElement;
IArchimateConcept target = relation.getTarget();
String s = target.getName();
return StringUtils.isSet(s) ? s : null;
}
return null;
}
use of com.archimatetool.model.IIdentifier in project archi-modelrepository-plugin by archi-contribs.
the class GraficoModelExporter method createAndSaveResourceForFolder.
/**
* For each folder inside model, create a directory and a Resource to save it.
* For each element, create a Resource to save it
*
* @param folderContainer Model or folder to work on
* @param folder Directory in which to generate files
* @throws IOException
*/
private void createAndSaveResourceForFolder(IFolderContainer folderContainer, File folder) throws IOException {
// Save each children folders
List<IFolder> allFolders = new ArrayList<IFolder>();
allFolders.addAll(folderContainer.getFolders());
for (IFolder tmpFolder : allFolders) {
File tmpFolderFile = new File(folder, getNameFor(tmpFolder));
tmpFolderFile.mkdirs();
createAndSaveResource(new File(tmpFolderFile, IGraficoConstants.FOLDER_XML), tmpFolder);
createAndSaveResourceForFolder(tmpFolder, tmpFolderFile);
}
// Save each children elements
if (folderContainer instanceof IFolder) {
// Save each children element
List<EObject> allElements = new ArrayList<EObject>();
allElements.addAll(((IFolder) folderContainer).getElements());
for (EObject tmpElement : allElements) {
createAndSaveResource(// $NON-NLS-1$ //$NON-NLS-2$
new File(folder, tmpElement.getClass().getSimpleName() + "_" + ((IIdentifier) tmpElement).getId() + ".xml"), tmpElement);
}
}
if (folderContainer instanceof IArchimateModel) {
createAndSaveResource(new File(folder, IGraficoConstants.FOLDER_XML), folderContainer);
}
}
use of com.archimatetool.model.IIdentifier in project archi-modelrepository-plugin by archi-contribs.
the class GraficoModelImporter method loadElement.
/**
* Create an eObject from an XML file. Basically load a resource.
*
* @param file
* @return
*/
private EObject loadElement(File file) {
// Create a new resource for selected file and add object to persist
XMLResource resource = (XMLResource) fResourceSet.getResource(URI.createFileURI(file.getAbsolutePath()), true);
// $NON-NLS-1$
resource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
IIdentifier element = (IIdentifier) resource.getContents().get(0);
// Update an ID -> Object mapping table (used as a cache to resolve proxies)
fIDLookup.put(element.getId(), element);
return element;
}
Aggregations