Search in sources :

Example 51 with IColumn

use of org.jboss.tools.hibernate.runtime.spi.IColumn in project jbosstools-hibernate by jbosstools.

the class Shape method getPropertyValue.

/**
 * Return the property value for the given propertyId, or null.
 * <p>The property view uses the IDs from the IPropertyDescriptors array
 * to obtain the value of the corresponding properties.</p>
 * @see #descriptors
 * @see #getPropertyDescriptors()
 */
@Override
public Object getPropertyValue(Object propertyId) {
    Object res = null;
    IColumn col = null;
    if (getOrmElement() instanceof IColumn) {
        col = (IColumn) getOrmElement();
    }
    IProperty prop = null;
    if (getOrmElement() instanceof IProperty) {
        prop = (IProperty) getOrmElement();
    }
    if (prop != null) {
        if (PROPERTY_NAME.equals(propertyId)) {
            res = prop.getName();
        } else if (PROPERTY_TYPE.equals(propertyId)) {
            IValue value = prop.getValue();
            if (value.isComponent()) {
                res = value.toString();
            } else {
                IType type = getTypeUsingExecContext(value);
                if (type != null) {
                    res = type.getAssociatedEntityName();
                }
            }
        } else if (PROPERTY_VALUE.equals(propertyId)) {
            res = prop.getValue().toString();
        } else if (PROPERTY_CLASS.equals(propertyId)) {
            if (prop.getPersistentClass() != null) {
                res = prop.getPersistentClass().getClassName();
            }
        } else if (PROPERTY_SELECT.equals(propertyId)) {
            res = Boolean.valueOf(prop.isSelectable()).toString();
        } else if (PROPERTY_INSERT.equals(propertyId)) {
            res = Boolean.valueOf(prop.isInsertable()).toString();
        } else if (PROPERTY_UPDATE.equals(propertyId)) {
            res = Boolean.valueOf(prop.isUpdateable()).toString();
        } else if (PROPERTY_CASCADE.equals(propertyId)) {
            res = prop.getCascade();
        } else if (PROPERTY_LAZY.equals(propertyId)) {
            res = Boolean.valueOf(prop.isLazy()).toString();
        } else if (PROPERTY_OPTIONAL.equals(propertyId)) {
            res = Boolean.valueOf(prop.isOptional()).toString();
        } else if (PROPERTY_NATURAL_IDENTIFIER.equals(propertyId)) {
            res = Boolean.valueOf(prop.isNaturalIdentifier()).toString();
        } else if (PROPERTY_OPTIMISTIC_LOCKED.equals(propertyId)) {
            res = Boolean.valueOf(prop.isOptimisticLocked()).toString();
        }
    } else if (col != null) {
        if (PROPERTY_NAME.equals(propertyId)) {
            res = col.getName();
        } else if (PROPERTY_TYPE.equals(propertyId)) {
            String sqlType = col.getSqlType();
            if (sqlType == null) {
                getOrmDiagram().getLabelProvider().updateColumnSqlType(col);
                sqlType = col.getSqlType();
            }
            StringBuffer name = new StringBuffer();
            if (sqlType != null) {
                name.append(sqlType.toUpperCase());
                name.append(HibernateUtils.getTable(col) != null && HibernateUtils.isPrimaryKey(col) ? " PK" : // $NON-NLS-1$  //$NON-NLS-2$
                "");
                name.append(HibernateUtils.getTable(col) != null && HibernateUtils.isForeignKey(col) ? " FK" : // $NON-NLS-1$ //$NON-NLS-2$
                "");
            }
            res = name.toString();
        } else if (PROPERTY_VALUE.equals(propertyId)) {
            res = col.getValue().toString();
        } else if (PROPERTY_NULLABLE.equals(propertyId)) {
            res = Boolean.valueOf(col.isNullable()).toString();
        } else if (PROPERTY_UNIQUE.equals(propertyId)) {
            res = Boolean.valueOf(col.isUnique()).toString();
        }
    }
    if (res == null) {
        res = super.getPropertyValue(propertyId);
    }
    return toEmptyStr(res);
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IType(org.jboss.tools.hibernate.runtime.spi.IType)

Example 52 with IColumn

use of org.jboss.tools.hibernate.runtime.spi.IColumn 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)

Example 53 with IColumn

use of org.jboss.tools.hibernate.runtime.spi.IColumn in project jbosstools-hibernate by jbosstools.

the class ConsoleConfigurationTest method testHQLListParameters.

