Search in sources :

Example 56 with IArchimateModel

use of com.archimatetool.model.IArchimateModel in project archi-modelrepository-plugin by archi-contribs.

the class AbortChangesHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IArchimateModel model = getActiveArchimateModel();
    if (model != null) {
        AbortChangesAction action = new AbortChangesAction(HandlerUtil.getActiveWorkbenchWindowChecked(event), model);
        action.run();
    }
    return null;
}
Also used : IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 57 with IArchimateModel

use of com.archimatetool.model.IArchimateModel in project archi-modelrepository-plugin by archi-contribs.

the class DeleteModelAction method run.

@Override
public void run() {
    boolean confirm = MessageDialog.openConfirm(fWindow.getShell(), Messages.DeleteModelAction_0, Messages.DeleteModelAction_2);
    if (!confirm) {
        return;
    }
    try {
        // See if the model is open and close it if it is
        IArchimateModel model = getRepository().locateModel();
        if (model != null) {
            boolean didClose = IEditorModelManager.INSTANCE.closeModel(model);
            if (!didClose) {
                return;
            }
        }
        // Delete folder
        FileUtils.deleteFolder(getRepository().getLocalRepositoryFolder());
        // Notify
        RepositoryListenerManager.INSTANCE.fireRepositoryChangedEvent(IRepositoryListener.REPOSITORY_DELETED, getRepository());
    } catch (IOException ex) {
        displayErrorDialog(Messages.DeleteModelAction_0, ex);
    }
}
Also used : IOException(java.io.IOException) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 58 with IArchimateModel

use of com.archimatetool.model.IArchimateModel in project archi-modelrepository-plugin by archi-contribs.

the class DeleteModelHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IArchimateModel model = getActiveArchimateModel();
    if (model != null) {
        DeleteModelAction action = new DeleteModelAction(HandlerUtil.getActiveWorkbenchWindowChecked(event), model);
        action.run();
    }
    return null;
}
Also used : IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 59 with IArchimateModel

use of com.archimatetool.model.IArchimateModel in project archi-modelrepository-plugin by archi-contribs.

the class ExtractModelFromCommitAction method run.

@Override
public void run() {
    File tempOutputFolder = getTempFolder();
    deleteFolder(tempOutputFolder);
    // Wlak the tree and get the contents of the commit
    try (Repository repository = Git.open(getRepository().getLocalRepositoryFolder()).getRepository()) {
        try (TreeWalk treeWalk = new TreeWalk(repository)) {
            treeWalk.addTree(fCommit.getTree());
            treeWalk.setRecursive(true);
            while (treeWalk.next()) {
                ObjectId objectId = treeWalk.getObjectId(0);
                ObjectLoader loader = repository.open(objectId);
                File file = new File(tempOutputFolder, treeWalk.getPathString());
                file.getParentFile().mkdirs();
                try (FileOutputStream out = new FileOutputStream(file)) {
                    loader.copyTo(out);
                }
            }
        }
    } catch (IOException ex) {
        displayErrorDialog(Messages.ExtractModelFromCommitAction_1, ex);
    }
    // Open the model with no file name
    try {
        GraficoModelImporter importer = new GraficoModelImporter(tempOutputFolder);
        IArchimateModel graficoModel = importer.importAsModel();
        if (graficoModel != null) {
            // Open it, this will do the necessary checks and add a command stack and an archive manager
            IEditorModelManager.INSTANCE.openModel(graficoModel);
            // Set model name
            // $NON-NLS-1$ //$NON-NLS-2$
            graficoModel.setName(graficoModel.getName() + " (" + fCommit.getName().substring(0, 8) + ")");
        } else {
            MessageDialog.openError(fWindow.getShell(), Messages.ExtractModelFromCommitAction_1, Messages.ExtractModelFromCommitAction_2);
        }
    } catch (IOException ex) {
        displayErrorDialog(Messages.ExtractModelFromCommitAction_1, ex);
    }
    // Clean up
    deleteFolder(tempOutputFolder);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ObjectId(org.eclipse.jgit.lib.ObjectId) FileOutputStream(java.io.FileOutputStream) ObjectLoader(org.eclipse.jgit.lib.ObjectLoader) IOException(java.io.IOException) File(java.io.File) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) GraficoModelImporter(org.archicontribs.modelrepository.grafico.GraficoModelImporter) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 60 with IArchimateModel

use of com.archimatetool.model.IArchimateModel in project archi-modelrepository-plugin by archi-contribs.

the class LoadModelFromRepositoryProvider method loadModel.

private IArchimateModel loadModel(File folder) throws IOException {
    GraficoModelImporter importer = new GraficoModelImporter(folder);
    IArchimateModel model = importer.importAsModel();
    if (importer.getUnresolvedObjects() != null) {
        throw new IOException(Messages.LoadModelFromRepositoryProvider_8);
    }
    // Add an Archive Manager and load images
    IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(model);
    model.setAdapter(IArchiveManager.class, archiveManager);
    archiveManager.loadImages();
    CommandLineState.setModel(model);
    return model;
}
Also used : IOException(java.io.IOException) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) GraficoModelImporter(org.archicontribs.modelrepository.grafico.GraficoModelImporter) 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