Author: vyemialyanchyk
Date: 2009-10-29 11:20:26 -0400 (Thu, 29 Oct 2009)
New Revision: 18352
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/ExportImageAction.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/ToggleForeignKeyConstraintAction.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/Connection.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ElementsFactory.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/OrmDiagram.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4956 - fixed
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/ExportImageAction.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/ExportImageAction.java 2009-10-29
14:45:30 UTC (rev 18351)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/ExportImageAction.java 2009-10-29
15:20:26 UTC (rev 18352)
@@ -41,6 +41,12 @@
import org.jboss.tools.hibernate.ui.diagram.DiagramViewerMessages;
import org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer;
+/**
+ * Export image into selected image format.
+ * "png", "jpg", "bmp" are supported.
+ *
+ * @author Vitali Yemialyanchyk
+ */
public class ExportImageAction extends DiagramBaseAction {
public static final String ACTION_ID = "export_as_image_id"; //$NON-NLS-1$
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/ToggleForeignKeyConstraintAction.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/ToggleForeignKeyConstraintAction.java 2009-10-29
14:45:30 UTC (rev 18351)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/ToggleForeignKeyConstraintAction.java 2009-10-29
15:20:26 UTC (rev 18352)
@@ -51,7 +51,6 @@
@Override
public boolean isEnabled() {
- // TODO: JBIDE-4956 -> still not implemented
- return false;
+ return true;
}
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/Connection.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/Connection.java 2009-10-29
14:45:30 UTC (rev 18351)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/Connection.java 2009-10-29
15:20:26 UTC (rev 18352)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
+ * Copyright (c) 2007-2009 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,
@@ -10,6 +10,11 @@
******************************************************************************/
package org.jboss.tools.hibernate.ui.diagram.editors.model;
+import org.hibernate.mapping.Column;
+import org.hibernate.mapping.Property;
+import org.hibernate.mapping.RootClass;
+import org.hibernate.mapping.Table;
+
/**
* Directed connection between 2 shapes, from source to target.
*
@@ -21,6 +26,9 @@
protected Shape source;
protected Shape target;
+ /**
+ * supported connection types
+ */
public enum ConnectionType {
ClassMapping,
PropertyMapping,
@@ -51,17 +59,43 @@
return target;
}
+ /**
+ * Detect connection type from connected source and target.
+ *
+ * @return
+ */
public ConnectionType getConnectionType() {
- if ((source instanceof OrmShape) && (target instanceof OrmShape)) {
- return ConnectionType.ClassMapping;
+ if (source instanceof OrmShape && target instanceof OrmShape) {
+ if ((source.getOrmElement() instanceof Table) && (target.getOrmElement()
instanceof Table)) {
+ return ConnectionType.ForeignKeyConstraint;
+ }
+ boolean bClassMapping = true;
+ if (!(source.getOrmElement() instanceof RootClass || source.getOrmElement() instanceof
Table)) {
+ bClassMapping = false;
+ }
+ if (!(target.getOrmElement() instanceof RootClass || target.getOrmElement() instanceof
Table)) {
+ bClassMapping = false;
+ }
+ if (bClassMapping) {
+ return ConnectionType.ClassMapping;
+ }
}
- if ((source instanceof OrmShape) || (target instanceof OrmShape)) {
- return ConnectionType.Association;
+ if ((source.getOrmElement() instanceof Table && target.getOrmElement()
instanceof Table) ||
+ (source.getOrmElement() instanceof Table && target.getOrmElement() instanceof
Column) ||
+ (source.getOrmElement() instanceof Column && target.getOrmElement() instanceof
Table) ||
+ (source.getOrmElement() instanceof Column && target.getOrmElement() instanceof
Column)) {
+ return ConnectionType.ForeignKeyConstraint;
}
- // TODO: what is ForeignKeyConstraint?
- //if ( ??? ) {
- // return ConnectionType.ForeignKeyConstraint;
- //}
+ if (((source instanceof OrmShape) ^ (target instanceof OrmShape))) {
+ boolean bAssociation = true;
+ if (!(!(source instanceof OrmShape) && source.getOrmElement() instanceof
Property) &&
+ !(!(target instanceof OrmShape) && target.getOrmElement() instanceof
Property)) {
+ bAssociation = false;
+ }
+ if (bAssociation) {
+ return ConnectionType.Association;
+ }
+ }
return ConnectionType.PropertyMapping;
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ElementsFactory.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ElementsFactory.java 2009-10-29
14:45:30 UTC (rev 18351)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ElementsFactory.java 2009-10-29
15:20:26 UTC (rev 18352)
@@ -21,6 +21,7 @@
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.DependantValue;
+import org.hibernate.mapping.ForeignKey;
import org.hibernate.mapping.Join;
import org.hibernate.mapping.OneToMany;
import org.hibernate.mapping.PersistentClass;
@@ -34,8 +35,10 @@
import org.hibernate.type.Type;
/**
+ * Responsible to create diagram elements for given
+ * Hibernate Console Configuration.
*
- * @author Vitali
+ * @author Vitali Yemialyanchyk
*/
public class ElementsFactory {
@@ -50,6 +53,45 @@
this.connections = connections;
}
+ @SuppressWarnings("unchecked")
+ public void createForeingKeyConnections() {
+ Iterator<OrmShape> it = elements.values().iterator();
+ while (it.hasNext()) {
+ final OrmShape shape = it.next();
+ Object ormElement = shape.getOrmElement();
+ if (ormElement instanceof Table) {
+ Table databaseTable = (Table)ormElement;
+ Iterator<ForeignKey> itFK =
(Iterator<ForeignKey>)databaseTable.getForeignKeyIterator();
+ while (itFK.hasNext()) {
+ final ForeignKey fk = itFK.next();
+ Table referencedTable = fk.getReferencedTable();
+ final OrmShape referencedShape = getOrCreateDatabaseTable(referencedTable);
+ //
+ Iterator<Column> itColumns = (Iterator<Column>)fk.columnIterator();
+ while (itColumns.hasNext()) {
+ Column col = itColumns.next();
+ Shape shapeColumn = shape.getChild(col);
+ Iterator<Column> itReferencedColumns = null;
+ if (fk.isReferenceToPrimaryKey()) {
+ itReferencedColumns =
+ (Iterator<Column>)referencedTable.getPrimaryKey().columnIterator();
+ } else {
+ itReferencedColumns =
+ (Iterator<Column>)fk.getReferencedColumns().iterator();
+ }
+ while (itReferencedColumns != null && itReferencedColumns.hasNext()) {
+ Column colReferenced = itReferencedColumns.next();
+ Shape shapeReferencedColumn = referencedShape.getChild(colReferenced);
+ if (shouldCreateConnection(shapeColumn, shapeReferencedColumn)) {
+ connections.add(new Connection(shapeColumn, shapeReferencedColumn));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
public void createChildren(BaseElement element) {
if (element.getClass().equals(ExpandableShape.class)) {
processExpand((ExpandableShape)element);
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/OrmDiagram.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/OrmDiagram.java 2009-10-29
14:45:30 UTC (rev 18351)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/OrmDiagram.java 2009-10-29
15:20:26 UTC (rev 18352)
@@ -187,6 +187,7 @@
}
updateChildrenList();
factory.createChildren(this);
+ factory.createForeingKeyConnections();
updateChildrenList();
if (getChildrenNumber() == 0) {
String error = DiagramViewerMessages.MessageShape_warning;