Search in sources :

Example 11 with OrmEditPart

use of org.jboss.tools.hibernate.ui.diagram.editors.parts.OrmEditPart 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 12 with OrmEditPart

use of org.jboss.tools.hibernate.ui.diagram.editors.parts.OrmEditPart 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 13 with OrmEditPart

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

the class PopupMenuProvider method buildContextMenu.

public void buildContextMenu(IMenuManager menu) {
    menu.add(new Separator(GROUP_OPEN_SOURCE));
    menu.add(new Separator(GROUP_EDIT));
    menu.add(new Separator(GROUP_ADDITIONAL_ACTIONS));
    // Add standard action groups to the menu
    // GEFActionConstants.addStandardActionGroups(menu);
    IAction action = null;
    if (getViewer().getSelection() instanceof StructuredSelection) {
        Shape selectedShape = null;
        IStructuredSelection selection = (IStructuredSelection) getViewer().getSelection();
        if (selection != null) {
            Object firstElement = selection.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 Shape) {
                selectedShape = (Shape) obj;
            }
        }
        if (selectedShape != null && selection.size() == 1) {
            Object first = selectedShape.getOrmElement();
            if (first instanceof IPersistentClass || (first instanceof IProperty && ((IProperty) first).classIsPropertyClass()) || first instanceof ITable || first instanceof IColumn) {
                action = getActionRegistry().getAction(OpenSourceAction.ACTION_ID);
                appendToGroup(GROUP_OPEN_SOURCE, action);
                createMenuItem(getMenu(), action);
                action = getActionRegistry().getAction(OpenMappingAction.ACTION_ID);
                appendToGroup(GROUP_OPEN_SOURCE, action);
                createMenuItem(getMenu(), action);
            }
        }
        boolean addToggleVisibleStateMenu = false;
        boolean addToggleExpandStateMenu = false;
        Iterator<?> it = selection.iterator();
        while (it.hasNext() && (!addToggleVisibleStateMenu || !addToggleExpandStateMenu)) {
            Object element = it.next();
            Object obj = null;
            if (element instanceof OrmEditPart) {
                obj = ((OrmEditPart) element).getModel();
            } else if (element instanceof AbstractTreeEditPart) {
                obj = ((AbstractTreeEditPart) element).getModel();
            }
            if (null != obj && obj instanceof OrmShape) {
                selectedShape = (Shape) obj;
                Object first = selectedShape.getOrmElement();
                if (first instanceof IPersistentClass || first instanceof ITable) {
                    addToggleVisibleStateMenu = true;
                }
            }
            if (null != obj && obj instanceof ExpandableShape) {
                addToggleExpandStateMenu = true;
            }
        }
        if (addToggleVisibleStateMenu) {
            action = getActionRegistry().getAction(ToggleShapeVisibleStateAction.ACTION_ID);
            appendToGroup(GROUP_EDIT, action);
            createMenuItem(getMenu(), action);
        }
        if (addToggleExpandStateMenu) {
            action = getActionRegistry().getAction(ToggleShapeExpandStateAction.ACTION_ID);
            appendToGroup(GROUP_EDIT, action);
            createMenuItem(getMenu(), action);
        }
    }
    action = getActionRegistry().getAction(ToggleConnectionsAction.ACTION_ID);
    appendToGroup(GROUP_EDIT, action);
    createMenuItem(getMenu(), action);
    action = getActionRegistry().getAction(AutoLayoutAction.ACTION_ID);
    appendToGroup(GROUP_ADDITIONAL_ACTIONS, action);
    createMenuItem(getMenu(), action);
    // action = getActionRegistry().getAction(CollapseAllAction.ACTION_ID);
    // appendToGroup(GROUP_EDIT, action);
    // createMenuItem(getMenu(), action);
    // action = getActionRegistry().getAction(ExpandAllAction.ACTION_ID);
    // appendToGroup(GROUP_EDIT, action);
    // createMenuItem(getMenu(), action);
    action = getActionRegistry().getAction(ExportImageAction.ACTION_ID);
    appendToGroup(GROUP_ADDITIONAL_ACTIONS, action);
    createMenuItem(getMenu(), action);
    // Add actions to the menu
    /**
     * /
     *		// is undo/redo operation so necessary for popup menu?
     *		menu.appendToGroup(
     *				GEFActionConstants.GROUP_UNDO, // target group id
     *				getAction(ActionFactory.UNDO.getId())); // action to add
     *		menu.appendToGroup(
     *				GEFActionConstants.GROUP_UNDO,
     *				getAction(ActionFactory.REDO.getId()));
     *		/*
     */
    menu.appendToGroup(// target group id
    GROUP_EDIT, // action to add
    getAction(ActionFactory.SELECT_ALL.getId()));
}
Also used : ExpandableShape(org.jboss.tools.hibernate.ui.diagram.editors.model.ExpandableShape) Shape(org.jboss.tools.hibernate.ui.diagram.editors.model.Shape) ExpandableShape(org.jboss.tools.hibernate.ui.diagram.editors.model.ExpandableShape) OrmShape(org.jboss.tools.hibernate.ui.diagram.editors.model.OrmShape) AbstractTreeEditPart(org.eclipse.gef.editparts.AbstractTreeEditPart) IAction(org.eclipse.jface.action.IAction) OrmEditPart(org.jboss.tools.hibernate.ui.diagram.editors.parts.OrmEditPart) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) OrmShape(org.jboss.tools.hibernate.ui.diagram.editors.model.OrmShape) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) Separator(org.eclipse.jface.action.Separator)

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