@Test
public void testHQLListParameters() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
    // fix for https://issues.jboss.org/browse/JBIDE-9392
    // the view calls jdbc connection
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IViewPart view = activePage.findView(QueryPageTabView.ID);
    if (view != null) {
        activePage.hideView(view);
        view.dispose();
    }
    consoleCfg.build();
    IConfiguration c = consoleCfg.getConfiguration();
    IPersistentClass rc = service.newRootClass();
    rc.setEntityName("java.awt.Button");
    rc.setClassName("java.awt.Button");
    IColumn column = service.newColumn("label");
    ITable table = service.newTable("faketable");
    IPrimaryKey pk = table.getPrimaryKey();
    pk.addColumn(column);
    rc.setTable(table);
    table.addColumn(column);
    IProperty fakeProp = service.newProperty();
    fakeProp.setName("label");
    IValue sv = service.newSimpleValue();
    sv.addColumn(column);
    sv.setTypeName("string");
    sv.setTable(table);
    fakeProp.setValue(sv);
    rc.setIdentifierProperty(fakeProp);
    rc.setIdentifier(fakeProp.getValue());
    c.addClass(rc);
    consoleCfg.buildSessionFactory();
    ConsoleQueryParameter paramA = new ConsoleQueryParameter(service, "a", typeFactory.getIntegerType(), new Integer[] { new Integer(1), new Integer(2) });
    ConsoleQueryParameter paramB = new ConsoleQueryParameter(service, "b", typeFactory.getIntegerType(), new Integer(3));
    ConsoleQueryParameter paramOrdered = new ConsoleQueryParameter(service, "0", typeFactory.getIntegerType(), new Integer(4));
    QueryInputModel model = new QueryInputModel(service);
    model.addParameter(paramA);
    model.addParameter(paramB);
    model.addParameter(paramOrdered);
    // $NON-NLS-1$
    QueryPage qp = consoleCfg.executeHQLQuery("select count(*) from java.awt.Button where 1 in ( ?, :a, :b )", model);
    Assert.assertNotNull(qp);
    try {
        // execute the query
        qp.getList();
    } catch (Exception e) {
    // ignore - there is fake mapping
    }
}
Also used : ConsoleQueryParameter(org.hibernate.console.ConsoleQueryParameter) IViewPart(org.eclipse.ui.IViewPart) QueryPage(org.hibernate.console.QueryPage) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) QueryInputModel(org.hibernate.console.QueryInputModel) IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Test(org.junit.Test)

Example 54 with IColumn

use of org.jboss.tools.hibernate.runtime.spi.IColumn in project jbosstools-hibernate by jbosstools.

the class ForeignKeyFacadeTest method testContainsColumn.

@Test
public void testContainsColumn() {
    Column column = new Column();
    IColumn columnFacade = FACADE_FACTORY.createColumn(column);
    Assert.assertFalse(foreignKeyFacade.containsColumn(columnFacade));
    Assert.assertEquals("containsColumn", methodName);
    Assert.assertArrayEquals(new Object[] { column }, arguments);
    foreignKey.addColumn(column);
    reset();
    Assert.assertTrue(foreignKeyFacade.containsColumn(columnFacade));
    Assert.assertEquals("containsColumn", methodName);
    Assert.assertArrayEquals(new Object[] { column }, arguments);
}
Also used : Column(org.hibernate.mapping.Column) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) Test(org.junit.Test)

Example 55 with IColumn

use of org.jboss.tools.hibernate.runtime.spi.IColumn in project jbosstools-hibernate by jbosstools.

the class ForeignKeyFacadeTest method testColumnIterator.

@Test
public void testColumnIterator() {
    Column column = new Column();
    foreignKey.addColumn(column);
    reset();
    Iterator<IColumn> iterator = foreignKeyFacade.columnIterator();
    Assert.assertEquals("columnIterator", methodName);
    Assert.assertArrayEquals(new Object[] {}, arguments);
    IColumn columnFacade = iterator.next();
    Assert.assertSame(column, ((IFacade) columnFacade).getTarget());
    Assert.assertFalse(iterator.hasNext());
}
Also used : Column(org.hibernate.mapping.Column) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) Test(org.junit.Test)

Aggregations

IColumn (org.jboss.tools.hibernate.runtime.spi.IColumn)86 Test (org.junit.Test)69 Column (org.hibernate.mapping.Column)68 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)26 SimpleValue (org.hibernate.mapping.SimpleValue)16 Table (org.hibernate.mapping.Table)16 ArrayList (java.util.ArrayList)12 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)9 AbstractForeignKeyFacade (org.jboss.tools.hibernate.runtime.common.AbstractForeignKeyFacade)7 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)7 IValue (org.jboss.tools.hibernate.runtime.spi.IValue)7 Iterator (java.util.Iterator)5 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)4 IPrimaryKey (org.jboss.tools.hibernate.runtime.spi.IPrimaryKey)4 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)3 Shape (org.jboss.tools.hibernate.ui.diagram.editors.model.Shape)3 FileNotFoundException (java.io.FileNotFoundException)2 HashMap (java.util.HashMap)2 List (java.util.List)2