Search in sources :

Example 1 with IArchiveManager

use of com.archimatetool.editor.model.IArchiveManager in project archi by archimatetool.

the class SaveModelProvider method saveModel.

private void saveModel(IArchimateModel model, File file) throws IOException {
    // Set model version
    model.setVersion(ModelVersion.VERSION);
    // File
    model.setFile(file);
    // Use Archive Manager to save contents
    IArchiveManager archiveManager = (IArchiveManager) model.getAdapter(IArchiveManager.class);
    archiveManager.saveModel();
    // Set CommandStack Save point
    CommandStack stack = (CommandStack) model.getAdapter(CommandStack.class);
    stack.markSaveLocation();
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) IArchiveManager(com.archimatetool.editor.model.IArchiveManager)

Example 2 with IArchiveManager

use of com.archimatetool.editor.model.IArchiveManager in project archi by archimatetool.

the class EditorModelManager method saveModel.

@Override
public boolean saveModel(IArchimateModel model) throws IOException {
    // Check integrity
    ModelChecker checker = new ModelChecker(model);
    if (!checker.checkAll()) {
        if (PlatformUI.isWorkbenchRunning()) {
            checker.showErrorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
        }
        return false;
    }
    // First time to save...
    if (model.getFile() == null) {
        File file = askSaveModel();
        if (file == null) {
            // cancelled
            return false;
        }
        model.setFile(file);
    }
    File file = model.getFile();
    // Save backup (if set in Preferences)
    if (Preferences.STORE.getBoolean(IPreferenceConstants.BACKUP_ON_SAVE) && file.exists()) {
        // $NON-NLS-1$
        FileUtils.copyFile(file, new File(model.getFile().getAbsolutePath() + ".bak"), false);
    }
    // Set model version
    model.setVersion(ModelVersion.VERSION);
    // Use Archive Manager to save contents
    IArchiveManager archiveManager = (IArchiveManager) model.getAdapter(IArchiveManager.class);
    archiveManager.saveModel();
    // Set CommandStack Save point
    CommandStack stack = (CommandStack) model.getAdapter(CommandStack.class);
    stack.markSaveLocation();
    // Send notification to Tree
    firePropertyChange(model, COMMAND_STACK_CHANGED, true, false);
    // Set all diagram models to be marked as "saved" - this is for the editor view persistence
    markDiagramModelsAsSaved(model);
    firePropertyChange(this, PROPERTY_MODEL_SAVED, null, model);
    return true;
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ModelChecker(com.archimatetool.editor.model.ModelChecker) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) File(java.io.File)

Example 3 with IArchiveManager

use of com.archimatetool.editor.model.IArchiveManager in project archi by archimatetool.

the class EditorModelManager method createNewArchiveManager.

/**
 * Create a new ArchiveManager for the model
 */
private IArchiveManager createNewArchiveManager(IArchimateModel model) {
    IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(model);
    model.setAdapter(IArchiveManager.class, archiveManager);
    // Load images now
    try {
        archiveManager.loadImages();
    } catch (IOException ex) {
        // $NON-NLS-1$
        Logger.logError("Could not load images", ex);
        ex.printStackTrace();
    }
    return archiveManager;
}
Also used : IOException(java.io.IOException) IArchiveManager(com.archimatetool.editor.model.IArchiveManager)

Example 4 with IArchiveManager

use of com.archimatetool.editor.model.IArchiveManager in project archi by archimatetool.

the class DiagramModelImageSection method setImage.

protected void setImage(Object selected) {
    String path = null;
    try {
        // User selected a file
        if (selected instanceof File) {
            File file = (File) selected;
            if (!file.exists() || !file.canRead()) {
                return;
            }
            IArchiveManager archiveManager = (IArchiveManager) ((IAdapter) getFirstSelectedObject()).getAdapter(IArchiveManager.class);
            path = archiveManager.addImageFromFile(file);
        } else // User selected a Gallery image path
        if (selected instanceof String) {
            path = (String) selected;
        } else // User selected nothing
        {
            return;
        }
    } catch (IOException ex) {
        ex.printStackTrace();
        MessageDialog.openError(getPart().getSite().getShell(), Messages.DiagramModelImageSection_5, Messages.DiagramModelImageSection_6);
        return;
    }
    CompoundCommand result = new CompoundCommand();
    for (EObject dmo : getEObjects()) {
        if (isAlive(dmo)) {
            Command cmd = new EObjectFeatureCommand(Messages.DiagramModelImageSection_7, dmo, IArchimatePackage.Literals.DIAGRAM_MODEL_IMAGE_PROVIDER__IMAGE_PATH, path);
            if (cmd.canExecute()) {
                result.add(cmd);
            }
        }
    }
    executeCommand(result.unwrap());
}
Also used : CompoundCommand(org.eclipse.gef.commands.CompoundCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) Command(org.eclipse.gef.commands.Command) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) EObject(org.eclipse.emf.ecore.EObject) IOException(java.io.IOException) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) File(java.io.File) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 5 with IArchiveManager

use of com.archimatetool.editor.model.IArchiveManager in project archi by archimatetool.

the class EditorModelManagerTests method createNewModel_IsValid.

@Test
public void createNewModel_IsValid() {
    IArchimateModel model = editorModelManager.createNewModel();
    assertNotNull(model);
    // Has default folders
    assertFalse(model.getFolders().isEmpty());
    // Has One Default View
    // $NON-NLS-1$
    assertTrue(model.getFolder(FolderType.DIAGRAMS).getElements().get(0) instanceof IArchimateDiagramModel);
    // Has a Command Stack
    assertTrue(model.getAdapter(CommandStack.class) instanceof CommandStack);
    // Has an Archive Manager
    assertTrue(model.getAdapter(IArchiveManager.class) instanceof IArchiveManager);
    // Has an ECore Adapter
    assertTrue(hasECoreAdapter(model));
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) IArchimateModel(com.archimatetool.model.IArchimateModel) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel) Test(org.junit.Test)

Aggregations

IArchiveManager (com.archimatetool.editor.model.IArchiveManager)23 IArchimateModel (com.archimatetool.model.IArchimateModel)11 CommandStack (org.eclipse.gef.commands.CommandStack)9 File (java.io.File)7 IOException (java.io.IOException)5 Image (org.eclipse.swt.graphics.Image)4 EObject (org.eclipse.emf.ecore.EObject)3 Test (org.junit.Test)3 ICanvasModel (com.archimatetool.canvas.model.ICanvasModel)2 CompatibilityHandlerException (com.archimatetool.editor.model.compatibility.CompatibilityHandlerException)2 ModelCompatibility (com.archimatetool.editor.model.compatibility.ModelCompatibility)2 IFolder (com.archimatetool.model.IFolder)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 Command (org.eclipse.gef.commands.Command)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 ICanvasModelImage (com.archimatetool.canvas.model.ICanvasModelImage)1 IIconic (com.archimatetool.canvas.model.IIconic)1 AddDiagramObjectCommand (com.archimatetool.editor.diagram.commands.AddDiagramObjectCommand)1 ModelChecker (com.archimatetool.editor.model.ModelChecker)1 EObjectFeatureCommand (com.archimatetool.editor.model.commands.EObjectFeatureCommand)1