Search in sources :

Example 71 with CompoundCommand

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

the class FormatPainterTool method createCommand.

protected CompoundCommand createCommand(PaintFormat pf, IDiagramModelComponent targetComponent) {
    CompoundCommand result = new CompoundCommand(Messages.FormatPainterTool_0);
    // IFontAttribute
    if (pf.getSourceComponent() instanceof IFontAttribute && targetComponent instanceof IFontAttribute) {
        IFontAttribute source = (IFontAttribute) pf.getSourceComponent();
        IFontAttribute target = (IFontAttribute) targetComponent;
        Command cmd = new FontStyleCommand(target, source.getFont());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        cmd = new FontColorCommand(target, source.getFontColor());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // ILineObject
    if (pf.getSourceComponent() instanceof ILineObject && targetComponent instanceof ILineObject) {
        ILineObject source = (ILineObject) pf.getSourceComponent();
        ILineObject target = (ILineObject) targetComponent;
        Command cmd = new LineColorCommand(target, source.getLineColor());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        cmd = new LineWidthCommand(target, source.getLineWidth());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // IBorderObject
    if (pf.getSourceComponent() instanceof IBorderObject && targetComponent instanceof IBorderObject) {
        IBorderObject source = (IBorderObject) pf.getSourceComponent();
        IBorderObject target = (IBorderObject) targetComponent;
        Command cmd = new BorderColorCommand(target, source.getBorderColor());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // ITextPosition
    if (pf.getSourceComponent() instanceof ITextPosition && targetComponent instanceof ITextPosition) {
        ITextPosition source = (ITextPosition) pf.getSourceComponent();
        ITextPosition target = (ITextPosition) targetComponent;
        Command cmd = new TextPositionCommand(target, source.getTextPosition());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // ITextAlignment
    if (pf.getSourceComponent() instanceof ITextAlignment && targetComponent instanceof ITextAlignment) {
        ITextAlignment source = (ITextAlignment) pf.getSourceComponent();
        ITextAlignment target = (ITextAlignment) targetComponent;
        Command cmd = new TextAlignmentCommand(target, source.getTextAlignment());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // IDiagramModelObject
    if (pf.getSourceComponent() instanceof IDiagramModelObject && targetComponent instanceof IDiagramModelObject) {
        IDiagramModelObject source = (IDiagramModelObject) pf.getSourceComponent();
        IDiagramModelObject target = (IDiagramModelObject) targetComponent;
        // Source fill colour is null which is "default"
        String fillColorString = source.getFillColor();
        if (fillColorString == null) {
            fillColorString = ColorFactory.convertColorToString(ColorFactory.getDefaultFillColor(source));
        }
        Command cmd = new FillColorCommand(target, fillColorString);
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        // Alpha fill opacity
        cmd = new DiagramModelObjectAlphaCommand(target, source.getAlpha());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        // Alpha line opacity
        cmd = new DiagramModelObjectOutlineAlphaCommand(target, source.getLineAlpha());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        // Gradient
        // $NON-NLS-1$
        cmd = new FeatureCommand("", target, IDiagramModelObject.FEATURE_GRADIENT, source.getGradient(), IDiagramModelObject.FEATURE_GRADIENT_DEFAULT);
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        // Icon Visibility, but paste only if the target object has an icon
        IObjectUIProvider provider = ObjectUIFactory.INSTANCE.getProvider(target);
        if (provider instanceof IGraphicalObjectUIProvider && ((IGraphicalObjectUIProvider) provider).hasIcon()) {
            // $NON-NLS-1$
            cmd = new FeatureCommand("", target, IDiagramModelObject.FEATURE_ICON_VISIBLE, source.getIconVisibleState(), IDiagramModelObject.FEATURE_ICON_VISIBLE_DEFAULT);
            if (cmd.canExecute()) {
                result.add(cmd);
            }
        }
    }
    // Archimate objects
    if (pf.getSourceComponent() instanceof IDiagramModelArchimateObject && targetComponent instanceof IDiagramModelArchimateObject) {
        IDiagramModelArchimateObject source = (IDiagramModelArchimateObject) pf.getSourceComponent();
        IDiagramModelArchimateObject target = (IDiagramModelArchimateObject) targetComponent;
        // Image Source
        Command cmd = new // $NON-NLS-1$
        FeatureCommand(// $NON-NLS-1$
        "", // $NON-NLS-1$
        target, // $NON-NLS-1$
        IDiagramModelArchimateObject.FEATURE_IMAGE_SOURCE, source.getImageSource(), IDiagramModelArchimateObject.FEATURE_IMAGE_SOURCE_DEFAULT);
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // IDiagramModelConnection
    if (pf.getSourceComponent() instanceof IDiagramModelConnection && targetComponent instanceof IDiagramModelConnection) {
        IDiagramModelConnection source = (IDiagramModelConnection) pf.getSourceComponent();
        IDiagramModelConnection target = (IDiagramModelConnection) targetComponent;
        // Connection text position
        Command cmd = new ConnectionTextPositionCommand(target, source.getTextPosition());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        // If a non-Archimate connection, connection line type
        if (!(target instanceof IDiagramModelArchimateConnection)) {
            cmd = new ConnectionLineTypeCommand(target, source.getType());
            if (cmd.canExecute()) {
                result.add(cmd);
            }
        }
    }
    // IIconic
    if (pf.getSourceComponent() instanceof IIconic && targetComponent instanceof IIconic) {
        IIconic source = (IIconic) pf.getSourceComponent();
        IIconic target = (IIconic) targetComponent;
        // If we have an image path and the source and target models are different, copy the image bytes
        String imagePath = source.getImagePath();
        if (imagePath != null && source.getArchimateModel() != target.getArchimateModel()) {
            IArchiveManager sourceArchiveManager = (IArchiveManager) source.getAdapter(IArchiveManager.class);
            IArchiveManager targetArchiveManager = (IArchiveManager) target.getAdapter(IArchiveManager.class);
            try {
                imagePath = targetArchiveManager.copyImageBytes(sourceArchiveManager, imagePath);
            } catch (IOException ex) {
                ex.printStackTrace();
                // $NON-NLS-1$
                Logger.logError("Could not copy image bytes when copying and pasting objects.", ex);
            }
        }
        // $NON-NLS-1$
        Command cmd = new EObjectFeatureCommand("", target, IArchimatePackage.Literals.DIAGRAM_MODEL_IMAGE_PROVIDER__IMAGE_PATH, imagePath);
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        // Image position
        // $NON-NLS-1$
        cmd = new EObjectFeatureCommand("", target, IArchimatePackage.Literals.ICONIC__IMAGE_POSITION, source.getImagePosition());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    return result;
}
Also used : FillColorCommand(com.archimatetool.editor.diagram.commands.FillColorCommand) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) FontColorCommand(com.archimatetool.editor.diagram.commands.FontColorCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) FeatureCommand(com.archimatetool.editor.model.commands.FeatureCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) IFontAttribute(com.archimatetool.model.IFontAttribute) LineWidthCommand(com.archimatetool.editor.diagram.commands.LineWidthCommand) FontStyleCommand(com.archimatetool.editor.diagram.commands.FontStyleCommand) DiagramModelObjectOutlineAlphaCommand(com.archimatetool.editor.diagram.commands.DiagramModelObjectOutlineAlphaCommand) ConnectionTextPositionCommand(com.archimatetool.editor.diagram.commands.ConnectionTextPositionCommand) TextAlignmentCommand(com.archimatetool.editor.diagram.commands.TextAlignmentCommand) LineColorCommand(com.archimatetool.editor.diagram.commands.LineColorCommand) ITextPosition(com.archimatetool.model.ITextPosition) IIconic(com.archimatetool.model.IIconic) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IOException(java.io.IOException) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) DiagramModelObjectAlphaCommand(com.archimatetool.editor.diagram.commands.DiagramModelObjectAlphaCommand) ILineObject(com.archimatetool.model.ILineObject) BorderColorCommand(com.archimatetool.editor.diagram.commands.BorderColorCommand) IBorderObject(com.archimatetool.model.IBorderObject) ITextAlignment(com.archimatetool.model.ITextAlignment) FontStyleCommand(com.archimatetool.editor.diagram.commands.FontStyleCommand) DiagramModelObjectAlphaCommand(com.archimatetool.editor.diagram.commands.DiagramModelObjectAlphaCommand) ConnectionTextPositionCommand(com.archimatetool.editor.diagram.commands.ConnectionTextPositionCommand) DiagramModelObjectOutlineAlphaCommand(com.archimatetool.editor.diagram.commands.DiagramModelObjectOutlineAlphaCommand) BorderColorCommand(com.archimatetool.editor.diagram.commands.BorderColorCommand) TextPositionCommand(com.archimatetool.editor.diagram.commands.TextPositionCommand) LineWidthCommand(com.archimatetool.editor.diagram.commands.LineWidthCommand) FontColorCommand(com.archimatetool.editor.diagram.commands.FontColorCommand) TextAlignmentCommand(com.archimatetool.editor.diagram.commands.TextAlignmentCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) ConnectionLineTypeCommand(com.archimatetool.editor.diagram.commands.ConnectionLineTypeCommand) FillColorCommand(com.archimatetool.editor.diagram.commands.FillColorCommand) LineColorCommand(com.archimatetool.editor.diagram.commands.LineColorCommand) FeatureCommand(com.archimatetool.editor.model.commands.FeatureCommand) Command(org.eclipse.gef.commands.Command) ConnectionLineTypeCommand(com.archimatetool.editor.diagram.commands.ConnectionLineTypeCommand) IGraphicalObjectUIProvider(com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider) ConnectionTextPositionCommand(com.archimatetool.editor.diagram.commands.ConnectionTextPositionCommand) TextPositionCommand(com.archimatetool.editor.diagram.commands.TextPositionCommand) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IObjectUIProvider(com.archimatetool.editor.ui.factory.IObjectUIProvider)

Example 72 with CompoundCommand

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

the class MagicConnectionCreationTool method createElementAndConnection.

/**
 * Create an Element and a connection in one go when user clicks on the canvas or in a non-Archimate Editpart
 */
private boolean createElementAndConnection(IDiagramModelArchimateComponent sourceDiagramModelComponent, Point location) {
    // Grab this now as it will disappear after menu is shown
    EditPartViewer viewer = getCurrentViewer();
    // What did we click on?
    GraphicalEditPart targetEditPart = (GraphicalEditPart) viewer.findObjectAt(getCurrentInput().getMouseLocation());
    // Target parent (default is the diagram itself)
    IDiagramModelContainer parent = sourceDiagramModelComponent.getDiagramModel();
    // If we clicked on a Group EditPart use that as parent
    if (targetEditPart instanceof GroupEditPart) {
        parent = (IDiagramModelContainer) targetEditPart.getModel();
    } else // Or did we click on something else? Then use the parent of that
    if (targetEditPart instanceof AbstractBaseEditPart) {
        targetEditPart = (GraphicalEditPart) targetEditPart.getParent();
        parent = (IDiagramModelContainer) targetEditPart.getModel();
    }
    boolean elementsFirst = ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.MAGIC_CONNECTOR_POLARITY);
    boolean modKeyPressed = getCurrentInput().isModKeyDown(SWT.MOD1);
    elementsFirst ^= modKeyPressed;
    Menu menu = new Menu(getCurrentViewer().getControl());
    // User will hover over element, then connection
    if (elementsFirst) {
        fSetRelationshipTypeWhenHoveringOnConnectionMenuItem = false;
        addElementActions(menu, sourceDiagramModelComponent);
    } else // User will hover over connection, then element
    {
        fSetRelationshipTypeWhenHoveringOnConnectionMenuItem = true;
        addConnectionActions(menu, sourceDiagramModelComponent);
    }
    menu.setVisible(true);
    // Modal menu
    Display display = menu.getDisplay();
    while (!menu.isDisposed() && menu.isVisible()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    // SWT Menu does not fire Selection Event when Windows touch display is enabled
    if (PlatformUtils.isWindows()) {
        while (display.readAndDispatch()) ;
    }
    if (!menu.isDisposed()) {
        menu.dispose();
    }
    eraseSourceFeedback();
    // No selection
    if (getFactory().getElementType() == null || getFactory().getRelationshipType() == null) {
        getFactory().clear();
        return false;
    }
    // Create Compound Command first
    CompoundCommand cmd = new CompoundCommand(Messages.MagicConnectionCreationTool_6);
    // If the EditPart's Figure is a Container, adjust the location to relative co-ords
    if (targetEditPart.getFigure() instanceof IContainerFigure) {
        ((IContainerFigure) targetEditPart.getFigure()).translateMousePointToRelative(location);
    } else // Or compensate for scrolled parent figure
    {
        IFigure contentPane = targetEditPart.getContentPane();
        contentPane.translateToRelative(location);
    }
    CreateNewDiagramObjectCommand cmd1 = new CreateNewDiagramObjectCommand(parent, getFactory().getElementType(), location, viewer);
    Command cmd2 = new CreateNewConnectionCommand(sourceDiagramModelComponent, cmd1.getNewObject(), getFactory().getRelationshipType());
    cmd.add(cmd1);
    cmd.add(cmd2);
    executeCommand(cmd);
    // Clear the factory
    getFactory().clear();
    return true;
}
Also used : AbstractBaseEditPart(com.archimatetool.editor.diagram.editparts.AbstractBaseEditPart) EditPartViewer(org.eclipse.gef.EditPartViewer) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer) GroupEditPart(com.archimatetool.editor.diagram.editparts.diagram.GroupEditPart) IContainerFigure(com.archimatetool.editor.diagram.figures.IContainerFigure) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) CreateDiagramArchimateConnectionWithDialogCommand(com.archimatetool.editor.diagram.commands.CreateDiagramArchimateConnectionWithDialogCommand) Command(org.eclipse.gef.commands.Command) Menu(org.eclipse.swt.widgets.Menu) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) Display(org.eclipse.swt.widgets.Display) IFigure(org.eclipse.draw2d.IFigure)

Example 73 with CompoundCommand

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

the class ArchimateDNDEditPolicy method getDropCommand.

@Override
protected Command getDropCommand(DiagramDropRequest request) {
    if (!(request.getData() instanceof IStructuredSelection)) {
        return null;
    }
    // XY drop point
    Point pt = getDropLocation(request);
    int origin = pt.x;
    int x = pt.x;
    int y = pt.y;
    fElementsToAdd = new ArrayList<IArchimateElement>();
    fRelationsToAdd = new ArrayList<IArchimateRelationship>();
    fDiagramRefsToAdd = new ArrayList<IDiagramModel>();
    // Gather an actual list of elements dragged onto the container, omitting duplicates and anything already on the diagram
    Object[] objects = ((IStructuredSelection) request.getData()).toArray();
    getElementsToAdd(objects);
    // Store the Diagram Model Components that will be added in this list
    List<IDiagramModelArchimateComponent> diagramComponentsThatWereAdded = new ArrayList<IDiagramModelArchimateComponent>();
    // Create a Compound Command - it has to be Non-Notifying or it's too slow (tested with Bill's UoB model!)
    CompoundCommand result = new NonNotifyingCompoundCommand(Messages.ArchimateDNDEditPolicy_0);
    // Add the Commands adding the Elements first
    for (IArchimateElement element : fElementsToAdd) {
        // Add Diagram object
        IDiagramModelArchimateObject dmo = ArchimateDiagramModelFactory.createDiagramModelArchimateObject(element);
        // Set location
        dmo.getBounds().setLocation(x, y);
        // Store it
        diagramComponentsThatWereAdded.add(dmo);
        // Add Command
        result.add(new AddDiagramObjectCommand(getTargetContainer(), dmo));
        // Increase x,y
        x += 150;
        if (x > origin + 400) {
            x = origin;
            y += 100;
        }
    }
    // Then any Diagram Model Ref Commands
    for (IDiagramModel diagramModel : fDiagramRefsToAdd) {
        result.add(new AddDiagramModelReferenceCommand(getTargetContainer(), diagramModel, x, y));
        x += 150;
        if (x > origin + 400) {
            x = origin;
            y += 100;
        }
    }
    // Add selected Relations to create connections to those elements on the diagram that don't already have them
    for (IArchimateRelationship relation : fRelationsToAdd) {
        // Find existing source & target components on the diagram that the new connection will link to
        List<IDiagramModelArchimateComponent> sources = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(getTargetDiagramModel(), relation.getSource());
        List<IDiagramModelArchimateComponent> targets = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(getTargetDiagramModel(), relation.getTarget());
        for (IDiagramModelComponent dcSource : sources) {
            for (IDiagramModelComponent dcTarget : targets) {
                if (dcSource instanceof IConnectable && dcTarget instanceof IConnectable) {
                    // Add a new connection between dcSource & dcTarget if there isn't already one on the diagram
                    if (dcTarget != dcSource && !DiagramModelUtils.hasDiagramModelArchimateConnection((IConnectable) dcSource, (IConnectable) dcTarget, relation)) {
                        // Check that source or target is not a hiden connection
                        if (!((dcSource instanceof IDiagramModelArchimateConnection && DiagramModelUtils.shouldBeHiddenConnection((IDiagramModelArchimateConnection) dcSource)) || (dcTarget instanceof IDiagramModelArchimateConnection && DiagramModelUtils.shouldBeHiddenConnection((IDiagramModelArchimateConnection) dcTarget)))) {
                            AddDiagramArchimateConnectionCommand cmd = new AddDiagramArchimateConnectionCommand((IConnectable) dcSource, (IConnectable) dcTarget, relation);
                            result.add(cmd);
                            // Store it
                            diagramComponentsThatWereAdded.add(cmd.getConnection());
                        }
                    }
                }
            }
        }
    }
    // Whether to add connections to elements
    Boolean value = (Boolean) request.getExtendedData().get(ArchimateDiagramTransferDropTargetListener.ADD_ELEMENT_CONNECTIONS);
    boolean addConnectionsToElements = value != null && value.booleanValue();
    // Newly added concepts will need new connections to both existing and newly added concepts
    for (IDiagramModelArchimateComponent dmComponent : diagramComponentsThatWereAdded) {
        IArchimateConcept archimateConcept = dmComponent.getArchimateConcept();
        for (IArchimateRelationship relation : ArchimateModelUtils.getAllRelationshipsForConcept(archimateConcept)) {
            /*
                 * If the user holds down the Copy key (Ctrl on win/lnx, Alt on Mac) then linked connections
                 * are not added on drag and drop. However, any selected relations' linked objects are added.
                 */
            if (!addConnectionsToElements && !fRelationsToAdd.contains(relation)) {
                continue;
            }
            // Find existing objects
            List<IDiagramModelArchimateComponent> sources = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(getTargetDiagramModel(), relation.getSource());
            List<IDiagramModelArchimateComponent> targets = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(getTargetDiagramModel(), relation.getTarget());
            // Add new ones too
            for (IDiagramModelArchimateComponent dmComponent2 : diagramComponentsThatWereAdded) {
                if (dmComponent != dmComponent2) {
                    IArchimateConcept archimateConcept2 = dmComponent2.getArchimateConcept();
                    if (archimateConcept2 == relation.getSource()) {
                        // Only need to add sources, not targets
                        sources.add(dmComponent2);
                    }
                }
            }
            // Make the Commands...
            for (IDiagramModelComponent dcSource : sources) {
                if (dcSource instanceof IConnectable && archimateConcept == relation.getTarget()) {
                    result.add(new AddDiagramArchimateConnectionCommand((IConnectable) dcSource, (IConnectable) dmComponent, relation));
                }
            }
            for (IDiagramModelComponent dcTarget : targets) {
                if (dcTarget instanceof IConnectable && archimateConcept == relation.getSource()) {
                    result.add(new AddDiagramArchimateConnectionCommand((IConnectable) dmComponent, (IConnectable) dcTarget, relation));
                }
            }
        }
    }
    // Then, if adding to an Archimate container type to create nesting, ask whether to add new relations if none exist...
    if (ConnectionPreferences.createRelationWhenAddingModelTreeElement() && getTargetContainer() instanceof IDiagramModelArchimateObject) {
        List<IDiagramModelArchimateObject> diagramObjectsThatWereAdded = new ArrayList<IDiagramModelArchimateObject>();
        for (IDiagramModelArchimateComponent dmc : diagramComponentsThatWereAdded) {
            if (dmc instanceof IDiagramModelArchimateObject) {
                diagramObjectsThatWereAdded.add((IDiagramModelArchimateObject) dmc);
            }
        }
        Command cmd = new CreateNestedArchimateConnectionsWithDialogCommand((IDiagramModelArchimateObject) getTargetContainer(), diagramObjectsThatWereAdded);
        result.add(cmd);
    }
    // return the full compound command
    return result;
}
Also used : CreateNestedArchimateConnectionsWithDialogCommand(com.archimatetool.editor.diagram.commands.CreateNestedArchimateConnectionsWithDialogCommand) ArrayList(java.util.ArrayList) AddDiagramObjectCommand(com.archimatetool.editor.diagram.commands.AddDiagramObjectCommand) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AddDiagramModelReferenceCommand(com.archimatetool.editor.diagram.commands.AddDiagramModelReferenceCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) IDiagramModel(com.archimatetool.model.IDiagramModel) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) IConnectable(com.archimatetool.model.IConnectable) IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) AddDiagramModelReferenceCommand(com.archimatetool.editor.diagram.commands.AddDiagramModelReferenceCommand) AddDiagramObjectCommand(com.archimatetool.editor.diagram.commands.AddDiagramObjectCommand) CreateNestedArchimateConnectionsWithDialogCommand(com.archimatetool.editor.diagram.commands.CreateNestedArchimateConnectionsWithDialogCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) Command(org.eclipse.gef.commands.Command) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) EObject(org.eclipse.emf.ecore.EObject) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject)

