Search in sources :

Example 6 with OrmShape

use of org.jboss.tools.hibernate.ui.diagram.editors.model.OrmShape in project jbosstools-hibernate by jbosstools.

the class MoveGuideCommand method undo.

public void undo() {
    guide.setPosition(guide.getPosition() - pDelta);
    Iterator<OrmShape> iter = guide.getParts().iterator();
    while (iter.hasNext()) {
        OrmShape part = (OrmShape) iter.next();
        Point location = part.getLocation().getCopy();
        if (guide.isHorizontal()) {
            location.y -= pDelta;
        } else {
            location.x -= pDelta;
        }
        part.setLocation(location);
    }
}
Also used : OrmShape(org.jboss.tools.hibernate.ui.diagram.editors.model.OrmShape) Point(org.eclipse.draw2d.geometry.Point)

Example 7 with OrmShape

use of org.jboss.tools.hibernate.ui.diagram.editors.model.OrmShape in project jbosstools-hibernate by jbosstools.

the class ShapesXYLayoutEditPolicy method createChangeConstraintCommand.

/**
 * @see org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#createChangeConstraintCommand(org.eclipse.gef.EditPart, java.lang.Object)
 */
protected Command createChangeConstraintCommand(ChangeBoundsRequest request, EditPart child, Object constraint) {
    if (!(child instanceof OrmShapeEditPart && constraint instanceof Rectangle)) {
        return super.createChangeConstraintCommand(request, child, constraint);
    }
    OrmShape part = (OrmShape) child.getModel();
    Command result = new ShapeSetConstraintCommand(part, request, ((Rectangle) constraint).getLocation());
    if ((request.getResizeDirection() & PositionConstants.NORTH_SOUTH) != 0) {
        Integer guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_HORIZONTAL_GUIDE);
        if (guidePos != null) {
            result = chainGuideAttachmentCommand(request, part, result, true);
        } else if (part.getHorizontalGuide() != null) {
            // SnapToGuides didn't provide a horizontal guide, but this part is attached
            // to a horizontal guide.  Now we check to see if the part is attached to
            // the guide along the edge being resized.  If that is the case, we need to
            // detach the part from the guide; otherwise, we leave it alone.
            int alignment = part.getHorizontalGuide().getAlignment(part);
            int edgeBeingResized = 0;
            if ((request.getResizeDirection() & PositionConstants.NORTH) != 0) {
                edgeBeingResized = -1;
            } else {
                edgeBeingResized = 1;
            }
            if (alignment == edgeBeingResized) {
                result = result.chain(new ChangeGuideCommand(part, true));
            }
        }
    }
    if ((request.getResizeDirection() & PositionConstants.EAST_WEST) != 0) {
        Integer guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_VERTICAL_GUIDE);
        if (guidePos != null) {
            result = chainGuideAttachmentCommand(request, part, result, false);
        } else if (part.getVerticalGuide() != null) {
            int alignment = part.getVerticalGuide().getAlignment(part);
            int edgeBeingResized = 0;
            if ((request.getResizeDirection() & PositionConstants.WEST) != 0) {
                edgeBeingResized = -1;
            } else {
                edgeBeingResized = 1;
            }
            if (alignment == edgeBeingResized) {
                result = result.chain(new ChangeGuideCommand(part, false));
            }
        }
    }
    if (request.getType().equals(REQ_MOVE_CHILDREN) || request.getType().equals(REQ_ALIGN_CHILDREN)) {
        result = chainGuideAttachmentCommand(request, part, result, true);
        result = chainGuideAttachmentCommand(request, part, result, false);
        result = chainGuideDetachmentCommand(request, part, result, true);
        result = chainGuideDetachmentCommand(request, part, result, false);
    }
    return result;
}
Also used : OrmShape(org.jboss.tools.hibernate.ui.diagram.editors.model.OrmShape) ShapeSetConstraintCommand(org.jboss.tools.hibernate.ui.diagram.editors.command.ShapeSetConstraintCommand) Command(org.eclipse.gef.commands.Command) ShapeSetConstraintCommand(org.jboss.tools.hibernate.ui.diagram.editors.command.ShapeSetConstraintCommand) ChangeGuideCommand(org.jboss.tools.hibernate.ui.diagram.editors.command.ChangeGuideCommand) Rectangle(org.eclipse.draw2d.geometry.Rectangle) ChangeGuideCommand(org.jboss.tools.hibernate.ui.diagram.editors.command.ChangeGuideCommand)

Example 8 with OrmShape

use of org.jboss.tools.hibernate.ui.diagram.editors.model.OrmShape in project jbosstools-hibernate by jbosstools.

the class ShapeHideAction method canPerformAction.

