Search in sources :

Example 1 with GraficoModelImporter

use of org.archicontribs.modelrepository.grafico.GraficoModelImporter 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 2 with GraficoModelImporter

use of org.archicontribs.modelrepository.grafico.GraficoModelImporter 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)2 IOException (java.io.IOException)2 GraficoModelImporter (org.archicontribs.modelrepository.grafico.GraficoModelImporter)2 IArchiveManager (com.archimatetool.editor.model.IArchiveManager)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1 ObjectLoader (org.eclipse.jgit.lib.ObjectLoader)1 Repository (org.eclipse.jgit.lib.Repository)1 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)1