Author: vyemialyanchyk
Date: 2011-01-17 07:52:20 -0500 (Mon, 17 Jan 2011)
New Revision: 28293
Added:
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/UtilTypeExtract.java
Modified:
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ComponentShape.java
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ElementsFactory.java
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ExpandableShape.java
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/MessageShape.java
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/OrmDiagram.java
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/OrmShape.java
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/Shape.java
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/SpecialOrmShape.java
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OrmImageMap.java
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OrmLabelMap.java
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OrmLabelProvider.java
Log:
https://issues.jboss.org/browse/JBIDE-8084 - fixed
Modified:
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ComponentShape.java
===================================================================
---
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ComponentShape.java 2011-01-17
12:52:11 UTC (rev 28292)
+++
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ComponentShape.java 2011-01-17
12:52:20 UTC (rev 28293)
@@ -20,8 +20,8 @@
*/
public class ComponentShape extends ExpandableShape {
- public ComponentShape(Object ioe) {
- super(ioe);
+ public ComponentShape(Object ioe, String consoleConfigName) {
+ super(ioe, consoleConfigName);
initModel();
}
@@ -32,10 +32,10 @@
Object ormElement = getOrmElement();
if (ormElement instanceof Property) {
Collection collection = (Collection)((Property)ormElement).getValue();
- Shape bodyOrmShape = new Shape(collection.getKey());
+ Shape bodyOrmShape = new Shape(collection.getKey(), getConsoleConfigName());
bodyOrmShape.setIndent(20);
addChild(bodyOrmShape);
- bodyOrmShape = new Shape(collection.getElement());
+ bodyOrmShape = new Shape(collection.getElement(), getConsoleConfigName());
bodyOrmShape.setIndent(20);
addChild(bodyOrmShape);
}
Modified:
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ElementsFactory.java
===================================================================
---
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ElementsFactory.java 2011-01-17
12:52:11 UTC (rev 28292)
+++
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ElementsFactory.java 2011-01-17
12:52:20 UTC (rev 28293)
@@ -16,9 +16,9 @@
import java.util.Iterator;
import java.util.Set;
-import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration;
-import org.hibernate.eclipse.console.HibernateConsolePlugin;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.console.KnownConfigurations;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Component;
@@ -44,13 +44,13 @@
*/
public class ElementsFactory {
- private final Configuration config;
+ private final String consoleConfigName;
private final HashMap<String, OrmShape> elements;
private final ArrayList<Connection> connections;
- public ElementsFactory(Configuration config, HashMap<String, OrmShape> elements,
+ public ElementsFactory(String consoleConfigName, HashMap<String, OrmShape>
elements,
ArrayList<Connection> connections) {
- this.config = config;
+ this.consoleConfigName = consoleConfigName;
this.elements = elements;
this.connections = connections;
}
@@ -117,13 +117,9 @@
OrmShape s = null;
Property property = (Property)element;
if (!property.isComposite()) {
- Type type = null;
- try {
- type = property.getType();
- } catch (HibernateException e) {
- //type is not accessible
- HibernateConsolePlugin.getDefault().logErrorMessage("HibernateException: ",
e); //$NON-NLS-1$
- }
+ final Configuration config = getConfig();
+ //
+ Type type = UtilTypeExtract.getTypeUsingExecContext(property.getValue(),
getConsoleConfig());
if (type != null && type.isEntityType()) {
EntityType et = (EntityType) type;
Object clazz = config != null ?
@@ -245,6 +241,7 @@
tableShape = getShape(databaseTable);
if (tableShape == null) {
tableShape = createShape(databaseTable);
+ final Configuration config = getConfig();
if (config != null) {
Iterator iterator = config.getClassMappings();
while (iterator.hasNext()) {
@@ -426,14 +423,14 @@
String key = Utils.getName(specialRootClass.getEntityName());
ormShape = elements.get(key);
if (null == ormShape) {
- ormShape = new SpecialOrmShape(specialRootClass);
+ ormShape = new SpecialOrmShape(specialRootClass, consoleConfigName);
elements.put(key, ormShape);
}
} else {
String key = Utils.getName(ormElement);
ormShape = elements.get(key);
if (null == ormShape) {
- ormShape = new OrmShape(ormElement);
+ ormShape = new OrmShape(ormElement, consoleConfigName);
elements.put(key, ormShape);
}
}
@@ -523,4 +520,19 @@
}
return true;
}
+
+ public ConsoleConfiguration getConsoleConfig() {
+ final KnownConfigurations knownConfigurations = KnownConfigurations.getInstance();
+ ConsoleConfiguration consoleConfig = knownConfigurations.find(consoleConfigName);
+ return consoleConfig;
+ }
+
+ public Configuration getConfig() {
+ Configuration config = null;
+ final ConsoleConfiguration consoleConfig = getConsoleConfig();
+ if (consoleConfig != null) {
+ config = consoleConfig.getConfiguration();
+ }
+ return config;
+ }
}
Modified:
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ExpandableShape.java
===================================================================
---
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ExpandableShape.java 2011-01-17
12:52:11 UTC (rev 28292)
+++
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ExpandableShape.java 2011-01-17
12:52:20 UTC (rev 28293)
@@ -25,8 +25,8 @@
protected boolean expanded = true;
- public ExpandableShape(Object ioe) {
- super(ioe);
+ public ExpandableShape(Object ioe, String consoleConfigName) {
+ super(ioe, consoleConfigName);
}
public boolean isExpanded() {
Modified:
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/MessageShape.java
===================================================================
---
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/MessageShape.java 2011-01-17
12:52:11 UTC (rev 28292)
+++
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/MessageShape.java 2011-01-17
12:52:20 UTC (rev 28293)
@@ -16,8 +16,8 @@
*/
public class MessageShape extends OrmShape {
- protected MessageShape(String error) {
- super(error);
+ protected MessageShape(String error, String consoleConfigName) {
+ super(error, consoleConfigName);
}
@Override
Modified:
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/OrmDiagram.java
===================================================================
---
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/OrmDiagram.java 2011-01-17
12:52:11 UTC (rev 28292)
+++
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/OrmDiagram.java 2011-01-17
12:52:20 UTC (rev 28293)
@@ -219,7 +219,7 @@
StringBuilder errorMessage = new StringBuilder();
Configuration config = getConfig(errorMessage);
final ElementsFactory factory = new ElementsFactory(
- config, elements, connections);
+ consoleConfigName, elements, connections);
for (int i = 0; i < roots.size(); i++) {
RootClass rc = roots.get(i);
if (rc != null) {
@@ -242,7 +242,7 @@
if (errorMessage.length() > 0) {
error = errorMessage.toString();
}
- addChild(new MessageShape(error));
+ addChild(new MessageShape(error, getConsoleConfigName()));
}
}
Modified:
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/OrmShape.java
===================================================================
---
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/OrmShape.java 2011-01-17
12:52:11 UTC (rev 28292)
+++
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/OrmShape.java 2011-01-17
12:52:20 UTC (rev 28293)
@@ -26,6 +26,8 @@
import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Subclass;
import org.hibernate.mapping.Table;
+import org.hibernate.mapping.Value;
+import org.hibernate.type.Type;
import org.jboss.tools.hibernate.ui.diagram.rulers.DiagramGuide;
/**
@@ -147,22 +149,22 @@
} // static
- public OrmShape(Object ioe) {
- super(ioe);
+ public OrmShape(Object ioe, String consoleConfigName) {
+ super(ioe, consoleConfigName);
initModel();
}
/**
* creates children of the shape,
*/
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({ "unchecked", "rawtypes" })
protected void initModel() {
Object ormElement = getOrmElement();
if (ormElement instanceof RootClass) {
RootClass rootClass = (RootClass)ormElement;
Property identifierProperty = rootClass.getIdentifierProperty();
if (identifierProperty != null) {
- addChild(new Shape(identifierProperty));
+ addChild(new Shape(identifierProperty, getConsoleConfigName()));
}
KeyValue identifier = rootClass.getIdentifier();
@@ -172,7 +174,7 @@
Iterator<Property> iterator = ((Component)identifier).getPropertyIterator();
while (iterator.hasNext()) {
Property property = iterator.next();
- addChild(new Shape(property));
+ addChild(new Shape(property, getConsoleConfigName()));
}
}
}
@@ -182,27 +184,25 @@
Property field = iterator.next();
if (!field.isBackRef()) {
if (!field.isComposite()) {
- boolean typeIsAccessible = true;
- if (field.getValue().isSimpleValue() &&
((SimpleValue)field.getValue()).isTypeSpecified()) {
- try {
- field.getValue().getType();
- } catch (Exception e) {
- typeIsAccessible = false;
- }
- }
+ final Value val = field.getValue();
Shape bodyOrmShape = null;
- if (field.getValue().isSimpleValue() &&
!((SimpleValue)field.getValue()).isTypeSpecified()) {
- bodyOrmShape = new Shape(field);
- } else if (typeIsAccessible && field.getValue() instanceof Collection) {
- bodyOrmShape = new ComponentShape(field);
- } else if (typeIsAccessible && field.getValue().getType().isEntityType())
{
- bodyOrmShape = new ExpandableShape(field);
+ if (val.isSimpleValue() && !((SimpleValue)val).isTypeSpecified()) {
+ bodyOrmShape = new Shape(field, getConsoleConfigName());
} else {
- bodyOrmShape = new Shape(field);
+ if (val instanceof Collection) {
+ bodyOrmShape = new ComponentShape(field, getConsoleConfigName());
+ } else {
+ Type 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);
+ Shape bodyOrmShape = new ExpandableShape(field, getConsoleConfigName());
addChild(bodyOrmShape);
}
}
@@ -212,7 +212,7 @@
Property identifierProperty = rootClass.getIdentifierProperty();
if (identifierProperty != null) {
- addChild(new Shape(identifierProperty));
+ addChild(new Shape(identifierProperty, getConsoleConfigName()));
}
KeyValue identifier = rootClass.getIdentifier();
@@ -220,7 +220,7 @@
Iterator<Property> iterator = ((Component)identifier).getPropertyIterator();
while (iterator.hasNext()) {
Property property = iterator.next();
- addChild(new Shape(property));
+ addChild(new Shape(property, getConsoleConfigName()));
}
}
@@ -240,17 +240,17 @@
}
Shape bodyOrmShape = null;
if (typeIsAccessible && field.getValue().isSimpleValue()) {
- bodyOrmShape = new Shape(field);
+ bodyOrmShape = new Shape(field, getConsoleConfigName());
} else if (typeIsAccessible && field.getValue().getType().isEntityType())
{
- bodyOrmShape = new ExpandableShape(field);
+ bodyOrmShape = new ExpandableShape(field, getConsoleConfigName());
} else if (typeIsAccessible &&
field.getValue().getType().isCollectionType()) {
- bodyOrmShape = new ComponentShape(field);
+ bodyOrmShape = new ComponentShape(field, getConsoleConfigName());
} else {
- bodyOrmShape = new Shape(field);
+ bodyOrmShape = new Shape(field, getConsoleConfigName());
}
addChild(bodyOrmShape);
} else {
- Shape bodyOrmShape = new ExpandableShape(field);
+ Shape bodyOrmShape = new ExpandableShape(field, getConsoleConfigName());
addChild(bodyOrmShape);
}
}
@@ -271,15 +271,15 @@
}
Shape bodyOrmShape = null;
if (typeIsAccessible && property.getValue().getType().isEntityType()) {
- bodyOrmShape = new ExpandableShape(property);
+ bodyOrmShape = new ExpandableShape(property, getConsoleConfigName());
} else if (typeIsAccessible &&
property.getValue().getType().isCollectionType()) {
- bodyOrmShape = new ComponentShape(property);
+ bodyOrmShape = new ComponentShape(property, getConsoleConfigName());
} else {
- bodyOrmShape = new Shape(property);
+ bodyOrmShape = new Shape(property, getConsoleConfigName());
}
addChild(bodyOrmShape);
} else {
- Shape bodyOrmShape = new ExpandableShape(property);
+ Shape bodyOrmShape = new ExpandableShape(property, getConsoleConfigName());
addChild(bodyOrmShape);
}
}
@@ -288,7 +288,7 @@
Iterator iterator = ((Table)getOrmElement()).getColumnIterator();
while (iterator.hasNext()) {
Column column = (Column)iterator.next();
- Shape bodyOrmShape = new Shape(column);
+ Shape bodyOrmShape = new Shape(column, getConsoleConfigName());
addChild(bodyOrmShape);
}
}
Modified:
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/Shape.java
===================================================================
---
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/Shape.java 2011-01-17
12:52:11 UTC (rev 28292)
+++
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/Shape.java 2011-01-17
12:52:20 UTC (rev 28293)
@@ -17,8 +17,8 @@
import org.eclipse.ui.IMemento;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.TextPropertyDescriptor;
-import org.hibernate.HibernateException;
-import org.hibernate.eclipse.console.HibernateConsolePlugin;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.console.KnownConfigurations;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.Property;
@@ -54,6 +54,10 @@
* only one BaseElement offspring has a parent - this is Shape
*/
private BaseElement parent;
+ /**
+ * name of Hibernate Console Configuration
+ */
+ private final String consoleConfigName;
private static IPropertyDescriptor[] descriptors_property;
private static IPropertyDescriptor[] descriptors_column;
@@ -105,8 +109,9 @@
} // static
- protected Shape(Object ioe) {
+ protected Shape(Object ioe, String consoleConfigName) {
ormElement = ioe;
+ this.consoleConfigName = consoleConfigName;
}
@Override
@@ -131,6 +136,10 @@
return res;
}
+ public String getConsoleConfigName() {
+ return consoleConfigName;
+ }
+
public void addConnection(Connection conn) {
if (conn == null || conn.getSource() == conn.getTarget()) {
throw new IllegalArgumentException();
@@ -293,13 +302,7 @@
if (value instanceof Component) {
res = prop.getValue().toString();
} else {
- Type type = null;
- try {
- type = prop.getType();
- } catch (HibernateException e) {
- //type is not accessible
- HibernateConsolePlugin.getDefault().logErrorMessage("HibernateException:
", e); //$NON-NLS-1$
- }
+ Type type = getTypeUsingExecContext(prop.getValue());
if (type != null) {
res = type.getReturnedClass().getName();
}
@@ -360,4 +363,14 @@
}
return toEmptyStr(res);
}
+
+ public ConsoleConfiguration getConsoleConfig() {
+ final KnownConfigurations knownConfigurations = KnownConfigurations.getInstance();
+ ConsoleConfiguration consoleConfig = knownConfigurations.find(consoleConfigName);
+ return consoleConfig;
+ }
+
+ public Type getTypeUsingExecContext(final Value val) {
+ return UtilTypeExtract.getTypeUsingExecContext(val, getConsoleConfig());
+ }
}
Modified:
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/SpecialOrmShape.java
===================================================================
---
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/SpecialOrmShape.java 2011-01-17
12:52:11 UTC (rev 28292)
+++
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/SpecialOrmShape.java 2011-01-17
12:52:20 UTC (rev 28293)
@@ -12,10 +12,6 @@
import java.util.Iterator;
-import org.hibernate.HibernateException;
-import org.hibernate.console.ConsoleConfiguration;
-import org.hibernate.console.execution.ExecutionContext.Command;
-import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.RootClass;
import org.hibernate.type.Type;
@@ -27,8 +23,8 @@
public class SpecialOrmShape extends OrmShape {
private Shape parentShape;
- public SpecialOrmShape(SpecialRootClass ioe) {
- super(ioe);
+ public SpecialOrmShape(SpecialRootClass ioe, String consoleConfigName) {
+ super(ioe, consoleConfigName);
}
/**
@@ -40,12 +36,12 @@
RootClass rootClass = (RootClass)getOrmElement();
Property identifierProperty = rootClass.getIdentifierProperty();
if (identifierProperty != null) {
- addChild(new Shape(identifierProperty));
+ addChild(new Shape(identifierProperty, getConsoleConfigName()));
}
SpecialRootClass src = (SpecialRootClass)getOrmElement();
if (src.getParentProperty() != null) {
- Shape bodyOrmShape = new Shape(src.getParentProperty());
+ Shape bodyOrmShape = new Shape(src.getParentProperty(), getConsoleConfigName());
addChild(bodyOrmShape);
parentShape = bodyOrmShape;
}
@@ -53,30 +49,14 @@
Iterator<Property> iterator = rootClass.getPropertyIterator();
while (iterator.hasNext()) {
Property field = iterator.next();
- Type type = null;
- if (getOrmDiagram() != null) {
- ConsoleConfiguration cfg = getOrmDiagram().getConsoleConfig();
- final Property fField = field;
- type = (Type) cfg.execute(new Command() {
- public Object execute() {
- return fField.getValue().getType();
- }
- });
- } else {
- try {
- type = field.getValue().getType();
- } catch (HibernateException e) {
- //type is not accessible
- HibernateConsolePlugin.getDefault().logErrorMessage("HibernateException:
", e); //$NON-NLS-1$
- }
- }
+ Type type = getTypeUsingExecContext(field.getValue());
Shape bodyOrmShape = null;
if (type != null && type.isEntityType()) {
- bodyOrmShape = new ExpandableShape(field);
+ bodyOrmShape = new ExpandableShape(field, getConsoleConfigName());
} else if (type != null && type.isCollectionType()) {
- bodyOrmShape = new ComponentShape(field);
+ bodyOrmShape = new ComponentShape(field, getConsoleConfigName());
} else {
- bodyOrmShape = new Shape(field);
+ bodyOrmShape = new Shape(field, getConsoleConfigName());
}
addChild(bodyOrmShape);
}
Added:
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/UtilTypeExtract.java
===================================================================
---
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/UtilTypeExtract.java
(rev 0)
+++
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/UtilTypeExtract.java 2011-01-17
12:52:20 UTC (rev 28293)
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.ui.diagram.editors.model;
+
+import org.hibernate.HibernateException;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.console.execution.ExecutionContext.Command;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
+import org.hibernate.mapping.Value;
+import org.hibernate.type.Type;
+
+/**
+ * @author vitali
+ */
+public class UtilTypeExtract {
+
+ public static Type getTypeUsingExecContext(final Value val, final ConsoleConfiguration
cfg) {
+ Type type = null;
+ if (val == null) {
+ return type;
+ }
+ try {
+ if (cfg != null) {
+ type = (Type) cfg.execute(new Command() {
+ public Object execute() {
+ return val.getType();
+ }
+ });
+ } else {
+ type = val.getType();
+ }
+ } catch (HibernateException e) {
+ //type is not accessible
+ HibernateConsolePlugin.getDefault().logErrorMessage("HibernateException: ",
e); //$NON-NLS-1$
+ } catch (Exception e) {
+ //type is not accessible
+ // EnumType -> setParameterValues(Properties parameters) in case parameters := null
NPE
+ // and this is only way to catch java.lang.reflect.InvocationTargetException
+ HibernateConsolePlugin.getDefault().logErrorMessage("Exception: ", e);
//$NON-NLS-1$
+ }
+ return type;
+ }
+
+}
Modified:
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OrmImageMap.java
===================================================================
---
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OrmImageMap.java 2011-01-17
12:52:11 UTC (rev 28292)
+++
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OrmImageMap.java 2011-01-17
12:52:20 UTC (rev 28293)
@@ -11,6 +11,7 @@
package org.jboss.tools.hibernate.ui.view;
import org.eclipse.jface.resource.ImageDescriptor;
+import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.mapping.Any;
import org.hibernate.mapping.Array;
import org.hibernate.mapping.Bag;
@@ -32,6 +33,7 @@
import org.hibernate.mapping.Value;
import org.hibernate.type.Type;
import org.jboss.tools.hibernate.ui.diagram.UiPlugin;
+import org.jboss.tools.hibernate.ui.diagram.editors.model.UtilTypeExtract;
/**
* Map: ORM object -> Image descriptor
@@ -40,14 +42,14 @@
private OrmImageMap() {}
- public static ImageDescriptor getImageDescriptor(final Object obj) {
+ public static ImageDescriptor getImageDescriptor(final Object obj, final
ConsoleConfiguration cfg) {
String imageName = null;
if (obj instanceof Table) {
imageName = getImageName((Table)obj);
} else if (obj instanceof Column) {
imageName = getImageName((Column)obj);
} else if (obj instanceof Property) {
- imageName = getImageName((Property)obj);
+ imageName = getImageName((Property)obj, cfg);
} else if (obj instanceof OneToMany) {
imageName = getImageName((OneToMany)obj);
} else if (obj instanceof SimpleValue) {
@@ -100,7 +102,7 @@
* @param field
* @return
*/
- public static String getImageName(Property field) {
+ public static String getImageName(Property field, final ConsoleConfiguration cfg) {
String str = "Image_PersistentFieldSimple"; //$NON-NLS-1$
if (field == null) {
return str;
@@ -121,12 +123,7 @@
} else if (value instanceof Any) {
str = "Image_PersistentFieldAny"; //$NON-NLS-1$
} else {
- Type type = null;
- try {
- type = field.getType();
- } catch (Exception ex) {
- // ignore it
- }
+ Type type = UtilTypeExtract.getTypeUsingExecContext(value, cfg);
if (type != null && type.isCollectionType()) {
if (value instanceof PrimitiveArray) {
str = "Image_Collection_primitive_array"; //$NON-NLS-1$
Modified:
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OrmLabelMap.java
===================================================================
---
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OrmLabelMap.java 2011-01-17
12:52:11 UTC (rev 28292)
+++
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OrmLabelMap.java 2011-01-17
12:52:20 UTC (rev 28293)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.hibernate.ui.view;
+import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.eclipse.console.workbench.TypeNameValueVisitor;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Component;
@@ -21,6 +22,7 @@
import org.hibernate.mapping.Table;
import org.hibernate.mapping.Value;
import org.hibernate.type.Type;
+import org.jboss.tools.hibernate.ui.diagram.editors.model.UtilTypeExtract;
import org.jboss.tools.hibernate.ui.diagram.editors.model.Utils;
/**
@@ -34,14 +36,14 @@
private OrmLabelMap() {}
- public static String getLabel(final Object obj) {
+ public static String getLabel(final Object obj, final ConsoleConfiguration cfg) {
String label = null;
if (obj instanceof Table) {
label = getParticularLabel((Table)obj);
} else if (obj instanceof Column) {
label = getParticularLabel((Column)obj);
} else if (obj instanceof Property) {
- label = getParticularLabel((Property)obj);
+ label = getParticularLabel((Property)obj, cfg);
} else if (obj instanceof OneToMany) {
label = getParticularLabel((OneToMany)obj);
} else if (obj instanceof SimpleValue) {
@@ -80,17 +82,12 @@
return name.toString();
}
- public static String getParticularLabel(Property field) {
+ public static String getParticularLabel(Property field, final ConsoleConfiguration cfg)
{
StringBuffer name = new StringBuffer();
name.append(field.getName());
name.append(" :"); //$NON-NLS-1$
String typeString = null;
- Type type = null;
- try {
- type = field.getType();
- } catch (Exception e) {
- // ignore - this is only way to catch java.lang.reflect.InvocationTargetException
- }
+ Type type = UtilTypeExtract.getTypeUsingExecContext(field.getValue(), cfg);
if (type != null && type.getReturnedClass() != null) {
typeString = type.getReturnedClass().getName();
} else {
Modified:
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OrmLabelProvider.java
===================================================================
---
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OrmLabelProvider.java 2011-01-17
12:52:11 UTC (rev 28292)
+++
branches/jbosstools-3.2.0.CR1/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OrmLabelProvider.java 2011-01-17
12:52:20 UTC (rev 28293)
@@ -97,7 +97,7 @@
@Override
public Image getImage(Object element) {
- ImageDescriptor descriptor = OrmImageMap.getImageDescriptor(element);
+ ImageDescriptor descriptor = OrmImageMap.getImageDescriptor(element,
getConsoleConfig());
if (descriptor == null) {
return null;
}
@@ -114,7 +114,7 @@
if (obj instanceof Column) {
updateColumnSqlType((Column)obj);
}
- return OrmLabelMap.getLabel(obj);
+ return OrmLabelMap.getLabel(obj, getConsoleConfig());
}
public void dispose() {