Search in sources :

Example 1 with IIdentifier

use of com.archimatetool.model.IIdentifier in project archi by archimatetool.

the class CreateEmptyModelProvider method createEmptyModelFromTemplate.

// Code taken from com.archimatetool.templates.impl.wizard.NewArchimateModelFromTemplateWizard
private IArchimateModel createEmptyModelFromTemplate(String template) throws IOException {
    File fileTemplate = new File(template);
    if (!fileTemplate.exists()) {
        throw new IOException(NLS.bind(Messages.CreateEmptyModelProvider_3, template));
    }
    // $NON-NLS-1$
    File tmp = File.createTempFile("~architemplate", null);
    tmp.deleteOnExit();
    // $NON-NLS-1$
    File file = ZipUtils.extractZipEntry(fileTemplate, "model.archimate", tmp);
    IArchimateModel model = LoadModelFromFileProvider.loadModel(file);
    if (model == null) {
        logError(Messages.CreateEmptyModelProvider_4);
        return null;
    }
    // New name
    // $NON-NLS-1$
    model.setName(Messages.CreateEmptyModelProvider_5 + " " + model.getName());
    // Set latest model version
    model.setVersion(ModelVersion.VERSION);
    // Set file to null
    model.setFile(null);
    // New IDs
    model.setId(model.getIDAdapter().getNewID());
    for (Iterator<EObject> iter = model.eAllContents(); iter.hasNext(); ) {
        EObject eObject = iter.next();
        if (eObject instanceof IIdentifier) {
            ((IIdentifier) eObject).setId(model.getIDAdapter().getNewID());
        }
    }
    logMessage(NLS.bind(Messages.CreateEmptyModelProvider_6, fileTemplate));
    return model;
}
Also used : IIdentifier(com.archimatetool.model.IIdentifier) EObject(org.eclipse.emf.ecore.EObject) IOException(java.io.IOException) File(java.io.File) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 2 with IIdentifier

use of com.archimatetool.model.IIdentifier in project archi by archimatetool.

the class ModelChecker method checkHasIdentifiers.

List<String> checkHasIdentifiers() {
    List<String> messages = new ArrayList<String>();
    for (Iterator<EObject> iter = fModel.eAllContents(); iter.hasNext(); ) {
        EObject eObject = iter.next();
        if (eObject instanceof IIdentifier && !StringUtils.isSet(((IIdentifier) eObject).getId())) {
            // $NON-NLS-1$
            String message = Messages.ModelChecker_10 + " " + ArchiLabelProvider.INSTANCE.getLabel(eObject);
            messages.add(message);
        }
    }
    return messages;
}
Also used : IIdentifier(com.archimatetool.model.IIdentifier) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList)

Example 3 with IIdentifier

use of com.archimatetool.model.IIdentifier in project archi by archimatetool.

the class CopySnapshotTests method testCopiedObjectsHaveIdentifiersAndParents.

private void testCopiedObjectsHaveIdentifiersAndParents(IDiagramModel newTargetDiagramModel) {
    List<IDiagramModelComponent> selected = new ArrayList<IDiagramModelComponent>();
    selected.addAll(getAllDiagramComponents(sourceDiagramModel));
    CopySnapshot snapshot = new CopySnapshot(selected);
    Command cmd = snapshot.getPasteCommand(newTargetDiagramModel, mock(GraphicalViewer.class), null, false);
    cmd.execute();
    for (TreeIterator<EObject> iter = newTargetDiagramModel.eAllContents(); iter.hasNext(); ) {
        EObject eObject = iter.next();
        assertNotNull(eObject.eContainer());
        if (eObject instanceof IIdentifier) {
            assertNotNull(((IIdentifier) eObject).getId());
        }
        if (eObject instanceof IDiagramModelArchimateComponent) {
            assertNotNull(((IDiagramModelArchimateComponent) eObject).getArchimateConcept());
            assertNotNull(((IDiagramModelArchimateComponent) eObject).getArchimateConcept().eContainer());
        }
    }
}
Also used : IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) GraphicalViewer(org.eclipse.gef.GraphicalViewer) IIdentifier(com.archimatetool.model.IIdentifier) Command(org.eclipse.gef.commands.Command) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent)

