Search in sources :

Example 11 with IIdentifier

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;
}
Also used : IDocumentable(com.archimatetool.model.IDocumentable) IIdentifier(com.archimatetool.model.IIdentifier) INameable(com.archimatetool.model.INameable) EObject(org.eclipse.emf.ecore.EObject) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 12 with IIdentifier

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);
    }
}
Also used : IIdentifier(com.archimatetool.model.IIdentifier) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) File(java.io.File) IArchimateModel(com.archimatetool.model.IArchimateModel) IFolder(com.archimatetool.model.IFolder)

Example 13 with IIdentifier

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;
}
Also used : IIdentifier(com.archimatetool.model.IIdentifier) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource)

Aggregations

IIdentifier (com.archimatetool.model.IIdentifier)13 EObject (org.eclipse.emf.ecore.EObject)8 File (java.io.File)6 IArchimateModel (com.archimatetool.model.IArchimateModel)5 ArrayList (java.util.ArrayList)4 INameable (com.archimatetool.model.INameable)2 IOException (java.io.IOException)2 TreeEditElementRequest (com.archimatetool.editor.views.tree.TreeEditElementRequest)1 IArchimateConcept (com.archimatetool.model.IArchimateConcept)1 IArchimateModelObject (com.archimatetool.model.IArchimateModelObject)1 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)1 IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)1 IDiagramModelComponent (com.archimatetool.model.IDiagramModelComponent)1 IDocumentable (com.archimatetool.model.IDocumentable)1 IFolder (com.archimatetool.model.IFolder)1 ITemplate (com.archimatetool.templates.model.ITemplate)1 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 UnresolvedObject (org.archicontribs.modelrepository.grafico.GraficoModelImporter.UnresolvedObject)1 URI (org.eclipse.emf.common.util.URI)1