Search in sources :

Example 1 with NewDiagramCommand

use of com.archimatetool.editor.views.tree.commands.NewDiagramCommand in project archi by archimatetool.

the class TreeModelViewActionFactory method createNewSketchAction.

private IAction createNewSketchAction(final IFolder folder) {
    IAction action = new Action(Messages.TreeModelViewActionFactory_2) {

        @Override
        public void run() {
            // Create a new Diagram Model, set its name
            ISketchModel sketchModel = IArchimateFactory.eINSTANCE.createSketchModel();
            sketchModel.setName(Messages.TreeModelViewActionFactory_3);
            // Defaults
            int defaultBackground = Preferences.STORE.getInt(IPreferenceConstants.SKETCH_DEFAULT_BACKGROUND);
            sketchModel.setBackground(defaultBackground);
            // Execute Command
            Command cmd = new NewDiagramCommand(folder, sketchModel, Messages.TreeModelViewActionFactory_3);
            CommandStack commandStack = (CommandStack) folder.getAdapter(CommandStack.class);
            commandStack.execute(cmd);
        }
    };
    action.setImageDescriptor(IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_SKETCH));
    return action;
}
Also used : NewDiagramCommand(com.archimatetool.editor.views.tree.commands.NewDiagramCommand) CommandStack(org.eclipse.gef.commands.CommandStack) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) IAction(org.eclipse.jface.action.IAction) NewDiagramCommand(com.archimatetool.editor.views.tree.commands.NewDiagramCommand) Command(org.eclipse.gef.commands.Command) NewElementCommand(com.archimatetool.editor.views.tree.commands.NewElementCommand) ISketchModel(com.archimatetool.model.ISketchModel)

Example 2 with NewDiagramCommand

use of com.archimatetool.editor.views.tree.commands.NewDiagramCommand in project archi by archimatetool.

the class NewCanvasFromTemplateWizard method createNewCanvasFromTemplate.

private void createNewCanvasFromTemplate(File file) throws IncompatibleModelException, IOException {
    // Ascertain if this is a zip file
    boolean isArchiveFormat = IArchiveManager.FACTORY.isArchiveFile(file);
    Resource resource = ArchimateResourceFactory.createNewResource(isArchiveFormat ? IArchiveManager.FACTORY.createArchiveModelURI(file) : URI.createFileURI(file.getAbsolutePath()));
    // Check model compatibility
    ModelCompatibility modelCompatibility = new ModelCompatibility(resource);
    // Wrap in try/catch to load as much as possible
    try {
        resource.load(null);
    } catch (IOException ex) {
        // Error occured loading model. Was it a disaster?
        try {
            modelCompatibility.checkErrors();
        }// Incompatible
         catch (IncompatibleModelException ex1) {
            fErrorMessage = NLS.bind(Messages.NewCanvasFromTemplateWizard_4, file) + "\n" + // $NON-NLS-1$
            ex1.getMessage();
            throw ex1;
        }
    }
    // And then fix any backward compatibility issues
    try {
        modelCompatibility.fixCompatibility();
    } catch (CompatibilityHandlerException ex) {
    }
    // Pull out the Canvas model
    IArchimateModel templateModel = (IArchimateModel) resource.getContents().get(0);
    IFolder folderViews = templateModel.getFolder(FolderType.DIAGRAMS);
    ICanvasModel canvasModel = (ICanvasModel) folderViews.getElements().get(0);
    // Create New UUIDs for elements...
    TemplateUtils.generateNewUUIDs(canvasModel);
    // Load the images from the template model's file now
    if (isArchiveFormat) {
        IArchiveManager archiveManager = (IArchiveManager) fFolder.getAdapter(IArchiveManager.class);
        archiveManager.loadImagesFromModelFile(file);
    }
    Command cmd = new NewDiagramCommand(fFolder, canvasModel, Messages.NewCanvasFromTemplateWizard_5);
    CommandStack commandStack = (CommandStack) fFolder.getAdapter(CommandStack.class);
    commandStack.execute(cmd);
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) Resource(org.eclipse.emf.ecore.resource.Resource) CompatibilityHandlerException(com.archimatetool.editor.model.compatibility.CompatibilityHandlerException) IOException(java.io.IOException) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) IncompatibleModelException(com.archimatetool.editor.model.compatibility.IncompatibleModelException) NewDiagramCommand(com.archimatetool.editor.views.tree.commands.NewDiagramCommand) NewDiagramCommand(com.archimatetool.editor.views.tree.commands.NewDiagramCommand) Command(org.eclipse.gef.commands.Command) ModelCompatibility(com.archimatetool.editor.model.compatibility.ModelCompatibility) ICanvasModel(com.archimatetool.canvas.model.ICanvasModel) IArchimateModel(com.archimatetool.model.IArchimateModel) IFolder(com.archimatetool.model.IFolder)

Example 3 with NewDiagramCommand

use of com.archimatetool.editor.views.tree.commands.NewDiagramCommand in project archi by archimatetool.

the class TreeModelViewActionFactory method createNewArchimateDiagramAction.

private IAction createNewArchimateDiagramAction(final IFolder folder) {
    IAction action = new Action(Messages.TreeModelViewActionFactory_0) {

        @Override
        public void run() {
            // Create a new Diagram Model, set its name
            IDiagramModel diagramModel = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
            diagramModel.setName(Messages.TreeModelViewActionFactory_1);
            // Execute Command
            Command cmd = new NewDiagramCommand(folder, diagramModel, Messages.TreeModelViewActionFactory_1);
            CommandStack commandStack = (CommandStack) folder.getAdapter(CommandStack.class);
            commandStack.execute(cmd);
        }
    };
    action.setImageDescriptor(IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_DIAGRAM));
    return action;
}
Also used : NewDiagramCommand(com.archimatetool.editor.views.tree.commands.NewDiagramCommand) CommandStack(org.eclipse.gef.commands.CommandStack) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) IAction(org.eclipse.jface.action.IAction) IDiagramModel(com.archimatetool.model.IDiagramModel) NewDiagramCommand(com.archimatetool.editor.views.tree.commands.NewDiagramCommand) Command(org.eclipse.gef.commands.Command) NewElementCommand(com.archimatetool.editor.views.tree.commands.NewElementCommand)

Aggregations

NewDiagramCommand (com.archimatetool.editor.views.tree.commands.NewDiagramCommand)3 Command (org.eclipse.gef.commands.Command)3 CommandStack (org.eclipse.gef.commands.CommandStack)3 NewElementCommand (com.archimatetool.editor.views.tree.commands.NewElementCommand)2 Action (org.eclipse.jface.action.Action)2 IAction (org.eclipse.jface.action.IAction)2 ICanvasModel (com.archimatetool.canvas.model.ICanvasModel)1 IArchiveManager (com.archimatetool.editor.model.IArchiveManager)1 CompatibilityHandlerException (com.archimatetool.editor.model.compatibility.CompatibilityHandlerException)1 IncompatibleModelException (com.archimatetool.editor.model.compatibility.IncompatibleModelException)1 ModelCompatibility (com.archimatetool.editor.model.compatibility.ModelCompatibility)1 IArchimateModel (com.archimatetool.model.IArchimateModel)1 IDiagramModel (com.archimatetool.model.IDiagramModel)1 IFolder (com.archimatetool.model.IFolder)1 ISketchModel (com.archimatetool.model.ISketchModel)1 IOException (java.io.IOException)1 Resource (org.eclipse.emf.ecore.resource.Resource)1