Search in sources :

Example 41 with CommandStack

use of org.eclipse.gef.commands.CommandStack in project archi by archimatetool.

the class ImportXMLProvider method run.

@Override
public void run(CommandLine commandLine) throws Exception {
    if (!hasCorrectOptions(commandLine)) {
        return;
    }
    // File
    String value = commandLine.getOptionValue(OPTION_IMPORT_XML);
    if (!StringUtils.isSet(value)) {
        logError(Messages.ImportXMLProvider_1);
        return;
    }
    File importFile = new File(value);
    if (!importFile.exists()) {
        logError(NLS.bind(Messages.ImportXMLProvider_2, value));
        return;
    }
    // Validate file
    logMessage(Messages.ImportXMLProvider_3);
    XMLValidator validator = new XMLValidator();
    validator.validateXML(importFile);
    logMessage(Messages.ImportXMLProvider_4);
    logMessage(NLS.bind(Messages.ImportXMLProvider_5, importFile.getPath()));
    XMLModelImporter importer = new XMLModelImporter();
    IArchimateModel model = importer.createArchiMateModel(importFile);
    if (model == null) {
        throw new IOException(Messages.ImportXMLProvider_6);
    }
    // Add an Archive Manager
    IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(model);
    model.setAdapter(IArchiveManager.class, archiveManager);
    // Add a Command Stack
    CommandStack cmdStack = new CommandStack();
    model.setAdapter(CommandStack.class, cmdStack);
    CommandLineState.setModel(model);
    logMessage(Messages.ImportXMLProvider_7);
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) XMLModelImporter(org.opengroup.archimate.xmlexchange.XMLModelImporter) IOException(java.io.IOException) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) File(java.io.File) IArchimateModel(com.archimatetool.model.IArchimateModel) XMLValidator(org.opengroup.archimate.xmlexchange.XMLValidator)

Example 42 with CommandStack

use of org.eclipse.gef.commands.CommandStack in project archi by archimatetool.

the class DeleteCommandHandlerTests method testDelete_More_Than_One_Model.

