Search in sources :

Example 1 with ILockable

use of com.archimatetool.model.ILockable in project archi by archimatetool.

the class BringForwardAction method createCommand.

private Command createCommand(List<?> selection) {
    GraphicalViewer viewer = getWorkbenchPart().getAdapter(GraphicalViewer.class);
    CompoundCommand result = new CompoundCommand(Messages.BringForwardAction_0);
    for (Object object : selection) {
        if (object instanceof GraphicalEditPart) {
            GraphicalEditPart editPart = (GraphicalEditPart) object;
            Object model = editPart.getModel();
            // This can happen if we do things wrong
            if (viewer != editPart.getViewer()) {
                // $NON-NLS-1$
                System.err.println("Wrong selection for viewer in " + getClass());
            }
            // Locked
            if (model instanceof ILockable && ((ILockable) model).isLocked()) {
                continue;
            }
            if (model instanceof IDiagramModelObject) {
                IDiagramModelObject diagramObject = (IDiagramModelObject) model;
                IDiagramModelContainer parent = (IDiagramModelContainer) diagramObject.eContainer();
                /*
                     * Parent can be null when objects are selected (with marquee tool) and transferred from one container
                     * to another and the Diagram Editor updates the enablement state of Actions.
                     */
                if (parent == null) {
                    continue;
                }
                List<IDiagramModelObject> modelChildren = parent.getChildren();
                int originalPos = modelChildren.indexOf(diagramObject);
                if (originalPos < modelChildren.size() - 1) {
                    result.add(new BringForwardCommand(parent, originalPos));
                }
            }
        }
    }
    return result.unwrap();
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) ILockable(com.archimatetool.model.ILockable)

Example 2 with ILockable

use of com.archimatetool.model.ILockable 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 DiagramImageEditPart) {
            DiagramImageEditPart part = (DiagramImageEditPart) object;
            IDiagramModelObject model = part.getModel();
            // Locked
            if (model instanceof ILockable && ((ILockable) model).isLocked()) {
                continue;
            }
            IBounds modelBounds = model.getBounds().getCopy();
            int currentHeight = modelBounds.getHeight();
            int currentWidth = modelBounds.getWidth();
            // Already set to default height and width
            if (currentHeight == -1 && currentWidth == -1) {
                continue;
            }
            // Get original default size
            DiagramImageFigure figure = part.getFigure();
            Dimension size = figure.getDefaultSize();
            if (size.height == 0 || size.width == 0) {
                continue;
            }
            float originalRatio = ((float) size.height / (float) size.width);
            float currentRatio = ((float) currentHeight / (float) currentWidth);
            // If the ratio is different within tolerance
            if (Math.abs(originalRatio - currentRatio) > 0.01) {
                int width = currentWidth;
                int height = currentHeight;
                if (currentWidth < currentHeight) {
                    width = (int) (currentHeight / originalRatio);
                } else {
                    height = (int) (currentWidth * originalRatio);
                }
                modelBounds.setWidth(width);
                modelBounds.setHeight(height);
                Command cmd = new SetConstraintObjectCommand(model, modelBounds);
                result.add(cmd);
            }
        }
    }
    return result.unwrap();
}
Also used : SetConstraintObjectCommand(com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand) DiagramImageFigure(com.archimatetool.editor.diagram.figures.diagram.DiagramImageFigure) SetConstraintObjectCommand(com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) IBounds(com.archimatetool.model.IBounds) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) DiagramImageEditPart(com.archimatetool.editor.diagram.editparts.diagram.DiagramImageEditPart) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) Dimension(org.eclipse.draw2d.geometry.Dimension) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) ILockable(com.archimatetool.model.ILockable)

Example 3 with ILockable

use of com.archimatetool.model.ILockable in project archi by archimatetool.

the class CopyAction method run.

@Override
public void run() {
    List<IDiagramModelComponent> selected = new ArrayList<IDiagramModelComponent>();
    for (Object object : getSelectedObjects()) {
        if (object instanceof EditPart) {
            Object model = ((EditPart) object).getModel();
            if (model instanceof ILockable && ((ILockable) model).isLocked()) {
                continue;
            }
            if (model instanceof IDiagramModelComponent) {
                selected.add((IDiagramModelComponent) model);
            }
        }
    }
    CopySnapshot clipBoardCopy = new CopySnapshot(selected);
    Clipboard.getDefault().setContents(clipBoardCopy);
    // Reset Paste Action
    fPasteAction.reset();
}
Also used : IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) ArrayList(java.util.ArrayList) EditPart(org.eclipse.gef.EditPart) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) ILockable(com.archimatetool.model.ILockable)

