Search in sources :

Example 1 with IColumn

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

the class OrmShape method initModel.

/**
 * creates children of the shape,
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void initModel() {
    Object ormElement = getOrmElement();
    if (ormElement instanceof IPersistentClass && ((IPersistentClass) ormElement).isInstanceOfRootClass()) {
        IPersistentClass rootClass = (IPersistentClass) ormElement;
        IProperty identifierProperty = rootClass.getIdentifierProperty();
        if (identifierProperty != null) {
            addChild(new Shape(identifierProperty, getConsoleConfigName()));
        }
        IValue identifier = rootClass.getIdentifier();
        if (identifier != null && identifier.isComponent()) {
            IValue component = identifier;
            if (component.isEmbedded()) {
                Iterator<IProperty> iterator = identifier.getPropertyIterator();
                while (iterator.hasNext()) {
                    IProperty property = iterator.next();
                    addChild(new Shape(property, getConsoleConfigName()));
                }
            }
        }
        Iterator<IProperty> iterator = rootClass.getPropertyIterator();
        while (iterator.hasNext()) {
            IProperty field = iterator.next();
            if (!field.isBackRef()) {
                if (!field.isComposite()) {
                    final IValue val = field.getValue();
                    Shape bodyOrmShape = null;
                    if (val.isSimpleValue() && val.isTypeSpecified()) {
                        bodyOrmShape = new Shape(field, getConsoleConfigName());
                    } else {
                        if (val.isCollection()) {
                            bodyOrmShape = new ComponentShape(field, getConsoleConfigName());
                        } else {
                            IType type = getTypeUsingExecContext(val);
                            if (type != null && type.isEntityType()) {
                                bodyOrmShape = new ExpandableShape(field, getConsoleConfigName());
                            } else {
                                bodyOrmShape = new Shape(field, getConsoleConfigName());
                            }
                        }
                    }
                    addChild(bodyOrmShape);
                } else {
                    Shape bodyOrmShape = new ExpandableShape(field, getConsoleConfigName());
                    addChild(bodyOrmShape);
                }
            }
        }
    } else if (ormElement instanceof IPersistentClass && ((IPersistentClass) ormElement).isInstanceOfSubclass()) {
        IPersistentClass rootClass = ((IPersistentClass) ormElement).getRootClass();
        IProperty identifierProperty = rootClass.getIdentifierProperty();
        if (identifierProperty != null) {
            addChild(new Shape(identifierProperty, getConsoleConfigName()));
        }
        IValue identifier = rootClass.getIdentifier();
        if (identifier.isComponent()) {
            Iterator<IProperty> iterator = identifier.getPropertyIterator();
            while (iterator.hasNext()) {
                IProperty property = iterator.next();
                addChild(new Shape(property, getConsoleConfigName()));
            }
        }
        Iterator<IProperty> iterator = rootClass.getPropertyIterator();
        while (iterator.hasNext()) {
            IProperty field = iterator.next();
            if (!field.isBackRef()) {
                if (!field.isComposite()) {
                    IValue fieldValue = field.getValue();
                    boolean typeIsAccessible = true;
                    if (fieldValue.isSimpleValue() && fieldValue.isTypeSpecified()) {
                        try {
                            field.getValue().getType();
                        } catch (Exception e) {
                            typeIsAccessible = false;
                        }
                    }
                    Shape bodyOrmShape = null;
                    if (typeIsAccessible && field.getValue().isSimpleValue()) {
                        bodyOrmShape = new Shape(field, getConsoleConfigName());
                    } else if (typeIsAccessible && field.getValue().getType().isEntityType()) {
                        bodyOrmShape = new ExpandableShape(field, getConsoleConfigName());
                    } else if (typeIsAccessible && field.getValue().getType().isCollectionType()) {
                        bodyOrmShape = new ComponentShape(field, getConsoleConfigName());
                    } else {
                        bodyOrmShape = new Shape(field, getConsoleConfigName());
                    }
                    addChild(bodyOrmShape);
                } else {
                    Shape bodyOrmShape = new ExpandableShape(field, getConsoleConfigName());
                    addChild(bodyOrmShape);
                }
            }
        }
        Iterator<IProperty> iter = ((IPersistentClass) ormElement).getPropertyIterator();
        while (iter.hasNext()) {
            IProperty property = iter.next();
            if (!property.isBackRef()) {
                if (!property.isComposite()) {
                    boolean typeIsAccessible = true;
                    IValue propertyValue = property.getValue();
                    if (propertyValue.isSimpleValue() && propertyValue.isTypeSpecified()) {
                        try {
                            property.getValue().getType();
                        } catch (Exception e) {
                            typeIsAccessible = false;
                        }
                    }
                    Shape bodyOrmShape = null;
                    if (typeIsAccessible && property.getValue().getType().isEntityType()) {
                        bodyOrmShape = new ExpandableShape(property, getConsoleConfigName());
                    } else if (typeIsAccessible && property.getValue().getType().isCollectionType()) {
                        bodyOrmShape = new ComponentShape(property, getConsoleConfigName());
                    } else {
                        bodyOrmShape = new Shape(property, getConsoleConfigName());
                    }
                    addChild(bodyOrmShape);
                } else {
                    Shape bodyOrmShape = new ExpandableShape(property, getConsoleConfigName());
                    addChild(bodyOrmShape);
                }
            }
        }
    } else if (ormElement instanceof ITable) {
        Iterator iterator = ((ITable) getOrmElement()).getColumnIterator();
        while (iterator.hasNext()) {
            IColumn column = (IColumn) iterator.next();
            Shape bodyOrmShape = new Shape(column, getConsoleConfigName());
            addChild(bodyOrmShape);
        }
    }
}
Also used : IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) IType(org.jboss.tools.hibernate.runtime.spi.IType) IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) Iterator(java.util.Iterator) ITable(org.jboss.tools.hibernate.runtime.spi.ITable)

Example 2 with IColumn

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

the class ShapeEditPart method getSelectionColor.

protected Color getSelectionColor() {
    Color result = ResourceManager.getInstance().getColor(new RGB(255, 0, 0));
    final Object el = getElement();
    if (el instanceof IPersistentClass || el instanceof IProperty) {
        result = ResourceManager.getInstance().getColor(new RGB(112, 161, 99));
    } else if (el instanceof IValue) {
        IValue value = (IValue) el;
        if (value.isSimpleValue() || value.isOneToMany()) {
            result = ResourceManager.getInstance().getColor(new RGB(112, 161, 99));
        }
    } else if (el instanceof ITable || el instanceof IColumn) {
        result = ResourceManager.getInstance().getColor(new RGB(66, 173, 247));
    }
    return result;
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) Color(org.eclipse.swt.graphics.Color) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) RGB(org.eclipse.swt.graphics.RGB) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 3 with IColumn

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

the class ForeignKeyFacadeTest method testGetReferencedColumns.

@Test
public void testGetReferencedColumns() {
    List<IColumn> list = foreignKeyFacade.getReferencedColumns();
    Assert.assertTrue(list.isEmpty());
    Assert.assertEquals("getReferencedColumns", methodName);
    Assert.assertArrayEquals(new Object[] {}, arguments);
    // recreate facade to reinitialize the instance variables
    foreignKeyFacade = new AbstractForeignKeyFacade(FACADE_FACTORY, foreignKey) {
    };
    Column column = new Column();
    ArrayList<Column> columns = new ArrayList<Column>();
    columns.add(column);
    foreignKey.addReferencedColumns(columns.iterator());
    reset();
    list = foreignKeyFacade.getReferencedColumns();
    Assert.assertFalse(list.isEmpty());
    Assert.assertEquals("getReferencedColumns", methodName);
    Assert.assertArrayEquals(new Object[] {}, arguments);
}
Also used : IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) Column(org.hibernate.mapping.Column) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) AbstractForeignKeyFacade(org.jboss.tools.hibernate.runtime.common.AbstractForeignKeyFacade) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 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 5 with IColumn

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

the class TableFacadeTest method testGetColumnIterator.

@Test
public void testGetColumnIterator() {
    Table table = new Table();
    ITable tableFacade = FACADE_FACTORY.createTable(table);
    Iterator<IColumn> columnIterator = tableFacade.getColumnIterator();
    Assert.assertFalse(columnIterator.hasNext());
    Column column = new Column("foo");
    table.addColumn(column);
    tableFacade = FACADE_FACTORY.createTable(table);
    columnIterator = tableFacade.getColumnIterator();
    IColumn columnFacade = columnIterator.next();
    Assert.assertSame(column, ((IFacade) columnFacade).getTarget());
}
Also used : Table(org.hibernate.mapping.Table) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) Column(org.hibernate.mapping.Column) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) 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