Search in sources :

Example 36 with CompoundCommand

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

the class TextPositionSection method createControls.

@Override
protected void createControls(Composite parent) {
    SelectionAdapter adapter = new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            for (int i = 0; i < fPositionButtons.length; i++) {
                // Select/deselects
                fPositionButtons[i].setSelection(e.widget == fPositionButtons[i]);
                // Commands
                if (fPositionButtons[i] == e.widget) {
                    int position = (Integer) fPositionButtons[i].getData();
                    CompoundCommand result = new CompoundCommand();
                    for (EObject textPosition : getEObjects()) {
                        if (((ITextPosition) textPosition).getTextPosition() != position && isAlive(textPosition)) {
                            Command cmd = new TextPositionCommand((ITextPosition) textPosition, position);
                            if (cmd.canExecute()) {
                                result.add(cmd);
                            }
                        }
                    }
                    executeCommand(result.unwrap());
                }
            }
        }
    };
    // $NON-NLS-1$
    createLabel(parent, Messages.TextPositionSection_3 + ":", ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER);
    Composite client = createComposite(parent, 3);
    for (int i = 0; i < fPositionButtons.length; i++) {
        fPositionButtons[i] = new Button(client, SWT.TOGGLE | SWT.FLAT);
        // Need to do it this way for Mac
        getWidgetFactory().adapt(fPositionButtons[i], true, true);
        fPositionButtons[i].addSelectionListener(adapter);
    }
    // Top Button
    fPositionButtons[0].setImage(IArchiImages.ImageFactory.getImage(IArchiImages.ICON_ALIGN_TEXT_TOP));
    fPositionButtons[0].setData(ITextPosition.TEXT_POSITION_TOP);
    // Middle Button
    fPositionButtons[1].setImage(IArchiImages.ImageFactory.getImage(IArchiImages.ICON_ALIGN_TEXT_MIDDLE));
    fPositionButtons[1].setData(ITextPosition.TEXT_POSITION_CENTRE);
    // Bottom Button
    fPositionButtons[2].setImage(IArchiImages.ImageFactory.getImage(IArchiImages.ICON_ALIGN_TEXT_BOTTOM));
    fPositionButtons[2].setData(ITextPosition.TEXT_POSITION_BOTTOM);
    // Help
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
}
Also used : ITextPosition(com.archimatetool.model.ITextPosition) Composite(org.eclipse.swt.widgets.Composite) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) TextPositionCommand(com.archimatetool.editor.diagram.commands.TextPositionCommand) Command(org.eclipse.gef.commands.Command) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) EObject(org.eclipse.emf.ecore.EObject) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TextPositionCommand(com.archimatetool.editor.diagram.commands.TextPositionCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 37 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand 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() {

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

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

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

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

                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 38 with CompoundCommand

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

the class UserPropertiesSection method createTableControl.

private void createTableControl(Composite parent) {
    // Table Composite
    Composite tableComp = createTableComposite(parent, SWT.NULL);
    TableColumnLayout tableLayout = (TableColumnLayout) tableComp.getLayout();
    // Table Viewer
    fTableViewer = new TableViewer(tableComp, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
    fTableViewer.getTable().setHeaderVisible(true);
    fTableViewer.getTable().setLinesVisible(true);
    addDragSupport();
    addDropSupport();
    // Help ID on table
    PlatformUI.getWorkbench().getHelpSystem().setHelp(fTableViewer.getTable(), HELP_ID);
    // Columns
    TableViewerColumn columnBlank = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
    tableLayout.setColumnData(columnBlank.getColumn(), new ColumnPixelData(24, false));
    TableViewerColumn columnKey = new TableViewerColumn(fTableViewer, SWT.NONE, 1);
    columnKey.getColumn().setText(Messages.UserPropertiesSection_0);
    tableLayout.setColumnData(columnKey.getColumn(), new ColumnWeightData(20, true));
    columnKey.setEditingSupport(new KeyEditingSupport(fTableViewer));
    // Click on Key Table Header
    columnKey.getColumn().addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            sortKeys();
        }
    });
    TableViewerColumn columnValue = new TableViewerColumn(fTableViewer, SWT.NONE, 2);
    columnValue.getColumn().setText(Messages.UserPropertiesSection_1);
    tableLayout.setColumnData(columnValue.getColumn(), new ColumnWeightData(80, true));
    columnValue.setEditingSupport(new ValueEditingSupport(fTableViewer));
    // Content Provider
    fTableViewer.setContentProvider(new IStructuredContentProvider() {

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        public void dispose() {
        }

        public Object[] getElements(Object inputElement) {
            return ((IProperties) inputElement).getProperties().toArray();
        }
    });
    // Label Provider
    fTableViewer.setLabelProvider(new LabelCellProvider());
    // Toolbar
    ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.VERTICAL);
    GridDataFactory.fillDefaults().align(SWT.END, SWT.TOP).applyTo(toolBar);
    ToolBarManager toolBarmanager = new ToolBarManager(toolBar);
    // New Property
    fActionNewProperty = new Action(Messages.UserPropertiesSection_2) {

        @Override
        public void run() {
            if (isAlive(fPropertiesElement)) {
                int index = -1;
                IProperty selected = (IProperty) ((IStructuredSelection) fTableViewer.getSelection()).getFirstElement();
                if (selected != null) {
                    index = fPropertiesElement.getProperties().indexOf(selected) + 1;
                }
                IProperty property = IArchimateFactory.eINSTANCE.createProperty();
                executeCommand(new NewPropertyCommand(fPropertiesElement.getProperties(), property, index));
                fTableViewer.editElement(property, 1);
            }
        }

        @Override
        public String getToolTipText() {
            return getText();
        }

        @Override
        public ImageDescriptor getImageDescriptor() {
            return IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_PLUS);
        }
    };
    // New Multiple Properties
    fActionNewMultipleProperty = new Action(Messages.UserPropertiesSection_3) {

        @Override
        public void run() {
            if (isAlive(fPropertiesElement)) {
                MultipleAddDialog dialog = new MultipleAddDialog(fPage.getSite().getShell());
                if (dialog.open() == Window.OK) {
                    executeCommand(dialog.getCommand());
                }
            }
        }

        @Override
        public String getToolTipText() {
            return getText();
        }

        @Override
        public ImageDescriptor getImageDescriptor() {
            return IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_MUTIPLE);
        }
    };
    // Remove Property
    fActionRemoveProperty = new Action(Messages.UserPropertiesSection_4) {

        @Override
        public void run() {
            if (isAlive(fPropertiesElement)) {
                CompoundCommand compoundCmd = new EObjectNonNotifyingCompoundCommand(fPropertiesElement) {

                    @Override
                    public String getLabel() {
                        return getCommands().size() > 1 ? Messages.UserPropertiesSection_5 : Messages.UserPropertiesSection_6;
                    }
                };
                for (Object o : ((IStructuredSelection) fTableViewer.getSelection()).toList()) {
                    Command cmd = new RemovePropertyCommand(fPropertiesElement.getProperties(), (IProperty) o);
                    compoundCmd.add(cmd);
                }
                executeCommand(compoundCmd);
            }
        }

        @Override
        public String getToolTipText() {
            return getText();
        }

        @Override
        public ImageDescriptor getImageDescriptor() {
            return IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_SMALL_X);
        }
    };
    fActionRemoveProperty.setEnabled(false);
    // Manage
    fActionShowKeyEditor = new Action(Messages.UserPropertiesSection_7) {

        @Override
        public void run() {
            if (isAlive(fPropertiesElement)) {
                UserPropertiesManagerDialog dialog = new UserPropertiesManagerDialog(fPage.getSite().getShell(), getArchimateModel());
                dialog.open();
            }
        }

        @Override
        public String getToolTipText() {
            return getText();
        }

        @Override
        public ImageDescriptor getImageDescriptor() {
            return IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_COG);
        }
    };
    toolBarmanager.add(fActionNewProperty);
    toolBarmanager.add(fActionNewMultipleProperty);
    toolBarmanager.add(fActionRemoveProperty);
    toolBarmanager.add(fActionShowKeyEditor);
    toolBarmanager.update(true);
    /*
         * Selection Listener
         */
    fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            fActionRemoveProperty.setEnabled(!event.getSelection().isEmpty());
        }
    });
    /*
         * Table Double-click on cell
         */
    fTableViewer.getTable().addListener(SWT.MouseDoubleClick, new Listener() {

        @Override
        public void handleEvent(Event event) {
            // Get Table item
            TableItem item = fTableViewer.getTable().getItem(new Point(event.x, event.y));
            // Double-click into empty table creates new Property
            if (item == null) {
                fActionNewProperty.run();
            } else // Handle selected item property double-clicked
            {
                if (item.getData() instanceof IProperty) {
                    handleDoubleClick((IProperty) item.getData());
                }
            }
        }
    });
    hookContextMenu();
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) EObjectNonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.EObjectNonNotifyingCompoundCommand) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) IMenuListener(org.eclipse.jface.action.IMenuListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) Listener(org.eclipse.swt.widgets.Listener) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) TableItem(org.eclipse.swt.widgets.TableItem) TableViewer(org.eclipse.jface.viewers.TableViewer) ColumnViewer(org.eclipse.jface.viewers.ColumnViewer) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) Viewer(org.eclipse.jface.viewers.Viewer) IProperties(com.archimatetool.model.IProperties) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ToolBarManager(org.eclipse.jface.action.ToolBarManager) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) EObjectNonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.EObjectNonNotifyingCompoundCommand) UpdatingTableColumnLayout(com.archimatetool.editor.ui.components.UpdatingTableColumnLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) IProperty(com.archimatetool.model.IProperty) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) Point(org.eclipse.swt.graphics.Point) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) Command(org.eclipse.gef.commands.Command) EObjectNonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.EObjectNonNotifyingCompoundCommand) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) ToolBar(org.eclipse.swt.widgets.ToolBar) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) EObject(org.eclipse.emf.ecore.EObject) TableViewer(org.eclipse.jface.viewers.TableViewer) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer)

