Author: dgeraskov
Date: 2011-11-09 06:59:14 -0500 (Wed, 09 Nov 2011)
New Revision: 36247
Added:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/TypedNode.java
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/CriteriaEditorAction.java
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/BaseNode.java
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/PersistentCollectionNode.java
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/TypeNode.java
Log:
Remove node dependencies from CriteriaEditorAction
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/BaseNode.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/BaseNode.java 2011-11-09
11:42:53 UTC (rev 36246)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/BaseNode.java 2011-11-09
11:59:14 UTC (rev 36247)
@@ -28,6 +28,7 @@
import javax.swing.tree.TreeNode;
+import org.eclipse.osgi.util.NLS;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.ImageConstants;
import org.hibernate.console.execution.ExecutionContext;
@@ -98,6 +99,14 @@
}
public abstract String getHQL();
+
+ public String getCriteria(){
+ final String criteria = ".createCriteria({0})"; //$NON-NLS-1$
+ final String sess = "session"; //$NON-NLS-1$
+ String enName = getName().substring(getName().lastIndexOf('.') + 1);
+ String enCriteria = NLS.bind(criteria, enName + ".class"); //$NON-NLS-1$
+ return sess + enCriteria;
+ }
public String getName() {
return name;
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/PersistentCollectionNode.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/PersistentCollectionNode.java 2011-11-09
11:42:53 UTC (rev 36246)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/PersistentCollectionNode.java 2011-11-09
11:59:14 UTC (rev 36247)
@@ -26,6 +26,7 @@
import javax.swing.tree.TreeNode;
+import org.eclipse.osgi.util.NLS;
import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
import org.hibernate.console.ConsoleMessages;
@@ -38,7 +39,7 @@
* @author MAX
*
*/
-public class PersistentCollectionNode extends BaseNode {
+public class PersistentCollectionNode extends BaseNode implements TypedNode{
BaseNode virtualNode;
CollectionType type;
@@ -83,6 +84,33 @@
public String getHQL() {
return ""; //$NON-NLS-1$
}
+
+ @Override
+ public String getCriteria() {
+ final String criteria = ".createCriteria({0})"; //$NON-NLS-1$
+ final String alias = "\n.createCriteria(\"{0}\",
\"{1}\")"; //$NON-NLS-1$
+ final String sess = "session"; //$NON-NLS-1$
+ String enName = "";//$NON-NLS-1$
+ String propCriteria = "";//$NON-NLS-1$
+ if (getName() != null){
+ if (getParent() instanceof BaseNode) {
+ BaseNode baseNodeParent = (BaseNode)getParent();
+ if (baseNodeParent instanceof TypedNode) {
+ TypedNode typedNodeParent = (TypedNode)baseNodeParent;
+ enName = typedNodeParent.getType().getName();
+ } else {
+ enName = baseNodeParent.getName();
+ }
+ enName = enName.substring(enName.lastIndexOf('.') + 1);
+ propCriteria = NLS.bind(alias, getName(), getName().charAt(0));
+ }
+ }
+ if ("".equals(enName)) { //$NON-NLS-1$
+ return ""; //$NON-NLS-1$
+ }
+ String enCriteria = NLS.bind(criteria, enName + ".class"); //$NON-NLS-1$
+ return sess + enCriteria + propCriteria;
+ }
public TreeNode getChildAt(int childIndex) {
checkChildren();
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/TypeNode.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/TypeNode.java 2011-11-09
11:42:53 UTC (rev 36246)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/TypeNode.java 2011-11-09
11:59:14 UTC (rev 36247)
@@ -21,6 +21,7 @@
*/
package org.hibernate.console.node;
+import org.eclipse.osgi.util.NLS;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.type.Type;
@@ -28,7 +29,7 @@
* @author MAX
*
*/
-public class TypeNode extends ClassNode {
+public class TypeNode extends ClassNode implements TypedNode{
Type type;
public TypeNode(NodeFactory factory, BaseNode parent, Type type, ClassMetadata metadata,
Object baseObject, boolean objectGraph) {
@@ -38,6 +39,32 @@
iconName = factory.getIconNameForType(type);
}
+ @Override
+ public String getCriteria() {
+ final String criteria = ".createCriteria({0})"; //$NON-NLS-1$
+ final String alias = "\n.createCriteria(\"{0}\",
\"{1}\")"; //$NON-NLS-1$
+ final String sess = "session"; //$NON-NLS-1$
+ String enName = "";//$NON-NLS-1$
+ String propCriteria = "";//$NON-NLS-1$
+ if (getName() != null){
+ if (getParent() instanceof BaseNode) {
+ BaseNode baseNodeParent = (BaseNode)getParent();
+ if (baseNodeParent instanceof TypedNode) {
+ TypedNode typedNodeParent = (TypedNode)baseNodeParent;
+ enName = typedNodeParent.getType().getName();
+ } else {
+ enName = baseNodeParent.getName();
+ }
+ enName = enName.substring(enName.lastIndexOf('.') + 1);
+ propCriteria = NLS.bind(alias, getName(), getName().charAt(0));
+ }
+ }
+ if ("".equals(enName)) { //$NON-NLS-1$
+ return ""; //$NON-NLS-1$
+ }
+ String enCriteria = NLS.bind(criteria, enName + ".class"); //$NON-NLS-1$
+ return sess + enCriteria + propCriteria;
+ }
public String renderLabel(boolean b) {
return super.renderLabel(b) + " : " +
getLabel(type.getReturnedClass().getName(),b); //$NON-NLS-1$
Added:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/TypedNode.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/TypedNode.java
(rev 0)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/node/TypedNode.java 2011-11-09
11:59:14 UTC (rev 36247)
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.hibernate.console.node;
+
+import org.hibernate.type.Type;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public interface TypedNode {
+
+ public Type getType();
+
+}
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/CriteriaEditorAction.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/CriteriaEditorAction.java 2011-11-09
11:42:53 UTC (rev 36246)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/CriteriaEditorAction.java 2011-11-09
11:59:14 UTC (rev 36247)
@@ -21,15 +21,11 @@
*/
package org.hibernate.eclipse.console.actions;
-import javax.swing.tree.TreeNode;
-
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.osgi.util.NLS;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.ImageConstants;
import org.hibernate.console.node.BaseNode;
-import org.hibernate.console.node.PersistentCollectionNode;
-import org.hibernate.console.node.TypeNode;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.console.utils.EclipseImages;
@@ -97,41 +93,7 @@
}
}
} else if (node instanceof BaseNode) {
- String prName = null;
- TreeNode treeNodeParent = null;
- if (node instanceof TypeNode) {
- TypeNode typeNode = (TypeNode)node;
- prName = typeNode.getName();
- treeNodeParent = typeNode.getParent();
- }
- else if (node instanceof PersistentCollectionNode) {
- PersistentCollectionNode persistentCollectionNode = (PersistentCollectionNode)node;
- prName = persistentCollectionNode.getName();
- treeNodeParent = persistentCollectionNode.getParent();
- }
- else {
- BaseNode baseNode = (BaseNode)node;
- enName = baseNode.getName();
- enName = enName.substring(enName.lastIndexOf('.') + 1);
- }
- if (prName != null) {
- if (treeNodeParent instanceof BaseNode) {
- BaseNode baseNodeParent = (BaseNode)treeNodeParent;
- if (baseNodeParent instanceof TypeNode) {
- TypeNode typeNodeParent = (TypeNode)baseNodeParent;
- enName = typeNodeParent.getType().getName();
- }
- else if (baseNodeParent instanceof PersistentCollectionNode) {
- PersistentCollectionNode persistentCollectionNodeParent =
(PersistentCollectionNode)baseNodeParent;
- enName = persistentCollectionNodeParent.getType().getName();
- }
- else {
- enName = baseNodeParent.getName();
- }
- enName = enName.substring(enName.lastIndexOf('.') + 1);
- propCriteria = NLS.bind(alias, prName, prName.charAt(0));
- }
- }
+ return ((BaseNode)node).getCriteria();
}
if ("".equals(enName)) { //$NON-NLS-1$
return ""; //$NON-NLS-1$