Search in sources :

Example 96 with IPersistentClass

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

the class OrmDiagram method refreshRootsFromNames.

public boolean refreshRootsFromNames() {
    final IConfiguration config = getConfig();
    if (config == null) {
        return false;
    }
    for (int i = 0; i < roots.size(); i++) {
        IPersistentClass newOrmElement = config.getClassMapping(entityNames.get(i));
        if (roots.get(i) == null) {
            if (newOrmElement == null) {
                continue;
            }
        } else if (roots.get(i).equals(newOrmElement)) {
            continue;
        }
        roots.set(i, newOrmElement);
    }
    return true;
}
Also used : IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Point(org.eclipse.draw2d.geometry.Point) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 97 with IPersistentClass

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

the class OrmShape method getPropertyValue.

@Override
public Object getPropertyValue(Object propertyId) {
    Object res = null;
    IPersistentClass rootClass = null;
    ITable table = null;
    Object ormElement = getOrmElement();
    if (ormElement instanceof IPersistentClass && ((IPersistentClass) ormElement).isInstanceOfRootClass()) {
        rootClass = (IPersistentClass) ormElement;
    } else if (ormElement instanceof IPersistentClass && ((IPersistentClass) ormElement).isInstanceOfSubclass()) {
    // rootClass = ((Subclass)ormElement).getRootClass();
    } else if (ormElement instanceof ITable) {
        table = (ITable) getOrmElement();
    }
    if (rootClass != null) {
        if (ENTITY_isAbstract.equals(propertyId)) {
            if (rootClass.isAbstract() != null) {
                res = rootClass.isAbstract().toString();
            }
        } else if (ENTITY_isCustomDeleteCallable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isCustomDeleteCallable()).toString();
        } else if (ENTITY_isCustomInsertCallable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isCustomInsertCallable()).toString();
        } else if (ENTITY_isCustomUpdateCallable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isCustomUpdateCallable()).toString();
        } else if (ENTITY_isDiscriminatorInsertable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isDiscriminatorInsertable()).toString();
        } else if (ENTITY_isDiscriminatorValueNotNull.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isDiscriminatorValueNotNull()).toString();
        } else if (ENTITY_isDiscriminatorValueNull.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isDiscriminatorValueNull()).toString();
        } else if (ENTITY_isExplicitPolymorphism.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isExplicitPolymorphism()).toString();
        } else if (ENTITY_isForceDiscriminator.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isForceDiscriminator()).toString();
        } else if (ENTITY_isInherited.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isInherited()).toString();
        } else if (ENTITY_isJoinedSubclass.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isJoinedSubclass()).toString();
        } else if (ENTITY_isLazy.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isLazy()).toString();
        } else if (ENTITY_isLazyPropertiesCacheable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isLazyPropertiesCacheable()).toString();
        } else if (ENTITY_isMutable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isMutable()).toString();
        } else if (ENTITY_isPolymorphic.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isPolymorphic()).toString();
        } else if (ENTITY_isVersioned.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isVersioned()).toString();
        } else if (ENTITY_batchSize.equals(propertyId)) {
            res = Integer.valueOf(rootClass.getBatchSize()).toString();
        } else if (ENTITY_cacheConcurrencyStrategy.equals(propertyId)) {
            res = rootClass.getCacheConcurrencyStrategy();
        } else if (ENTITY_className.equals(propertyId)) {
            res = rootClass.getClassName();
        } else if (ENTITY_customSQLDelete.equals(propertyId)) {
            res = rootClass.getCustomSQLDelete();
        } else if (ENTITY_customSQLInsert.equals(propertyId)) {
            res = rootClass.getCustomSQLInsert();
        } else if (ENTITY_customSQLUpdate.equals(propertyId)) {
            res = rootClass.getCustomSQLUpdate();
        } else if (ENTITY_discriminatorValue.equals(propertyId)) {
            res = rootClass.getDiscriminatorValue();
        } else if (ENTITY_entityName.equals(propertyId)) {
            res = rootClass.getEntityName();
        } else if (ENTITY_loaderName.equals(propertyId)) {
            res = rootClass.getLoaderName();
        } else if (ENTITY_optimisticLockMode.equals(propertyId)) {
            res = Integer.valueOf(rootClass.getOptimisticLockMode()).toString();
        } else if (ENTITY_table.equals(propertyId)) {
            if (rootClass.getTable() != null) {
                res = rootClass.getTable().getName();
            }
        } else if (ENTITY_where.equals(propertyId)) {
            res = rootClass.getWhere();
        }
    }
    if (table != null) {
        if (TABLE_catalog.equals(propertyId)) {
            res = table.getCatalog();
        } else if (TABLE_comment.equals(propertyId)) {
            res = table.getComment();
        } else if (TABLE_name.equals(propertyId)) {
            res = table.getName();
        } else if (TABLE_primaryKey.equals(propertyId)) {
            if (table.getPrimaryKey() != null) {
                res = table.getPrimaryKey().getName();
            }
        } else if (TABLE_rowId.equals(propertyId)) {
            res = table.getRowId();
        } else if (TABLE_schema.equals(propertyId)) {
            res = table.getSchema();
        } else if (TABLE_subselect.equals(propertyId)) {
            res = table.getSubselect();
        } else if (TABLE_hasDenormalizedTables.equals(propertyId)) {
            res = Boolean.valueOf(table.hasDenormalizedTables()).toString();
        } else if (TABLE_isAbstract.equals(propertyId)) {
            res = Boolean.valueOf(table.isAbstract()).toString();
        } else if (TABLE_isAbstractUnionTable.equals(propertyId)) {
            res = Boolean.valueOf(table.isAbstractUnionTable()).toString();
        } else if (TABLE_isPhysicalTable.equals(propertyId)) {
            res = Boolean.valueOf(table.isPhysicalTable()).toString();
        }
    }
    if (res == null) {
        res = super.getPropertyValue(propertyId);
    }
    return toEmptyStr(res);
}
Also used : ITable(org.jboss.tools.hibernate.runtime.spi.ITable) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 98 with IPersistentClass

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

