use of org.jboss.tools.hibernate.runtime.spi.IProperty in project jbosstools-hibernate by jbosstools.
the class ElementsFactory method refreshComponentReferences.
protected void refreshComponentReferences(ComponentShape componentShape) {
IProperty property = (IProperty) componentShape.getOrmElement();
IValue v = property.getValue();
if (!v.isCollection()) {
return;
}
IValue collection = v;
IValue component = collection.getElement();
Shape csChild0 = null, csChild1 = null;
Iterator<Shape> tmp = componentShape.getChildrenIterator();
if (tmp.hasNext()) {
csChild0 = tmp.next();
}
if (tmp.hasNext()) {
csChild1 = tmp.next();
}
OrmShape childShape = null;
if (component.isComponent()) {
childShape = elements.get(component.getComponentClassName());
if (childShape == null) {
childShape = getOrCreateComponentClass(property);
}
IValue value = (IValue) csChild0.getOrmElement();
OrmShape tableShape = getOrCreateDatabaseTable(value.getTable());
if (tableShape != null) {
Iterator<IColumn> it = value.getColumnIterator();
while (it.hasNext()) {
IColumn el = it.next();
Shape shape = tableShape.getChild(el);
if (shouldCreateConnection(csChild0, shape)) {
connections.add(new Connection(csChild0, shape));
}
}
}
if (shouldCreateConnection(csChild1, childShape)) {
connections.add(new Connection(csChild1, childShape));
}
} else if (collection.isOneToMany()) {
childShape = getOrCreateAssociationClass(property);
if (childShape != null) {
if (shouldCreateConnection(csChild1, childShape)) {
connections.add(new Connection(csChild1, childShape));
}
OrmShape keyTableShape = getOrCreateDatabaseTable(collection.getKey().getTable());
Iterator<IColumn> it = collection.getKey().getColumnIterator();
while (it.hasNext()) {
Object el = it.next();
if (el instanceof IColumn) {
IColumn col = (IColumn) el;
Shape shape = keyTableShape.getChild(col);
if (shouldCreateConnection(csChild0, shape)) {
connections.add(new Connection(csChild0, shape));
}
}
}
}
} else {
// this is case: if (collection.isMap() || collection.isSet())
childShape = getOrCreateDatabaseTable(collection.getCollectionTable());
if (childShape != null) {
Iterator<IColumn> it = ((IValue) csChild0.getOrmElement()).getColumnIterator();
while (it.hasNext()) {
Object el = it.next();
if (el instanceof IColumn) {
IColumn col = (IColumn) el;
Shape shape = childShape.getChild(col);
if (shouldCreateConnection(csChild0, shape)) {
connections.add(new Connection(csChild0, shape));
}
}
}
it = ((IValue) csChild1.getOrmElement()).getColumnIterator();
while (it.hasNext()) {
Object el = it.next();
if (el instanceof IColumn) {
IColumn col = (IColumn) el;
Shape shape = childShape.getChild(col);
if (shouldCreateConnection(csChild1, shape)) {
connections.add(new Connection(csChild1, shape));
}
}
}
}
}
}
use of org.jboss.tools.hibernate.runtime.spi.IProperty 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);
}
use of org.jboss.tools.hibernate.runtime.spi.IProperty 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);
}
}
use of org.jboss.tools.hibernate.runtime.spi.IProperty 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()));
}
use of org.jboss.tools.hibernate.runtime.spi.IProperty 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;
}
Aggregations