Example 39 with CompoundCommand

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

the class UserPropertiesSection method movePropertiesToIndex.

private void movePropertiesToIndex(List<IProperty> propertiesToMove, int index) {
    EList<IProperty> properties = fPropertiesElement.getProperties();
    // Sanity check
    if (index < 0) {
        index = 0;
    }
    if (index > properties.size()) {
        index = properties.size();
    }
    CompoundCommand compoundCmd = new CompoundCommand(Messages.UserPropertiesSection_8);
    for (IProperty property : propertiesToMove) {
        int oldIndex = properties.indexOf(property);
        if (index > oldIndex) {
            index--;
        }
        if (index == oldIndex) {
            break;
        }
        compoundCmd.add(new MovePropertyCommand(properties, property, index));
        index++;
    }
    executeCommand(compoundCmd.unwrap());
}
Also used : IProperty(com.archimatetool.model.IProperty) Point(org.eclipse.swt.graphics.Point) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) EObjectNonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.EObjectNonNotifyingCompoundCommand)

Example 40 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project knime-core by knime.

the class WorkflowSelectionDragEditPartsTracker method getCommand.

/**
 * Asks each edit part in the
 * {@link org.eclipse.gef.tools.AbstractTool#getOperationSet() operation set}
 * to contribute to a {@link CompoundCommand} after first setting the
 * request type to either {@link org.eclipse.gef.RequestConstants#REQ_MOVE}
 * or {@link org.eclipse.gef.RequestConstants#REQ_ORPHAN}, depending on the
 * result of {@link #isMove()}.
 *
 * Additionally the method creates a command to adapt connections where both
 * node container are include in the drag operation.
 *
 * {@inheritDoc}
 */