Example 4 with IIdentifier

use of com.archimatetool.model.IIdentifier in project archi by archimatetool.

the class NewArchimateModelFromTemplateWizard method performFinish.

@Override
public boolean performFinish() {
    // Get template
    ITemplate template = fMainPage.getSelectedTemplate();
    if (template == null) {
        return false;
    }
    getContainer().getShell().setVisible(false);
    fErrorMessage = null;
    final File zipFile = template.getFile();
    if (zipFile != null && zipFile.exists()) {
        BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {

            @Override
            public void run() {
                try {
                    // $NON-NLS-1$
                    File tmp = File.createTempFile("~architemplate", null);
                    tmp.deleteOnExit();
                    File file = ZipUtils.extractZipEntry(zipFile, TemplateManager.ZIP_ENTRY_MODEL, tmp);
                    if (file != null && file.exists()) {
                        IArchimateModel model = IEditorModelManager.INSTANCE.openModel(file);
                        if (model != null) {
                            // New name
                            // $NON-NLS-1$
                            model.setName(Messages.NewArchimateModelFromTemplateWizard_1 + " " + model.getName());
                            // Set latest model version (need to do this in case we immediately save as Template)
                            model.setVersion(ModelVersion.VERSION);
                            // Set file to null
                            model.setFile(null);
                            // New IDs
                            model.setId(model.getIDAdapter().getNewID());
                            for (Iterator<EObject> iter = model.eAllContents(); iter.hasNext(); ) {
                                EObject eObject = iter.next();
                                if (eObject instanceof IIdentifier) {
                                    ((IIdentifier) eObject).setId(model.getIDAdapter().getNewID());
                                }
                            }
                            // Edit in-place in Tree
                            UIRequestManager.INSTANCE.fireRequest(new TreeEditElementRequest(this, model));
                        } else {
                            fErrorMessage = Messages.NewArchimateModelFromTemplateWizard_2;
                        }
                    } else {
                        fErrorMessage = Messages.NewArchimateModelFromTemplateWizard_2;
                    }
                    tmp.delete();
                } catch (IOException ex) {
                    ex.printStackTrace();
                    fErrorMessage = ex.getMessage();
                }
            }
        });
    }
    if (fErrorMessage != null) {
        MessageDialog.openError(getShell(), Messages.NewArchimateModelFromTemplateWizard_3, fErrorMessage);
        getContainer().getShell().setVisible(true);
    }
    return fErrorMessage == null;
}
Also used : IIdentifier(com.archimatetool.model.IIdentifier) EObject(org.eclipse.emf.ecore.EObject) Iterator(java.util.Iterator) TreeEditElementRequest(com.archimatetool.editor.views.tree.TreeEditElementRequest) ITemplate(com.archimatetool.templates.model.ITemplate) IOException(java.io.IOException) File(java.io.File) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 5 with IIdentifier

use of com.archimatetool.model.IIdentifier in project archi by archimatetool.

the class IDAdapter method notifyChanged.

@Override
public void notifyChanged(Notification msg) {
    super.notifyChanged(msg);
    if (msg.getEventType() == Notification.ADD) {
        if (msg.getNewValue() instanceof IIdentifier) {
            IIdentifier element = (IIdentifier) msg.getNewValue();
            String id = element.getId();
            // Element has no ID so allocate one
            if (id == null) {
                element.setId(getNewID());
            } else // Register the ID to the list when loading in from file
            {
                registerID(id);
            }
        }
    }
}
Also used : IIdentifier(com.archimatetool.model.IIdentifier)

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