the class SpecialOrmShape method initModel.

/**
 * creates children of the shape,
 */
@Override
protected void initModel() {
    IPersistentClass rootClass = (IPersistentClass) getOrmElement();
    IProperty identifierProperty = rootClass.getIdentifierProperty();
    if (identifierProperty != null) {
        addChild(new Shape(identifierProperty, getConsoleConfigName()));
    }
    IPersistentClass src = (IPersistentClass) getOrmElement();
    if (src.getParentProperty() != null) {
        Shape bodyOrmShape = new Shape(src.getParentProperty(), getConsoleConfigName());
        addChild(bodyOrmShape);
        parentShape = bodyOrmShape;
    }
    Iterator<IProperty> iterator = rootClass.getPropertyIterator();
    while (iterator.hasNext()) {
        IProperty field = iterator.next();
        IValue v = field.getValue();
        IType type = getTypeUsingExecContext(v);
        Shape bodyOrmShape = null;
        if (type != null && type.isEntityType()) {
            bodyOrmShape = new ExpandableShape(field, getConsoleConfigName());
        } else if (type != null && type.isCollectionType()) {
            bodyOrmShape = new ComponentShape(field, getConsoleConfigName());
        } else {
            bodyOrmShape = new Shape(field, getConsoleConfigName());
        }
        addChild(bodyOrmShape);
    }
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) IType(org.jboss.tools.hibernate.runtime.spi.IType)

Example 99 with IPersistentClass

use of org.jboss.tools.hibernate.runtime.spi.IPersistentClass 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 100 with IPersistentClass

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

the class Utils method getName.

public static String getName(Object obj) {
    // $NON-NLS-1$
    String res = "";
    if (obj instanceof IPersistentClass) {
        IPersistentClass rootClass = (IPersistentClass) obj;
        if (rootClass.getEntityName() != null) {
            res = rootClass.getEntityName();
        } else {
            res = rootClass.getClassName();
        }
    } else if (obj instanceof ITable) {
        res = getTableName((ITable) obj);
    } else if (obj instanceof IProperty) {
        IProperty property = (IProperty) obj;
        // $NON-NLS-1$
        res = getName(property.getPersistentClass()) + "." + property.getName();
    } else if (obj instanceof IValue && ((IValue) obj).isSimpleValue()) {
        IValue sv = (IValue) obj;
        // $NON-NLS-1$
        res = getTableName(sv.getTable()) + "." + sv.getForeignKeyName();
    } else if (obj instanceof String) {
        res = (String) obj;
    }
    if (res.length() > 0 && res.indexOf(".") < 0) {
        // $NON-NLS-1$
        return "default." + res;
    }
    if (res.length() == 0) {
        // $NON-NLS-1$
        res = "null";
    }
    return res;
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Aggregations

IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)175 Test (org.junit.Test)97 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)60 IValue (org.jboss.tools.hibernate.runtime.spi.IValue)51 RootClass (org.hibernate.mapping.RootClass)47 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)46 PersistentClass (org.hibernate.mapping.PersistentClass)43 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)19 AbstractPersistentClassFacade (org.jboss.tools.hibernate.runtime.common.AbstractPersistentClassFacade)16 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)16 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)14 OneToMany (org.hibernate.mapping.OneToMany)12 HashMap (java.util.HashMap)8 Iterator (java.util.Iterator)8 JoinedSubclass (org.hibernate.mapping.JoinedSubclass)8 PrimitiveArray (org.hibernate.mapping.PrimitiveArray)8 Property (org.hibernate.mapping.Property)8 SingleTableSubclass (org.hibernate.mapping.SingleTableSubclass)8 IEditorPart (org.eclipse.ui.IEditorPart)7 PartInitException (org.eclipse.ui.PartInitException)7