Author: mdryakhlenkov
Date: 2007-07-05 08:01:25 -0400 (Thu, 05 Jul 2007)
New Revision: 2312
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ComponentShape.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/Connection.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ExpandeableShape.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ModelElement.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmDiagram.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmShape.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/Shape.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/SpecialOrmShape.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/SpecialRootClass.java
Log:
JBIDE-559: Hibernate diagram editor cleanup
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ComponentShape.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ComponentShape.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ComponentShape.java 2007-07-05
12:01:25 UTC (rev 2312)
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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.veditor.editors.model;
+
+import java.util.Iterator;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.hibernate.mapping.Collection;
+import org.hibernate.mapping.Column;
+import org.hibernate.mapping.Component;
+import org.hibernate.mapping.Property;
+import org.hibernate.mapping.RootClass;
+import org.hibernate.mapping.Table;
+
+public class ComponentShape extends ExpandeableShape {
+ public static final String SET_CHILDS_HIDEN = "set childs hiden";
+
+ protected boolean childsHiden = true;
+
+ public ComponentShape(Object ioe) {
+ super(ioe);
+ Shape bodyOrmShape;
+ if (ioe instanceof Property) {
+ Collection collection = (Collection)((Property)ioe).getValue();
+ bodyOrmShape = new Shape(collection.getKey());
+ bodyOrmShape.setIndent(20);
+ getChildren().add(bodyOrmShape);
+ bodyOrmShape = new Shape(collection.getElement());
+ bodyOrmShape.setIndent(20);
+ getChildren().add(bodyOrmShape);
+ }
+ }
+
+ protected void setChildsHiden(boolean hiden) {
+ for (int i = 0; i < getChildren().size(); i++)
+ ((Shape)getChildren().get(i)).setHiden(hiden);
+ }
+
+ public void refreshChildsHiden(OrmDiagram ormDiagram) {
+ childsHiden = !childsHiden;
+ for (int i = 0; i < getChildren().size(); i++)
+ ((Shape)getChildren().get(i)).setHiden(childsHiden);
+ firePropertyChange(SET_CHILDS_HIDEN, null, new Boolean(childsHiden));
+ ormDiagram.refreshComponentReferences(this);
+ }
+}
\ No newline at end of file
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/Connection.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/Connection.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/Connection.java 2007-07-05
12:01:25 UTC (rev 2312)
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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.veditor.editors.model;
+
+public class Connection extends ModelElement {
+ public static final String HIDE_SELECTION = "hide selection";
+ public static final String SHOW_SELECTION = "show selection";
+ public static final String SET_HIDEN = "set hiden";
+
+ private Shape source;
+ private Shape target;
+
+ private int needHide;
+
+ public Connection(Shape s, Shape newTarget) {
+ if (s == null || newTarget == null || s == newTarget) {
+ throw new IllegalArgumentException();
+ }
+ needHide = 2;
+ this.source = s;
+ this.target = newTarget;
+ source.addConnection(this);
+ target.addConnection(this);
+ }
+
+ public Shape getSource() {
+ return source;
+ }
+
+ public Shape getTarget() {
+ return target;
+ }
+
+ public void hideSelection() {
+ firePropertyChange(HIDE_SELECTION, null, null);
+ source.firePropertyChange(Shape.HIDE_SELECTION, null, null);
+ target.firePropertyChange(Shape.HIDE_SELECTION, null, null);
+ }
+
+ public void showSelection() {
+ firePropertyChange(SHOW_SELECTION, null, null);
+ source.firePropertyChange(Shape.SHOW_SELECTION, null, null);
+ target.firePropertyChange(Shape.SHOW_SELECTION, null, null);
+ }
+
+ public void setHiden(boolean hiden) {
+ if(hiden) {
+ needHide--;
+ if(needHide == 0)
+ return;
+ } else {
+ needHide++;
+ if(needHide == 1)
+ return;
+ }
+ firePropertyChange(SET_HIDEN, null, new Boolean(hiden));
+ }
+
+ public boolean isHiden() {
+ return needHide != 2;
+ }
+}
\ No newline at end of file
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ExpandeableShape.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ExpandeableShape.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ExpandeableShape.java 2007-07-05
12:01:25 UTC (rev 2312)
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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.veditor.editors.model;
+
+import java.beans.PropertyChangeEvent;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.swt.graphics.RGB;
+import org.jboss.tools.hibernate.ui.veditor.editors.parts.ResourceManager;
+
+public class ExpandeableShape extends Shape {
+
+ public static final String SHOW_REFERENCES = "show references";
+
+ private boolean refHide = false;
+
+ public ExpandeableShape(Object ioe) {
+ super(ioe);
+ }
+
+ public void refreshReferences(Object model) {
+ refHide = !refHide;
+ if (model instanceof OrmDiagram) {
+ ((OrmDiagram)model).processExpand(this);
+ }
+ firePropertyChange(SHOW_REFERENCES, null, new Boolean(refHide));
+ }
+
+ protected boolean getHide() {
+ return refHide;
+ }
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ModelElement.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ModelElement.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ModelElement.java 2007-07-05
12:01:25 UTC (rev 2312)
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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.veditor.editors.model;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class ModelElement{
+
+ private transient PropertyChangeSupport pcsDelegate = new PropertyChangeSupport(this);
+
+ public synchronized void addPropertyChangeListener(PropertyChangeListener l) {
+ if (l == null) {
+ throw new IllegalArgumentException();
+ }
+ pcsDelegate.addPropertyChangeListener(l);
+ }
+
+ protected void firePropertyChange(String property, Object oldValue, Object newValue) {
+ if (pcsDelegate.hasListeners(property)) {
+ pcsDelegate.firePropertyChange(property, oldValue, newValue);
+ }
+ }
+
+ public synchronized void removePropertyChangeListener(PropertyChangeListener l) {
+ if (l != null) {
+ pcsDelegate.removePropertyChangeListener(l);
+ }
+ }
+
+ private List children = new OList();
+ private ModelElement parent;
+
+ public List getChildren(){
+ return children;
+ }
+
+ public ModelElement getParent(){
+ return parent;
+ }
+
+ public void setParent(ModelElement element){
+ parent = element;
+ }
+
+ class OList extends ArrayList{
+ public OList(){
+
+ }
+
+ public boolean add(Object item){
+ if(item instanceof ModelElement)((ModelElement)item).setParent(ModelElement.this);
+ return super.add(item);
+ }
+
+ public boolean remove(Object item){
+ if(item instanceof ModelElement)((ModelElement)item).setParent(null);
+ return super.remove(item);
+ }
+ }
+
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmDiagram.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmDiagram.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmDiagram.java 2007-07-05
12:01:25 UTC (rev 2312)
@@ -0,0 +1,387 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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.veditor.editors.model;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.draw2d.geometry.Point;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.console.ImageConstants;
+import org.hibernate.console.KnownConfigurations;
+import org.hibernate.mapping.Bag;
+import org.hibernate.mapping.Collection;
+import org.hibernate.mapping.Column;
+import org.hibernate.mapping.Component;
+import org.hibernate.mapping.DependantValue;
+import org.hibernate.mapping.Formula;
+import org.hibernate.mapping.KeyValue;
+import org.hibernate.mapping.ManyToOne;
+import org.hibernate.mapping.Map;
+import org.hibernate.mapping.OneToMany;
+import org.hibernate.mapping.OneToOne;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.Property;
+import org.hibernate.mapping.RootClass;
+import org.hibernate.mapping.Set;
+import org.hibernate.mapping.SimpleValue;
+import org.hibernate.mapping.SingleTableSubclass;
+import org.hibernate.mapping.Table;
+import org.hibernate.mapping.Value;
+import org.hibernate.type.EntityType;
+import org.hibernate.type.Type;
+import org.jboss.tools.hibernate.ui.veditor.VisualEditorPlugin;
+import org.jboss.tools.hibernate.ui.veditor.editors.autolayout.IItemInfo;
+import org.jboss.tools.hibernate.ui.veditor.editors.autolayout.ILinkInfo;
+
+
+public class OrmDiagram extends ModelElement {
+
+ public static final String REFRESH = "refresh";
+ public static final String DIRTY = "dirty";
+ private static final String qualifiedNameString =
"OrmDiagramChildrenLocations";
+ private boolean dirty = false;
+ private String childrenLocations[];
+ private IResource resource = null;
+ private HashMap<String,OrmShape> elements = new HashMap<String,OrmShape>();
+ private RootClass ormElement;
+ private Configuration configuration;
+
+
+ public OrmDiagram(Configuration configuration, RootClass ioe) {
+ this.configuration = configuration;
+ ormElement = (RootClass)ioe;
+ if (ormElement instanceof RootClass) {
+ String string = "";
+// resource
=((RootClass)ormElement).getPersistentClassMapping().getStorage().getResource();
+// try {
+// int i = 0;
+// String tempString;
+// do {
+// tempString = resource.getPersistentProperty(new
QualifiedName(VisualEditorPlugin.PLUGIN_ID,qualifiedNameString+i++));
+// string += tempString;
+// } while (tempString != null);
+// } catch (CoreException e) {
+//// ExceptionHandler.logThrowableError(e, e.getMessage());
+// }
+ childrenLocations = string.split("#");
+ } //else
+// throw new IllegalArgumentException();
+ getOrCreatePersistentClass(ormElement, null);
+
+ }
+
+ public HashMap getCloneElements() {
+ return (HashMap)elements.clone();
+ }
+
+ public RootClass getOrmElement() {
+ return ormElement;
+ }
+
+ public void refresh() {
+ saveHelper();
+ getChildren().clear();
+ elements.clear();
+// if(
((IPersistentClass)ormElement).getProjectMapping().findClass(ormElement.getName()) !=
null)
+/// getOrCreatePersistentClass((IPersistentClass)ormElement, null);
+ firePropertyChange(REFRESH, null, null);
+ }
+
+ public void save() {
+ String string = "";
+ saveHelper();
+ for (int i = 0; i < childrenLocations.length; i++)
+ string+=childrenLocations[i]+"#";
+ if(resource.exists() && string.length() > 0)
+ try {
+ int i = 0;
+ while(string.length() > 2048*(i+1)) {
+ resource.setPersistentProperty((new
QualifiedName(VisualEditorPlugin.PLUGIN_ID,qualifiedNameString+i)),
+ string.substring(2048*i,2048*(i++)+2047));
+ }
+ resource.setPersistentProperty((new
QualifiedName(VisualEditorPlugin.PLUGIN_ID,qualifiedNameString+i)),
+ string.substring(2048*i));
+ } catch (CoreException e) {
+// ExceptionHandler.logThrowableError(e, e.getMessage());
+ }
+ }
+
+ private void saveHelper() {
+ childrenLocations = new String[getChildren().size()];
+ for (int i = 0; i < getChildren().size(); i++) {
+ OrmShape shape = (OrmShape) getChildren().get(i);
+ Object ormElement = shape.getOrmElement();
+ if (ormElement instanceof RootClass) {
+ childrenLocations[i] = ((RootClass)ormElement).getClassName() + "@";
+ } else if (ormElement instanceof Table) {
+ childrenLocations[i] = ((Table)ormElement).getSchema() + "." +
((Table)ormElement).getName()+"@";
+// } else if (ormElement instanceof Component) {
+// childrenLocations[i] =
((Component)ormElement).getComponentClassName()+"@";
+ }
+ childrenLocations[i] += shape.getLocation().x + ";" +
shape.getLocation().y+";" + shape.isHiden();
+ }
+ }
+
+ private OrmShape createShape(Object ormElement) {
+ OrmShape ormShape = null;
+ if (ormElement instanceof RootClass) {
+ ormShape = new OrmShape(ormElement);
+ getChildren().add(ormShape);
+ elements.put(((RootClass)ormElement).getClassName(), ormShape);
+ } else if (ormElement instanceof Table) {
+ ormShape = new OrmShape(ormElement);
+ getChildren().add(ormShape);
+ Table table = (Table)ormElement;
+ elements.put(table.getSchema() + "." + table.getName(), ormShape);
+ } else if (ormElement instanceof Property) {
+// ormShape = new OrmShape(ormElement);
+ SpecialRootClass specialRootClass = new SpecialRootClass((Property)ormElement);
+ ormShape = new SpecialOrmShape(specialRootClass);
+ getChildren().add(ormShape);
+// Property property = (Property)ormElement;
+// elements.put(property.getPersistentClass().getEntityName() + "." +
property.getName(), ormShape);
+ elements.put(specialRootClass.getClassName(), ormShape);
+ } else if (ormElement instanceof SingleTableSubclass) {
+ ormShape = new OrmShape(ormElement);
+ getChildren().add(ormShape);
+ elements.put(((SingleTableSubclass)ormElement).getEntityName(), ormShape);
+ }
+ return ormShape;
+ }
+
+ private OrmShape getOrCreatePersistentClass(PersistentClass persistentClass, Table
componentClassDatabaseTable){
+ OrmShape classShape = null;
+ OrmShape shape = null;
+ if(persistentClass != null) {
+ classShape = elements.get(persistentClass.getClassName());
+ if (classShape == null) classShape = createShape(persistentClass);
+ if(componentClassDatabaseTable == null && persistentClass.getTable() != null)
+ componentClassDatabaseTable = persistentClass.getTable();
+ if(componentClassDatabaseTable != null) {
+ shape = elements.get(componentClassDatabaseTable.getSchema() + "." +
componentClassDatabaseTable.getName());
+ if (shape == null) shape = getOrCreateDatabaseTable(componentClassDatabaseTable);
+ createConnections(classShape, shape);
+ new Connection(classShape, shape);
+ }
+ RootClass rc = (RootClass)persistentClass;
+ Iterator iter = rc.getSubclassIterator();
+ while (iter.hasNext()) {
+ SingleTableSubclass singleTableSubclass = (SingleTableSubclass)iter.next();
+ OrmShape singleTableSubclassShape =
elements.get(singleTableSubclass.getEntityPersisterClass().getCanonicalName());
+ if (singleTableSubclassShape == null) singleTableSubclassShape =
createShape(singleTableSubclass);
+ new Connection(singleTableSubclassShape, shape);
+ }
+// if (persistentClass.getPersistentClassMapping() != null) {
+// Iterator iter
=((IHibernateClassMapping)(persistentClass).getPersistentClassMapping()).getJoinIterator();
+// while ( iter.hasNext() ) {
+// IJoinMapping jm =(IJoinMapping)iter.next();
+// shape = (OrmShape)elements.get(jm.getTable().getName());
+// if(shape == null)
+// shape = getOrCreateDatabaseTable(jm.getTable());
+// createConnections(classShape, shape);
+// }
+// }
+ }
+ return classShape;
+ }
+ private OrmShape getOrCreateDatabaseTable(Table databaseTable){
+ OrmShape tableShape = null;
+ if(databaseTable != null) {
+ String tableName = databaseTable.getSchema() + "." +
databaseTable.getName();
+ tableShape = (OrmShape)elements.get(tableName);
+ if(tableShape == null) {
+ tableShape = createShape(databaseTable);
+ Iterator iterator = getConfiguration().getClassMappings();
+ while (iterator.hasNext()) {
+ Object clazz = iterator.next();
+ if (clazz instanceof RootClass) {
+ RootClass cls = (RootClass)clazz;
+ Table table = cls.getTable();
+ if (tableName.equals(table.getName() + "." + table.getName())) {
+ if (elements.get(cls.getClassName()) == null)
+ getOrCreatePersistentClass(cls, null);
+ }
+// } else if (clazz instanceof SingleTableSubclass) {
+// SingleTableSubclass singleTableSubclass = (SingleTableSubclass)clazz;
+// getOrCreatePersistentClass(singleTableSubclass, null);
+ }
+ }
+// IPersistentClassMapping persistentClassMappings[] =
databaseTable.getPersistentClassMappings();
+// for (int j = 0; j < persistentClassMappings.length; j++) {
+// if(persistentClassMappings[j].getPersistentClass() != null ) {
+// OrmShape shape =
(OrmShape)elements.get(persistentClassMappings[j].getPersistentClass().getName());
+// if(shape == null)
+// getOrCreatePersistentClass(persistentClassMappings[j].getPersistentClass(),
null);
+// }
+// }
+ }
+ }
+ return tableShape;
+ }
+
+ private void createConnections(ExpandeableShape persistentClass, ExpandeableShape
databaseTable){
+ int i = 0;
+ boolean check = (persistentClass.getOrmElement() instanceof SpecialRootClass);
+ Iterator persistentFields = persistentClass.getChildren().iterator();
+ List databaseColumns = databaseTable.getChildren();
+ List databaseColumns2 = new ArrayList();
+ Iterator iterator = null;
+ while (persistentFields.hasNext()) {
+ Shape shape = (Shape) persistentFields.next();
+ Object element = shape.getOrmElement();
+ if (element instanceof Property && (!check ||
((SpecialRootClass)persistentClass.getOrmElement()).getParentProperty() != element)) {
+ Value value = ((Property)element).getValue();
+ iterator = value.getColumnIterator();
+ while (iterator.hasNext()) {
+ Object o = iterator.next();
+ if (o instanceof Column) {
+ Column databaseColumn = (Column)o;
+ for (int j = 0; j < databaseColumns.size(); j++) {
+ if
(databaseColumn.getName().equals(((Column)((Shape)databaseColumns.get(j)).getOrmElement()).getName()))
{
+ Shape databaseShape = (Shape)databaseColumns.remove(j);
+ new Connection(shape, databaseShape);
+ databaseColumns2.add(i++, databaseShape);
+ }
+ }
+ }
+ }
+ }
+ }
+ databaseColumns.addAll(databaseColumns2);
+ }
+
+ public String[] getChildrenLocations() {
+ return childrenLocations;
+ }
+
+ public boolean isDirty() {
+ return dirty;
+ }
+
+ public void setDirty(boolean dirty) {
+ if(this.dirty != dirty) {
+ this.dirty = dirty;
+ firePropertyChange(DIRTY, null, null);
+ }
+ }
+
+ public void processExpand(ExpandeableShape shape) {
+ Object element = shape.getOrmElement();
+ if (element instanceof Property) {
+ Type type = ((Property)element).getType();
+ if (type.isEntityType()) {
+ EntityType et = (EntityType) type;
+ RootClass rootClass =
(RootClass)getConfiguration().getClassMapping(et.getAssociatedEntityName());
+ OrmShape s = getOrCreatePersistentClass(rootClass, null);
+ HashMap targets = new HashMap();
+ Iterator iterator = shape.getSourceConnections().iterator();
+ while (iterator.hasNext()) {
+ Connection connection = (Connection)iterator.next();
+ connection.setHiden(shape.getHide());
+ Object el = connection.getTarget().getOrmElement();
+ if (el instanceof Column) {
+ targets.put(((Column)el).getName(), connection.getTarget());
+ } else if (el instanceof RootClass) {
+ targets.put(((RootClass)el).getClassName(), connection.getTarget());
+ }
+ }
+ KeyValue id = rootClass.getIdentifier();
+ iterator = id.getColumnIterator();
+ while (iterator.hasNext()) {
+ Column column = (Column)iterator.next();
+ if (targets.get(column.getName()) != null) {
+ new Connection(s, (Shape)targets.get(column.getName()));
+ }
+ }
+ new Connection(shape, s);
+ firePropertyChange(REFRESH, null, null);
+ }
+ }
+ }
+
+ protected Configuration getConfiguration() {
+ return configuration;
+ }
+
+ protected void refreshComponentReferences(ComponentShape componentShape) {
+ Property property = (Property)componentShape.getOrmElement();
+ Type valueType = property.getValue().getType();
+ if (valueType.isCollectionType()) {
+ Collection collection = (Collection)property.getValue();
+ Value component = collection.getElement();
+ if (component instanceof Component) {//valueType.isComponentType()
+ OrmShape childShape =
(OrmShape)elements.get(((Component)component).getComponentClassName());
+ if(childShape == null) childShape = getOrCreateComponentClass(property);
+ new Connection((Shape)(componentShape.getChildren().get(1)), childShape);
+ } else if (collection.isOneToMany()) {
+ OrmShape childShape = getOrCreateAssociationClass(property);
+ new Connection((Shape)(componentShape.getChildren().get(1)), childShape);
+ OrmShape keyTableShape = getOrCreateDatabaseTable(collection.getKey().getTable());
+ Iterator iter = collection.getKey().getColumnIterator();
+ while (iter.hasNext()) {
+ Column col = (Column)iter.next();
+ Shape keyColumnShape = keyTableShape.getChild(col);
+ if (keyColumnShape != null) new
Connection((Shape)(componentShape.getChildren().get(0)), keyColumnShape);
+ }
+ } else if (collection.isMap() || collection.isSet()) {
+ OrmShape childShape = getOrCreateDatabaseTable(collection.getCollectionTable());
+ Shape keyShape =
childShape.getChild((Column)((DependantValue)((Shape)componentShape.getChildren().get(0)).getOrmElement()).getColumnIterator().next());
+ new Connection((Shape)componentShape.getChildren().get(0), keyShape);
+
+ Iterator iter =
((SimpleValue)((Shape)componentShape.getChildren().get(1)).getOrmElement()).getColumnIterator();
+ while (iter.hasNext()) {
+ Column col = (Column)iter.next();
+ Shape elementShape = childShape.getChild(col);
+ new Connection((Shape)componentShape.getChildren().get(1), elementShape);
+ }
+ }
+ setDirty(true);
+ firePropertyChange(REFRESH, null, null);
+ }
+ }
+
+ private OrmShape getOrCreateComponentClass(Property property) {
+ OrmShape classShape = null;
+ Component component = (Component)((Collection)property.getValue()).getElement();
+ if (component != null) {
+ classShape = createShape(property);
+ OrmShape tableShape = (OrmShape)elements.get(component.getTable().getSchema() +
"." + component.getTable().getName());
+ if (tableShape == null) tableShape = getOrCreateDatabaseTable(component.getTable());
+ createConnections(classShape, tableShape);
+ new Connection(classShape, tableShape);
+ Shape parentShape = ((SpecialOrmShape)classShape).getParentShape();
+ OrmShape parentClassShape =
(OrmShape)elements.get(((Property)parentShape.getOrmElement()).getPersistentClass().getClassName());
+ new Connection(parentShape, parentClassShape);
+ }
+ return classShape;
+ }
+
+ private OrmShape getOrCreateAssociationClass(Property property) {
+ OrmShape classShape = null;
+ OneToMany component = (OneToMany)((Collection)property.getValue()).getElement();
+ if (component != null) {
+ classShape = (OrmShape)elements.get(component.getAssociatedClass().getClassName());
+ if (classShape == null) classShape = createShape(component.getAssociatedClass());
+ OrmShape tableShape =
(OrmShape)elements.get(component.getAssociatedClass().getTable().getSchema() +
"." + component.getAssociatedClass().getTable().getName());
+ if (tableShape == null) tableShape =
getOrCreateDatabaseTable(component.getAssociatedClass().getTable());
+ createConnections(classShape, tableShape);
+ new Connection(classShape, tableShape);
+ }
+ return classShape;
+ }
+}
\ No newline at end of file
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmShape.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmShape.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmShape.java 2007-07-05
12:01:25 UTC (rev 2312)
@@ -0,0 +1,199 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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.veditor.editors.model;
+
+import java.util.Iterator;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.hibernate.mapping.Collection;
+import org.hibernate.mapping.Column;
+import org.hibernate.mapping.Component;
+import org.hibernate.mapping.KeyValue;
+import org.hibernate.mapping.Property;
+import org.hibernate.mapping.RootClass;
+import org.hibernate.mapping.SimpleValue;
+import org.hibernate.mapping.SingleTableSubclass;
+import org.hibernate.mapping.Table;
+
+public class OrmShape extends ExpandeableShape {
+ public static final String SET_HIDEN = "set hiden";
+
+ public static final String LOCATION_PROP = "OrmShape.Location";
+ private Point location = new Point(0, 0);
+ protected boolean hiden = false;
+
+ public OrmShape(Object ioe) {
+ super(ioe);
+ generate();
+ }
+
+ protected void generate() {
+ Shape bodyOrmShape;
+ Object ormElement = getOrmElement();
+ if (ormElement instanceof RootClass) {
+ RootClass rootClass = (RootClass)getOrmElement();
+ Property identifierProperty = rootClass.getIdentifierProperty();
+ if (identifierProperty != null) {
+ getChildren().add(new Shape(identifierProperty));
+ }
+
+ KeyValue identifier = rootClass.getIdentifier();
+ if (identifier instanceof Component) {
+ Iterator iterator = ((Component)identifier).getPropertyIterator();
+ while (iterator.hasNext()) {
+ Property property = (Property) iterator.next();
+ getChildren().add(new Shape(property));
+ }
+ }
+
+ Iterator iterator = rootClass.getPropertyIterator();
+ while (iterator.hasNext()) {
+ Property field = (Property)iterator.next();
+ if (!field.isComposite()) {
+ if (field.getValue().getType().isEntityType()) {
+ bodyOrmShape = new ExpandeableShape(field);
+ } else if (field.getValue().getType().isCollectionType()) {
+ bodyOrmShape = new ComponentShape(field);
+ } else {
+ bodyOrmShape = new Shape(field);
+ }
+ getChildren().add(bodyOrmShape);
+ } else {
+ Component component = (Component)field.getValue();
+ Iterator iter = component.getPropertyIterator();
+ while (iter.hasNext()) {
+ Property property = (Property)iter.next();
+ if (property.getValue().getType().isEntityType()) {
+ bodyOrmShape = new ExpandeableShape(property);
+ } else if (property.getValue().getType().isCollectionType()) {
+ bodyOrmShape = new ComponentShape(property);
+ } else {
+ bodyOrmShape = new Shape(property);
+ }
+ getChildren().add(bodyOrmShape);
+ }
+ }
+ }
+ } else if (ormElement instanceof SingleTableSubclass) {
+ RootClass rootClass = ((SingleTableSubclass)ormElement).getRootClass();
+
+ Property identifierProperty = rootClass.getIdentifierProperty();
+ if (identifierProperty != null) {
+ getChildren().add(new Shape(identifierProperty));
+ }
+
+ KeyValue identifier = rootClass.getIdentifier();
+ if (identifier instanceof Component) {
+ Iterator iterator = ((Component)identifier).getPropertyIterator();
+ while (iterator.hasNext()) {
+ Property property = (Property) iterator.next();
+ getChildren().add(new Shape(property));
+ }
+ }
+
+ Iterator iterator = rootClass.getPropertyIterator();
+ while (iterator.hasNext()) {
+ Property field = (Property)iterator.next();
+ if (!field.isComposite()) {
+ if (field.getValue().getType().isEntityType()) {
+ bodyOrmShape = new ExpandeableShape(field);
+ } else if (field.getValue().getType().isCollectionType()) {
+ bodyOrmShape = new ComponentShape(field);
+ } else {
+ bodyOrmShape = new Shape(field);
+ }
+ getChildren().add(bodyOrmShape);
+ } else {
+ Component component = (Component)field.getValue();
+ Iterator iter = component.getPropertyIterator();
+ while (iter.hasNext()) {
+ Property property = (Property)iter.next();
+ if (property.getValue().getType().isEntityType()) {
+ bodyOrmShape = new ExpandeableShape(property);
+ } else if (property.getValue().getType().isCollectionType()) {
+ bodyOrmShape = new ComponentShape(property);
+ } else {
+ bodyOrmShape = new Shape(property);
+ }
+ getChildren().add(bodyOrmShape);
+ }
+ }
+ }
+ Iterator iter = ((SingleTableSubclass)ormElement).getPropertyIterator();
+ while (iter.hasNext()) {
+ Property property = (Property)iter.next();
+ if (property.getValue().getType().isEntityType()) {
+ bodyOrmShape = new ExpandeableShape(property);
+ } else if (property.getValue().getType().isCollectionType()) {
+ bodyOrmShape = new ComponentShape(property);
+ } else {
+ bodyOrmShape = new Shape(property);
+ }
+ getChildren().add(bodyOrmShape);
+ }
+ } else if (ormElement instanceof Table) {
+ Iterator iterator = ((Table)getOrmElement()).getColumnIterator();
+ while (iterator.hasNext()) {
+ Column column = (Column)iterator.next();
+ bodyOrmShape = new Shape(column);
+ getChildren().add(bodyOrmShape);
+ }
+ }
+ }
+
+ public Shape getChild(Column ormElement) {
+ Shape shape = null;
+ Iterator iter = getChildren().iterator();
+ while (iter.hasNext()) {
+ Shape child = (Shape)iter.next();
+ Object childElement = child.getOrmElement();
+ if (childElement instanceof Column &&
ormElement.getName().equals(((Column)childElement).getName())) {
+ return child;
+ }
+ }
+ return shape;
+ }
+
+ protected void setHiden(boolean hiden) {
+ super.setHiden(hiden);
+ for (int i = 0; i < getChildren().size(); i++)
+ ((Shape)getChildren().get(i)).setHiden(hiden);
+ }
+
+ public void refreshHiden() {
+ hiden = !hiden;
+ setElementHidden(this, hiden);
+ firePropertyChange(SET_HIDEN, null, new Boolean(hiden));
+ }
+
+ private void setElementHidden(ModelElement element, boolean hidden){
+ for (int i = 0; i < element.getChildren().size(); i++){
+ ((Shape)element.getChildren().get(i)).setHiden(hidden);
+ setElementHidden((ModelElement)element.getChildren().get(i), hidden);
+ }
+ }
+
+ public Point getLocation() {
+ return location.getCopy();
+ }
+
+ public void setLocation(Point newLocation) {
+ if (newLocation == null) {
+ throw new IllegalArgumentException();
+ }
+ location.setLocation(newLocation);
+ firePropertyChange(LOCATION_PROP, null, location);
+ }
+
+ public boolean isHiden() {
+ return hiden;
+ }
+}
\ No newline at end of file
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/Shape.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/Shape.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/Shape.java 2007-07-05
12:01:25 UTC (rev 2312)
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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.veditor.editors.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Shape extends ModelElement {
+
+ private int indent = 0;
+
+ private List<Connection> sourceConnections = new ArrayList<Connection>();
+ private List<Connection> targetConnections = new ArrayList<Connection>();
+
+ public static final String HIDE_SELECTION = "hide selection";
+ public static final String SHOW_SELECTION = "show selection";
+ public static final String SET_FOCUS = "set focus";
+
+ private Object ormElement;
+
+ protected Shape(Object ioe) {
+ ormElement = ioe;
+ }
+
+ public void addConnection(Connection conn) {
+ if (conn == null || conn.getSource() == conn.getTarget()) {
+ throw new IllegalArgumentException();
+ }
+ if (conn.getSource() == this) {
+ sourceConnections.add(conn);
+ } else if (conn.getTarget() == this) {
+ targetConnections.add(conn);
+ }
+ }
+
+
+ public List<Connection> getSourceConnections() {
+ return new ArrayList<Connection>(sourceConnections);
+ }
+
+ public List<Connection> getTargetConnections() {
+ return new ArrayList<Connection>(targetConnections);
+ }
+
+ public Object getOrmElement() {
+ return ormElement;
+ }
+
+ public void hideSelection() {
+ firePropertyChange(HIDE_SELECTION, null, null);
+ }
+
+ public void showSelection() {
+ firePropertyChange(SHOW_SELECTION, null, null);
+ }
+
+ public void setFocus() {
+ firePropertyChange(SET_FOCUS, null, null);
+ }
+
+ public int getIndent() {
+ return indent;
+ }
+
+ protected void setIndent(int indent) {
+ this.indent = indent;
+ }
+
+ protected void setHiden(boolean hiden) {
+ for (int i = 0; i < sourceConnections.size(); i++)
+ ((Connection)sourceConnections.get(i)).setHiden(hiden);
+ for (int i = 0; i < targetConnections.size(); i++)
+ ((Connection)targetConnections.get(i)).setHiden(hiden);
+ }
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/SpecialOrmShape.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/SpecialOrmShape.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/SpecialOrmShape.java 2007-07-05
12:01:25 UTC (rev 2312)
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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.veditor.editors.model;
+
+import java.util.Iterator;
+
+import org.hibernate.mapping.Property;
+import org.hibernate.mapping.RootClass;
+
+public class SpecialOrmShape extends OrmShape {
+ private Shape parentShape;
+
+ public SpecialOrmShape(SpecialRootClass ioe) {
+ super(ioe);
+ }
+
+ protected void generate() {
+ Shape bodyOrmShape;
+ RootClass rootClass = (RootClass)getOrmElement();
+ Property identifierProperty = rootClass.getIdentifierProperty();
+ if (identifierProperty != null) getChildren().add(new Shape(identifierProperty));
+
+ SpecialRootClass src = (SpecialRootClass)getOrmElement();
+ if (src.getParentProperty() != null) {
+ bodyOrmShape = new Shape(src.getParentProperty());
+ getChildren().add(bodyOrmShape);
+ parentShape = bodyOrmShape;
+ }
+
+ Iterator iterator = (rootClass).getPropertyIterator();
+ while (iterator.hasNext()) {
+ Property field = (Property)iterator.next();
+ if (field.getValue().getType().isEntityType()) {
+ bodyOrmShape = new ExpandeableShape(field);
+ } else if (field.getValue().getType().isCollectionType()) {
+ bodyOrmShape = new ComponentShape(field);
+ } else {
+ bodyOrmShape = new Shape(field);
+ }
+ getChildren().add(bodyOrmShape);
+ }
+ }
+
+ protected Shape getParentShape() {
+ return parentShape;
+ }
+
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/SpecialRootClass.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/SpecialRootClass.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/SpecialRootClass.java 2007-07-05
12:01:25 UTC (rev 2312)
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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.veditor.editors.model;
+
+import java.util.Iterator;
+
+import org.hibernate.mapping.Collection;
+import org.hibernate.mapping.Column;
+import org.hibernate.mapping.Component;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.Property;
+import org.hibernate.mapping.RootClass;
+
+public class SpecialRootClass extends RootClass {
+
+ private Property property;
+ private Property parentProperty;
+
+ public SpecialRootClass(Property property) {
+ super();
+ this.property = property;
+ generate();
+ }
+
+ private void generate() {
+ if (property != null) {
+ Collection collection = (Collection)property.getValue();
+ Component component = (Component)collection.getElement();
+ setClassName(component.getComponentClassName());
+ PersistentClass ownerClass = collection.getOwner();
+ if (component.getParentProperty() != null) {
+ Property property = ownerClass.getProperty(component.getParentProperty());
+ if (property == null &&
ownerClass.getIdentifierProperty().getName().equals(component.getParentProperty())) {
+ property = ownerClass.getIdentifierProperty();
+ }
+ if (property != null) parentProperty = ownerClass.getIdentifierProperty();
+ }
+ Iterator iterator = component.getPropertyIterator();
+ while (iterator.hasNext()) {
+ Property property = (Property)iterator.next();
+ if (property != null) addProperty(property);
+ }
+ }
+ }
+
+ protected Property getParentProperty() {
+ return parentProperty;
+ }
+
+ public Property getProperty() {
+ return this.property;
+ }
+}