[jboss-svn-commits] JBL Code SVN: r32554 - in labs/jbossrules/trunk: drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/dt and 3 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Apr 13 11:42:43 EDT 2010


Author: baunax
Date: 2010-04-13 11:42:41 -0400 (Tue, 13 Apr 2010)
New Revision: 32554

Modified:
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/FactPattern.java
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/dt/TemplateModel.java
   labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ActionInsertFactWidget.java
   labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ActionValueEditor.java
   labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ConstraintValueEditor.java
   labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FactPatternWidget.java
   labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FromCollectCompositeFactPatternWidget.java
   labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ModellerWidgetFactory.java
   labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleModeller.java
   labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleModellerWidgetFactory.java
   labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleTemplateEditor.java
   labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/TemplateModellerWidgetFactory.java
   labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/packages/SuggestionCompletionCache.java
   labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/util/BRDRTPersistenceTest.java
Log:
GUVNOR-527 Add the ability of creating Business Rules Templates using drools-templates
- removed isTemplate param and moved it to RuleModel
- Search in every Patterns and Actions for template's variables

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/FactPattern.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/FactPattern.java	2010-04-13 15:30:21 UTC (rev 32553)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/FactPattern.java	2010-04-13 15:42:41 UTC (rev 32554)
@@ -57,9 +57,8 @@
     public FieldConstraint[] getFieldConstraints() {
         if (this.constraintList == null) {
             return new FieldConstraint[0];
-        } else {
-            return this.constraintList.constraints;
-        }
+        } 
+        return this.constraintList.constraints;
     }
 
     public void setFieldConstraints(final List sortedConstraints) {

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/dt/TemplateModel.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/dt/TemplateModel.java	2010-04-13 15:30:21 UTC (rev 32553)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/dt/TemplateModel.java	2010-04-13 15:42:41 UTC (rev 32554)
@@ -5,15 +5,23 @@
 import java.util.List;
 import java.util.Map;
 
+import org.drools.guvnor.client.modeldriven.brl.ActionFieldList;
 import org.drools.guvnor.client.modeldriven.brl.ActionFieldValue;
-import org.drools.guvnor.client.modeldriven.brl.ActionInsertFact;
+import org.drools.guvnor.client.modeldriven.brl.CompositeFactPattern;
+import org.drools.guvnor.client.modeldriven.brl.CompositeFieldConstraint;
+import org.drools.guvnor.client.modeldriven.brl.DSLSentence;
 import org.drools.guvnor.client.modeldriven.brl.FactPattern;
 import org.drools.guvnor.client.modeldriven.brl.FieldConstraint;
+import org.drools.guvnor.client.modeldriven.brl.FreeFormLine;
+import org.drools.guvnor.client.modeldriven.brl.FromAccumulateCompositeFactPattern;
+import org.drools.guvnor.client.modeldriven.brl.FromCollectCompositeFactPattern;
+import org.drools.guvnor.client.modeldriven.brl.FromCompositeFactPattern;
 import org.drools.guvnor.client.modeldriven.brl.IAction;
 import org.drools.guvnor.client.modeldriven.brl.IPattern;
 import org.drools.guvnor.client.modeldriven.brl.ISingleFieldConstraint;
 import org.drools.guvnor.client.modeldriven.brl.PortableObject;
 import org.drools.guvnor.client.modeldriven.brl.RuleModel;
+import org.drools.guvnor.client.modeldriven.brl.SingleFieldConstraint;
 
 public class TemplateModel extends RuleModel implements PortableObject {
 	private Map<String, List<String>> table = new HashMap<String, List<String>>();
@@ -84,30 +92,32 @@
 	
 	public Map<String, Integer> getInterpolationVariables() {
 		Map<String, Integer> result = new HashMap<String, Integer>();
-        for (IPattern pattern : this.lhs) {
-            if (pattern instanceof FactPattern) {
-                FactPattern fact = (FactPattern) pattern;
-                for (FieldConstraint fc : fact.getFieldConstraints()) {
-                    if (fc instanceof ISingleFieldConstraint) {
-                        ISingleFieldConstraint con = (ISingleFieldConstraint) fc;
-                        if (ISingleFieldConstraint.TYPE_TEMPLATE == con.constraintValueType && !result.containsKey(con.value)) {
-                            result.put(con.value, result.size());
-                        }
-                    }
-                }
-            }
-        }
-        for (IAction action : this.rhs) {
-            if (action instanceof ActionInsertFact) {
-                ActionInsertFact fact = (ActionInsertFact) action;
-                for (ActionFieldValue afv : fact.fieldValues) {
-                	if (afv.nature == ActionFieldValue.TYPE_TEMPLATE && !result.containsKey(afv.value)) {
-                		result.put(afv.value, result.size());
-                	}
-                }
-            }
-        }
-        return result;
+		new RuleModelVisitor(result).visit(this);
+		return result;
+//        for (IPattern pattern : this.lhs) {
+//            if (pattern instanceof FactPattern) {
+//                FactPattern fact = (FactPattern) pattern;
+//                for (FieldConstraint fc : fact.getFieldConstraints()) {
+//                    if (fc instanceof ISingleFieldConstraint) {
+//                        ISingleFieldConstraint con = (ISingleFieldConstraint) fc;
+//                        if (ISingleFieldConstraint.TYPE_TEMPLATE == con.constraintValueType && !result.containsKey(con.value)) {
+//                            result.put(con.value, result.size());
+//                        }
+//                    }
+//                }
+//            }
+//        }
+//        for (IAction action : this.rhs) {
+//            if (action instanceof ActionInsertFact) {
+//                ActionInsertFact fact = (ActionInsertFact) action;
+//                for (ActionFieldValue afv : fact.fieldValues) {
+//                	if (afv.nature == ActionFieldValue.TYPE_TEMPLATE && !result.containsKey(afv.value)) {
+//                		result.put(afv.value, result.size());
+//                	}
+//                }
+//            }
+//        }
+//        return result;
 	}
 
 	public Map<String, List<String>> getTable() {
@@ -134,5 +144,133 @@
 		getTable().get(varName).set(rowIndex, newValue);
 	}
 	
-	
+	public static class RuleModelVisitor  {
+
+        private Map<String, Integer> vars;
+
+        public RuleModelVisitor(Map<String, Integer> vars) {
+            this.vars = vars;
+        }
+
+        public void visit(Object o) {
+        	if (o == null) {
+        		return;
+        	}
+        	if (o instanceof RuleModel) {
+				visitRuleModel((RuleModel) o);
+			} else if (o instanceof FactPattern) {
+				visitFactPattern((FactPattern) o);
+			} else if (o instanceof CompositeFieldConstraint) {
+				visitCompositeFieldConstraint((CompositeFieldConstraint) o);
+			} else if (o instanceof SingleFieldConstraint) {
+				visitSingleFieldConstraint((SingleFieldConstraint) o);
+			} else if (o instanceof CompositeFactPattern) {
+				visitCompositeFactPattern((CompositeFactPattern) o);
+			} else if (o instanceof FromCompositeFactPattern) {
+				visitFromCompositeFactPattern((FromCompositeFactPattern) o);
+			} else if (o instanceof FreeFormLine) {
+				visitFreeFormLine((FreeFormLine) o);
+			} else if (o instanceof FromCollectCompositeFactPattern) {
+				visitFromCollectCompositeFactPattern((FromCollectCompositeFactPattern) o);
+			} else if (o instanceof FromAccumulateCompositeFactPattern) {
+				visitFromAccumulateCompositeFactPattern((FromAccumulateCompositeFactPattern) o);
+			} else if (o instanceof DSLSentence) {
+				visitDSLSentence((DSLSentence) o);
+			} else if (o instanceof ActionFieldList) {
+				visitActionFieldList((ActionFieldList) o);
+			}
+        }
+        
+        private void visitActionFieldList(ActionFieldList afl) {
+            for (ActionFieldValue afv : afl.fieldValues) {
+            	if (afv.nature == ActionFieldValue.TYPE_TEMPLATE && !vars.containsKey(afv.value)) {
+            		vars.put(afv.value, vars.size());
+            	}
+            }
+		}
+
+		public void visitRuleModel(RuleModel model) {
+			if (model.lhs != null) {
+				for (IPattern pat : model.lhs) {
+					visit(pat);
+				}
+			}
+			if (model.rhs != null) {
+				for (IAction action : model.rhs) {
+					visit(action);
+				}
+			}
+		}
+
+		private void visitFactPattern(FactPattern pattern) {
+            for (FieldConstraint fc : pattern.getFieldConstraints()) {
+				visit(fc);
+			}
+        }
+        
+		private void visitCompositeFieldConstraint(CompositeFieldConstraint cfc) {
+			if (cfc.constraints != null) {
+				for (FieldConstraint fc : cfc.constraints) {
+					visit(fc);
+				}
+			}
+        }
+        
+		private void visitSingleFieldConstraint(SingleFieldConstraint sfc) {
+        	if (ISingleFieldConstraint.TYPE_TEMPLATE == sfc.constraintValueType && !vars.containsKey(sfc.value)) {
+        		vars.put(sfc.value, vars.size());
+        	}
+        }
+
+		private void visitFreeFormLine(FreeFormLine ffl) {
+           parseStringPattern(ffl.text);
+        }
+
+		private void visitCompositeFactPattern(CompositeFactPattern pattern) {
+			if (pattern.patterns != null) {
+				for (FactPattern fp : pattern.patterns) {
+					visit(fp);
+				}
+			}
+        }
+
+		private void visitFromCompositeFactPattern(FromCompositeFactPattern pattern) {
+        	visit(pattern.getFactPattern());
+        }
+
+		private void visitFromCollectCompositeFactPattern(FromCollectCompositeFactPattern pattern) {
+        	visit(pattern.getFactPattern());
+        	visit(pattern.getRightPattern());
+        }
+
+		private void visitFromAccumulateCompositeFactPattern(FromAccumulateCompositeFactPattern pattern) {
+        	visit(pattern.getFactPattern());
+        	visit(pattern.getSourcePattern());
+        	
+        	parseStringPattern(pattern.getActionCode());
+        	parseStringPattern(pattern.getInitCode());
+        	parseStringPattern(pattern.getReverseCode());
+        }
+
+		private void visitDSLSentence(final DSLSentence sentence) {
+            parseStringPattern(sentence.sentence);
+        }
+		
+		private void parseStringPattern(String text) {
+        	if (text == null || text.length() == 0) {
+        		return;
+        	}
+        	int pos = 0;
+        	while ((pos = text.indexOf("@{", pos)) != -1) {
+        		int end = text.indexOf('}', pos + 2);
+        		if (end != -1) {
+        			String var = text.substring(pos + 2, end);
+        			pos = end + 1;
+        			if (!vars.containsKey(var)) {
+        				vars.put(var, vars.size());
+        			}
+        		}
+        	}
+		}
+    }	
 }

Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ActionInsertFactWidget.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ActionInsertFactWidget.java	2010-04-13 15:30:21 UTC (rev 32553)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ActionInsertFactWidget.java	2010-04-13 15:42:41 UTC (rev 32554)
@@ -47,18 +47,16 @@
     private final String factType;
     private Constants constants = GWT.create(Constants.class);
     private boolean readOnly;
-	private boolean template;
 
     public ActionInsertFactWidget(RuleModeller mod, ActionInsertFact set) {
         this(mod, set, null);
     }
 
-    public ActionInsertFactWidget(RuleModeller mod, ActionInsertFact set,Boolean readOnly, boolean template) {
+    public ActionInsertFactWidget(RuleModeller mod, ActionInsertFact set,Boolean readOnly) {
         super(mod);
         this.model = set;
         this.layout = new DirtyableFlexTable();
         this.factType = set.factType;
-        this.template = template;
 
         SuggestionCompletionEngine completions = this.getModeller().getSuggestionCompletions();
         this.fieldCompletions = completions.getFieldCompletions( FieldAccessorsAndMutators.MUTATOR,
@@ -82,10 +80,6 @@
     
 	}
 
-    public ActionInsertFactWidget(RuleModeller mod, ActionInsertFact set,Boolean readOnly) {
-		this(mod, set, readOnly, false);
-    }
-
 	private void doLayout() {
         layout.clear();
         layout.setWidget( 0, 0, getAssertLabel() );
@@ -124,7 +118,7 @@
     private Widget valueEditor(final ActionFieldValue val) {
         SuggestionCompletionEngine completions = this.getModeller().getSuggestionCompletions();
     	DropDownData enums = completions.getEnums(this.factType, this.model.fieldValues, val.field);
-    	return new ActionValueEditor(val, enums,this.getModeller(),val.type,this.readOnly, isTemplate());
+    	return new ActionValueEditor(val, enums,this.getModeller(),val.type,this.readOnly);
     }
 
     private Widget fieldSelector(final ActionFieldValue val) {
@@ -217,11 +211,4 @@
     public boolean isReadOnly() {
         return this.readOnly;
     }
-
-	public boolean isTemplate() {
-		return template;
-	}
-
-
-
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ActionValueEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ActionValueEditor.java	2010-04-13 15:30:21 UTC (rev 32553)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ActionValueEditor.java	2010-04-13 15:42:41 UTC (rev 32554)
@@ -44,11 +44,10 @@
     private RuleModeller model = null;
     private String variableType = null;
     private boolean readOnly;
-	private boolean template;
 
     public ActionValueEditor(final ActionFieldValue val,
             final DropDownData enums, boolean readOnly) {
-        this(val, enums, null, null, readOnly, false);
+        this(val, enums, null, null, readOnly);
     }
 
     public ActionValueEditor(final ActionFieldValue val,
@@ -63,15 +62,10 @@
         this(val, enums, model, variableType, false);
     }
 
-    public ActionValueEditor(ActionFieldValue val, DropDownData enums,
-			RuleModeller model, String type, boolean readOnly) {
-    	this(val, enums, model, type, readOnly, false);
-	}
-
     public ActionValueEditor(final ActionFieldValue val,
             final DropDownData enums,
             RuleModeller model,
-            String variableType, boolean readOnly, boolean template) {
+            String variableType, boolean readOnly) {
 
         this.readOnly = readOnly;
 
@@ -84,7 +78,6 @@
         this.value = val;
         this.model = model;
         this.variableType = variableType;
-        this.template = template;
         refresh();
         initWidget(root);
     }
@@ -318,7 +311,7 @@
                 new InfoPopup(constants.Literal(),
                 constants.ALiteralValueMeansTheValueAsTypedInIeItsNotACalculation())));
         
-        if(isTemplate()){
+        if(model.isTemplate()){
 	        Button templateButton = new Button(constants.TemplateKey(), new ClickListener() {
 	            public void onClick(Widget arg0) {
 	                value.nature = ActionFieldValue.TYPE_TEMPLATE;
@@ -413,8 +406,4 @@
         h.add(popup);
         return h;
     }
-    
-    public boolean isTemplate(){
-    	return this.template;
-    }
 }

Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ConstraintValueEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ConstraintValueEditor.java	2010-04-13 15:30:21 UTC (rev 32553)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ConstraintValueEditor.java	2010-04-13 15:42:41 UTC (rev 32554)
@@ -65,23 +65,10 @@
     private Constants constants = ((Constants) GWT.create(Constants.class));
     private String fieldType;
     private boolean readOnly;
-	private boolean template;
 
-    /**
-     * @param con The constraint being edited.
-     */
-    public ConstraintValueEditor(FactPattern pattern,
-            String fieldName,
-            ISingleFieldConstraint con,
-            RuleModeller modeller,
-            String valueType /* eg is numeric */,
-            boolean readOnly) {
-    	this(pattern, fieldName, con, modeller, valueType, readOnly, false);
-    }
-
     public ConstraintValueEditor(FactPattern pattern, String fieldName,
     		ISingleFieldConstraint con, RuleModeller modeller, String valueType,
-			boolean readOnly, boolean template) {
+			boolean readOnly) {
         this.pattern = pattern;
         this.fieldName = fieldName;
         this.sce = modeller.getSuggestionCompletions();
@@ -89,7 +76,6 @@
         this.panel = new SimplePanel();
         this.model = modeller.getModel();
         this.modeller = modeller;
-        this.template = template;
 
         valueType = sce.getFieldType(pattern.factType, fieldName);
         this.fieldType = valueType;
@@ -275,7 +261,7 @@
                 new InfoPopup(constants.LiteralValue(),
                 constants.LiteralValTip())));
 
-        if(isTemplate()){
+		if (modeller.isTemplate()) {
 	        String templateKeyLabel = constants.TemplateKey();
 	        Button templateKeyButton = new Button(templateKeyLabel);
 	        templateKeyButton.addClickListener(new ClickListener() {
@@ -381,8 +367,4 @@
     public boolean isDirty() {
         return super.isDirty();
     }
-
-	public boolean isTemplate() {
-		return template;
-	}
 }

Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FactPatternWidget.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FactPatternWidget.java	2010-04-13 15:30:21 UTC (rev 32553)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FactPatternWidget.java	2010-04-13 15:42:41 UTC (rev 32554)
@@ -56,25 +56,17 @@
     private Constants constants = ((Constants) GWT.create(Constants.class));
     private String customLabel;
     private boolean readOnly;
-	private boolean template;
 
     public FactPatternWidget(RuleModeller mod, IPattern p,
             boolean canBind) {
         this(mod, p, null, canBind,null);
     }
 
-    public FactPatternWidget(RuleModeller mod, IPattern p,
-            boolean canBind, Boolean readOnly) {
-        this(mod, p, null, canBind, readOnly);
-    }
-
      public FactPatternWidget(RuleModeller mod, IPattern p,
             String customLabel, boolean canBind) {
          this(mod, p, null, canBind, null);
      }
 
-    
-
     /**
      * Creates a new FactPatternWidget
      * @param mod
@@ -84,23 +76,18 @@
      * @param readOnly if the widget should be in RO mode. If this parameter
      * is null, the readOnly attribute is calculated.
      */
-    public FactPatternWidget(RuleModeller mod, IPattern p,
-            String customLabel, boolean canBind, Boolean readOnly) {
-    	this(mod, p, customLabel, canBind, readOnly, false);
-    }
 
     public FactPatternWidget(RuleModeller ruleModeller, IPattern pattern,
-			boolean canBind, Boolean readOnly, boolean template) {
-    	this(ruleModeller, pattern, null, canBind, readOnly, template);
+			boolean canBind, Boolean readOnly) {
+    	this(ruleModeller, pattern, null, canBind, readOnly);
 	}
 
     public FactPatternWidget(RuleModeller mod, IPattern p,
-            String customLabel, boolean canBind, Boolean readOnly, boolean template) {
+            String customLabel, boolean canBind, Boolean readOnly) {
         super(mod);
         this.pattern = (FactPattern) p;
         this.completions = mod.getSuggestionCompletions();
         this.bindable = canBind;
-        this.template = template;
         
         this.connectives = new Connectives();
         this.connectives.setCompletions(completions);
@@ -386,9 +373,6 @@
             pred.add(new SmallLabel(c.value));
         }
 
-
-
-
         return pred;
     }
 
@@ -436,7 +420,7 @@
 
     private Widget valueEditor(final SingleFieldConstraint c, String factType) {
         //String type = this.modeller.getSuggestionCompletions().getFieldType( factType, c.fieldName );
-        return new ConstraintValueEditor(pattern, c.fieldName, c, this.getModeller(), c.fieldType,this.readOnly, isTemplate());
+        return new ConstraintValueEditor(pattern, c.fieldName, c, this.getModeller(), c.fieldType,this.readOnly);
     }
 
     private Widget operatorDropDown(final SingleFieldConstraint c) {
@@ -528,9 +512,4 @@
     public boolean isReadOnly() {
         return this.readOnly;
     }
-
-	public boolean isTemplate() {
-		return template;
-	}
-
 }

Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FromCollectCompositeFactPatternWidget.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FromCollectCompositeFactPatternWidget.java	2010-04-13 15:30:21 UTC (rev 32553)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FromCollectCompositeFactPatternWidget.java	2010-04-13 15:42:41 UTC (rev 32554)
@@ -40,10 +40,10 @@
 
     private void initExtraLeftSidePatternFactTypes(){
         extraLeftSidePatternFactTypes = new HashMap<String, String>();
-        extraLeftSidePatternFactTypes.put("java.util.ArrayList", "java.util.ArrayList");
-        extraLeftSidePatternFactTypes.put("java.util.LinkedList", "java.util.LinkedArrayList");
-        extraLeftSidePatternFactTypes.put("java.util.HashSet", "java.util.HashSet");
-        extraLeftSidePatternFactTypes.put("java.util.LinkedHashSet", "java.util.LinkedHashSet");
+        extraLeftSidePatternFactTypes.put("java.util.Collection", "java.util.Collection");
+        extraLeftSidePatternFactTypes.put("java.util.List", "java.util.List");
+        extraLeftSidePatternFactTypes.put("java.util.Set", "java.util.Set");
+        extraLeftSidePatternFactTypes.put("java.lang.Number", "java.lang.Number");
     }
 
     @Override
@@ -175,7 +175,6 @@
             }
         });
 
-
         final Button fromBtn = new Button(constants.From());
         final Button fromAccumulateBtn = new Button(constants.FromAccumulate());
         final Button fromCollectBtn = new Button(constants.FromCollect());
@@ -218,7 +217,8 @@
     @Override
     protected void calculateReadOnly() {
         if (this.pattern.factPattern != null) {
-            this.readOnly = !(this.getExtraLeftSidePatternFactTypes().containsKey(this.pattern.factPattern.factType) || this.getModeller().getSuggestionCompletions().containsFactType(this.pattern.factPattern.factType));
+            this.readOnly = !(this.getExtraLeftSidePatternFactTypes().containsKey(this.pattern.factPattern.factType) 
+            		|| this.getModeller().getSuggestionCompletions().containsFactType(this.pattern.factPattern.factType));
         }
     }
 

Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ModellerWidgetFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ModellerWidgetFactory.java	2010-04-13 15:30:21 UTC (rev 32553)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ModellerWidgetFactory.java	2010-04-13 15:42:41 UTC (rev 32554)
@@ -12,7 +12,7 @@
 	 * @param readOnly
 	 * @return
 	 */
-	public abstract RuleModellerWidget getWidget(RuleModeller ruleModeller,
+	public RuleModellerWidget getWidget(RuleModeller ruleModeller,
 			IAction action, Boolean readOnly);
 
 	/**
@@ -22,7 +22,9 @@
 	 * @param readOnly
 	 * @return
 	 */
-	public abstract RuleModellerWidget getWidget(RuleModeller ruleModeller,
+	public RuleModellerWidget getWidget(RuleModeller ruleModeller,
 			IPattern pattern, Boolean readOnly);
+	
+	public boolean isTemplate();
 
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleModeller.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleModeller.java	2010-04-13 15:30:21 UTC (rev 32553)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleModeller.java	2010-04-13 15:42:41 UTC (rev 32554)
@@ -1234,4 +1234,8 @@
 	public RuleModeller getRuleModeller() {
 		return this;
 	}
+
+	public boolean isTemplate() {
+		return widgetFactory.isTemplate();
+	}
 }

Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleModellerWidgetFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleModellerWidgetFactory.java	2010-04-13 15:30:21 UTC (rev 32553)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleModellerWidgetFactory.java	2010-04-13 15:42:41 UTC (rev 32554)
@@ -29,7 +29,7 @@
             return new ActionSetFieldWidget(ruleModeller, (ActionSetField) action,readOnly);
         } 
         if (action instanceof ActionInsertFact) {
-            return new ActionInsertFactWidget(ruleModeller, (ActionInsertFact) action, readOnly, isTemplate());
+            return new ActionInsertFactWidget(ruleModeller, (ActionInsertFact) action, readOnly);
         } 
         if (action instanceof ActionRetractFact) {
             return new ActionRetractFactWidget(ruleModeller, (ActionRetractFact) action, readOnly);
@@ -53,7 +53,7 @@
 	 */
 	public RuleModellerWidget getWidget(RuleModeller ruleModeller, IPattern pattern, Boolean readOnly){
         if (pattern instanceof FactPattern) {
-            return new FactPatternWidget(ruleModeller, pattern, true, readOnly, isTemplate());
+            return new FactPatternWidget(ruleModeller, pattern, true, readOnly);
         } 
         if (pattern instanceof CompositeFactPattern) {
             return new CompositeFactPatternWidget(ruleModeller, (CompositeFactPattern) pattern, readOnly);
@@ -80,7 +80,7 @@
 
 	}
 
-	protected boolean isTemplate(){
+	public boolean isTemplate(){
 		return false;
 	}
 }

Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleTemplateEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleTemplateEditor.java	2010-04-13 15:30:21 UTC (rev 32553)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleTemplateEditor.java	2010-04-13 15:42:41 UTC (rev 32554)
@@ -49,13 +49,13 @@
 		model = (TemplateModel) asset.content;
 		TabPanel tPanel = new TabPanel();
 		tPanel.setAutoWidth(true);
-		tPanel.setAutoHeight(true);
+//		tPanel.setAutoHeight(true);
 		
 		Panel pnl = new Panel();
 		pnl.setAutoWidth(true);
 		pnl.setClosable(false);
 		pnl.setTitle("Template Editor");
-		pnl.setAutoHeight(true);
+//		pnl.setAutoHeight(true);
 		ruleModeller = new RuleModeller(asset, new TemplateModellerWidgetFactory());
 		pnl.add(ruleModeller);
 		tPanel.add(pnl);
@@ -64,7 +64,7 @@
 		pnl.setAutoWidth(true);
 		pnl.setClosable(false);
 		pnl.setTitle("Template Data");
-		pnl.setAutoHeight(true);
+//		pnl.setAutoHeight(true);
 		pnl.add(buildTemplateTable());
 		pnl.setId("tplTable");
 		tPanel.add(pnl);
@@ -172,8 +172,9 @@
 	@Override
 	public void resetDirty() {
 		super.resetDirty();
-		store.commitChanges();
-		
+		if (store != null) {
+			store.commitChanges();
+		}
 	}
 
 	public RuleModeller getRuleModeller() {

Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/TemplateModellerWidgetFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/TemplateModellerWidgetFactory.java	2010-04-13 15:30:21 UTC (rev 32553)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/TemplateModellerWidgetFactory.java	2010-04-13 15:42:41 UTC (rev 32554)
@@ -3,7 +3,7 @@
 public class TemplateModellerWidgetFactory extends RuleModellerWidgetFactory {
 
 	@Override
-	protected boolean isTemplate() {
+	public boolean isTemplate() {
 		return true;
 	}
 }

Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/packages/SuggestionCompletionCache.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/packages/SuggestionCompletionCache.java	2010-04-13 15:30:21 UTC (rev 32553)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/packages/SuggestionCompletionCache.java	2010-04-13 15:42:41 UTC (rev 32554)
@@ -80,7 +80,7 @@
     }
 
     public SuggestionCompletionEngine getEngineFromCache(String packageName) {
-        SuggestionCompletionEngine eng = (SuggestionCompletionEngine) cache.get( packageName );
+        SuggestionCompletionEngine eng = cache.get( packageName );
         if (eng == null) {
             ErrorPopup.showMessage(constants.UnableToGetContentAssistanceForThisRule());
             return null;
@@ -117,8 +117,8 @@
         	if (done != null) {
         		done.execute();
         	}
-//            cache.remove( packageName );
-//            loadPackage( packageName, done );
+            cache.remove( packageName );
+            loadPackage( packageName, done );
         } else {
             done.execute();
         }

Modified: labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/util/BRDRTPersistenceTest.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/util/BRDRTPersistenceTest.java	2010-04-13 15:30:21 UTC (rev 32553)
+++ labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/util/BRDRTPersistenceTest.java	2010-04-13 15:42:41 UTC (rev 32554)
@@ -7,6 +7,7 @@
 import org.drools.guvnor.client.modeldriven.brl.ActionFieldValue;
 import org.drools.guvnor.client.modeldriven.brl.ActionInsertFact;
 import org.drools.guvnor.client.modeldriven.brl.FactPattern;
+import org.drools.guvnor.client.modeldriven.brl.FreeFormLine;
 import org.drools.guvnor.client.modeldriven.brl.IAction;
 import org.drools.guvnor.client.modeldriven.brl.IPattern;
 import org.drools.guvnor.client.modeldriven.brl.ISingleFieldConstraint;
@@ -75,6 +76,69 @@
         assertEquals(expected, drl);
 	}
 
+	public void testFreeFormLine() {
+		String expected = 
+			"rule \"with composite_1\"\n" + 
+			"	dialect \"mvel\"\n" + 
+			"	when\n" + 
+			"		$p : Person( name == \"diegoll\" )\n" + 
+			"		Cheese(type == \"Gouda\", price < 17)\n" + 
+			"	then\n" + 
+			"		Person fact0 = new Person();\n" + 
+			"		fact0.setAge( 87 );\n" + 
+			"		insert(fact0 );\n" + 
+			"end\n" + 
+			"\n" + 
+			"rule \"with composite_0\"\n" + 
+			"	dialect \"mvel\"\n" + 
+			"	when\n" + 
+			"		$p : Person( name == \"baunax\" )\n" + 
+			"		Cheese(type == \"Cheddar\", price < 23)\n" + 
+			"	then\n" + 
+			"		Person fact0 = new Person();\n" + 
+			"		fact0.setAge( 34 );\n" + 
+			"		insert(fact0 );\n" + 
+			"end";
+
+		TemplateModel m = new TemplateModel();
+		m.name = "with composite";
+		m.lhs = new IPattern[2];
+		m.rhs = new IAction[1];
+
+		FactPattern fp = new FactPattern("Person");
+		fp.boundName = "$p";
+
+		SingleFieldConstraint sfc = new SingleFieldConstraint("name");
+		sfc.fieldName = "name";
+		sfc.value = "name";
+		sfc.operator = "==";
+
+		sfc.constraintValueType = ISingleFieldConstraint.TYPE_TEMPLATE;
+		fp.addConstraint(sfc);
+
+		m.lhs[0] = fp;
+		
+		FreeFormLine ffl = new FreeFormLine();
+		ffl.text = "Cheese(type == \"@{type}\", price < @{price})";
+		
+		m.lhs[1] = ffl;
+
+		ActionInsertFact aif = new ActionInsertFact("Person");
+		ActionFieldValue afv = new ActionFieldValue("age", "age", ""); 
+		afv.nature = ActionFieldValue.TYPE_TEMPLATE;
+
+		aif.addFieldValue(afv);
+		m.rhs[0] = aif;
+
+		m.addRow(new String[] {"baunax", "Cheddar", "23", "34"});
+		m.addRow(new String[] {"diegoll", "Gouda", "17", "87"});
+		final String drl = p.marshal(m);
+		log.info("drl :\n{}", drl);
+
+		assertNotNull(drl);
+		assertEquals(expected, drl);
+	}
+
 	public void testEmptyDataWithRHS() {
 		String expected = 
 				"rule \"with composite_1\"\n" + 



More information about the jboss-svn-commits mailing list