Search in sources :

Example 16 with IArchimateModel

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

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

the class ExportCSVProvider method run.

@Override
public void run(CommandLine commandLine) throws Exception {
    if (!hasCorrectOptions(commandLine)) {
        return;
    }
    IArchimateModel model = CommandLineState.getModel();
    if (model == null) {
        throw new IOException(Messages.ExportCSVProvider_1);
    }
    // Folder
    String value = commandLine.getOptionValue(OPTION_EXPORT_CSV);
    if (!StringUtils.isSet(value)) {
        logError(Messages.ExportCSVProvider_2);
        return;
    }
    File folderOutput = new File(value);
    folderOutput.mkdirs();
    if (!folderOutput.exists()) {
        logError(NLS.bind(Messages.ExportCSVProvider_3, value));
        return;
    }
    CSVExporter exporter = new CSVExporter(model);
    // Delimiter
    value = commandLine.getOptionValue(OPTION_DELIMITER);
    if (StringUtils.isSet(value)) {
        switch(value) {
            case // $NON-NLS-1$
            "\\t":
                exporter.setDelimiter('\t');
                break;
            case // $NON-NLS-1$
            ";":
                exporter.setDelimiter(';');
                break;
            default:
                exporter.setDelimiter(',');
                break;
        }
    }
    // File prefix
    value = commandLine.getOptionValue(OPTION_FILE_PREFIX);
    if (StringUtils.isSet(value)) {
        exporter.setFilePrefix(value);
    }
    // Encoding
    value = commandLine.getOptionValue(OPTION_ENCODING);
    if (StringUtils.isSet(value)) {
        exporter.setEncoding(value);
    }
    // Use leading
    exporter.setUseLeadingCharsHack(commandLine.hasOption(OPTION_LEADING_CHARS_HACK));
    // Strip newlines
    exporter.setStripNewLines(commandLine.hasOption(OPTION_STRIP_NEW_LINES));
    logMessage(NLS.bind(Messages.ExportCSVProvider_4, model.getName(), folderOutput.getPath()));
    exporter.export(folderOutput);
    logMessage(Messages.ExportCSVProvider_5);
}
Also used : CSVExporter(com.archimatetool.csv.export.CSVExporter) IOException(java.io.IOException) IArchimateModel(com.archimatetool.model.IArchimateModel) File(java.io.File)

Example 18 with IArchimateModel

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

the class SaveAction method updateState.

@Override
public void updateState() {
    IArchimateModel model = getActiveArchimateModel();
    setEnabled(IEditorModelManager.INSTANCE.isModelDirty(model));
}
Also used : IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 19 with IArchimateModel

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

the class EditorModelManager method createNewModel.

@Override
public IArchimateModel createNewModel() {
    IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
    model.setName(Messages.EditorModelManager_0);
    model.setDefaults();
    // Add one default diagram
    IDiagramModel diagramModel = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
    diagramModel.setName(Messages.EditorModelManager_1);
    model.getFolder(FolderType.DIAGRAMS).getElements().add(diagramModel);
    // Register
    registerModel(model);
    return model;
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 20 with IArchimateModel

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

the class EditorModelManager method askSaveModel.

/**
 * Ask user for file name to save model
 * @return the file or null
 */
private File askSaveModel() {
    // On Mac if the app is minimised in the dock Display.getCurrent().getActiveShell() will return null
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    // Get focus on Mac
    shell.setActive();
    FileDialog dialog = new FileDialog(shell, SWT.SAVE);
    // $NON-NLS-1$
    dialog.setFilterExtensions(new String[] { ARCHIMATE_FILE_WILDCARD, "*.*" });
    String path = dialog.open();
    if (path == null) {
        return null;
    }
    // Only Windows adds the extension by default
    if (dialog.getFilterIndex() == 0 && !path.endsWith(ARCHIMATE_FILE_EXTENSION)) {
        path += ARCHIMATE_FILE_EXTENSION;
    }
    File file = new File(path);
    // Make sure we don't already have it open
    for (IArchimateModel m : getModels()) {
        if (file.equals(m.getFile())) {
            MessageDialog.openWarning(shell, Messages.EditorModelManager_8, NLS.bind(Messages.EditorModelManager_9, file));
            return null;
        }
    }
    // Make sure the file does not already exist
    if (file.exists()) {
        boolean result = MessageDialog.openQuestion(shell, Messages.EditorModelManager_10, NLS.bind(Messages.EditorModelManager_11, file));
        if (!result) {
            return null;
        }
    }
    return file;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) 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