Example 74 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);
    // Font
    UIUtils.setFontFromPreferences(fTableViewer.getTable(), IPreferenceConstants.PROPERTIES_TABLE_FONT, true);
    // Mac Silicon Item height
    UIUtils.fixMacSiliconItemHeight(fTableViewer.getTable());
    // Edit cell on double-click and add Tab key traversal
    TableViewerEditor.create(fTableViewer, new ColumnViewerEditorActivationStrategy(fTableViewer) {

        @Override
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return super.isEditorActivationEvent(event) || (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION);
        }
    }, ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEEP_EDITOR_ON_DOUBLE_CLICK | ColumnViewerEditor.KEYBOARD_ACTIVATION);
    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 ColumnWeightData(3, false));
    columnBlank.getColumn().setWidth(38);
    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(77, true));
    columnValue.setEditingSupport(new ValueEditingSupport(fTableViewer));
    // Content Provider
    fTableViewer.setContentProvider(new IStructuredContentProvider() {

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

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return ((IProperties) inputElement).getProperties().toArray();
        }
    });
    // Label Provider
    fTableViewer.setLabelProvider(new LabelCellProvider());
    // Enable tooltips
    ColumnViewerToolTipSupport.enableFor(fTableViewer);
    // Toolbar
    ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.VERTICAL);
    getWidgetFactory().adapt(toolBar);
    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)) {
                // complete any current editing
                fTableViewer.applyEditorValue();
                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((e) -> {
        fActionRemoveProperty.setEnabled(!e.getSelection().isEmpty());
    });
    /*
         * Table Double-click
         */
    fTableViewer.getTable().addListener(SWT.MouseDoubleClick, (e) -> {
        // Get Table item
        Point pt = new Point(e.x, e.y);
        TableItem item = fTableViewer.getTable().getItem(pt);
        // Double-click into empty table creates new Property
        if (item == null) {
            fActionNewProperty.run();
        } else // Double-clicked in column 0 with item
        if (item.getData() instanceof IProperty) {
            Rectangle rect = item.getBounds(0);
            if (rect.contains(pt)) {
                handleDoubleClick((IProperty) item.getData());
            }
        }
    });
    /*
         * Edit table row on key press
         */
    fTableViewer.getTable().addKeyListener(KeyListener.keyPressedAdapter(e -> {
        if (e.keyCode == SWT.CR) {
            Object selected = fTableViewer.getStructuredSelection().getFirstElement();
            if (selected != null) {
                fTableViewer.editElement(selected, 1);
            }
        }
    }));
    hookContextMenu();
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) EObjectNonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.EObjectNonNotifyingCompoundCommand) Arrays(java.util.Arrays) Notification(org.eclipse.emf.common.notify.Notification) DND(org.eclipse.swt.dnd.DND) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) CellEditor(org.eclipse.jface.viewers.CellEditor) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) Point(org.eclipse.swt.graphics.Point) IArchimateModel(com.archimatetool.model.IArchimateModel) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) Matcher(java.util.regex.Matcher) Composite(org.eclipse.swt.widgets.Composite) PartInitException(org.eclipse.ui.PartInitException) ColorConstants(org.eclipse.draw2d.ColorConstants) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Separator(org.eclipse.jface.action.Separator) PlatformUI(org.eclipse.ui.PlatformUI) UpdatingTableColumnLayout(com.archimatetool.editor.ui.components.UpdatingTableColumnLayout) MenuManager(org.eclipse.jface.action.MenuManager) Set(java.util.Set) LightweightEContentAdapter(com.archimatetool.model.util.LightweightEContentAdapter) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) Transfer(org.eclipse.swt.dnd.Transfer) Window(org.eclipse.jface.window.Window) StringUtils(com.archimatetool.editor.utils.StringUtils) SWT(org.eclipse.swt.SWT) ColumnViewer(org.eclipse.jface.viewers.ColumnViewer) ECollections(org.eclipse.emf.common.util.ECollections) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) UIUtils(com.archimatetool.editor.ui.UIUtils) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ArrayList(java.util.ArrayList) IProperties(com.archimatetool.model.IProperties) Listener(org.eclipse.swt.widgets.Listener) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) GridData(org.eclipse.swt.layout.GridData) TableItem(org.eclipse.swt.widgets.TableItem) IArchimatePackage(com.archimatetool.model.IArchimatePackage) TableViewerEditor(org.eclipse.jface.viewers.TableViewerEditor) Shell(org.eclipse.swt.widgets.Shell) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) IActionBars(org.eclipse.ui.IActionBars) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) Color(org.eclipse.swt.graphics.Color) IMenuManager(org.eclipse.jface.action.IMenuManager) IArchiImages(com.archimatetool.editor.ui.IArchiImages) GridLayout(org.eclipse.swt.layout.GridLayout) EObjectNonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.EObjectNonNotifyingCompoundCommand) ColumnViewerEditor(org.eclipse.jface.viewers.ColumnViewerEditor) TableViewer(org.eclipse.jface.viewers.TableViewer) IPreferenceConstants(com.archimatetool.editor.preferences.IPreferenceConstants) IAction(org.eclipse.jface.action.IAction) ToolBar(org.eclipse.swt.widgets.ToolBar) HTMLUtils(com.archimatetool.editor.utils.HTMLUtils) ViewerCell(org.eclipse.jface.viewers.ViewerCell) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ColumnViewerToolTipSupport(org.eclipse.jface.viewers.ColumnViewerToolTipSupport) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) Button(org.eclipse.swt.widgets.Button) IArchimateFactory(com.archimatetool.model.IArchimateFactory) ExtendedTitleAreaDialog(com.archimatetool.editor.ui.components.ExtendedTitleAreaDialog) EObject(org.eclipse.emf.ecore.EObject) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) List(java.util.List) IProperty(com.archimatetool.model.IProperty) Command(org.eclipse.gef.commands.Command) ISelection(org.eclipse.jface.viewers.ISelection) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) StringComboBoxCellEditor(com.archimatetool.editor.ui.components.StringComboBoxCellEditor) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IMenuListener(org.eclipse.jface.action.IMenuListener) BasicEList(org.eclipse.emf.common.util.BasicEList) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) Table(org.eclipse.swt.widgets.Table) Event(org.eclipse.swt.widgets.Event) HashSet(java.util.HashSet) ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) Iterator(java.util.Iterator) Viewer(org.eclipse.jface.viewers.Viewer) MalformedURLException(java.net.MalformedURLException) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) GlobalActionDisablementHandler(com.archimatetool.editor.ui.components.GlobalActionDisablementHandler) Action(org.eclipse.jface.action.Action) EditingSupport(org.eclipse.jface.viewers.EditingSupport) EList(org.eclipse.emf.common.util.EList) ToolBarManager(org.eclipse.jface.action.ToolBarManager) KeyListener(org.eclipse.swt.events.KeyListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) Comparator(java.util.Comparator) LabelProvider(org.eclipse.jface.viewers.LabelProvider) Control(org.eclipse.swt.widgets.Control) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) Listener(org.eclipse.swt.widgets.Listener) IMenuListener(org.eclipse.jface.action.IMenuListener) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) KeyListener(org.eclipse.swt.events.KeyListener) TableItem(org.eclipse.swt.widgets.TableItem) Rectangle(org.eclipse.swt.graphics.Rectangle) ColumnViewer(org.eclipse.jface.viewers.ColumnViewer) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) IProperties(com.archimatetool.model.IProperties) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ToolBarManager(org.eclipse.jface.action.ToolBarManager) EObjectNonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.EObjectNonNotifyingCompoundCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) 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) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) Point(org.eclipse.swt.graphics.Point) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) EObjectNonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.EObjectNonNotifyingCompoundCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) ToolBar(org.eclipse.swt.widgets.ToolBar) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) Event(org.eclipse.swt.widgets.Event) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) EObject(org.eclipse.emf.ecore.EObject) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 75 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) EObjectNonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.EObjectNonNotifyingCompoundCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Aggregations

CompoundCommand (org.eclipse.gef.commands.CompoundCommand)193 Command (org.eclipse.gef.commands.Command)86 EObject (org.eclipse.emf.ecore.EObject)40 ArrayList (java.util.ArrayList)28 EditPart (org.eclipse.gef.EditPart)28 List (java.util.List)24 EObjectFeatureCommand (com.archimatetool.editor.model.commands.EObjectFeatureCommand)23 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)22 SelectionEvent (org.eclipse.swt.events.SelectionEvent)22 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)18 Point (org.eclipse.draw2d.geometry.Point)16 IElementParameter (org.talend.core.model.process.IElementParameter)16 Combo (org.eclipse.swt.widgets.Combo)15 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 Rectangle (org.eclipse.draw2d.geometry.Rectangle)14 ChangeBoundsRequest (org.eclipse.gef.requests.ChangeBoundsRequest)14 INode (org.talend.core.model.process.INode)14 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14