Author: vyemialyanchyk
Date: 2009-09-29 08:32:40 -0400 (Tue, 29 Sep 2009)
New Revision: 17792
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/DiagramViewer.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/view/ObjectEditorInput.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4865 - fixed
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/DiagramViewer.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/DiagramViewer.java 2009-09-29
12:00:36 UTC (rev 17791)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/DiagramViewer.java 2009-09-29
12:32:40 UTC (rev 17792)
@@ -13,7 +13,6 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -275,64 +274,30 @@
public boolean isDirty() {
return ormDiagram.isDirty();
}
-
- protected String getItemName(RootClass rootClass) {
- String res = rootClass.getEntityName();
- if (res == null) {
- res = rootClass.getClassName();
- }
- if (res == null) {
- res = rootClass.getNodeName();
- }
- res = res.substring(res.lastIndexOf(".") + 1); //$NON-NLS-1$
- return res;
- }
protected void setInput(IEditorInput input) {
ObjectEditorInput objectEditorInput = (ObjectEditorInput)input;
ConsoleConfiguration configuration = objectEditorInput.getConfiguration();
- Object obj = objectEditorInput.getObject();
- setPartName(DiagramViewerMessages.DiagramViewer_diagram_for + " " +
getDiagramName(obj)); //$NON-NLS-1$
- if (obj instanceof RootClass) {
- RootClass rootClass = (RootClass)obj;
+ ArrayList<RootClass> roots = objectEditorInput.getRootClasses();
+ setPartName(DiagramViewerMessages.DiagramViewer_diagram_for + " " +
objectEditorInput.getName()); //$NON-NLS-1$
+ if (roots.size() == 1) {
+ RootClass rootClass = roots.get(0);
ormDiagram = new OrmDiagram(configuration, rootClass);
- } else if (obj instanceof RootClass[]) {
- RootClass[] rootClasses = (RootClass[])obj;
+ } else if (roots.size() > 1) {
+ RootClass[] rootClasses = roots.toArray(new RootClass[0]);
ormDiagram = new OrmDiagram(configuration, rootClasses);
}
super.setInput(input);
loadProperties();
}
- protected String getDiagramName(Object obj) {
- String name = ""; //$NON-NLS-1$
- if (obj instanceof RootClass) {
- RootClass rootClass = (RootClass)obj;
- name = getItemName(rootClass);
- } else if (obj instanceof RootClass[]) {
- RootClass[] rootClasses = (RootClass[])obj;
- ArrayList<String> names = new ArrayList<String>();
- for (int i = 0; i < rootClasses.length; i++) {
- names.add(getItemName(rootClasses[i]));
- }
- // sort to get same name for same combinations of entities
- Collections.sort(names);
- name = names.size() > 0 ? names.get(0) : ""; //$NON-NLS-1$
- for (int i = 1; i < rootClasses.length; i++) {
- name += " & " + names.get(i); //$NON-NLS-1$
- }
- }
- return name;
- }
-
public String getDiagramName() {
IEditorInput input = getEditorInput();
- Object obj = null;
if (input instanceof ObjectEditorInput) {
ObjectEditorInput objectEditorInput = (ObjectEditorInput)input;
- obj = objectEditorInput.getObject();
+ return objectEditorInput.getName();
}
- return getDiagramName(obj);
+ return ""; //$NON-NLS-1$
}
/**
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-09-29
12:00:36 UTC (rev 17791)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ElementsFactory.java 2009-09-29
12:32:40 UTC (rev 17792)
@@ -58,7 +58,8 @@
}
Iterator<Shape> it = element.getChildrenList().iterator();
while (it.hasNext()) {
- createChildren(it.next());
+ final Shape shape = it.next();
+ createChildren(shape);
}
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/ObjectEditorInput.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/ObjectEditorInput.java 2009-09-29
12:00:36 UTC (rev 17791)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/ObjectEditorInput.java 2009-09-29
12:32:40 UTC (rev 17792)
@@ -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,43 +10,89 @@
******************************************************************************/
package org.jboss.tools.hibernate.ui.view;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IPersistableElement;
import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.mapping.RootClass;
/**
*
+ * author: ?
+ * author: Vitali Yemialyanchyk
*/
public class ObjectEditorInput implements IEditorInput{
- protected Object fObject;
+ protected ArrayList<RootClass> roots;
protected ConsoleConfiguration configuration;
- public ObjectEditorInput(ConsoleConfiguration configuration, Object object) {
- fObject = object;
+ public ObjectEditorInput(ConsoleConfiguration configuration, RootClass rc) {
+ roots = new ArrayList<RootClass>();
+ roots.add(rc);
this.configuration = configuration;
}
- public Object getObject() {
- return fObject;
+ public ObjectEditorInput(ConsoleConfiguration configuration, RootClass[] rcs) {
+ roots = new ArrayList<RootClass>();
+ for (int i = 0; i < rcs.length; i++) {
+ roots.add(rcs[i]);
+ }
+ Collections.sort(roots, new RootClassComparator());
+ this.configuration = configuration;
}
+
+ public class RootClassComparator implements Comparator<RootClass> {
+ public int compare(RootClass o1, RootClass o2) {
+ return getItemName(o1).compareTo(getItemName(o2));
+ }
+ }
-
public boolean exists() {
return false;
}
+ public ArrayList<RootClass> getRootClasses() {
+ return roots;
+ }
public ImageDescriptor getImageDescriptor() {
return ImageDescriptor.getMissingImageDescriptor();
}
-
public String getName() {
- return ""; //$NON-NLS-1$
+ return getDiagramName();
}
+ public String getDiagramName() {
+ String name = ""; //$NON-NLS-1$
+ ArrayList<String> names = new ArrayList<String>();
+ for (int i = 0; i < roots.size(); i++) {
+ names.add(getItemName(roots.get(i)));
+ }
+ // sort to get same name for same combinations of entities
+ Collections.sort(names);
+ name = names.size() > 0 ? names.get(0) : ""; //$NON-NLS-1$
+ for (int i = 1; i < names.size(); i++) {
+ name += " & " + names.get(i); //$NON-NLS-1$
+ }
+ return name;
+ }
+
+ protected String getItemName(RootClass rootClass) {
+ String res = rootClass.getEntityName();
+ if (res == null) {
+ res = rootClass.getClassName();
+ }
+ if (res == null) {
+ res = rootClass.getNodeName();
+ }
+ res = res.substring(res.lastIndexOf(".") + 1); //$NON-NLS-1$
+ return res;
+ }
public IPersistableElement getPersistable() {
return null;
@@ -68,10 +114,29 @@
}
public boolean equals(Object obj) {
- return (obj instanceof ObjectEditorInput && ((ObjectEditorInput)obj).fObject ==
fObject);
+ boolean res = false;
+ if (!(obj instanceof ObjectEditorInput)) {
+ return res;
+ }
+ final ObjectEditorInput oei = (ObjectEditorInput)obj;
+ if (!configuration.equals(oei.getConfiguration())) {
+ return res;
+ }
+ final ArrayList<RootClass> rootsOei = oei.getRootClasses();
+ if (roots.size() != rootsOei.size()) {
+ return res;
+ }
+ res = true;
+ for (int i = 0; i < roots.size(); i++) {
+ if (!roots.get(i).equals(rootsOei.get(i))) {
+ res = false;
+ break;
+ }
+ }
+ return res;
}
public int hashCode() {
- return fObject.hashCode();
+ return roots.hashCode() + configuration.hashCode();
}
}