Search in sources :

Example 51 with CompoundCommand

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

the class DiagramCommandFactory method createDeleteDiagramConnectionCommand.

/**
 * @param connection
 * @return A new Delete Diagram Connection Command
 */
public static Command createDeleteDiagramConnectionCommand(IDiagramModelConnection connection) {
    CompoundCommand result = new CompoundCommand();
    __addDeleteDiagramConnectionCommands(connection, result);
    return result.unwrap();
}
Also used : CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 52 with CompoundCommand

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

the class ResetAspectRatioAction method createCommand.

private Command createCommand(List<?> objects) {
    CompoundCommand result = new CompoundCommand();
    for (Object object : objects) {
        if (object instanceof AbstractConnectedEditPart) {
            AbstractConnectedEditPart editPart = (AbstractConnectedEditPart) object;
            AbstractDiagramModelObjectFigure figure = (AbstractDiagramModelObjectFigure) editPart.getFigure();
            IDiagramModelObject dmo = editPart.getModel();
            // Diagram Image object with image or Iconic type with image and Fill setting
            if (!isDiagramObjectWithImage(dmo) && !isIconicWithImageFill(dmo, figure)) {
                continue;
            }
            // Locked
            if (dmo instanceof ILockable && ((ILockable) dmo).isLocked()) {
                continue;
            }
            IBounds modelBounds = dmo.getBounds().getCopy();
            int currentHeight = modelBounds.getHeight();
            int currentWidth = modelBounds.getWidth();
            // Sanity check
            if (currentHeight < 1 || currentWidth < 1) {
                continue;
            }
            float currentRatio = ((float) currentHeight / (float) currentWidth);
            float otherRatio = 0;
            // Image object type
            if (dmo instanceof IDiagramModelImage) {
                // This will return the image's proper size (unsized) if there is an image, else the object's size
                Dimension size = figure.getDefaultSize();
                if (size.height == 0 || size.width == 0) {
                    continue;
                }
                otherRatio = ((float) size.height / (float) size.width);
            } else // Iconic and fill type is fill and has an image
            {
                Rectangle imageBounds = figure.getIconicDelegate().getImage().getBounds();
                otherRatio = ((float) imageBounds.height / (float) imageBounds.width);
            }
            // If the ratio is different (within tolerance)
            if (otherRatio != 0 && Math.abs(otherRatio - currentRatio) > 0.01) {
                if (currentWidth < currentHeight) {
                    currentWidth = (int) (currentHeight / otherRatio);
                } else {
                    currentHeight = (int) (currentWidth * otherRatio);
                }
                modelBounds.setWidth(currentWidth);
                modelBounds.setHeight(currentHeight);
                Command cmd = new SetConstraintObjectCommand(dmo, modelBounds);
                result.add(cmd);
            }
        }
    }
    return result.unwrap();
}
Also used : AbstractDiagramModelObjectFigure(com.archimatetool.editor.diagram.figures.AbstractDiagramModelObjectFigure) AbstractConnectedEditPart(com.archimatetool.editor.diagram.editparts.AbstractConnectedEditPart) IBounds(com.archimatetool.model.IBounds) Rectangle(org.eclipse.swt.graphics.Rectangle) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) Dimension(org.eclipse.draw2d.geometry.Dimension) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) SetConstraintObjectCommand(com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand) SetConstraintObjectCommand(com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) IDiagramModelImage(com.archimatetool.model.IDiagramModelImage) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) ILockable(com.archimatetool.model.ILockable)

Example 53 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 54 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 55 with CompoundCommand

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

the class AssociationRelationshipSection method createControls.

@Override
protected void createControls(Composite parent) {
    createLabel(parent, Messages.AssociationRelationshipSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER);
    fButtonDirected = getWidgetFactory().createButton(parent, null, SWT.CHECK);
    fButtonDirected.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            CompoundCommand result = new CompoundCommand();
            for (EObject relationship : getEObjects()) {
                if (isAlive(relationship)) {
                    Command cmd = new EObjectFeatureCommand(Messages.AssociationRelationshipSection_1, relationship, IArchimatePackage.Literals.ASSOCIATION_RELATIONSHIP__DIRECTED, fButtonDirected.getSelection());
                    if (cmd.canExecute()) {
                        result.add(cmd);
                    }
                }
            }
            executeCommand(result.unwrap());
        }
    });
    // Help ID
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
}
Also used : CompoundCommand(org.eclipse.gef.commands.CompoundCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) Command(org.eclipse.gef.commands.Command) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) EObject(org.eclipse.emf.ecore.EObject) SelectionEvent(org.eclipse.swt.events.SelectionEvent) 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