[jboss-svn-commits] JBL Code SVN: r31389 - labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Feb 3 13:13:31 EST 2010


Author: baunax
Date: 2010-02-03 13:13:31 -0500 (Wed, 03 Feb 2010)
New Revision: 31389

Modified:
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ExpressionBuilder.java
Log:
added support for strings

Modified: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ExpressionBuilder.java
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ExpressionBuilder.java	2010-02-03 18:13:04 UTC (rev 31388)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ExpressionBuilder.java	2010-02-03 18:13:31 UTC (rev 31389)
@@ -157,34 +157,44 @@
 //		return null;
 	}
 
+	private void onCollectionChange(String value) {
+		if ("size".contains(value)) {
+			expression.appendPart(new ExpressionMethod("size", "int", SuggestionCompletionEngine.TYPE_NUMERIC));
+		} else if ("isEmpty".equals(value)) {
+			expression.appendPart(new ExpressionMethod("isEmpty", "boolean", SuggestionCompletionEngine.TYPE_BOOLEAN));
+		} else {
+			ExpressionCollectionIndex collectionIndex;
+			String factName = getCompletionEngine().getFactNameFromType(getCurrentParametricType());
+			if (getCurrentParametricType() != null && factName != null) {
+				collectionIndex = new ExpressionCollectionIndex("get", getCurrentParametricType(), factName);
+			} else {
+				collectionIndex = new ExpressionCollectionIndex("get", "java.lang.Object", SuggestionCompletionEngine.TYPE_OBJECT);
+			}
+			if ("first".equals(value)) {
+				collectionIndex.putParam("index", new ExpressionFormLine(new ExpressionText("0")));
+				expression.appendPart(collectionIndex);
+			} else if ("last".equals(value)) {
+				ExpressionFormLine index = new ExpressionFormLine(expression);
+				index.appendPart(new ExpressionMethod("size", "int", SuggestionCompletionEngine.TYPE_NUMERIC));
+				index.appendPart(new ExpressionText("-1"));
+				
+				collectionIndex.putParam("index", index);
+				expression.appendPart(collectionIndex);
+			} 
+		}
+	}
+	
 	private void onChangeSelection(String value) {
 		String prevFactName = null;
 		if (DELETE_VALUE.equals(value)) {
 			expression.removeLast();
 		} else if (SuggestionCompletionEngine.TYPE_COLLECTION.equals(getCurrentGenericType())) {
-			if ("size".contains(value)) {
+			onCollectionChange(value);
+		} else if (SuggestionCompletionEngine.TYPE_STRING.equals(getCurrentGenericType())) {
+			if ("size".equals(value)) {
 				expression.appendPart(new ExpressionMethod("size", "int", SuggestionCompletionEngine.TYPE_NUMERIC));
 			} else if ("isEmpty".equals(value)) {
-				expression.appendPart(new ExpressionMethod("isEmpty", "boolean", SuggestionCompletionEngine.TYPE_BOOLEAN));
-			} else {
-				ExpressionCollectionIndex collectionIndex;
-				String factName = getCompletionEngine().getFactNameFromType(getCurrentParametricType());
-				if (getCurrentParametricType() != null && factName != null) {
-					collectionIndex = new ExpressionCollectionIndex("get", getCurrentParametricType(), factName);
-				} else {
-					collectionIndex = new ExpressionCollectionIndex("get", "java.lang.Object", SuggestionCompletionEngine.TYPE_OBJECT);
-				}
-				if ("first".equals(value)) {
-					collectionIndex.putParam("index", new ExpressionFormLine(new ExpressionText("0")));
-					expression.appendPart(collectionIndex);
-				} else if ("last".equals(value)) {
-					ExpressionFormLine index = new ExpressionFormLine(expression);
-					index.appendPart(new ExpressionMethod("size", "int", SuggestionCompletionEngine.TYPE_NUMERIC));
-					index.appendPart(new ExpressionText("-1"));
-					
-					collectionIndex.putParam("index", index);
-					expression.appendPart(collectionIndex);
-				} 
+				expression.appendPart(new ExpressionText(".size() == 0", "", SuggestionCompletionEngine.TYPE_NUMERIC));
 			}
 		} else {
 			int dotPos = value.indexOf('.');
@@ -235,8 +245,8 @@
 		}
 		
 		if (SuggestionCompletionEngine.TYPE_STRING.equals(getCurrentGenericType())) {
-			completions.put("size()", METHOD_VALUE_PREFIX + "size");
-			completions.put("isEmpty()", METHOD_VALUE_PREFIX + "isEmpty");
+			completions.put("size()", "size");
+			completions.put("isEmpty()", "isEmpty");
 			return completions;
 		}
 		
@@ -244,8 +254,6 @@
 				SuggestionCompletionEngine.TYPE_NUMERIC.equals(getCurrentGenericType()) ||
 				SuggestionCompletionEngine.TYPE_DATE.equals(getCurrentGenericType()) ||
 				SuggestionCompletionEngine.TYPE_OBJECT.equals(getCurrentGenericType())) {
-			completions.put("size()", METHOD_VALUE_PREFIX + "size");
-			completions.put("isEmpty()", METHOD_VALUE_PREFIX + "isEmpty");
 			return completions;
 		}
 		
@@ -269,12 +277,8 @@
 					completions.put(field, FIElD_VALUE_PREFIX + "." + field);
 				}
 			}
-		} else {
-			String prevFactName = getCompletionEngine().getFactNameFromType(getPreviousClassType());
-			if (prevFactName != null) {
-//				getCompletionEngine().get
-			}
-		}
+		} 
+		//else {We don't know anything about this type, so return empty map}
 		return completions;
 	}
 



More information about the jboss-svn-commits mailing list