Search in sources :

Example 91 with CommandStack

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

the class DeleteCommandHandlerTests method testDelete_Elements.

@Test
public void testDelete_Elements() {
    String[] elementIDs = new String[] { "31a27739", "8ab84e91", "46d0abd5", "8ecabfc2" };
    List<IArchimateElement> elements = new ArrayList<IArchimateElement>();
    for (String id : elementIDs) {
        elements.add((IArchimateElement) ArchimateModelUtils.getObjectByID(model, id));
    }
    // Ensure these elements are referenced in diagrams
    for (IArchimateElement element : elements) {
        assertTrue(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
    }
    // Delete them
    DeleteCommandHandler commandHandler = new DeleteCommandHandler(treeModelViewer, elements.toArray());
    commandHandler.delete();
    // Test that they are all gone in the model and in the referenced diagrams
    for (IArchimateElement element : elements) {
        assertFalse(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
        assertNull(ArchimateModelUtils.getObjectByID(model, element.getId()));
    }
    // And just for good measure, we'll undo it
    CommandStack commandStack = (CommandStack) model.getAdapter(CommandStack.class);
    commandStack.undo();
    // And find them all back again!
    for (IArchimateElement element : elements) {
        assertTrue(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
        assertNotNull(ArchimateModelUtils.getObjectByID(model, element.getId()));
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ArrayList(java.util.ArrayList) IArchimateElement(com.archimatetool.model.IArchimateElement) Test(org.junit.Test)

Example 92 with CommandStack

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

the class AbstractDiagramEditor method setInput.

@Override
public void setInput(IEditorInput input) {
    super.setInput(input);
    // This first - set model
    fDiagramModel = ((DiagramEditorInput) input).getDiagramModel();
    // Listen to notifications from diagram model and main model for name changes to update part
    eCoreAdapter.add(fDiagramModel, fDiagramModel.getArchimateModel());
    // Edit Domain before init
    // Use CommandStack from Model
    DefaultEditDomain domain = new DefaultEditDomain(this) {

        private CommandStack stack;

        @Override
        public CommandStack getCommandStack() {
            if (stack == null) {
                stack = (CommandStack) fDiagramModel.getAdapter(CommandStack.class);
            }
            return stack;
        }
    };
    setEditDomain(domain);
    // Part Name
    setPartName(input.getName());
    // Listen to App Prefs changes
    ArchiPlugin.PREFERENCES.addPropertyChangeListener(appPreferencesListener);
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) DefaultEditDomain(org.eclipse.gef.DefaultEditDomain)

Example 93 with CommandStack

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

the class DiagramEditorFindReplaceProvider method doReplaceStringCommand.

void doReplaceStringCommand(EditPart editPart, String newText) {
    Command command = createCommand(editPart, newText);
    CommandStack stack = (CommandStack) ((IAdapter) editPart.getModel()).getAdapter(CommandStack.class);
    if (command != null && stack != null) {
        stack.execute(command);
    }
}
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)

Example 94 with CommandStack

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

the class ConnectionRouterAction method run.

@Override
public void run() {
    if (isChecked()) {
        CommandStack stack = part.getAdapter(CommandStack.class);
        stack.execute(new ConnectionRouterTypeCommand(diagramModel, getType()));
    }
}
Also used : ConnectionRouterTypeCommand(com.archimatetool.editor.diagram.commands.ConnectionRouterTypeCommand) CommandStack(org.eclipse.gef.commands.CommandStack)

Example 95 with CommandStack

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

the class EditorModelManager method load.

@Override
public IArchimateModel load(File file) throws IOException {
    if (file == null || !file.exists()) {
        return null;
    }
    // Create the Resource
    Resource resource = IArchiveManager.FACTORY.createResource(file);
    // Check model compatibility
    ModelCompatibility modelCompatibility = new ModelCompatibility(resource);
    // Load the model file
    try {
        resource.load(null);
    } catch (IOException ex) {
        // Error occured loading model.
        try {
            modelCompatibility.checkErrors();
        } catch (IncompatibleModelException ex1) {
            // $NON-NLS-1$
            throw new IOException(NLS.bind(Messages.EditorModelManager_10, file) + "\n" + ex1.getMessage());
        }
    }
    IArchimateModel model = (IArchimateModel) resource.getContents().get(0);
    // And then fix any backward compatibility issues
    try {
        modelCompatibility.fixCompatibility();
    } catch (CompatibilityHandlerException ex) {
    }
    // Set file
    model.setFile(file);
    // Check defaults
    model.setDefaults();
    // New Command Stack
    CommandStack cmdStack = new CommandStack();
    model.setAdapter(CommandStack.class, cmdStack);
    // New Archive Manager and load images
    IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(model);
    model.setAdapter(IArchiveManager.class, archiveManager);
    archiveManager.loadImages();
    return model;
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ModelCompatibility(com.archimatetool.editor.model.compatibility.ModelCompatibility) Resource(org.eclipse.emf.ecore.resource.Resource) CompatibilityHandlerException(com.archimatetool.editor.model.compatibility.CompatibilityHandlerException) IOException(java.io.IOException) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) IArchimateModel(com.archimatetool.model.IArchimateModel) IncompatibleModelException(com.archimatetool.editor.model.compatibility.IncompatibleModelException)

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