Search in sources :

Example 81 with CommandStack

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

the class PasteAction method run.

@Override
public void run() {
    if (!hasValidSelection()) {
        setEnabled(false);
        return;
    }
    IFolder parent = (IFolder) getSelection().getFirstElement();
    CompoundCommand compoundCommand = new NonNotifyingCompoundCommand() {

        @Override
        public String getLabel() {
            return getCommands().size() > 1 ? Messages.PasteAction_1 : super.getLabel();
        }
    };
    for (IArchimateModelObject selected : TreeModelCutAndPaste.INSTANCE.getObjects()) {
        if (isAllowedToPaste(parent, selected)) {
            if (selected instanceof IFolder) {
                // This first - folders go in folders
                compoundCommand.add(new MoveFolderCommand(parent, (IFolder) selected));
            } else {
                compoundCommand.add(new MoveObjectCommand(parent, selected));
            }
        }
    }
    CommandStack commandStack = (CommandStack) parent.getAdapter(CommandStack.class);
    if (commandStack != null) {
        commandStack.execute(compoundCommand);
        TreeModelCutAndPaste.INSTANCE.clear();
        ((TreeViewer) getSelectionProvider()).expandToLevel(parent, 1);
    }
}
Also used : NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) CommandStack(org.eclipse.gef.commands.CommandStack) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) TreeViewer(org.eclipse.jface.viewers.TreeViewer) MoveFolderCommand(com.archimatetool.editor.views.tree.commands.MoveFolderCommand) IFolder(com.archimatetool.model.IFolder) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) MoveObjectCommand(com.archimatetool.editor.views.tree.commands.MoveObjectCommand)

Example 82 with CommandStack

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

the class TreeModelViewActionFactory method createNewFolderAction.

private IAction createNewFolderAction(final IFolder folder) {
    IAction action = new Action(Messages.NewFolderAction_0) {

        @Override
        public void run() {
            // Create a new Folder, set its name
            IFolder newFolder = IArchimateFactory.eINSTANCE.createFolder();
            newFolder.setName(Messages.NewFolderAction_1);
            newFolder.setType(FolderType.USER);
            // Execute Command
            Command cmd = new NewFolderCommand(folder, newFolder);
            CommandStack commandStack = (CommandStack) folder.getAdapter(CommandStack.class);
            commandStack.execute(cmd);
        }
    };
    IObjectUIProvider provider = ObjectUIFactory.INSTANCE.getProvider(folder);
    action.setImageDescriptor(provider.getImageDescriptor());
    return action;
}
Also used : 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) NewFolderCommand(com.archimatetool.editor.views.tree.commands.NewFolderCommand) Command(org.eclipse.gef.commands.Command) NewElementCommand(com.archimatetool.editor.views.tree.commands.NewElementCommand) NewFolderCommand(com.archimatetool.editor.views.tree.commands.NewFolderCommand) IFolder(com.archimatetool.model.IFolder) IObjectUIProvider(com.archimatetool.editor.ui.factory.IObjectUIProvider)

Example 83 with CommandStack

use of org.eclipse.gef.commands.CommandStack 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) NewFolderCommand(com.archimatetool.editor.views.tree.commands.NewFolderCommand) Command(org.eclipse.gef.commands.Command) NewElementCommand(com.archimatetool.editor.views.tree.commands.NewElementCommand)

Example 84 with CommandStack

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

the class TreeModelViewActionFactory method createNewElementAction.

private IAction createNewElementAction(final IFolder folder, final EClass eClass) {
    IAction action = new Action(ArchiLabelProvider.INSTANCE.getDefaultName(eClass)) {

        @Override
        public void run() {
            // Create a new Archimate Element, set its name
            IArchimateElement element = (IArchimateElement) IArchimateFactory.eINSTANCE.create(eClass);
            element.setName(getText());
            // Execute Command
            Command cmd = new NewElementCommand(folder, element);
            CommandStack commandStack = (CommandStack) folder.getAdapter(CommandStack.class);
            commandStack.execute(cmd);
        }
    };
    action.setImageDescriptor(ArchiLabelProvider.INSTANCE.getImageDescriptor(eClass));
    return action;
}
Also used : 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) NewFolderCommand(com.archimatetool.editor.views.tree.commands.NewFolderCommand) Command(org.eclipse.gef.commands.Command) NewElementCommand(com.archimatetool.editor.views.tree.commands.NewElementCommand) NewElementCommand(com.archimatetool.editor.views.tree.commands.NewElementCommand) IArchimateElement(com.archimatetool.model.IArchimateElement)

Example 85 with CommandStack

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

the class DeleteCommandHandler method getCompoundCommand.

/**
 * Get, and if need be create, a CompoundCommand to which to add the object to be deleted command
 */
private CompoundCommand getCompoundCommand(IAdapter object) {
    // 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 " + getClass());
        return null;
    }
    // Now get or create a Compound Command
    CompoundCommand compoundCommand = fCommandMap.get(stack);
    if (compoundCommand == null) {
        compoundCommand = new DeleteElementsCompoundCommand(fObjectToSelectAfterDeletion);
        fCommandMap.put(stack, compoundCommand);
    }
    return compoundCommand;
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

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