Search in sources :

Example 6 with OrmEditPart

use of org.jboss.tools.hibernate.ui.diagram.editors.parts.OrmEditPart in project jbosstools-hibernate by jbosstools.

the class ToggleShapeVisibleStateAction method canPerformAction.

@SuppressWarnings("unchecked")
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) {
            Object ormElement = ((OrmShape) obj).getOrmElement();
            if (ormElement instanceof IPersistentClass || ormElement instanceof ITable) {
                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) Iterator(java.util.Iterator) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 7 with OrmEditPart

use of org.jboss.tools.hibernate.ui.diagram.editors.parts.OrmEditPart in project jbosstools-hibernate by jbosstools.

the class ToggleShapeVisibleStateAction method getCommand.

@SuppressWarnings("unchecked")
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) {
            selectedShape.add((OrmShape) obj);
        }
    }
    OrmShape primalElement = null;
    if (getSelection() instanceof IStructuredSelection) {
        Object firstElement = ((IStructuredSelection) getSelection()).getFirstElement();
        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) {
            primalElement = (OrmShape) obj;
        }
    }
    if (selectedShape.size() > 0) {
        cc.add(new ToggleShapeVisibleStateCommand(selectedShape, primalElement));
    }
    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) Iterator(java.util.Iterator) ToggleShapeVisibleStateCommand(org.jboss.tools.hibernate.ui.diagram.editors.command.ToggleShapeVisibleStateCommand) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 8 with OrmEditPart

use of org.jboss.tools.hibernate.ui.diagram.editors.parts.OrmEditPart in project jbosstools-hibernate by jbosstools.

the class DiagramViewer method getSelectedElements.

public Set<Shape> getSelectedElements() {
    Set<Shape> ret = new HashSet<Shape>();
    List<?> selectedEditParts = getGraphicalViewer().getSelectedEditParts();
    Iterator<?> iterator = selectedEditParts.iterator();
    while (iterator.hasNext()) {
        Object elem = iterator.next();
        if (elem instanceof OrmEditPart) {
            Shape shape = (Shape) ((OrmEditPart) elem).getModel();
            ret.add(shape);
        }
    }
    return ret;
}
Also used : Shape(org.jboss.tools.hibernate.ui.diagram.editors.model.Shape) OrmEditPart(org.jboss.tools.hibernate.ui.diagram.editors.parts.OrmEditPart) HashSet(java.util.HashSet)

Example 9 with OrmEditPart

use of org.jboss.tools.hibernate.ui.diagram.editors.parts.OrmEditPart in project jbosstools-hibernate by jbosstools.

the class ShapeCollapseAction method getCommand.

public Command getCommand() {
    CompoundCommand cc = new CompoundCommand();
    if (getSelectedObjects().isEmpty()) {
        return cc;
    }
    List<ExpandableShape> selectedShape = new ArrayList<ExpandableShape>();
    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 ExpandableShape) {
            ExpandableShape es = (ExpandableShape) obj;
            if (es.isExpanded()) {
                selectedShape.add(es);
            }
        }
    }
    if (selectedShape.size() > 0) {
        cc.add(new ToggleShapeExpandStateCommand(selectedShape, null));
    }
    return cc;
}
Also used : ExpandableShape(org.jboss.tools.hibernate.ui.diagram.editors.model.ExpandableShape) AbstractTreeEditPart(org.eclipse.gef.editparts.AbstractTreeEditPart) OrmEditPart(org.jboss.tools.hibernate.ui.diagram.editors.parts.OrmEditPart) ArrayList(java.util.ArrayList) ToggleShapeExpandStateCommand(org.jboss.tools.hibernate.ui.diagram.editors.command.ToggleShapeExpandStateCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 10 with OrmEditPart

use of org.jboss.tools.hibernate.ui.diagram.editors.parts.OrmEditPart in project jbosstools-hibernate by jbosstools.

the class ShapeExpandAction 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 ExpandableShape) {
            ExpandableShape es = (ExpandableShape) obj;
            if (!es.isExpanded()) {
                res = true;
            }
        }
    }
    return res;
}
Also used : ExpandableShape(org.jboss.tools.hibernate.ui.diagram.editors.model.ExpandableShape) AbstractTreeEditPart(org.eclipse.gef.editparts.AbstractTreeEditPart) OrmEditPart(org.jboss.tools.hibernate.ui.diagram.editors.parts.OrmEditPart)

Aggregations

OrmEditPart (org.jboss.tools.hibernate.ui.diagram.editors.parts.OrmEditPart)13 AbstractTreeEditPart (org.eclipse.gef.editparts.AbstractTreeEditPart)12 OrmShape (org.jboss.tools.hibernate.ui.diagram.editors.model.OrmShape)7 ArrayList (java.util.ArrayList)6 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)6 ExpandableShape (org.jboss.tools.hibernate.ui.diagram.editors.model.ExpandableShape)6 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)4 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 ToggleShapeExpandStateCommand (org.jboss.tools.hibernate.ui.diagram.editors.command.ToggleShapeExpandStateCommand)3 ToggleShapeVisibleStateCommand (org.jboss.tools.hibernate.ui.diagram.editors.command.ToggleShapeVisibleStateCommand)3 Iterator (java.util.Iterator)2 Shape (org.jboss.tools.hibernate.ui.diagram.editors.model.Shape)2 HashSet (java.util.HashSet)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