Search in sources :

Example 41 with IArchimateModel

use of com.archimatetool.model.IArchimateModel 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 42 with IArchimateModel

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

the class HTMLReportHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IArchimateModel model = getActiveArchimateModel();
    if (model != null) {
        try {
            HTMLReportExporter exporter = new HTMLReportExporter(model);
            exporter.export();
        } catch (IOException ex) {
            MessageDialog.openError(workbenchWindow.getShell(), Messages.HTMLReportAction_0, ex.getMessage());
            ex.printStackTrace();
        }
    }
    return null;
}
Also used : IOException(java.io.IOException) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 43 with IArchimateModel

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

the class HTMLReportProvider method run.

@Override
public void run(CommandLine commandLine) throws Exception {
    if (!hasCorrectOptions(commandLine)) {
        return;
    }
    String sOutput = commandLine.getOptionValue(OPTION_CREATE_HTML_REPORT);
    if (!StringUtils.isSet(sOutput)) {
        logError(Messages.HTMLReportProvider_1);
        return;
    }
    File folderOutput = new File(sOutput);
    folderOutput.mkdirs();
    if (!folderOutput.exists()) {
        logError(NLS.bind(Messages.HTMLReportProvider_2, sOutput));
        return;
    }
    IArchimateModel model = CommandLineState.getModel();
    if (model == null) {
        throw new IOException(Messages.HTMLReportProvider_3);
    }
    logMessage(NLS.bind(Messages.HTMLReportProvider_4, model.getName(), sOutput));
    HTMLReportExporter ex = new HTMLReportExporter(model);
    // $NON-NLS-1$
    ex.createReport(folderOutput, "index.html");
    logMessage(Messages.HTMLReportProvider_5);
}
Also used : HTMLReportExporter(com.archimatetool.reports.html.HTMLReportExporter) IOException(java.io.IOException) File(java.io.File) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 44 with IArchimateModel

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

the class UserPropertiesSection method getAllUniquePropertyKeysForModel.

/**
 * @return All unique Property Keys for an entire model (sorted)
 */
private String[] getAllUniquePropertyKeysForModel() {
    IArchimateModel model = getArchimateModel();
    List<String> list = new ArrayList<String>();
    for (Iterator<EObject> iter = model.eAllContents(); iter.hasNext(); ) {
        EObject element = iter.next();
        if (element instanceof IProperty) {
            String key = ((IProperty) element).getKey();
            if (StringUtils.isSetAfterTrim(key) && !list.contains(key)) {
                list.add(key);
            }
        }
    }
    String[] items = list.toArray(new String[list.size()]);
    Arrays.sort(items, new Comparator<String>() {

        @Override
        public int compare(String s1, String s2) {
            return s1.compareToIgnoreCase(s2);
        }
    });
    return items;
}
Also used : IProperty(com.archimatetool.model.IProperty) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 45 with IArchimateModel

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

the class TreeModelView method propertyChange.

// ======================================================================
// Listen to Property Changes from IEditorModelManager
// ======================================================================
@Override
public void propertyChange(PropertyChangeEvent evt) {
    String propertyName = evt.getPropertyName();
    Object source = evt.getSource();
    // New Model created or opened
    if (propertyName == IEditorModelManager.PROPERTY_MODEL_CREATED || propertyName == IEditorModelManager.PROPERTY_MODEL_OPENED) {
        getViewer().refresh();
        IArchimateModel model = (IArchimateModel) evt.getNewValue();
        // Expand and Select new node
        getViewer().expandToLevel(model.getFolder(FolderType.DIAGRAMS), 1);
        getViewer().setSelection(new StructuredSelection(model), true);
    } else // Model removed
    if (propertyName == IEditorModelManager.PROPERTY_MODEL_REMOVED) {
        getViewer().refresh();
    } else // Model dirty state, so update Actions and modified state of source (asterisk on model node)
    if (propertyName == IEditorModelManager.COMMAND_STACK_CHANGED) {
        updateActions();
        getViewer().update(source, null);
    } else // Ecore Events will come so turn tree refresh off
    if (propertyName == IEditorModelManager.PROPERTY_ECORE_EVENTS_START) {
        super.propertyChange(evt);
        // Remove Syncing
        TreeSelectionSynchroniser.INSTANCE.setSynchronise(false);
    } else // Ecore Events have finished so turn tree refresh on
    if (propertyName == IEditorModelManager.PROPERTY_ECORE_EVENTS_END) {
        super.propertyChange(evt);
        // Add Syncing
        TreeSelectionSynchroniser.INSTANCE.setSynchronise(true);
    } else {
        super.propertyChange(evt);
    }
}
Also used : IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) IArchimateModel(com.archimatetool.model.IArchimateModel)

Aggregations

IArchimateModel (com.archimatetool.model.IArchimateModel)124 Test (org.junit.Test)51 File (java.io.File)35 IOException (java.io.IOException)22 IArchimateElement (com.archimatetool.model.IArchimateElement)14 EObject (org.eclipse.emf.ecore.EObject)14 IArchiveManager (com.archimatetool.editor.model.IArchiveManager)13 ArchimateTestModel (com.archimatetool.testingtools.ArchimateTestModel)13 IDiagramModel (com.archimatetool.model.IDiagramModel)12 CommandStack (org.eclipse.gef.commands.CommandStack)11 IFolder (com.archimatetool.model.IFolder)10 ArrayList (java.util.ArrayList)10 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)9 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)9 IArchimateModelObject (com.archimatetool.model.IArchimateModelObject)7 IArchimateDiagramModel (com.archimatetool.model.IArchimateDiagramModel)6 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)6 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)5 IIdentifier (com.archimatetool.model.IIdentifier)5 GraficoModelLoader (org.archicontribs.modelrepository.grafico.GraficoModelLoader)5