Search in sources :

Example 86 with CommandStack

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

the class RenameCommandHandler method getCompoundCommand.

/**
 * Get, and if need be create, a CompoundCommand to which to add the object to be renamed command
 */
private static CompoundCommand getCompoundCommand(IAdapter object, Hashtable<CommandStack, CompoundCommand> commandMap) {
    // Get the Command Stack registered to the object
    CommandStack stack = (CommandStack) object.getAdapter(CommandStack.class);
    if (stack == null) {
        // $NON-NLS-1$
        System.err.println("CommandStack was null in getCompoundCommand");
        return null;
    }
    // Now get or create a Compound Command
    CompoundCommand compoundCommand = commandMap.get(stack);
    if (compoundCommand == null) {
        compoundCommand = new NonNotifyingCompoundCommand(Messages.RenameCommandHandler_0);
        commandMap.put(stack, compoundCommand);
    }
    return compoundCommand;
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand)

Example 87 with CommandStack

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

the class TreeModelViewerDragDropHandler method moveTreeObjects.

/**
 * Move Tree Objects
 */
void moveTreeObjects(IFolder newParent, Object[] objects) {
    final CompoundCommand compoundCommand = new NonNotifyingCompoundCommand() {

        @Override
        public String getLabel() {
            return getCommands().size() > 1 ? Messages.TreeModelViewerDragDropHandler_0 : super.getLabel();
        }
    };
    for (Object object : objects) {
        if (object instanceof IFolder) {
            // This first - folders go in folders
            if (!newParent.getFolders().contains(object)) {
                compoundCommand.add(new MoveFolderCommand(newParent, (IFolder) object));
            }
        } else if (object instanceof IArchimateModelObject) {
            if (!newParent.getElements().contains(object)) {
                compoundCommand.add(new MoveObjectCommand(newParent, (IArchimateModelObject) object));
            }
        }
    }
    CommandStack stack = (CommandStack) newParent.getAdapter(CommandStack.class);
    stack.execute(compoundCommand);
}
Also used : NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) CommandStack(org.eclipse.gef.commands.CommandStack) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) MoveFolderCommand(com.archimatetool.editor.views.tree.commands.MoveFolderCommand) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) EObject(org.eclipse.emf.ecore.EObject) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) IFolder(com.archimatetool.model.IFolder) MoveObjectCommand(com.archimatetool.editor.views.tree.commands.MoveObjectCommand)

Example 88 with CommandStack

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

the class ArchimateTestModel method loadModelWithCommandStack.

/**
 * Load the Archimate model with a Command Stack added
 * @return The model
 * @throws IOException
 */
public IArchimateModel loadModelWithCommandStack() throws IOException {
    model = loadModel();
    // Add a Command Stack
    CommandStack cmdStack = new CommandStack();
    model.setAdapter(CommandStack.class, cmdStack);
    return model;
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack)

Example 89 with CommandStack

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

the class ArchimateTestModel method createNewModel.

/**
 * Replica of EditorModelManager#createNewModel()
 * Adds Command Stack and ArchiveManager
 */
public IArchimateModel createNewModel() {
    model = IArchimateFactory.eINSTANCE.createArchimateModel();
    model.setDefaults();
    // Add one default diagram model
    addNewArchimateDiagramModel();
    // Add a Command Stack
    CommandStack cmdStack = new CommandStack();
    model.setAdapter(CommandStack.class, cmdStack);
    // Add an Archive Manager
    IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(model);
    model.setAdapter(IArchiveManager.class, archiveManager);
    return model;
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) IArchiveManager(com.archimatetool.editor.model.IArchiveManager)

Example 90 with CommandStack

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

the class CreateMapViewCheatSheetAction method run.

@Override
public void run(String[] params, ICheatSheetManager manager) {
    IViewPart viewPart = ViewManager.showViewPart(ITreeModelView.ID, true);
    if (viewPart == null) {
        MessageDialog.openWarning(Display.getCurrent().getActiveShell(), Messages.CreateMapViewCheatSheetAction_0, Messages.CreateMapViewCheatSheetAction_1);
        return;
    }
    IArchimateModel model = viewPart.getAdapter(IArchimateModel.class);
    if (model == null) {
        MessageDialog.openWarning(Display.getCurrent().getActiveShell(), Messages.CreateMapViewCheatSheetAction_2, Messages.CreateMapViewCheatSheetAction_3);
        return;
    }
    EList<IDiagramModel> diagramModels = model.getDiagramModels();
    if (diagramModels.size() < 2) {
        MessageDialog.openWarning(Display.getCurrent().getActiveShell(), Messages.CreateMapViewCheatSheetAction_4, Messages.CreateMapViewCheatSheetAction_5);
        return;
    }
    CommandStack stack = (CommandStack) model.getAdapter(CommandStack.class);
    if (stack != null) {
        stack.execute(new NewMapViewCommand(model));
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) IViewPart(org.eclipse.ui.IViewPart) IDiagramModel(com.archimatetool.model.IDiagramModel) IArchimateModel(com.archimatetool.model.IArchimateModel)

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