@Test
public void testDelete_More_Than_One_Model() throws IOException {
    // Use another instance of the same model
    ArchimateTestModel tm2 = new ArchimateTestModel(TEST_MODEL_FILE);
    IArchimateModel model2 = tm2.loadModelWithCommandStack();
    // Elements
    String[] elementIDs = new String[] { "31a27739", "8ab84e91", "46d0abd5", "8ecabfc2" };
    // Select them from both models
    List<IArchimateElement> elements1 = new ArrayList<IArchimateElement>();
    for (String id : elementIDs) {
        elements1.add((IArchimateElement) ArchimateModelUtils.getObjectByID(model, id));
    }
    List<IArchimateElement> elements2 = new ArrayList<IArchimateElement>();
    for (String id : elementIDs) {
        elements2.add((IArchimateElement) ArchimateModelUtils.getObjectByID(model2, id));
    }
    List<IArchimateElement> allElements = new ArrayList<IArchimateElement>(elements1);
    allElements.addAll(elements2);
    assertEquals(8, allElements.size());
    // Zap
    DeleteCommandHandler commandHandler = new DeleteCommandHandler(treeModelViewer, allElements.toArray());
    commandHandler.delete();
    // Test that they are all gone in the models and in the referenced diagrams
    for (IArchimateElement element : elements1) {
        assertFalse(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
        assertNull(ArchimateModelUtils.getObjectByID(model, element.getId()));
    }
    for (IArchimateElement element : elements2) {
        assertFalse(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
        assertNull(ArchimateModelUtils.getObjectByID(model2, element.getId()));
    }
    // And just for good measure, we'll undo it...once for each model
    CommandStack commandStack1 = (CommandStack) model.getAdapter(CommandStack.class);
    commandStack1.undo();
    CommandStack commandStack2 = (CommandStack) model2.getAdapter(CommandStack.class);
    commandStack2.undo();
    // And find them all back again!
    for (IArchimateElement element : elements1) {
        assertTrue(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
        assertNotNull(ArchimateModelUtils.getObjectByID(model, element.getId()));
    }
    for (IArchimateElement element : elements2) {
        assertTrue(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
        assertNotNull(ArchimateModelUtils.getObjectByID(model2, element.getId()));
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ArrayList(java.util.ArrayList) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateModel(com.archimatetool.model.IArchimateModel) ArchimateTestModel(com.archimatetool.testingtools.ArchimateTestModel) Test(org.junit.Test)

Example 43 with CommandStack

use of org.eclipse.gef.commands.CommandStack 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);
    if (archiveManager == null) {
        archiveManager = IArchiveManager.FACTORY.createArchiveManager(model);
        model.setAdapter(IArchiveManager.class, archiveManager);
    }
    archiveManager.saveModel();
    // Set CommandStack Save point if we have one
    CommandStack stack = (CommandStack) model.getAdapter(CommandStack.class);
    if (stack != null) {
        stack.markSaveLocation();
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) IArchiveManager(com.archimatetool.editor.model.IArchiveManager)

Example 44 with CommandStack

use of org.eclipse.gef.commands.CommandStack in project archi by archimatetool.

the class UserPropertiesManagerDialog method okPressed.

@Override
protected void okPressed() {
    super.okPressed();
    CompoundCommand compoundCmd = new CompoundCommand(Messages.UserPropertiesManagerDialog_11) {

        @Override
        public void execute() {
            BusyIndicator.showWhile(null, new Runnable() {

                @Override
                public void run() {
                    doSuperExecute();
                }
            });
        }

        @Override
        public void undo() {
            BusyIndicator.showWhile(null, new Runnable() {

                @Override
                public void run() {
                    doSuperUndo();
                }
            });
        }

        @Override
        public void redo() {
            BusyIndicator.showWhile(null, new Runnable() {

                @Override
                public void run() {
                    doSuperRedo();
                }
            });
        }

        void doSuperExecute() {
            super.execute();
        }

        void doSuperUndo() {
            super.undo();
        }

        void doSuperRedo() {
            super.redo();
        }
    };
    checkRenames(compoundCmd);
    checkDeletions(compoundCmd);
    CommandStack stack = (CommandStack) fArchimateModel.getAdapter(CommandStack.class);
    stack.execute(compoundCmd.unwrap());
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 45 with CommandStack

use of org.eclipse.gef.commands.CommandStack in project archi by archimatetool.

the class RenameCommandHandler method doRenameCommands.

/**
 * Rename elements to matching newNames by issuing a CompundCommand(s) on the CommandStack(s)
 * @param elements
 * @param newNames
 */
public static void doRenameCommands(List<INameable> elements, List<String> newNames) {
    // Must match sizes
    if (elements.size() != newNames.size() || elements.isEmpty()) {
        return;
    }
    /*
         * If renaming elements from more than one model in the tree we need to use the
         * Command Stack allocated to each model. And then allocate one CompoundCommand per Command Stack.
         */
    Hashtable<CommandStack, CompoundCommand> commandMap = new Hashtable<CommandStack, CompoundCommand>();
    for (int i = 0; i < elements.size(); i++) {
        INameable element = elements.get(i);
        String newName = newNames.get(i);
        CompoundCommand compoundCommand = getCompoundCommand((IAdapter) element, commandMap);
        if (compoundCommand != null) {
            Command cmd = new // $NON-NLS-1$
            EObjectFeatureCommand(// $NON-NLS-1$
            Messages.RenameCommandHandler_0 + " " + element.getName(), // $NON-NLS-1$
            element, IArchimatePackage.Literals.NAMEABLE__NAME, newName);
            compoundCommand.add(cmd);
        } else {
            // $NON-NLS-1$
            System.err.println("Could not get CompoundCommand in doRenameCommands");
        }
    }
    // Execute the Commands on the CommandStack(s) - there could be more than one if more than one model open in the Tree
    for (Entry<CommandStack, CompoundCommand> entry : commandMap.entrySet()) {
        entry.getKey().execute(entry.getValue().unwrap());
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) Command(org.eclipse.gef.commands.Command) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) Hashtable(java.util.Hashtable) INameable(com.archimatetool.model.INameable) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand)

Aggregations

CommandStack (org.eclipse.gef.commands.CommandStack)105 Command (org.eclipse.gef.commands.Command)32 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)14 IArchiveManager (com.archimatetool.editor.model.IArchiveManager)13 AbstractMultiPageTalendEditor (org.talend.designer.core.ui.AbstractMultiPageTalendEditor)13 IArchimateModel (com.archimatetool.model.IArchimateModel)12 ModelTransactionCommand (org.whole.lang.ui.commands.ModelTransactionCommand)12 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)12 NonNotifyingCompoundCommand (com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand)10 EditPart (org.eclipse.gef.EditPart)10 INode (org.talend.core.model.process.INode)10 Node (org.talend.designer.core.ui.editor.nodes.Node)9 IEntity (org.whole.lang.model.IEntity)9 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 PersistenceException (org.talend.commons.exception.PersistenceException)8 EObjectFeatureCommand (com.archimatetool.editor.model.commands.EObjectFeatureCommand)7 IFolder (com.archimatetool.model.IFolder)6 IOException (java.io.IOException)6 IEditorPart (org.eclipse.ui.IEditorPart)6