Author: dazarov
Date: 2007-07-17 10:01:31 -0400 (Tue, 17 Jul 2007)
New Revision: 2466
Modified:
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/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/parts/ComponentShapeEditPart.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ExpandeableShapeEditPart.java
Log:
http://jira.jboss.com/jira/browse/EXIN-365
Modified:
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 2007-07-17
13:28:12 UTC (rev 2465)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ComponentShape.java 2007-07-17
14:01:31 UTC (rev 2466)
@@ -16,7 +16,7 @@
public class ComponentShape extends ExpandeableShape {
public static final String SET_CHILDS_HIDEN = "set childs hiden";
- protected boolean childsHiden = true;
+ //protected boolean childsHiden = true;
@@ -40,16 +40,18 @@
}
public void refreshChildsHiden(OrmDiagram ormDiagram) {
- childsHiden = !childsHiden;
+ refHide = !refHide;
for (int i = 0; i < getChildren().size(); i++)
- ((Shape)getChildren().get(i)).setHiden(childsHiden);
+ ((Shape)getChildren().get(i)).setHiden(!refHide);
- if(!childsHiden)
- ormDiagram.refreshComponentReferences(this);
- else
- ormDiagram.hideReferences(this);
+ if(refHide)
+ if(first){
+ ormDiagram.refreshComponentReferences(this);
+ first=false;
+ }
- firePropertyChange(SET_CHILDS_HIDEN, null, new Boolean(childsHiden));
+
+ firePropertyChange(SET_CHILDS_HIDEN, null, new Boolean(!refHide));
}
}
\ No newline at end of file
Modified:
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 2007-07-17
13:28:12 UTC (rev 2465)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ExpandeableShape.java 2007-07-17
14:01:31 UTC (rev 2466)
@@ -22,7 +22,8 @@
public static final String SHOW_REFERENCES = "show references";
- private boolean refHide = false;
+ protected boolean refHide = false;
+ protected boolean first=true;
private OrmShape reference=null;
@@ -33,6 +34,11 @@
public OrmShape getReference(){
return reference;
}
+
+ public boolean isReferenceVisible(){
+ return refHide;
+ }
+
public ExpandeableShape(Object ioe) {
super(ioe);
}
@@ -40,10 +46,12 @@
public void refreshReferences(Object model) {
refHide = !refHide;
if (model instanceof OrmDiagram) {
- if(refHide)
- ((OrmDiagram)model).processExpand(this);
- else
- ((OrmDiagram)model).processCollapse(this);
+ if(refHide){
+ if(first){
+ ((OrmDiagram)model).processExpand(this);
+ first = false;
+ }
+ }
}
firePropertyChange(SHOW_REFERENCES, null, new Boolean(refHide));
}
Modified:
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 2007-07-17
13:28:12 UTC (rev 2465)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ModelElement.java 2007-07-17
14:01:31 UTC (rev 2466)
@@ -53,6 +53,16 @@
parent = element;
}
+ public OrmDiagram getOrmDiagram(){
+ ModelElement element = this;
+ while(true){
+ if(element.getParent() == null)break;
+ if(element.getParent() instanceof OrmDiagram) return (OrmDiagram)element.getParent();
+ element = element.getParent();
+ }
+ return null;
+ }
+
class OList extends ArrayList{
public OList(){
Modified:
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 2007-07-17
13:28:12 UTC (rev 2465)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmDiagram.java 2007-07-17
14:01:31 UTC (rev 2466)
@@ -150,7 +150,7 @@
return ormShape;
}
- private OrmShape getShape(Object ormElement) {
+ public OrmShape getShape(Object ormElement) {
OrmShape ormShape = null;
if (ormElement instanceof RootClass) {
ormShape = elements.get(((RootClass)ormElement).getEntityName());
@@ -166,52 +166,7 @@
return ormShape;
}
- private OrmShape removePersistentClass(PersistentClass persistentClass){
- Table componentClassDatabaseTable=null;
- 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){
- removeLinks(shape);
- getChildren().remove(shape);
- elements.remove(componentClassDatabaseTable.getSchema() + "." +
componentClassDatabaseTable.getName());
- }
- }
- 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){
- removeLinks(singleTableSubclassShape);
- getChildren().remove(singleTableSubclassShape);
- elements.remove(singleTableSubclass.getEntityPersisterClass().getCanonicalName());
- }
- }
- if (persistentClass.getIdentifier() instanceof Component) {
- Component identifier = (Component)persistentClass.getIdentifier();
- if (!identifier.getComponentClassName().equals(identifier.getOwner().getClassName()))
{
- OrmShape componentClassShape = elements.get(identifier.getComponentClassName());
- if (componentClassShape != null){
- removeLinks(componentClassShape);
- getChildren().remove(componentClassShape);
- elements.remove(identifier.getComponentClassName());
- }
- String tableName = identifier.getTable().getSchema() + "." +
identifier.getTable().getName();
- elements.remove(tableName);
- }
- }
- }
- return classShape;
- }
-
private OrmShape getOrCreatePersistentClass(PersistentClass persistentClass, Table
componentClassDatabaseTable){
OrmShape classShape = null;
OrmShape shape = null;
@@ -349,53 +304,6 @@
}
}
- public void processCollapse(ExpandeableShape shape) {
- Object element = shape.getOrmElement();
- OrmShape reference = shape.getReference();
- if(reference != null){
- if(element instanceof RootClass){
- RootClass rc = (RootClass)element;
- Table table = rc.getTable();
- OrmShape sh = getShape(table);
- removeLinks(sh);
- getChildren().remove(sh);
- elements.remove(sh);
- }
- if (element instanceof Property) {
- Property property = (Property)element;
- if (!property.isComposite()) {
- Type type = ((Property)element).getType();
- if (type.isEntityType()) {
- EntityType et = (EntityType) type;
- Object clazz = getConfiguration().getClassMapping(et.getAssociatedEntityName());
- if (clazz instanceof RootClass) {
- RootClass rootClass = (RootClass)clazz;
-
- removePersistentClass(rootClass);
- } else if (clazz instanceof SingleTableSubclass) {
- removePersistentClass(((SingleTableSubclass)clazz).getRootClass());
-
- }
- }
- } else {
- removePersistentClass(new SpecialRootClass(property));
-
- }
- for(int i = reference.getChildren().size()-1;i>=0;i--){
- if(reference.getChildren().get(i) instanceof ExpandeableShape)
- processCollapse((ComponentShape)reference.getChildren().get(i));
- if(reference.getChildren().get(i) instanceof ComponentShape)
- hideReferences((ComponentShape)reference.getChildren().get(i));
- }
- removeLinks(reference);
- getChildren().remove(reference);
- elements.remove(reference);
- shape.setReference(null);
- }
- firePropertyChange(REFRESH, null, null);
- }
- }
-
public void processExpand(ExpandeableShape shape) {
OrmShape s=null;
Object element = shape.getOrmElement();
@@ -438,7 +346,8 @@
} else {
s = getOrCreatePersistentClass(new SpecialRootClass(property), null);
}
- shape.setReference(s);
+ if(!shape.getParent().equals(s))
+ shape.setReference(s);
firePropertyChange(REFRESH, null, null);
}
}
@@ -447,123 +356,6 @@
return configuration;
}
- public void hideShapes(ExpandeableShape hidenShape){
- OrmShape reference = hidenShape.getReference();
- if(reference != null){
- Object element = reference.getOrmElement();
- if(element instanceof RootClass){
- RootClass rc = (RootClass)element;
- Table table = rc.getTable();
- OrmShape shape = getShape(table);
- removeLinks(shape);
- getChildren().remove(shape);
- elements.remove(shape);
- }
- for(int i = reference.getChildren().size()-1;i>=0;i--){
- if(reference.getChildren().get(i) instanceof ComponentShape)
- hideReferences((ComponentShape)reference.getChildren().get(i));
- if(reference.getChildren().get(i) instanceof ExpandeableShape)
- processCollapse((ComponentShape)reference.getChildren().get(i));
- }
- removeLinks(reference);
- getChildren().remove(reference);
- elements.remove(reference);
- hidenShape.setReference(null);
- }
- removeLinks(hidenShape);
- firePropertyChange(REFRESH, null, null);
- }
-
- protected void hideReferences(ComponentShape componentShape) {
- OrmShape reference = componentShape.getReference();
- if(reference != null){
- Object element = reference.getOrmElement();
- if(element instanceof RootClass){
- RootClass rc = (RootClass)element;
- Table table = rc.getTable();
- OrmShape shape = getShape(table);
- removeLinks(shape);
- getChildren().remove(shape);
- elements.remove(shape);
- }
- 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) {
- Component comp = (Component)((Collection)property.getValue()).getElement();
- if (comp != null) {
- OrmShape classShape = createShape(property);
- OrmShape tableShape = (OrmShape)elements.get(component.getTable().getSchema() +
"." + component.getTable().getName());
- removeLinks(tableShape);
- elements.remove(component.getTable().getSchema() + "." +
component.getTable().getName());
- }
- } else if (collection.isOneToMany()) {
- OneToMany comp = (OneToMany)((Collection)property.getValue()).getElement();
- if (comp != null){
- Shape sh = elements.get(comp.getAssociatedClass().getTable().getSchema() +
"." + comp.getAssociatedClass().getTable().getName());
- removeLinks(sh);
- elements.remove(comp.getAssociatedClass().getTable().getSchema() + "." +
comp.getAssociatedClass().getTable().getName());
- Shape sh2 = elements.get(comp.getAssociatedClass().getEntityName());
- removeLinks(sh2);
- elements.remove(comp.getAssociatedClass().getEntityName());
- }
- } else if (collection.isMap() || collection.isSet()) {
- Table databaseTable = collection.getCollectionTable();
- OrmShape tableShape = null;
- if(databaseTable != null) {
- String tableName = databaseTable.getSchema() + "." +
databaseTable.getName();
- tableShape = (OrmShape)elements.get(tableName);
- if(tableShape != null) {
- 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.getEntityName()) != null)
- elements.remove(cls.getEntityName());
- }
- }
- }
- elements.remove(tableName);
- }
- }
- }
- }
- for(int i = reference.getChildren().size()-1;i>=0;i--){
- if(reference.getChildren().get(i) instanceof ComponentShape)
- hideReferences((ComponentShape)reference.getChildren().get(i));
- if(reference.getChildren().get(i) instanceof ExpandeableShape)
- processCollapse((ComponentShape)reference.getChildren().get(i));
- }
- removeLinks(reference);
- getChildren().remove(reference);
- elements.remove(reference);
- componentShape.setReference(null);
- }
- removeLinks(componentShape);
- firePropertyChange(REFRESH, null, null);
- }
-
- protected void removeLinks(Shape shape){
- Connection con;
- for(int i=shape.getSourceConnections().size()-1;i>=0;i--){
- con = shape.getSourceConnections().get(i);
- con.getTarget().getTargetConnections().remove(con);
- shape.getSourceConnections().remove(con);
- }
- for(int i=shape.getTargetConnections().size()-1;i>=0;i--){
- con = shape.getTargetConnections().get(i);
- con.getSource().getSourceConnections().remove(con);
- shape.getTargetConnections().remove(con);
- }
- for(int i=shape.getChildren().size()-1;i>=0;i--){
- removeLinks((Shape)shape.getChildren().get(i));
- }
- }
protected void refreshComponentReferences(ComponentShape componentShape) {
OrmShape childShape = null;
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ComponentShapeEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ComponentShapeEditPart.java 2007-07-17
13:28:12 UTC (rev 2465)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ComponentShapeEditPart.java 2007-07-17
14:01:31 UTC (rev 2466)
@@ -28,8 +28,10 @@
import org.jboss.tools.hibernate.ui.veditor.editors.figures.ComponentFigure;
import org.jboss.tools.hibernate.ui.veditor.editors.figures.TitleLabel;
import org.jboss.tools.hibernate.ui.veditor.editors.model.ComponentShape;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.ExpandeableShape;
import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmDiagram;
import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmShape;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.Shape;
public class ComponentShapeEditPart extends ExpandeableShapeEditPart {
@@ -70,8 +72,10 @@
figure.setSize(i,-1);
else
figure.setSize(-1,-1);
-
- refresh();
+
+ refreshReference((ExpandeableShape)getCastedModel());
+
+
((OrmShape)getParent().getModel()).refreshReference();
} else {
super.propertyChange(evt);
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ExpandeableShapeEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ExpandeableShapeEditPart.java 2007-07-17
13:28:12 UTC (rev 2465)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ExpandeableShapeEditPart.java 2007-07-17
14:01:31 UTC (rev 2466)
@@ -16,12 +16,18 @@
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.gef.EditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.RequestConstants;
import org.eclipse.swt.graphics.RGB;
+import org.hibernate.mapping.RootClass;
+import org.hibernate.mapping.Table;
import org.jboss.tools.hibernate.ui.veditor.editors.figures.TitleLabel;
import org.jboss.tools.hibernate.ui.veditor.editors.figures.TopLineBorder;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.ComponentShape;
import org.jboss.tools.hibernate.ui.veditor.editors.model.ExpandeableShape;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmDiagram;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmShape;
import org.jboss.tools.hibernate.ui.veditor.editors.model.Shape;
@@ -61,6 +67,8 @@
((IFigure)getFigure().getChildren().get(0)).setForegroundColor(ResourceManager.getInstance().getColor(new
RGB(0,0,0)));
}
}else if (ExpandeableShape.SHOW_REFERENCES.equals(prop)) {
+
+ refreshReference((ExpandeableShape)getCastedModel());
// ((IFigure)getFigure().getChildren().get(0)).setBackgroundColor(getSelectionColor());
// ((IFigure)getFigure().getChildren().get(0)).setForegroundColor(ResourceManager.getInstance().getColor(new
RGB(255,255,255)));
} else {
@@ -68,6 +76,49 @@
}
}
+ protected void refreshReference(ExpandeableShape shape){
+ OrmShape refShape = shape.getReference();
+ if(refShape == null) return;
+ OrmEditPart refPart = (OrmEditPart)getViewer().getEditPartRegistry().get(refShape);
+ if(refPart != null){
+ refPart.getFigure().setVisible(shape.isReferenceVisible());
+ setLinksVisible(refPart, shape.isReferenceVisible());
+ }
+ Object element = refShape.getOrmElement();
+ if(element instanceof RootClass){
+ RootClass rc = (RootClass)element;
+ Table table = rc.getTable();
+ OrmShape tableShape = refShape.getOrmDiagram().getShape(table);
+ OrmEditPart tablePart =
(OrmEditPart)getViewer().getEditPartRegistry().get(tableShape);
+ if(tablePart != null){
+ tablePart.getFigure().setVisible(shape.isReferenceVisible());
+ setLinksVisible(tablePart, shape.isReferenceVisible());
+ }
+ }
+ for(int i=0;i<refShape.getChildren().size();i++){
+ if(refShape.getChildren().get(i) instanceof ExpandeableShape){
+ refreshReference((ExpandeableShape)refShape.getChildren().get(i));
+ }
+ }
+ }
+
+ private void setLinksVisible(OrmEditPart editPart, boolean flag){
+ ConnectionEditPart link;
+ OrmEditPart child;
+ for(int i=0;i<editPart.getSourceConnections().size();i++){
+ link = (ConnectionEditPart)editPart.getSourceConnections().get(i);
+ link.getFigure().setVisible(flag);
+ }
+ for(int i=0;i<editPart.getTargetConnections().size();i++){
+ link = (ConnectionEditPart)editPart.getTargetConnections().get(i);
+ link.getFigure().setVisible(flag);
+ }
+ for(int i=0;i<editPart.getChildren().size();i++){
+ child = (OrmEditPart)editPart.getChildren().get(i);
+ setLinksVisible(child, flag);
+ }
+ }
+
protected List getModelChildren() {
return ((ExpandeableShape)getModel()).getChildren();
}