Example 4 with ILockable

use of com.archimatetool.model.ILockable in project archi by archimatetool.

the class DefaultEditPartSizeAction method createDefaultSizeCommand.

private Command createDefaultSizeCommand(List<?> objects) {
    CompoundCommand command = new CompoundCommand();
    for (Object object : objects) {
        if (object instanceof GraphicalEditPart) {
            GraphicalEditPart part = (GraphicalEditPart) object;
            if (part.getModel() instanceof IDiagramModelObject) {
                IDiagramModelObject model = (IDiagramModelObject) part.getModel();
                if (model instanceof ILockable && ((ILockable) model).isLocked()) {
                    continue;
                }
                IFigure figure = part.getFigure();
                if (figure instanceof IDiagramModelObjectFigure) {
                    Dimension defaultSize = ((IDiagramModelObjectFigure) figure).getDefaultSize();
                    IBounds bounds = model.getBounds().getCopy();
                    if (bounds.getWidth() != defaultSize.width || bounds.getHeight() != defaultSize.height) {
                        bounds.setWidth(defaultSize.width);
                        bounds.setHeight(defaultSize.height);
                        Command cmd = new SetConstraintObjectCommand(model, bounds);
                        command.add(cmd);
                    }
                }
            }
        }
    }
    return command.unwrap();
}
Also used : 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) IBounds(com.archimatetool.model.IBounds) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelObjectFigure(com.archimatetool.editor.diagram.figures.IDiagramModelObjectFigure) Dimension(org.eclipse.draw2d.geometry.Dimension) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) ILockable(com.archimatetool.model.ILockable) IFigure(org.eclipse.draw2d.IFigure)

Example 5 with ILockable

use of com.archimatetool.model.ILockable in project archi by archimatetool.

the class LockObjectAction method createLockCommand.

private Command createLockCommand(List<?> objects) {
    CompoundCommand command = new CompoundCommand();
    boolean lock = isToLock();
    for (Object object : objects) {
        if (object instanceof EditPart) {
            EditPart part = (EditPart) object;
            if (part.getModel() instanceof ILockable) {
                ILockable model = (ILockable) part.getModel();
                if (model.isLocked() != lock) {
                    Command cmd = new LockObjectCommand(model, lock);
                    command.add(cmd);
                }
            }
        }
    }
    return command.unwrap();
}
Also used : Command(org.eclipse.gef.commands.Command) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) LockObjectCommand(com.archimatetool.editor.diagram.commands.LockObjectCommand) LockObjectCommand(com.archimatetool.editor.diagram.commands.LockObjectCommand) EditPart(org.eclipse.gef.EditPart) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) ILockable(com.archimatetool.model.ILockable)

Aggregations

ILockable (com.archimatetool.model.ILockable)8 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)6 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)6 Command (org.eclipse.gef.commands.Command)4 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)3 LockObjectCommand (com.archimatetool.editor.diagram.commands.LockObjectCommand)2 SetConstraintObjectCommand (com.archimatetool.editor.diagram.commands.SetConstraintObjectCommand)2 IBounds (com.archimatetool.model.IBounds)2 IDiagramModelContainer (com.archimatetool.model.IDiagramModelContainer)2 Dimension (org.eclipse.draw2d.geometry.Dimension)2 EditPart (org.eclipse.gef.EditPart)2 GraphicalViewer (org.eclipse.gef.GraphicalViewer)2 DiagramImageEditPart (com.archimatetool.editor.diagram.editparts.diagram.DiagramImageEditPart)1 IDiagramModelObjectFigure (com.archimatetool.editor.diagram.figures.IDiagramModelObjectFigure)1 DiagramImageFigure (com.archimatetool.editor.diagram.figures.diagram.DiagramImageFigure)1 IDiagramModelComponent (com.archimatetool.model.IDiagramModelComponent)1 ArrayList (java.util.ArrayList)1 IFigure (org.eclipse.draw2d.IFigure)1 EObject (org.eclipse.emf.ecore.EObject)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1