@Override
protected Command getCommand() {
    CompoundCommand command = new CompoundCommand();
    command.setDebugLabel("Drag Object Tracker");
    Iterator iter = getOperationSet().iterator();
    Request request = getTargetRequest();
    if (isCloneActive()) {
        request.setType(REQ_CLONE);
    } else if (isMove()) {
        request.setType(REQ_MOVE);
    } else {
        request.setType(REQ_ORPHAN);
    }
    if (!isCloneActive()) {
        while (iter.hasNext()) {
            EditPart editPart = (EditPart) iter.next();
            command.add(editPart.getCommand(request));
        }
    }
    // now add the commands for the node-embraced connections
    ConnectionContainerEditPart[] connectionsToAdapt = getEmbracedConnections(getOperationSet());
    for (ConnectionContainerEditPart connectionPart : connectionsToAdapt) {
        command.add(connectionPart.getBendpointAdaptionCommand(request));
    }
    if (!isMove() || isCloneActive()) {
        if (!isCloneActive()) {
            request.setType(REQ_ADD);
        }
        if (getTargetEditPart() == null) {
            command.add(UnexecutableCommand.INSTANCE);
        } else {
            command.add(getTargetEditPart().getCommand(getTargetRequest()));
        }
    }
    return command;
}
Also used : ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) Iterator(java.util.Iterator) Request(org.eclipse.gef.Request) AbstractPortEditPart(org.knime.workbench.editor2.editparts.AbstractPortEditPart) AbstractWorkflowPortBarEditPart(org.knime.workbench.editor2.editparts.AbstractWorkflowPortBarEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) EditPart(org.eclipse.gef.EditPart) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Aggregations

CompoundCommand (org.eclipse.gef.commands.CompoundCommand)148 Command (org.eclipse.gef.commands.Command)63 EObject (org.eclipse.emf.ecore.EObject)28 ArrayList (java.util.ArrayList)23 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)22 EObjectFeatureCommand (com.archimatetool.editor.model.commands.EObjectFeatureCommand)17 List (java.util.List)16 EditPart (org.eclipse.gef.EditPart)16 IElementParameter (org.talend.core.model.process.IElementParameter)16 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)15 Node (org.talend.designer.core.ui.editor.nodes.Node)15 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)14 Point (org.eclipse.draw2d.geometry.Point)14 Rectangle (org.eclipse.draw2d.geometry.Rectangle)14 INode (org.talend.core.model.process.INode)14 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14 RepositoryNode (org.talend.repository.model.RepositoryNode)13 SelectionEvent (org.eclipse.swt.events.SelectionEvent)12 ConnectionItem (org.talend.core.model.properties.ConnectionItem)12 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)11