Author: vyemialyanchyk
Date: 2008-04-10 07:09:57 -0400 (Thu, 10 Apr 2008)
New Revision: 7478
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/VisualEditor.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/DiagramEditPart.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1559
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/VisualEditor.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/VisualEditor.java 2008-04-10
07:03:35 UTC (rev 7477)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/VisualEditor.java 2008-04-10
11:09:57 UTC (rev 7478)
@@ -141,9 +141,21 @@
super.setInput(input);
ObjectEditorInput objectEditorInput = (ObjectEditorInput)input;
ConsoleConfiguration configuration = objectEditorInput.getConfiguration();
- RootClass rootClass = (RootClass)(objectEditorInput).getObject();
- setPartName("Diagram for " + rootClass.getEntityName());
- ormDiagram = new OrmDiagram(configuration, rootClass,
objectEditorInput.getJavaProject());
+ Object obj = objectEditorInput.getObject();
+ if (obj instanceof RootClass) {
+ RootClass rootClass = (RootClass)obj;
+ setPartName("Diagram for " + rootClass.getEntityName());
+ ormDiagram = new OrmDiagram(configuration, rootClass,
objectEditorInput.getJavaProject());
+ }
+ else if (obj instanceof RootClass[]) {
+ RootClass[] rootClasses = (RootClass[])obj;
+ String name = rootClasses.length > 0 ? rootClasses[0].getEntityName() :
"";
+ for (int i = 1; i < rootClasses.length; i++) {
+ name += " & " + rootClasses[i].getEntityName();
+ }
+ setPartName("Diagram for " + name);
+ ormDiagram = new OrmDiagram(configuration, rootClasses,
objectEditorInput.getJavaProject());
+ }
}
public Object getAdapter(Class type) {
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 2008-04-10
07:03:35 UTC (rev 7477)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmDiagram.java 2008-04-10
11:09:57 UTC (rev 7478)
@@ -55,30 +55,54 @@
private boolean dirty = false;
private String childrenLocations[];
private HashMap<String,OrmShape> elements = new HashMap<String,OrmShape>();
- private RootClass ormElement;
+ private RootClass[] ormElements;
private Configuration configuration;
private ConsoleConfiguration consoleConfiguration;
private IJavaProject javaProject;
- private String entityName;
+ private String[] entityNames;
public static final String HIBERNATE_MAPPING_LAYOUT_FOLDER_NAME =
"hibernateMapping";
public OrmDiagram(ConsoleConfiguration configuration, RootClass ioe, IJavaProject
javaProject) {
consoleConfiguration = configuration;
this.configuration = configuration.getConfiguration();
- ormElement = (RootClass)ioe;
- entityName = ioe.getEntityName();
+ ormElements = new RootClass[1];
+ ormElements[0] = ioe;
+ entityNames = new String[1];
+ entityNames[0] = ioe.getEntityName();
this.javaProject = javaProject;
- if (ormElement instanceof RootClass) {
+ if (ioe instanceof RootClass) {
String string = "";
childrenLocations = string.split("#");
}
- getOrCreatePersistentClass(ormElement, null);
+ getOrCreatePersistentClass(ormElements[0], null);
expandModel(this);
load();
setDirty(false);
}
+ public OrmDiagram(ConsoleConfiguration configuration, RootClass[] ioe, IJavaProject
javaProject) {
+ consoleConfiguration = configuration;
+ this.configuration = configuration.getConfiguration();
+ ormElements = new RootClass[ioe.length];
+ System.arraycopy(ioe, 0, ormElements, 0, ioe.length);
+ entityNames = new String[ioe.length];
+ for (int i = 0; i < ormElements.length; i++) {
+ entityNames[i] = ormElements[i].getEntityName();
+ }
+ this.javaProject = javaProject;
+ if (ioe instanceof RootClass[]) {
+ String string = "";
+ childrenLocations = string.split("#");
+ }
+ for (int i = 0; i < ormElements.length; i++) {
+ getOrCreatePersistentClass(ormElements[i], null);
+ }
+ expandModel(this);
+ load();
+ setDirty(false);
+ }
+
private IPath getStoreFolderPath() {
return
javaProject.getProject().getLocation().append(".settings").append(HIBERNATE_MAPPING_LAYOUT_FOLDER_NAME);
}
@@ -88,26 +112,48 @@
}
private String getStoreFileName() {
- return consoleConfiguration.getName() + "_" +
getOrmElement().getClassName();
+ String name = ormElements.length > 0 ? ormElements[0].getClassName() :
"";
+ for (int i = 1; i < ormElements.length; i++) {
+ name += "_" + ormElements[i].getClassName();
+ }
+ return consoleConfiguration.getName() + "_" + name;
}
public HashMap getCloneElements() {
return (HashMap)elements.clone();
}
- public RootClass getOrmElement() {
- return ormElement;
+ public RootClass getOrmElement(int idx) {
+ if (0 > idx || idx >= ormElements.length) {
+ return null;
+ }
+ return ormElements[idx];
}
+ public RootClass[] getOrmElements() {
+ return ormElements;
+ }
+
public void refresh() {
- RootClass newOrmElement = (RootClass) consoleConfiguration
- .getConfiguration().getClassMapping(entityName);
- if (ormElement.equals(newOrmElement)) return;
- ormElement = newOrmElement;
+ boolean bRefresh = false;
+ for (int i = 0; i < ormElements.length; i++) {
+ RootClass newOrmElement = (RootClass) consoleConfiguration
+ .getConfiguration().getClassMapping(entityNames[i]);
+ if (ormElements[i].equals(newOrmElement)) {
+ continue;
+ }
+ ormElements[i] = newOrmElement;
+ bRefresh = true;
+ }
+ if (!bRefresh) {
+ return;
+ }
saveHelper();
getChildren().clear();
elements.clear();
- getOrCreatePersistentClass(ormElement, null);
+ for (int i = 0; i < ormElements.length; i++) {
+ getOrCreatePersistentClass(ormElements[i], null);
+ }
expandModel(this);
load();
firePropertyChange(REFRESH, null, null);
@@ -141,22 +187,38 @@
private OrmShape createShape(Object ormElement) {
OrmShape ormShape = null;
if (ormElement instanceof RootClass) {
- ormShape = new OrmShape(ormElement);
- getChildren().add(ormShape);
- elements.put(HibernateUtils.getPersistentClassName(((RootClass)ormElement).getEntityName()),
ormShape);
+ String key =
HibernateUtils.getPersistentClassName(((RootClass)ormElement).getEntityName());
+ ormShape = (OrmShape)elements.get(key);
+ if (null == ormShape) {
+ ormShape = new OrmShape(ormElement);
+ getChildren().add(ormShape);
+ elements.put(key, ormShape);
+ }
} else if (ormElement instanceof Table) {
- ormShape = new OrmShape(ormElement);
- getChildren().add(ormShape);
- elements.put(HibernateUtils.getTableName((Table)ormElement), ormShape);
+ String key = HibernateUtils.getTableName((Table)ormElement);
+ ormShape = (OrmShape)elements.get(key);
+ if (null == ormShape) {
+ ormShape = new OrmShape(ormElement);
+ getChildren().add(ormShape);
+ elements.put(key, ormShape);
+ }
} else if (ormElement instanceof Property) {
SpecialRootClass specialRootClass = new SpecialRootClass((Property)ormElement);
- ormShape = new SpecialOrmShape(specialRootClass);
- getChildren().add(ormShape);
- elements.put(HibernateUtils.getPersistentClassName(specialRootClass.getEntityName()),
ormShape);
+ String key = HibernateUtils.getPersistentClassName(specialRootClass.getEntityName());
+ ormShape = (OrmShape)elements.get(key);
+ if (null == ormShape) {
+ ormShape = new SpecialOrmShape(specialRootClass);
+ getChildren().add(ormShape);
+ elements.put(key, ormShape);
+ }
} else if (ormElement instanceof Subclass) {
- ormShape = new OrmShape(ormElement);
- getChildren().add(ormShape);
- elements.put(HibernateUtils.getPersistentClassName(((Subclass)ormElement).getEntityName()),
ormShape);
+ String key =
HibernateUtils.getPersistentClassName(((Subclass)ormElement).getEntityName());
+ ormShape = (OrmShape)elements.get(key);
+ if (null == ormShape) {
+ ormShape = new OrmShape(ormElement);
+ getChildren().add(ormShape);
+ elements.put(key, ormShape);
+ }
}
return ormShape;
}
@@ -246,7 +308,7 @@
componentClassShape =
getOrCreateComponentClass(((RootClass)persistentClass).getIdentifierProperty());
Shape idPropertyShape =
classShape.getChild(persistentClass.getIdentifierProperty());
- if (idPropertyShape != null) {
+ if (idPropertyShape != null && !isConnectionExist(idPropertyShape,
componentClassShape)) {
new Connection(idPropertyShape, componentClassShape);
idPropertyShape.firePropertyChange(REFRESH, null, null);
componentClassShape.firePropertyChange(REFRESH, null, null);
@@ -440,7 +502,7 @@
} else if (collection.isOneToMany()) {
childShape = getOrCreateAssociationClass(property);
-if (childShape == null) return;
+ if (childShape == null) return;
if(!isConnectionExist((Shape)(componentShape.getChildren().get(1)), childShape)){
new Connection((Shape)(componentShape.getChildren().get(1)), childShape);
((Shape)(componentShape.getChildren().get(1))).firePropertyChange(REFRESH, null,
null);
@@ -626,7 +688,7 @@
try {
folder.create(true, true, null);
- file = folder.getFile(consoleConfiguration.getName() + "_" +
getOrmElement().getClassName());
+ file = folder.getFile(getStoreFileName());
if (!file.exists()) {
file.create(source, true, null);
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/DiagramEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/DiagramEditPart.java 2008-04-10
07:03:35 UTC (rev 7477)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/DiagramEditPart.java 2008-04-10
11:09:57 UTC (rev 7478)
@@ -95,7 +95,7 @@
int point = 1;
int pointX = calculateTableLocation();
String string, xy[];
- for (int i = 0; i < childrenLocations.length; i++)
+ for (int i = 0; i < childrenLocations.length; i++) {
if (childrenLocations[i].indexOf('@') != -1
&& childrenLocations[i].indexOf(';') != -1) {
string = childrenLocations[i].substring(0, childrenLocations[i]
@@ -121,9 +121,10 @@
point = tempPoint;
}
}
- if (getCastedModel().getOrmElement() instanceof RootClass) {
- RootClass persistentClass = (RootClass) getCastedModel()
- .getOrmElement();
+ }
+ RootClass[] ormElements = getCastedModel().getOrmElements();
+ for (int i = 0; i < childrenLocations.length; i++) {
+ RootClass persistentClass = ormElements[i];
ormShape = (OrmShape) hashMap.remove(persistentClass
.getEntityName());
if (ormShape != null) {