private boolean canPerformAction() {
    boolean res = false;
    if (getSelectedObjects().isEmpty()) {
        return res;
    }
    Iterator<?> it = getSelectedObjects().iterator();
    while (it.hasNext() && !res) {
        Object firstElement = it.next();
        Object obj = null;
        if (firstElement instanceof OrmEditPart) {
            obj = ((OrmEditPart) firstElement).getModel();
        } else if (firstElement instanceof AbstractTreeEditPart) {
            obj = ((AbstractTreeEditPart) firstElement).getModel();
        }
        if (null != obj && obj instanceof OrmShape) {
            OrmShape ormShape = (OrmShape) obj;
            Object ormElement = ormShape.getOrmElement();
            if (ormElement instanceof IPersistentClass || ormElement instanceof ITable) {
                if (ormShape.isVisible()) {
                    res = true;
                }
            }
        }
    }
    return res;
}
Also used : OrmShape(org.jboss.tools.hibernate.ui.diagram.editors.model.OrmShape) AbstractTreeEditPart(org.eclipse.gef.editparts.AbstractTreeEditPart) OrmEditPart(org.jboss.tools.hibernate.ui.diagram.editors.parts.OrmEditPart) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 9 with OrmShape

use of org.jboss.tools.hibernate.ui.diagram.editors.model.OrmShape in project jbosstools-hibernate by jbosstools.

the class ShapeHideAction method getCommand.

public Command getCommand() {
    CompoundCommand cc = new CompoundCommand();
    if (getSelectedObjects().isEmpty()) {
        return cc;
    }
    List<OrmShape> selectedShape = new ArrayList<OrmShape>();
    Iterator<?> it = getSelectedObjects().iterator();
    while (it.hasNext()) {
        Object firstElement = it.next();
        Object obj = null;
        if (firstElement instanceof OrmEditPart) {
            obj = ((OrmEditPart) firstElement).getModel();
        } else if (firstElement instanceof AbstractTreeEditPart) {
            obj = ((AbstractTreeEditPart) firstElement).getModel();
        }
        if (null != obj && obj instanceof OrmShape) {
            OrmShape ormShape = (OrmShape) obj;
            if (ormShape.isVisible()) {
                selectedShape.add(ormShape);
            }
        }
    }
    if (selectedShape.size() > 0) {
        cc.add(new ToggleShapeVisibleStateCommand(selectedShape, null));
    }
    return cc;
}
Also used : OrmShape(org.jboss.tools.hibernate.ui.diagram.editors.model.OrmShape) AbstractTreeEditPart(org.eclipse.gef.editparts.AbstractTreeEditPart) OrmEditPart(org.jboss.tools.hibernate.ui.diagram.editors.parts.OrmEditPart) ArrayList(java.util.ArrayList) ToggleShapeVisibleStateCommand(org.jboss.tools.hibernate.ui.diagram.editors.command.ToggleShapeVisibleStateCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 10 with OrmShape

use of org.jboss.tools.hibernate.ui.diagram.editors.model.OrmShape in project jbosstools-hibernate by jbosstools.

the class MoveGuideCommand method execute.

public void execute() {
    guide.setPosition(guide.getPosition() + pDelta);
    Iterator<OrmShape> iter = guide.getParts().iterator();
    while (iter.hasNext()) {
        OrmShape part = iter.next();
        Point location = part.getLocation().getCopy();
        if (guide.isHorizontal()) {
            location.y += pDelta;
        } else {
            location.x += pDelta;
        }
        part.setLocation(location);
    }
}
Also used : OrmShape(org.jboss.tools.hibernate.ui.diagram.editors.model.OrmShape) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

OrmShape (org.jboss.tools.hibernate.ui.diagram.editors.model.OrmShape)12 AbstractTreeEditPart (org.eclipse.gef.editparts.AbstractTreeEditPart)7 OrmEditPart (org.jboss.tools.hibernate.ui.diagram.editors.parts.OrmEditPart)7 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)5 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)5 ArrayList (java.util.ArrayList)3 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)3 ToggleShapeVisibleStateCommand (org.jboss.tools.hibernate.ui.diagram.editors.command.ToggleShapeVisibleStateCommand)3 Iterator (java.util.Iterator)2 Point (org.eclipse.draw2d.geometry.Point)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 Command (org.eclipse.gef.commands.Command)1 IAction (org.eclipse.jface.action.IAction)1 Separator (org.eclipse.jface.action.Separator)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 IColumn (org.jboss.tools.hibernate.runtime.spi.IColumn)1 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)1 ChangeGuideCommand (org.jboss.tools.hibernate.ui.diagram.editors.command.ChangeGuideCommand)1 ShapeSetConstraintCommand (org.jboss.tools.hibernate.ui.diagram.editors.command.ShapeSetConstraintCommand)1