[jboss-svn-commits] JBL Code SVN: r32097 - in labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client: modeldriven/ui and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Mar 15 15:11:19 EDT 2010


Author: eaa
Date: 2010-03-15 15:11:19 -0400 (Mon, 15 Mar 2010)
New Revision: 32097

Modified:
   labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/messages/Constants.java
   labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/messages/Constants.properties
   labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/CompositeFactPatternWidget.java
   labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ConstraintValueEditor.java
   labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ExpressionBuilder.java
   labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FactPatternWidget.java
   labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FromAccumulateCompositeFactPatternWidget.java
   labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FromCollectCompositeFactPatternWidget.java
   labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FromCompositeFactPatternWidget.java
   labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleModeller.java
   labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/factPattern/Connectives.java
   labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/ActionToolbar.java
   labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/WorkingSetSelectorPopup.java
Log:
RuleModeller is refreshed after WS are selected.
LHS widgets are read-only when refer to Fact types now allowed in current WSs

Modified: labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/messages/Constants.java
===================================================================
--- labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/messages/Constants.java	2010-03-15 16:00:28 UTC (rev 32096)
+++ labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/messages/Constants.java	2010-03-15 19:11:19 UTC (rev 32097)
@@ -2047,4 +2047,6 @@
     String NewWorkingSet();
     String CreateWorkingSet();
     String WorkingSetName();
+
+    String ErrorLoadingRules();
 }

Modified: labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/messages/Constants.properties
===================================================================
--- labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/messages/Constants.properties	2010-03-15 16:00:28 UTC (rev 32096)
+++ labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/messages/Constants.properties	2010-03-15 19:11:19 UTC (rev 32097)
@@ -991,4 +991,5 @@
 WorkingSets=WorkingSets
 NewWorkingSet=New WorkingSet
 CreateWorkingSet=Create a WorkingSet
-WorkingSetName=WorkingSet name
\ No newline at end of file
+WorkingSetName=WorkingSet name
+ErrorLoadingRules=Error loading rules.
\ No newline at end of file

Modified: labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/CompositeFactPatternWidget.java
===================================================================
--- labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/CompositeFactPatternWidget.java	2010-03-15 16:00:28 UTC (rev 32096)
+++ labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/CompositeFactPatternWidget.java	2010-03-15 19:11:19 UTC (rev 32097)
@@ -46,6 +46,7 @@
     protected DirtyableFlexTable                             layout;
     protected RuleModeller                     modeller;
     protected Constants constants = ((Constants) GWT.create(Constants.class));
+    protected boolean readOnly;
 
     public CompositeFactPatternWidget(RuleModeller modeller,
                                       CompositeFactPattern pattern) {
@@ -56,6 +57,21 @@
         this.layout = new DirtyableFlexTable();
         this.layout.setStyleName( "model-builderInner-Background" );
 
+        this.readOnly = false;
+        if (this.pattern != null && this.pattern.patterns != null){
+            for (int i = 0; i < this.pattern.patterns.length; i++) {
+                FactPattern factPattern = this.pattern.patterns[i];
+                if (!completions.containsFactType(factPattern.factType)){
+                    this.readOnly = true;
+                    break;
+                }
+            }
+        }
+
+        if (this.readOnly){
+            layout.addStyleName("editor-disabled-widget");
+        }
+
         doLayout();
         initWidget( layout );
     }
@@ -76,7 +92,7 @@
             for ( int i = 0; i < facts.length; i++ ) {
                 vert.add( new FactPatternWidget( modeller,
                                                  facts[i],
-                                                 false ) );
+                                                 false,this.readOnly ) );
             }
             this.layout.setWidget( 1,
                                    1,
@@ -97,7 +113,7 @@
             lbl += " <font color='red'>" + constants.clickToAddPatterns() + "</font>";
         }
 
-        return new ClickableLabel( lbl + ":", click, !this.modeller.lockLHS() ) ;
+        return new ClickableLabel( lbl + ":", click, !(this.modeller.lockLHS() || this.readOnly) ) ;
     }
 
     /**

Modified: labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ConstraintValueEditor.java
===================================================================
--- labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ConstraintValueEditor.java	2010-03-15 16:00:28 UTC (rev 32096)
+++ labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ConstraintValueEditor.java	2010-03-15 19:11:19 UTC (rev 32097)
@@ -15,7 +15,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 import java.util.List;
 
 import org.drools.guvnor.client.common.DirtyableComposite;
@@ -55,43 +54,46 @@
  */
 public class ConstraintValueEditor extends DirtyableComposite {
 
-    private final FactPattern                pattern;
-    private final String                     fieldName;
+    private final FactPattern pattern;
+    private final String fieldName;
     private final SuggestionCompletionEngine sce;
-    private final ISingleFieldConstraint     constraint;
-    private final Panel                      panel;
-    private final RuleModel                  model;
-    private final RuleModeller               modeller;
-    private final boolean                    numericValue;
-    private DropDownData                     dropDownData;
-    private Constants                        constants = ((Constants) GWT.create( Constants.class ));
-    private String                           fieldType;
+    private final ISingleFieldConstraint constraint;
+    private final Panel panel;
+    private final RuleModel model;
+    private final RuleModeller modeller;
+    private final boolean numericValue;
+    private DropDownData dropDownData;
+    private Constants constants = ((Constants) GWT.create(Constants.class));
+    private String fieldType;
+    private boolean readOnly;
 
     /**
      * @param con The constraint being edited.
      */
     public ConstraintValueEditor(FactPattern pattern,
-                                 String fieldName,
-                                 ISingleFieldConstraint con,
-                                 RuleModeller modeller,
-                                 String valueType /* eg is numeric */) {
+            String fieldName,
+            ISingleFieldConstraint con,
+            RuleModeller modeller,
+            String valueType /* eg is numeric */,
+            boolean readOnly) {
         this.pattern = pattern;
         this.fieldName = fieldName;
         this.constraint = con;
+        this.readOnly = readOnly;
         this.sce = modeller.getSuggestionCompletions();
-        valueType = sce.getFieldType( pattern.factType,
-                                      fieldName );
+        valueType = sce.getFieldType(pattern.factType,
+                fieldName);
         this.fieldType = valueType;
-        if ( SuggestionCompletionEngine.TYPE_NUMERIC.equals( valueType ) ) {
+        if (SuggestionCompletionEngine.TYPE_NUMERIC.equals(valueType)) {
             this.numericValue = true;
         } else {
             this.numericValue = false;
         }
-        if ( SuggestionCompletionEngine.TYPE_BOOLEAN.equals( valueType ) ) {
-            this.dropDownData = DropDownData.create( new String[]{"true", "false"} ); //NON-NLS
+        if (SuggestionCompletionEngine.TYPE_BOOLEAN.equals(valueType)) {
+            this.dropDownData = DropDownData.create(new String[]{"true", "false"}); //NON-NLS
         } else {
-            this.dropDownData = sce.getEnums( pattern,
-                                              fieldName );
+            this.dropDownData = sce.getEnums(pattern,
+                    fieldName);
         }
 
         this.model = modeller.getModel();
@@ -99,104 +101,113 @@
 
         panel = new SimplePanel();
         refreshEditor();
-        initWidget( panel );
+        initWidget(panel);
 
     }
 
     private void refreshEditor() {
         panel.clear();
+        if (constraint.constraintValueType == SingleFieldConstraint.TYPE_UNDEFINED) {
+            Image clickme = new Image("images/edit.gif"); //NON-NLS
+            clickme.addClickListener(new ClickListener() {
 
-        if ( constraint.constraintValueType == SingleFieldConstraint.TYPE_UNDEFINED ) {
-            Image clickme = new Image( "images/edit.gif" ); //NON-NLS
-            clickme.addClickListener( new ClickListener() {
                 public void onClick(Widget w) {
-                    showTypeChoice( w,
-                                    constraint );
+                    showTypeChoice(w,
+                            constraint);
                 }
-            } );
-            panel.add( clickme );
+            });
+            panel.add(clickme);
         } else {
-            switch ( constraint.constraintValueType ) {
-                case SingleFieldConstraint.TYPE_LITERAL :
-                    if ( this.dropDownData != null ) {
-                        panel.add( new EnumDropDownLabel( this.pattern,
-                                                          this.fieldName,
-                                                          this.sce,
-                                                          this.constraint ) );
-                    } else if ( SuggestionCompletionEngine.TYPE_DATE.equals( this.fieldType ) ) {
+            switch (constraint.constraintValueType) {
+                case SingleFieldConstraint.TYPE_LITERAL:
+                    if (this.dropDownData != null) {
+                        panel.add(new EnumDropDownLabel(this.pattern,
+                                this.fieldName,
+                                this.sce,
+                                this.constraint));
+                    } else if (SuggestionCompletionEngine.TYPE_DATE.equals(this.fieldType)) {
 
-                        DatePickerLabel datePicker = new DatePickerLabel( constraint.value );
+                        DatePickerLabel datePicker = new DatePickerLabel(constraint.value);
 
                         // Set the default time
                         this.constraint.value = datePicker.getDateString();
 
-                        datePicker.addValueChanged( new ValueChanged() {
-                            public void valueChanged(String newValue) {
-                                constraint.value = newValue;
-                            }
-                        } );
+                        if (!this.readOnly) {
+                            datePicker.addValueChanged(new ValueChanged() {
 
-                        panel.add( datePicker );
+                                public void valueChanged(String newValue) {
+                                    constraint.value = newValue;
+                                }
+                            });
 
+                            panel.add(datePicker);
+                        } else {
+                            panel.add(new SmallLabel(this.constraint.value));
+                        }
                     } else {
-                        panel.add( new DefaultLiteralEditor( this.constraint,
-                                                             this.numericValue ) );
+                        if (!this.readOnly) {
+                            panel.add(new DefaultLiteralEditor(this.constraint,
+                                    this.numericValue));
+                        } else {
+                            panel.add(new SmallLabel(this.constraint.value));
+                        }
                     }
                     break;
-                case SingleFieldConstraint.TYPE_RET_VALUE :
-                    panel.add( returnValueEditor() );
+                case SingleFieldConstraint.TYPE_RET_VALUE:
+                    panel.add(returnValueEditor());
                     break;
-                case SingleFieldConstraint.TYPE_EXPR_BUILDER :
-                    panel.add( expressionEditor() );
+                case SingleFieldConstraint.TYPE_EXPR_BUILDER:
+                    panel.add(expressionEditor());
                     break;
-                case SingleFieldConstraint.TYPE_VARIABLE :
-                    panel.add( variableEditor() );
+                case SingleFieldConstraint.TYPE_VARIABLE:
+                    panel.add(variableEditor());
                     break;
-                default :
+                default:
                     break;
             }
         }
     }
 
     private Widget variableEditor() {
-        List vars = this.model.getBoundVariablesInScope( this.constraint );
+        List vars = this.model.getBoundVariablesInScope(this.constraint);
 
         final ListBox box = new ListBox();
 
-        if ( this.constraint.value == null ) {
-            box.addItem( constants.Choose() );
+        if (this.constraint.value == null) {
+            box.addItem(constants.Choose());
         }
 
         int j = 0;
-        for ( int i = 0; i < vars.size(); i++ ) {
-            String var = (String) vars.get( i );
-            FactPattern f = model.getBoundFact( var );
-            String fv = model.getFieldConstraint( var );
-            if ( (f != null && f.factType.equals( this.fieldType )) || (fv != null && fv.equals( this.fieldType )) ) {
-                box.addItem( var );
-                if ( this.constraint.value != null && this.constraint.value.equals( var ) ) {
-                    box.setSelectedIndex( j );
+        for (int i = 0; i < vars.size(); i++) {
+            String var = (String) vars.get(i);
+            FactPattern f = model.getBoundFact(var);
+            String fv = model.getFieldConstraint(var);
+            if ((f != null && f.factType.equals(this.fieldType)) || (fv != null && fv.equals(this.fieldType))) {
+                box.addItem(var);
+                if (this.constraint.value != null && this.constraint.value.equals(var)) {
+                    box.setSelectedIndex(j);
                 }
                 j++;
             } else {
                 // for collection, present the list of possible bound variable
-                String factCollectionType = sce.getParametricFieldType( pattern.factType,
-                                                                        this.fieldName );
-                if ( (f != null && factCollectionType != null && f.factType.equals( factCollectionType )) || (factCollectionType != null && factCollectionType.equals( fv )) ) {
-                    box.addItem( var );
-                    if ( this.constraint.value != null && this.constraint.value.equals( var ) ) {
-                        box.setSelectedIndex( j );
+                String factCollectionType = sce.getParametricFieldType(pattern.factType,
+                        this.fieldName);
+                if ((f != null && factCollectionType != null && f.factType.equals(factCollectionType)) || (factCollectionType != null && factCollectionType.equals(fv))) {
+                    box.addItem(var);
+                    if (this.constraint.value != null && this.constraint.value.equals(var)) {
+                        box.setSelectedIndex(j);
                     }
                     j++;
                 }
             }
         }
 
-        box.addChangeListener( new ChangeListener() {
+        box.addChangeListener(new ChangeListener() {
+
             public void onChange(Widget w) {
-                constraint.value = box.getItemText( box.getSelectedIndex() );
+                constraint.value = box.getItemText(box.getSelectedIndex());
             }
-        } );
+        });
 
         return box;
     }
@@ -205,24 +216,24 @@
      * An editor for the retval "formula" (expression).
      */
     private Widget returnValueEditor() {
-        TextBox box = new BoundTextBox( constraint );
+        TextBox box = new BoundTextBox(constraint);
         String msg = constants.FormulaEvaluateToAValue();
-        Image img = new Image( "images/function_assets.gif" ); //NON-NLS
-        img.setTitle( msg );
-        box.setTitle( msg );
-        Widget ed = widgets( img,
-                             box );
+        Image img = new Image("images/function_assets.gif"); //NON-NLS
+        img.setTitle(msg);
+        box.setTitle(msg);
+        Widget ed = widgets(img,
+                box);
         return ed;
     }
 
     private Widget expressionEditor() {
-        if (!(this.constraint instanceof SingleFieldConstraint)){
-            throw new IllegalArgumentException("Expected SingleFieldConstraint, but "+constraint.getClass().getName()+" found.");
+        if (!(this.constraint instanceof SingleFieldConstraint)) {
+            throw new IllegalArgumentException("Expected SingleFieldConstraint, but " + constraint.getClass().getName() + " found.");
         }
-        ExpressionBuilder builder = new ExpressionBuilder(this.modeller, ((SingleFieldConstraint)this.constraint).getExpression());
+        ExpressionBuilder builder = new ExpressionBuilder(this.modeller, ((SingleFieldConstraint) this.constraint).getExpression());
         String msg = constants.ExpressionEditor();
-        Widget ed = widgets( new HTML("&nbsp;"),
-                             builder );
+        Widget ed = widgets(new HTML("&nbsp;"),
+                builder);
         return ed;
     }
 
@@ -230,88 +241,91 @@
      * Show a list of possibilities for the value type.
      */
     private void showTypeChoice(Widget w,
-                                final ISingleFieldConstraint con) {
-        final FormStylePopup form = new FormStylePopup( "images/newex_wiz.gif",
-                                                        constants.FieldValue() );
+            final ISingleFieldConstraint con) {
+        final FormStylePopup form = new FormStylePopup("images/newex_wiz.gif",
+                constants.FieldValue());
 
-        Button lit = new Button( constants.LiteralValue() );
-        lit.addClickListener( new ClickListener() {
+        Button lit = new Button(constants.LiteralValue());
+        lit.addClickListener(new ClickListener() {
+
             public void onClick(Widget w) {
                 con.constraintValueType = SingleFieldConstraint.TYPE_LITERAL;
-                doTypeChosen( form );
+                doTypeChosen(form);
             }
+        });
+        form.addAttribute(constants.LiteralValue() + ":",
+                widgets(lit,
+                new InfoPopup(constants.LiteralValue(),
+                constants.LiteralValTip())));
 
-        } );
-        form.addAttribute( constants.LiteralValue() + ":",
-                           widgets( lit,
-                                    new InfoPopup( constants.LiteralValue(),
-                                                   constants.LiteralValTip() ) ) );
+        form.addRow(new HTML("<hr/>"));
+        form.addRow(new SmallLabel(constants.AdvancedOptions()));
 
-        form.addRow( new HTML( "<hr/>" ) );
-        form.addRow( new SmallLabel( constants.AdvancedOptions() ) );
-
         //only want to show variables if we have some !
-        if ( this.model.getBoundVariablesInScope( this.constraint ).size() > 0 || SuggestionCompletionEngine.TYPE_COLLECTION.equals( this.fieldType ) ) {
+        if (this.model.getBoundVariablesInScope(this.constraint).size() > 0 || SuggestionCompletionEngine.TYPE_COLLECTION.equals(this.fieldType)) {
             List vars = this.model.getBoundFacts();
             boolean foundABouncVariableThatMatches = false;
-            for ( int i = 0; i < vars.size(); i++ ) {
-                String var = (String) vars.get( i );
-                FactPattern f = model.getBoundFact( var );
-                String fieldConstraint = model.getFieldConstraint( var );
+            for (int i = 0; i < vars.size(); i++) {
+                String var = (String) vars.get(i);
+                FactPattern f = model.getBoundFact(var);
+                String fieldConstraint = model.getFieldConstraint(var);
 
-                if ( (f != null && f.factType.equals( this.fieldType )) || this.fieldType.equals( fieldConstraint ) ) {
+                if ((f != null && f.factType.equals(this.fieldType)) || this.fieldType.equals(fieldConstraint)) {
                     foundABouncVariableThatMatches = true;
                     break;
                 } else {
                     // for collection, present the list of possible bound variable
-                    String factCollectionType = sce.getParametricFieldType( pattern.factType,
-                                                                            this.fieldName );
-                    if ( (f != null && factCollectionType != null && f.factType.equals( factCollectionType )) || (factCollectionType != null && factCollectionType.equals( fieldConstraint )) ) {
+                    String factCollectionType = sce.getParametricFieldType(pattern.factType,
+                            this.fieldName);
+                    if ((f != null && factCollectionType != null && f.factType.equals(factCollectionType)) || (factCollectionType != null && factCollectionType.equals(fieldConstraint))) {
                         foundABouncVariableThatMatches = true;
                         break;
                     }
                 }
             }
-            if ( foundABouncVariableThatMatches == true ) {
-                Button variable = new Button( constants.BoundVariable() );
-                variable.addClickListener( new ClickListener() {
+            if (foundABouncVariableThatMatches == true) {
+                Button variable = new Button(constants.BoundVariable());
+                variable.addClickListener(new ClickListener() {
+
                     public void onClick(Widget w) {
                         con.constraintValueType = SingleFieldConstraint.TYPE_VARIABLE;
-                        doTypeChosen( form );
+                        doTypeChosen(form);
                     }
-                } );
-                form.addAttribute( constants.AVariable(),
-                                   widgets( variable,
-                                            new InfoPopup( constants.ABoundVariable(),
-                                                           constants.BoundVariableTip() ) ) );
+                });
+                form.addAttribute(constants.AVariable(),
+                        widgets(variable,
+                        new InfoPopup(constants.ABoundVariable(),
+                        constants.BoundVariableTip())));
             }
         }
 
-        Button formula = new Button( constants.NewFormula() );
-        formula.addClickListener( new ClickListener() {
+        Button formula = new Button(constants.NewFormula());
+        formula.addClickListener(new ClickListener() {
+
             public void onClick(Widget w) {
                 con.constraintValueType = SingleFieldConstraint.TYPE_RET_VALUE;
-                doTypeChosen( form );
+                doTypeChosen(form);
             }
-        } );
+        });
 
-        form.addAttribute( constants.AFormula() + ":",
-                           widgets( formula,
-                                    new InfoPopup( constants.AFormula(),
-                                                   constants.FormulaExpressionTip() ) ) );
+        form.addAttribute(constants.AFormula() + ":",
+                widgets(formula,
+                new InfoPopup(constants.AFormula(),
+                constants.FormulaExpressionTip())));
 
-        Button expression = new Button( constants.ExpressionEditor() );
-        expression.addClickListener( new ClickListener() {
+        Button expression = new Button(constants.ExpressionEditor());
+        expression.addClickListener(new ClickListener() {
+
             public void onClick(Widget w) {
                 con.constraintValueType = SingleFieldConstraint.TYPE_EXPR_BUILDER;
-                doTypeChosen( form );
+                doTypeChosen(form);
             }
-        } );
+        });
 
-        form.addAttribute( constants.ExpressionEditor() + ":",
-                           widgets( expression,
-                                    new InfoPopup(  constants.ExpressionEditor(),
-                                                    constants.ExpressionEditor() ) ) );
+        form.addAttribute(constants.ExpressionEditor() + ":",
+                widgets(expression,
+                new InfoPopup(constants.ExpressionEditor(),
+                constants.ExpressionEditor())));
 
 
         form.show();
@@ -323,16 +337,15 @@
     }
 
     private Panel widgets(Widget left,
-                          Widget right) {
+            Widget right) {
         HorizontalPanel panel = new HorizontalPanel();
-        panel.add( left );
-        panel.add( right );
-        panel.setWidth( "100%" );
+        panel.add(left);
+        panel.add(right);
+        panel.setWidth("100%");
         return panel;
     }
 
     public boolean isDirty() {
         return super.isDirty();
     }
-
 }

Modified: labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ExpressionBuilder.java
===================================================================
--- labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ExpressionBuilder.java	2010-03-15 16:00:28 UTC (rev 32096)
+++ labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ExpressionBuilder.java	2010-03-15 19:11:19 UTC (rev 32097)
@@ -23,305 +23,321 @@
 
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.user.client.ui.ChangeListener;
-import com.google.gwt.user.client.ui.FlowPanel;
+import com.google.gwt.user.client.ui.HorizontalPanel;
 import com.google.gwt.user.client.ui.ListBox;
 import com.google.gwt.user.client.ui.Widget;
 import com.gwtext.client.widgets.form.Label;
+import org.drools.guvnor.client.common.SmallLabel;
 
 public class ExpressionBuilder extends DirtyableComposite {
 
-	private static final String DELETE_VALUE = "_delete_";
-	private static final String FIElD_VALUE_PREFIX = "fl";
-	private static final String VARIABLE_VALUE_PREFIX = "va";
-	private static final String GLOBAL_COLLECTION_VALUE_PREFIX = "gc";
-	private static final String GLOBAL_VARIABLE_VALUE_PREFIX = "gv";
-	private static final String METHOD_VALUE_PREFIX = "mt";
+    private static final String DELETE_VALUE = "_delete_";
+    private static final String FIElD_VALUE_PREFIX = "fl";
+    private static final String VARIABLE_VALUE_PREFIX = "va";
+    private static final String GLOBAL_COLLECTION_VALUE_PREFIX = "gc";
+    private static final String GLOBAL_VARIABLE_VALUE_PREFIX = "gv";
+    private static final String METHOD_VALUE_PREFIX = "mt";
+    private Constants constants = ((Constants) GWT.create(Constants.class));
+    //private FlowPanel panel = new FlowPanel();
+    private HorizontalPanel panel = new HorizontalPanel();
+    private RuleModeller modeller;
+    private ExpressionFormLine expression;
+    private boolean readOnly;
 
-	private Constants constants = ((Constants) GWT.create(Constants.class));
-	private FlowPanel panel = new FlowPanel();
+    public ExpressionBuilder(RuleModeller modeller,
+            ExpressionFormLine expression) {
+        this(modeller, expression, false);
+    }
 
-	private RuleModeller modeller;
-	private ExpressionFormLine expression;
+    public ExpressionBuilder(RuleModeller modeller,
+            ExpressionFormLine expression, boolean readOnly) {
+        super();
+        this.readOnly = readOnly;
+        this.expression = expression;
+        this.modeller = modeller;
+        if (expression == null || expression.getText().length() == 0) {
+            if (this.readOnly) {
+                panel.add(new SmallLabel("<b>-</b"));
+            } else {
+                panel.add(createStartPointWidget());
+            }
+        } else {
+            if (this.readOnly) {
+                panel.add(new SmallLabel("<b>" + expression.getText() + "</b"));
+            } else {
+                panel.add(new SmallLabel("<b>" + expression.getText() + ".</b"));
+                panel.add(getWidgetForCurrentType());
+            }
+        }
+        initWidget(panel);
+    }
 
-	public ExpressionBuilder(RuleModeller modeller,
-			ExpressionFormLine expression) {
-		super();
-		this.expression = expression;
-		this.modeller = modeller;
-		if (expression == null || expression.getText().length() == 0) {
-			panel.add(createStartPointWidget());
-		} else {
-			panel.add(new Label(expression.getText()));
-			panel.add(getWidgetForCurrentType());
-		}
-		initWidget(panel);
-	}
+    private Widget createStartPointWidget() {
+        ListBox startPoint = new ListBox();
+        panel.add(startPoint);
 
-	private Widget createStartPointWidget() {
-		ListBox startPoint = new ListBox();
-		panel.add(startPoint);
+        startPoint.addItem(constants.ChooseDotDotDot(), "");
 
-		startPoint.addItem(constants.ChooseDotDotDot(), "");
-
-		//TODO {baunax} uncomment when global collections is implemented.
+        //TODO {baunax} uncomment when global collections is implemented.
 //		for (String gc : getCompletionEngine().getGlobalCollections()) {
 //			startPoint.addItem(gc, GLOBAL_COLLECTION_VALUE_PREFIX + "." + gc);
 //		}
 
-		for (String gv : getCompletionEngine().getGlobalVariables()) {
-			startPoint.addItem(gv, GLOBAL_VARIABLE_VALUE_PREFIX + "." + gv);
-		}
+        for (String gv : getCompletionEngine().getGlobalVariables()) {
+            startPoint.addItem(gv, GLOBAL_VARIABLE_VALUE_PREFIX + "." + gv);
+        }
 
-		for (String v : getRuleModel().getBoundFacts()) {
-			startPoint.addItem(v, VARIABLE_VALUE_PREFIX + "." + v);
-		}
+        for (String v : getRuleModel().getBoundFacts()) {
+            startPoint.addItem(v, VARIABLE_VALUE_PREFIX + "." + v);
+        }
 
-		startPoint.setVisibleItemCount(1);
-		startPoint.addChangeListener(new ChangeListener() {
-			public void onChange(Widget sender) {
-				ListBox lb = (ListBox) sender;
-				int index = lb.getSelectedIndex();
-				if (index > 0) {
-					ExpressionBuilder.this.makeDirty();
-					startPointChange(lb.getValue(index));
-				}
-			}
-		});
-		return startPoint;
-	}
+        startPoint.setVisibleItemCount(1);
+        startPoint.addChangeListener(new ChangeListener() {
 
-	private void startPointChange(String value) {
-		panel.clear();
-		Widget w;
-		int dotPos = value.indexOf('.');
-		String prefix = value.substring(0, dotPos);
-		String attrib = value.substring(dotPos + 1);
-		if (prefix.equals(VARIABLE_VALUE_PREFIX)) {
-			FactPattern fact = getRuleModel().getBoundFact(attrib);
-			ExpressionVariable variable = new ExpressionVariable(fact);
-			expression.appendPart(variable);
-			
-		} 
-		else if (prefix.equals(GLOBAL_VARIABLE_VALUE_PREFIX)) {
-			String globalVarType = getCompletionEngine().getGlobalVariable(attrib);
-			ExpressionGlobalVariable variable = new ExpressionGlobalVariable(attrib, globalVarType, globalVarType);
-			expression.appendPart(variable);
-		}
-		w = getWidgetForCurrentType();
+            public void onChange(Widget sender) {
+                ListBox lb = (ListBox) sender;
+                int index = lb.getSelectedIndex();
+                if (index > 0) {
+                    ExpressionBuilder.this.makeDirty();
+                    startPointChange(lb.getValue(index));
+                }
+            }
+        });
+        return startPoint;
+    }
 
-		if (!expression.isEmpty()) {
-			panel.add(new Label(expression.getText()));
-		}
-		if (w != null) {
-			panel.add(w);
-		}
-		// panel.add(getWidgetFor(startPoint.getValue(index)));
-		// ExpressionBuilder.this.expression.appendText(v);
-	}
+    private void startPointChange(String value) {
+        panel.clear();
+        Widget w;
+        int dotPos = value.indexOf('.');
+        String prefix = value.substring(0, dotPos);
+        String attrib = value.substring(dotPos + 1);
+        if (prefix.equals(VARIABLE_VALUE_PREFIX)) {
+            FactPattern fact = getRuleModel().getBoundFact(attrib);
+            ExpressionVariable variable = new ExpressionVariable(fact);
+            expression.appendPart(variable);
 
-	private Widget getWidgetForCurrentType() {
-		if (expression.isEmpty()) {
-			return createStartPointWidget();
-		}
-		String factName = getCompletionEngine().getFactNameFromType(
-				getCurrentClassType());
-		if (factName != null) {
-			ListBox lb = new ListBox();
-			lb.setVisibleItemCount(1);
-			lb.addItem(constants.ChooseDotDotDot(), "");
-			lb.addItem("<==" + constants.DeleteItem(), DELETE_VALUE);
-			for (Map.Entry<String, String> entry : getCompletionsForCurrentType()
-					.entrySet()) {
-				lb.addItem(entry.getKey(), entry.getValue());
-			}
+        } else if (prefix.equals(GLOBAL_VARIABLE_VALUE_PREFIX)) {
+            String globalVarType = getCompletionEngine().getGlobalVariable(attrib);
+            ExpressionGlobalVariable variable = new ExpressionGlobalVariable(attrib, globalVarType, globalVarType);
+            expression.appendPart(variable);
+        }
+        w = getWidgetForCurrentType();
 
-			lb.addChangeListener(new ChangeListener() {
-				public void onChange(Widget sender) {
-					ListBox box = (ListBox) sender;
-					panel.remove(box);
-					if (box.getSelectedIndex() > 0) {
-						onChangeSelection(box.getValue(box.getSelectedIndex()));
-					}
-				}
-			});
-			return lb;
-		} else {//if (SuggestionCompletionEngine.TYPE_COLLECTION.equals(getCurrentGenericType())) {
-			ListBox lb = new ListBox();
-			lb.setVisibleItemCount(1);
-			lb.addItem(constants.ChooseDotDotDot(), "");
-			lb.addItem("<==" + constants.DeleteItem(), DELETE_VALUE);
-			for (Map.Entry<String, String> entry : getCompletionsForCurrentType().entrySet()) {
-				lb.addItem(entry.getKey(), entry.getValue());
-			}
-			lb.addChangeListener(new ChangeListener() {
-				public void onChange(Widget sender) {
-					ListBox box = (ListBox) sender;
-					panel.remove(box);
-					if (box.getSelectedIndex() > 0) {
-						onChangeSelection(box.getValue(box.getSelectedIndex()));
-					}
-				}
-			});
-			return lb;
-		}
+        if (!expression.isEmpty()) {
+            panel.add(new Label(expression.getText()));
+        }
+        if (w != null) {
+            panel.add(w);
+        }
+
+        // panel.add(getWidgetFor(startPoint.getValue(index)));
+        // ExpressionBuilder.this.expression.appendText(v);
+    }
+
+    private Widget getWidgetForCurrentType() {
+        if (expression.isEmpty()) {
+            return createStartPointWidget();
+        }
+        String factName = getCompletionEngine().getFactNameFromType(
+                getCurrentClassType());
+        if (factName != null) {
+            ListBox lb = new ListBox();
+            lb.setVisibleItemCount(1);
+            lb.addItem(constants.ChooseDotDotDot(), "");
+            lb.addItem("<==" + constants.DeleteItem(), DELETE_VALUE);
+            for (Map.Entry<String, String> entry : getCompletionsForCurrentType().entrySet()) {
+                lb.addItem(entry.getKey(), entry.getValue());
+            }
+
+            lb.addChangeListener(new ChangeListener() {
+
+                public void onChange(Widget sender) {
+                    ListBox box = (ListBox) sender;
+                    panel.remove(box);
+                    if (box.getSelectedIndex() > 0) {
+                        onChangeSelection(box.getValue(box.getSelectedIndex()));
+                    }
+                }
+            });
+            return lb;
+        } else {//if (SuggestionCompletionEngine.TYPE_COLLECTION.equals(getCurrentGenericType())) {
+            ListBox lb = new ListBox();
+            lb.setVisibleItemCount(1);
+            lb.addItem(constants.ChooseDotDotDot(), "");
+            lb.addItem("<==" + constants.DeleteItem(), DELETE_VALUE);
+            for (Map.Entry<String, String> entry : getCompletionsForCurrentType().entrySet()) {
+                lb.addItem(entry.getKey(), entry.getValue());
+            }
+            lb.addChangeListener(new ChangeListener() {
+
+                public void onChange(Widget sender) {
+                    ListBox box = (ListBox) sender;
+                    panel.remove(box);
+                    if (box.getSelectedIndex() > 0) {
+                        onChangeSelection(box.getValue(box.getSelectedIndex()));
+                    }
+                }
+            });
+            return lb;
+        }
 //		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())) {
-			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 ExpressionText(".size() == 0", "", SuggestionCompletionEngine.TYPE_NUMERIC));
-			}
-		} else {
-			int dotPos = value.indexOf('.');
-			String prefix = value.substring(0, dotPos);
-			String attrib = value.substring(dotPos + 1);
+    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"));
 
-			prevFactName = getCompletionEngine().getFactNameFromType(
-					getCurrentClassType());
+                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())) {
+            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 ExpressionText(".size() == 0", "", SuggestionCompletionEngine.TYPE_NUMERIC));
+            }
+        } else {
+            int dotPos = value.indexOf('.');
+            String prefix = value.substring(0, dotPos);
+            String attrib = value.substring(dotPos + 1);
+
+            prevFactName = getCompletionEngine().getFactNameFromType(
+                    getCurrentClassType());
 //			String genericType = SuggestionCompletionEngine.TYPE_OBJECT;
-			if (FIElD_VALUE_PREFIX.equals(prefix)) {
-				String fieldClassName = getCompletionEngine().getFieldClassName(prevFactName, attrib);
-				String fieldGenericType = getCompletionEngine().getFieldType(prevFactName, attrib);
-				if (SuggestionCompletionEngine.TYPE_COLLECTION.equals(fieldGenericType)) {
-					String fieldParametricType = getCompletionEngine().getParametricFieldType(prevFactName, attrib);
-					expression.appendPart(new ExpressionCollection(attrib, fieldClassName, fieldGenericType, fieldParametricType));
-				} else {
-					expression.appendPart(new ExpressionField(attrib, fieldClassName, fieldGenericType));
-				}
-			} else if (METHOD_VALUE_PREFIX.equals(prefix)) {
-				MethodInfo mi = getCompletionEngine().getMethodinfo(prevFactName, attrib);
-				if (SuggestionCompletionEngine.TYPE_COLLECTION.equals(mi.getGenericType())) {
-					expression.appendPart(new ExpressionCollection(attrib, mi.getReturnClassType(), mi.getGenericType(), mi.getParametricReturnType()));
-				} else {
-					expression.appendPart( new ExpressionMethod(mi.getName(), mi.getReturnClassType(), mi.getGenericType()));
-				}
-			}
-		}
-		Widget w = getWidgetForCurrentType();
+            if (FIElD_VALUE_PREFIX.equals(prefix)) {
+                String fieldClassName = getCompletionEngine().getFieldClassName(prevFactName, attrib);
+                String fieldGenericType = getCompletionEngine().getFieldType(prevFactName, attrib);
+                if (SuggestionCompletionEngine.TYPE_COLLECTION.equals(fieldGenericType)) {
+                    String fieldParametricType = getCompletionEngine().getParametricFieldType(prevFactName, attrib);
+                    expression.appendPart(new ExpressionCollection(attrib, fieldClassName, fieldGenericType, fieldParametricType));
+                } else {
+                    expression.appendPart(new ExpressionField(attrib, fieldClassName, fieldGenericType));
+                }
+            } else if (METHOD_VALUE_PREFIX.equals(prefix)) {
+                MethodInfo mi = getCompletionEngine().getMethodinfo(prevFactName, attrib);
+                if (SuggestionCompletionEngine.TYPE_COLLECTION.equals(mi.getGenericType())) {
+                    expression.appendPart(new ExpressionCollection(attrib, mi.getReturnClassType(), mi.getGenericType(), mi.getParametricReturnType()));
+                } else {
+                    expression.appendPart(new ExpressionMethod(mi.getName(), mi.getReturnClassType(), mi.getGenericType()));
+                }
+            }
+        }
+        Widget w = getWidgetForCurrentType();
 
-		panel.clear();
-		if (!expression.isEmpty()) {
-			panel.add(new Label(expression.getText()));
-		}
-		if (w != null) {
-			panel.add(w);
-		}
-	}
+        panel.clear();
+        if (!expression.isEmpty()) {
+            panel.add(new Label(expression.getText()));
+        }
+        if (w != null) {
+            panel.add(w);
+        }
+    }
 
-	private Map<String, String> getCompletionsForCurrentType() {
-		Map<String, String> completions = new LinkedHashMap<String, String>();
-		
-		if (SuggestionCompletionEngine.TYPE_COLLECTION.equals(getCurrentGenericType())) {
-			completions.put("size()", "size");
-			completions.put("first()","first");
-			completions.put("last()", "last");
-			completions.put("isEmpty()", "isEmpty");
-			return completions;
-		}
-		
-		if (SuggestionCompletionEngine.TYPE_STRING.equals(getCurrentGenericType())) {
-			completions.put("size()", "size");
-			completions.put("isEmpty()", "isEmpty");
-			return completions;
-		}
-		
-		if (SuggestionCompletionEngine.TYPE_BOOLEAN.equals(getCurrentGenericType()) || 
-				SuggestionCompletionEngine.TYPE_NUMERIC.equals(getCurrentGenericType()) ||
-				SuggestionCompletionEngine.TYPE_DATE.equals(getCurrentGenericType()) ||
-				SuggestionCompletionEngine.TYPE_OBJECT.equals(getCurrentGenericType())) {
-			return completions;
-		}
-		
-		String factName = getCompletionEngine().getFactNameFromType(getCurrentClassType());
-		if (factName != null) {
-			//we currently only support 0 param method calls
-			List<String> methodNames = getCompletionEngine()
-					.getMethodFullNames(factName, 0);
+    private Map<String, String> getCompletionsForCurrentType() {
+        Map<String, String> completions = new LinkedHashMap<String, String>();
 
-			for (String field : getCompletionEngine().getFieldCompletions(
-					factName)) {
-				boolean changed = false;
-				for (Iterator<String> i = methodNames.iterator(); i.hasNext();) {
-					String method = i.next();
-					if (method.startsWith(field)) {
-						completions.put(method, METHOD_VALUE_PREFIX + "." + method);
-						i.remove();
-						changed = true;
-					}
-				}
-				if (!changed) {
-					completions.put(field, FIElD_VALUE_PREFIX + "." + field);
-				}
-			}
-		} 
-		//else {We don't know anything about this type, so return empty map}
-		return completions;
-	}
+        if (SuggestionCompletionEngine.TYPE_COLLECTION.equals(getCurrentGenericType())) {
+            completions.put("size()", "size");
+            completions.put("first()", "first");
+            completions.put("last()", "last");
+            completions.put("isEmpty()", "isEmpty");
+            return completions;
+        }
 
-	private String getCurrentPartName() {
-		return expression.getCurrentName();
-	}
+        if (SuggestionCompletionEngine.TYPE_STRING.equals(getCurrentGenericType())) {
+            completions.put("size()", "size");
+            completions.put("isEmpty()", "isEmpty");
+            return completions;
+        }
 
-	private RuleModel getRuleModel() {
-		return modeller.getModel();
-	}
+        if (SuggestionCompletionEngine.TYPE_BOOLEAN.equals(getCurrentGenericType())
+                || SuggestionCompletionEngine.TYPE_NUMERIC.equals(getCurrentGenericType())
+                || SuggestionCompletionEngine.TYPE_DATE.equals(getCurrentGenericType())
+                || SuggestionCompletionEngine.TYPE_OBJECT.equals(getCurrentGenericType())) {
+            return completions;
+        }
 
-	private SuggestionCompletionEngine getCompletionEngine() {
-		return modeller.getSuggestionCompletions();
-	}
+        String factName = getCompletionEngine().getFactNameFromType(getCurrentClassType());
+        if (factName != null) {
+            //we currently only support 0 param method calls
+            List<String> methodNames = getCompletionEngine().getMethodFullNames(factName, 0);
 
-	private String getCurrentClassType() {
-		return expression.getClassType();
-	}
-	
-	private String getCurrentGenericType() {
-		return expression.getGenericType();
-	}
-	
-	private String getCurrentParametricType() {
-		return expression.getParametricType();
-	}
-	
-	private String getPreviousClassType() {
-		return expression.getPreviousType();
-	}
-	
-	private ExpressionPart getRootExpression() {
-		return expression.getRootExpression();
-	}
+            for (String field : getCompletionEngine().getFieldCompletions(
+                    factName)) {
+                boolean changed = false;
+                for (Iterator<String> i = methodNames.iterator(); i.hasNext();) {
+                    String method = i.next();
+                    if (method.startsWith(field)) {
+                        completions.put(method, METHOD_VALUE_PREFIX + "." + method);
+                        i.remove();
+                        changed = true;
+                    }
+                }
+                if (!changed) {
+                    completions.put(field, FIElD_VALUE_PREFIX + "." + field);
+                }
+            }
+        }
+        //else {We don't know anything about this type, so return empty map}
+        return completions;
+    }
+
+    private String getCurrentPartName() {
+        return expression.getCurrentName();
+    }
+
+    private RuleModel getRuleModel() {
+        return modeller.getModel();
+    }
+
+    private SuggestionCompletionEngine getCompletionEngine() {
+        return modeller.getSuggestionCompletions();
+    }
+
+    private String getCurrentClassType() {
+        return expression.getClassType();
+    }
+
+    private String getCurrentGenericType() {
+        return expression.getGenericType();
+    }
+
+    private String getCurrentParametricType() {
+        return expression.getParametricType();
+    }
+
+    private String getPreviousClassType() {
+        return expression.getPreviousType();
+    }
+
+    private ExpressionPart getRootExpression() {
+        return expression.getRootExpression();
+    }
 }

Modified: labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FactPatternWidget.java
===================================================================
--- labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FactPatternWidget.java	2010-03-15 16:00:28 UTC (rev 32096)
+++ labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FactPatternWidget.java	2010-03-15 19:11:19 UTC (rev 32097)
@@ -15,8 +15,6 @@
  * limitations under the License.
  */
 
-
-
 import java.util.ArrayList;
 import java.util.List;
 
@@ -50,24 +48,45 @@
  */
 public class FactPatternWidget extends DirtyableComposite {
 
-    private FactPattern                pattern;
+    private FactPattern pattern;
     private SuggestionCompletionEngine completions;
-    private RuleModeller               modeller;
-    private DirtyableFlexTable         layout = new DirtyableFlexTable();
-    private Connectives                connectives;
-    private PopupCreator               popupCreator;
-    private boolean                    bindable;
+    private RuleModeller modeller;
+    private DirtyableFlexTable layout = new DirtyableFlexTable();
+    private Connectives connectives;
+    private PopupCreator popupCreator;
+    private boolean bindable;
     private Constants constants = ((Constants) GWT.create(Constants.class));
-
     private String customLabel;
+    private boolean readOnly;
 
     public FactPatternWidget(RuleModeller mod, IPattern p,
             boolean canBind) {
-        this(mod, p, null, 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
+     * @param p
+     * @param customLabel
+     * @param canBind
+     * @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.pattern = (FactPattern) p;
         this.completions = mod.getSuggestionCompletions();
         this.modeller = mod;
@@ -86,19 +105,33 @@
 
         this.customLabel = customLabel;
 
-        layout.setWidget( 0, 0, getPatternLabel() );
+        //if readOnly == null, the RO attribute is calculated.
+        if (readOnly == null){
+            this.readOnly = !completions.containsFactType(this.pattern.factType);
+        }else{
+            this.readOnly = readOnly;
+        }
+
+        layout.setWidget(0, 0, getPatternLabel());
         FlexCellFormatter formatter = layout.getFlexCellFormatter();
-        formatter.setAlignment( 0, 0, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_BOTTOM );
-        formatter.setStyleName( 0, 0, "modeller-fact-TypeHeader" );
+        formatter.setAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_BOTTOM);
+        formatter.setStyleName(0, 0, "modeller-fact-TypeHeader");
 
         ArrayList sortedConst = sortConstraints(pattern.getFieldConstraints());
         pattern.setFieldConstraints(sortedConst);
         drawConstraints(sortedConst);
 
+        
 
-        if ( bindable ) layout.setStyleName( "modeller-fact-pattern-Widget" );
-        initWidget( layout );
+        if (this.readOnly){
+            layout.addStyleName("editor-disabled-widget");
+        }
 
+        if (bindable) {
+            layout.addStyleName("modeller-fact-pattern-Widget");
+        }
+        initWidget(layout);
+
     }
 
     /**
@@ -112,7 +145,7 @@
      * */
     private void drawConstraints(ArrayList sortedConst) {
         final DirtyableFlexTable table = new DirtyableFlexTable();
-        layout.setWidget( 1, 0, table );
+        layout.setWidget(1, 0, table);
         List parents = new ArrayList();
 
         for (int i = 0; i < sortedConst.size(); i++) {
@@ -126,7 +159,7 @@
                     FieldConstraint storedParent = (FieldConstraint) parents.get(j);
                     if (storedParent != null && storedParent.equals(parent)) {
                         tabs = j + 1;
-                        for(int k = j + 1; k < parents.size(); k++) {
+                        for (int k = j + 1; k < parents.size(); k++) {
                             parents.remove(j + 1);
                         }
                         parents.add(current);
@@ -143,19 +176,20 @@
 
             //now the clear icon
             final int currentRow = i;
-            Image clear = new ImageButton( "images/delete_faded.gif" );//NON-NLS
+            Image clear = new ImageButton("images/delete_faded.gif");//NON-NLS
             clear.setTitle(constants.RemoveThisWholeRestriction());
-            clear.addClickListener( new ClickListener() {
+            clear.addClickListener(new ClickListener() {
+
                 public void onClick(Widget w) {
                     if (Window.confirm(constants.RemoveThisItem())) {
-                        pattern.removeConstraint( currentRow );
+                        pattern.removeConstraint(currentRow);
                         modeller.refreshWidget();
                     }
                 }
-            } );
+            });
 
-            if (!this.modeller.lockLHS()) {
-                table.setWidget( currentRow, 5, clear );
+            if (!(this.modeller.lockLHS() || this.readOnly)) {
+                table.setWidget(currentRow, 5, clear);
             }
 
         }
@@ -176,7 +210,7 @@
                 int index = sortedConst.indexOf(single.parent);
                 if (single.parent == null) {
                     sortedConst.add(single);
-                } else if (index >= 0){
+                } else if (index >= 0) {
                     sortedConst.add(index + 1, single);
                 } else {
                     insertSingleFieldConstraint(single, sortedConst);
@@ -207,10 +241,10 @@
     private void renderFieldConstraint(final DirtyableFlexTable inner, int row, FieldConstraint constraint, boolean showBinding, int tabs) {
         //if nesting, or predicate, then it will need to span 5 cols.
         if (constraint instanceof SingleFieldConstraint) {
-            renderSingleFieldConstraint( modeller, inner, row, (SingleFieldConstraint) constraint, showBinding, tabs );
+            renderSingleFieldConstraint(modeller, inner, row, (SingleFieldConstraint) constraint, showBinding, tabs);
         } else if (constraint instanceof CompositeFieldConstraint) {
-            inner.setWidget( row, 1, compositeFieldConstraintEditor((CompositeFieldConstraint) constraint) );
-            inner.getFlexCellFormatter().setColSpan( row, 1, 5 );
+            inner.setWidget(row, 1, compositeFieldConstraintEditor((CompositeFieldConstraint) constraint));
+            inner.getFlexCellFormatter().setColSpan(row, 1, 5);
             inner.setWidget(row, 0, new HTML("&nbsp;&nbsp;&nbsp;&nbsp;")); //NON-NLS
         }
     }
@@ -224,10 +258,10 @@
 
 
         ClickListener click = new ClickListener() {
+
             public void onClick(Widget w) {
-                popupCreator.showPatternPopupForComposite( w, constraint );
+                popupCreator.showPatternPopupForComposite(w, constraint);
             }
-
         };
 
         if (constraint.compositeJunctionType.equals(CompositeFieldConstraint.COMPOSITE_TYPE_AND)) {
@@ -236,30 +270,33 @@
             desc = constants.AnyOf() + ":";
         }
 
-        t.setWidget(0, 0, new ClickableLabel(desc, click, !modeller.lockLHS()));
+        t.setWidget(0, 0, new ClickableLabel(desc, click, !(modeller.lockLHS() || this.readOnly)));
         t.getFlexCellFormatter().setColSpan(0, 0, 2);
         //t.getFlexCellFormatter().setWidth(0, 0, "15%");
 
         FieldConstraint[] nested = constraint.constraints;
         DirtyableFlexTable inner = new DirtyableFlexTable();
-        inner.setStyleName( "modeller-inner-nested-Constraints" ); //NON-NLS
+        inner.setStyleName("modeller-inner-nested-Constraints"); //NON-NLS
         if (nested != null) {
-            for ( int i = 0; i < nested.length; i++ ) {
-                this.renderFieldConstraint( inner, i, nested[i], false, 0 );
+            for (int i = 0; i < nested.length; i++) {
+                this.renderFieldConstraint(inner, i, nested[i], false, 0);
                 //add in remove icon here...
                 final int currentRow = i;
-                Image clear = new ImageButton( "images/delete_faded.gif" ); //NON-NLS
+                Image clear = new ImageButton("images/delete_faded.gif"); //NON-NLS
                 clear.setTitle(constants.RemoveThisNestedRestriction());
 
-                clear.addClickListener( new ClickListener() {
+                clear.addClickListener(new ClickListener() {
+
                     public void onClick(Widget w) {
                         if (Window.confirm(constants.RemoveThisItemFromNestedConstraint())) {
-                            constraint.removeConstraint( currentRow );
+                            constraint.removeConstraint(currentRow);
                             modeller.refreshWidget();
                         }
                     }
-                } );
-                if (!modeller.lockLHS()) inner.setWidget( i, 5, clear );
+                });
+                if (!(modeller.lockLHS() || this.readOnly)) {
+                    inner.setWidget(i, 5, clear);
+                }
             }
         }
 
@@ -268,8 +305,6 @@
         return t;
     }
 
-
-
     /**
      * Applies a single field constraint to the given table, and start row.
      */
@@ -283,25 +318,28 @@
         inner.setWidget(row, 0, new HTML("&nbsp;&nbsp;&nbsp;&nbsp;"));
         //inner.getFlexCellFormatter().setWidth(row, 0, "15%");
         //DOCNHERON
-        if ( constraint.constraintValueType != SingleFieldConstraint.TYPE_PREDICATE ) {
+        if (constraint.constraintValueType != SingleFieldConstraint.TYPE_PREDICATE) {
 
-            inner.setWidget( row, 0 + col, fieldLabel(constraint, showBinding, tabs * 20));
-            inner.setWidget( row, 1+ col, operatorDropDown( constraint ) );
-            inner.setWidget( row, 2+ col, valueEditor( constraint, constraint.fieldType ) );
-            inner.setWidget( row, 3+ col, connectives.connectives( constraint, constraint.fieldType ) );
-            Image addConnective = new ImageButton( "images/add_connective.gif" ); //NON-NLS
+            inner.setWidget(row, 0 + col, fieldLabel(constraint, showBinding, tabs * 20));
+            inner.setWidget(row, 1 + col, operatorDropDown(constraint));
+            inner.setWidget(row, 2 + col, valueEditor(constraint, constraint.fieldType));
+            inner.setWidget(row, 3 + col, connectives.connectives(constraint, constraint.fieldType));
+            Image addConnective = new ImageButton("images/add_connective.gif"); //NON-NLS
             addConnective.setTitle(constants.AddMoreOptionsToThisFieldsValues());
-            addConnective.addClickListener( new ClickListener() {
+            addConnective.addClickListener(new ClickListener() {
+
                 public void onClick(Widget w) {
                     constraint.addNewConnective();
                     modeller.refreshWidget();
                 }
-            } );
+            });
 
-            if (!modeller.lockLHS()) inner.setWidget( row, 4+ col, addConnective );
+            if (!(modeller.lockLHS() || this.readOnly)) {
+                inner.setWidget(row, 4 + col, addConnective);
+            }
         } else if (constraint.constraintValueType == SingleFieldConstraint.TYPE_PREDICATE) {
-            inner.setWidget( row, 0+ col, predicateEditor(constraint) );
-            inner.getFlexCellFormatter().setColSpan( row, 0, 5 );
+            inner.setWidget(row, 0 + col, predicateEditor(constraint));
+            inner.getFlexCellFormatter().setColSpan(row, 0, 5);
         }
     }
 
@@ -311,54 +349,64 @@
     private Widget predicateEditor(final SingleFieldConstraint c) {
 
         HorizontalPanel pred = new HorizontalPanel();
-        pred.setWidth( "100%" );
+        pred.setWidth("100%");
         Image img = new Image("images/function_assets.gif"); //NON-NLS
         img.setTitle(constants.FormulaBooleanTip());
 
-        pred.add( img );
+        pred.add(img);
         if (c.value == null) {
-        	c.value = "";
+            c.value = "";
         }
+
         final TextBox box = new TextBox();
-        box.setText( c.value );
-        box.addChangeListener( new ChangeListener() {
-            public void onChange(Widget w) {
-                c.value = box.getText();
-                modeller.makeDirty();
-            }
-        });
+        box.setText(c.value);
 
-        box.setWidth( "100%" );
-        pred.add( box );
+        if (!(this.modeller.lockLHS() || this.readOnly)) {
+            box.addChangeListener(new ChangeListener() {
+
+                public void onChange(Widget w) {
+                    c.value = box.getText();
+                    modeller.makeDirty();
+                }
+            });
+            box.setWidth("100%");
+            pred.add(box);
+        } else {
+            pred.add(new SmallLabel(c.value));
+        }
+
+
+
+
         return pred;
     }
 
-
     /**
      * This returns the pattern label.
      */
     private Widget getPatternLabel() {
         ClickListener click = new ClickListener() {
+
             public void onClick(Widget w) {
-                popupCreator.showPatternPopup( w, pattern.factType, null );
+                popupCreator.showPatternPopup(w, pattern.factType, null);
             }
         };
 
-        String patternName = (pattern.boundName != null) ? pattern.factType  + " <b>[" + pattern.boundName + "]</b>" : pattern.factType;
+        String patternName = (pattern.boundName != null) ? pattern.factType + " <b>[" + pattern.boundName + "]</b>" : pattern.factType;
 
         String desc = this.getCustomLabel();
-        if (desc == null){
+        if (desc == null) {
             if (pattern.constraintList != null && pattern.constraintList.constraints.length > 0) {
                 desc = Format.format(constants.ThereIsAAn0With(), patternName);
             } else {
                 desc = Format.format(constants.ThereIsAAn0(), patternName);
             }
             desc = anA(desc, patternName);
-        }else{
+        } else {
             desc = Format.format(desc, patternName);
         }
 
-        return  new ClickableLabel( desc , click, !modeller.lockLHS()) ;
+        return new ClickableLabel(desc, click, !(modeller.lockLHS() || this.readOnly));
     }
 
     /** Change to an/a depending on context - only for english */
@@ -377,31 +425,40 @@
 
     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.modeller,  c.fieldType);
+        return new ConstraintValueEditor(pattern, c.fieldName, c, this.modeller, c.fieldType,this.readOnly);
     }
 
     private Widget operatorDropDown(final SingleFieldConstraint c) {
-        String[] ops = completions.getOperatorCompletions( pattern.factType, c.fieldName );
-        final ListBox box = new ListBox();
-        box.addItem(constants.pleaseChoose(), "" );
-        for ( int i = 0; i < ops.length; i++ ) {
-            String op = ops[i];
-            box.addItem( HumanReadable.getOperatorDisplayName( op ), op );
-            if ( op.equals( c.operator ) ) {
-                box.setSelectedIndex( i + 1 );
+        if (!(this.modeller.lockLHS() || this.readOnly)) {
+            String[] ops = completions.getOperatorCompletions(pattern.factType, c.fieldName);
+            final ListBox box = new ListBox();
+            box.addItem(constants.pleaseChoose(), "");
+            for (int i = 0; i < ops.length; i++) {
+                String op = ops[i];
+                box.addItem(HumanReadable.getOperatorDisplayName(op), op);
+                if (op.equals(c.operator)) {
+                    box.setSelectedIndex(i + 1);
+                }
+
             }
 
+            box.addChangeListener(new ChangeListener() {
+
+                public void onChange(Widget w) {
+                    c.operator = box.getValue(box.getSelectedIndex());
+                    if (c.operator.equals("")) {
+                        c.operator = null;
+                    }
+                    modeller.makeDirty();
+                }
+            });
+
+            return box;
+        } else {
+            SmallLabel sl = new SmallLabel("<b>"+(c.operator==null?constants.pleaseChoose():HumanReadable.getOperatorDisplayName(c.operator))+"</b>");
+            return sl;
         }
 
-        box.addChangeListener( new ChangeListener() {
-            public void onChange(Widget w) {
-                c.operator = box.getValue( box.getSelectedIndex() );
-                if (c.operator.equals("")) c.operator = null;
-                modeller.makeDirty();
-            }
-        } );
-
-        return box;
     }
 
     /**
@@ -411,32 +468,33 @@
      */
     private Widget fieldLabel(final SingleFieldConstraint con, boolean showBinding, int padding) {//, final Command onChange) {
         HorizontalPanel ab = new HorizontalPanel();
-        ab.setStyleName( "modeller-field-Label" );
+        ab.setStyleName("modeller-field-Label");
 
         if (!con.isBound()) {
-            if (bindable && showBinding) {
+            if (bindable && showBinding && !(this.modeller.lockLHS() || this.readOnly)) {
 
-            	ClickListener click = new ClickListener() {
+                ClickListener click = new ClickListener() {
+
                     public void onClick(Widget w) {
-                        String[] fields = completions.getFieldCompletions( con.fieldType );
+                        String[] fields = completions.getFieldCompletions(con.fieldType);
                         popupCreator.showBindFieldPopup(w, con, fields, popupCreator);
                     }
                 };
 
-                Image bind = new ImageButton( "images/edit_tiny.gif", constants.GiveFieldVarName()); //NON-NLS
+                Image bind = new ImageButton("images/edit_tiny.gif", constants.GiveFieldVarName()); //NON-NLS
 
-                bind.addClickListener( click);
-                ClickableLabel cl = new ClickableLabel(con.fieldName, click, !modeller.lockLHS());
+                bind.addClickListener(click);
+                ClickableLabel cl = new ClickableLabel(con.fieldName, click, !(this.modeller.lockLHS() || this.readOnly));
                 DOM.setStyleAttribute(cl.getElement(), "marginLeft", "" + padding + "pt"); //NON-NLS
-                ab.add( cl );
+                ab.add(cl);
                 //ab.add( bind );
             } else {
                 ab.add(new SmallLabel(con.fieldName));
             }
-            
+
         } else {
-        	ab.add(new SmallLabel(con.fieldName));
-            ab.add( new SmallLabel(" <b>[" + con.fieldBinding + "]</b>") );       //NON-NLS
+            ab.add(new SmallLabel(con.fieldName));
+            ab.add(new SmallLabel(" <b>[" + con.fieldBinding + "]</b>"));       //NON-NLS
         }
 
 
@@ -451,12 +509,8 @@
         this.customLabel = customLabel;
     }
 
-
-    
-
     public boolean isDirty() {
         return layout.hasDirty();
     }
 
-
-}
\ No newline at end of file
+}

Modified: labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FromAccumulateCompositeFactPatternWidget.java
===================================================================
--- labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FromAccumulateCompositeFactPatternWidget.java	2010-03-15 16:00:28 UTC (rev 32096)
+++ labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FromAccumulateCompositeFactPatternWidget.java	2010-03-15 19:11:19 UTC (rev 32097)
@@ -28,6 +28,11 @@
 public class FromAccumulateCompositeFactPatternWidget extends FromCompositeFactPatternWidget {
 
     public FromAccumulateCompositeFactPatternWidget(RuleModeller modeller,
+            FromAccumulateCompositeFactPattern pattern, Boolean readOnly) {
+        super(modeller, pattern, readOnly);
+    }
+
+    public FromAccumulateCompositeFactPatternWidget(RuleModeller modeller,
             FromAccumulateCompositeFactPattern pattern) {
         super(modeller, pattern);
     }
@@ -58,26 +63,26 @@
         int r = 0;
 
         if (pattern.getFactPattern() == null) {
-            panel.setWidget(r++, 0, new ClickableLabel("<br> <font color='red'>" + constants.clickToAddPattern() + "</font>", leftPatternclick, !this.modeller.lockLHS()));
+            panel.setWidget(r++, 0, new ClickableLabel("<br> <font color='red'>" + constants.clickToAddPattern() + "</font>", leftPatternclick, !(this.modeller.lockLHS() || this.readOnly)));
         }
 
 
         panel.setWidget(r++, 0, new HTML(lbl));
 
         if (this.getFromAccumulatePattern().getSourcePattern() == null) {
-            panel.setWidget(r++, 0, new ClickableLabel("<br> <font color='red'>" + constants.clickToAddPattern() + "</font>", sourcePatternClick, !this.modeller.lockLHS()));
+            panel.setWidget(r++, 0, new ClickableLabel("<br> <font color='red'>" + constants.clickToAddPattern() + "</font>", sourcePatternClick, !(this.modeller.lockLHS() || this.readOnly)));
         } else {
             IPattern rPattern = this.getFromAccumulatePattern().getSourcePattern();
 
             Widget patternWidget = null;
             if (rPattern instanceof FactPattern) {
-                patternWidget = new FactPatternWidget(modeller, rPattern, constants.All0with(), true);
+                patternWidget = new FactPatternWidget(modeller, rPattern, constants.All0with(), true,this.readOnly);
             } else if (rPattern instanceof FromAccumulateCompositeFactPattern) {
-                patternWidget = new FromAccumulateCompositeFactPatternWidget(modeller, (FromAccumulateCompositeFactPattern) rPattern);
+                patternWidget = new FromAccumulateCompositeFactPatternWidget(modeller, (FromAccumulateCompositeFactPattern) rPattern,this.readOnly);
             } else if (rPattern instanceof FromCollectCompositeFactPattern) {
-                patternWidget = new FromCollectCompositeFactPatternWidget(modeller, (FromCollectCompositeFactPattern) rPattern);
+                patternWidget = new FromCollectCompositeFactPatternWidget(modeller, (FromCollectCompositeFactPattern) rPattern,this.readOnly);
             } else if (rPattern instanceof FromCompositeFactPattern) {
-                patternWidget = new FromCompositeFactPatternWidget(modeller, (FromCompositeFactPattern) rPattern);
+                patternWidget = new FromCompositeFactPatternWidget(modeller, (FromCompositeFactPattern) rPattern,this.readOnly);
             } else {
                 throw new IllegalArgumentException("Unsuported pattern " + rPattern + " for right side of FROM ACCUMULATE");
             }
@@ -133,6 +138,7 @@
         codePanel.setTitle("Custom Code");
         codePanel.setAutoHeight(true);
         codePanel.add(codeTable);
+        codePanel.setDisabled(this.readOnly);
         tPanel.add(codePanel);
 
         DirtyableFlexTable functionTable = new DirtyableFlexTable();
@@ -151,6 +157,7 @@
         functionPanel.setTitle("Function");
         functionPanel.setAutoHeight(true);
         functionPanel.add(functionTable);
+        functionPanel.setDisabled(this.readOnly);
         tPanel.add(functionPanel);
 
         ChangeListener changeListener = new ChangeListener() {
@@ -202,6 +209,7 @@
         tPanel.setBodyBorder(false);
         tPanel.setWidth(200);
 
+        tPanel.setDisabled(this.readOnly);
 
 //        functionTable.setVisible(useFunction);
 //        codeTable.setVisible(!useFunction);
@@ -312,4 +320,6 @@
     private FromAccumulateCompositeFactPattern getFromAccumulatePattern() {
         return (FromAccumulateCompositeFactPattern) this.pattern;
     }
+
+
 }

Modified: labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FromCollectCompositeFactPatternWidget.java
===================================================================
--- labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FromCollectCompositeFactPatternWidget.java	2010-03-15 16:00:28 UTC (rev 32096)
+++ labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FromCollectCompositeFactPatternWidget.java	2010-03-15 19:11:19 UTC (rev 32097)
@@ -29,6 +29,11 @@
         super(modeller, pattern);
     }
 
+    public FromCollectCompositeFactPatternWidget(RuleModeller modeller,
+            FromCollectCompositeFactPattern pattern,Boolean readOnly) {
+        super(modeller, pattern, readOnly);
+    }
+
     @Override
     protected Widget getCompositeLabel() {
 
@@ -54,26 +59,26 @@
         int r = 0;
 
         if (pattern.getFactPattern() == null) {
-            panel.setWidget(r++, 0, new ClickableLabel("<br> <font color='red'>" + constants.clickToAddPatterns() + "</font>", leftPatternclick, !this.modeller.lockLHS()));
+            panel.setWidget(r++, 0, new ClickableLabel("<br> <font color='red'>" + constants.clickToAddPatterns() + "</font>", leftPatternclick, !(this.modeller.lockLHS() || this.readOnly)));
         }
 
 
         panel.setWidget(r++, 0, new HTML(lbl));
 
         if (this.getFromCollectPattern().getRightPattern() == null) {
-            panel.setWidget(r++, 0, new ClickableLabel("<br> <font color='red'>" + constants.clickToAddPatterns() + "</font>", rightPatternclick, !this.modeller.lockLHS()));
+            panel.setWidget(r++, 0, new ClickableLabel("<br> <font color='red'>" + constants.clickToAddPatterns() + "</font>", rightPatternclick, !(this.modeller.lockLHS() || this.readOnly)));
         } else {
             IPattern rPattern = this.getFromCollectPattern().getRightPattern();
 
             Widget patternWidget = null;
             if (rPattern instanceof FactPattern) {
-                patternWidget = new FactPatternWidget(modeller, rPattern, constants.All0with(), true);
+                patternWidget = new FactPatternWidget(modeller, rPattern, constants.All0with(), true, this.readOnly);
             } else if (rPattern instanceof FromAccumulateCompositeFactPattern) {
-                patternWidget = new FromAccumulateCompositeFactPatternWidget(modeller, (FromAccumulateCompositeFactPattern) rPattern);
+                patternWidget = new FromAccumulateCompositeFactPatternWidget(modeller, (FromAccumulateCompositeFactPattern) rPattern,this.readOnly);
             } else if (rPattern instanceof FromCollectCompositeFactPattern) {
-                patternWidget = new FromCollectCompositeFactPatternWidget(modeller, (FromCollectCompositeFactPattern) rPattern);
+                patternWidget = new FromCollectCompositeFactPatternWidget(modeller, (FromCollectCompositeFactPattern) rPattern,this.readOnly);
             } else if (rPattern instanceof FromCompositeFactPattern) {
-                patternWidget = new FromCompositeFactPatternWidget(modeller, (FromCompositeFactPattern) rPattern);
+                patternWidget = new FromCompositeFactPatternWidget(modeller, (FromCompositeFactPattern) rPattern,this.readOnly);
             } else {
                 throw new IllegalArgumentException("Unsuported pattern " + rPattern + " for right side of FROM COLLECT");
             }

Modified: labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FromCompositeFactPatternWidget.java
===================================================================
--- labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FromCompositeFactPatternWidget.java	2010-03-15 16:00:28 UTC (rev 32096)
+++ labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FromCompositeFactPatternWidget.java	2010-03-15 19:11:19 UTC (rev 32097)
@@ -30,14 +30,31 @@
     protected DirtyableFlexTable layout;
     protected RuleModeller modeller;
     protected Constants constants = ((Constants) GWT.create(Constants.class));
+    protected boolean readOnly;
 
     public FromCompositeFactPatternWidget(RuleModeller modeller,
             FromCompositeFactPattern pattern) {
+        this(modeller, pattern, null);
+    }
+
+    public FromCompositeFactPatternWidget(RuleModeller modeller,
+            FromCompositeFactPattern pattern, Boolean readOnly) {
         this.pattern = pattern;
         this.modeller = modeller;
 
+        //if readOnly is null, the readOnly attribute is calculated.
+        if (readOnly == null) {
+            this.calculateReadOnly();
+        }else{
+            this.readOnly = readOnly;
+        }
+
+
         this.layout = new DirtyableFlexTable();
-        this.layout.setStyleName("model-builderInner-Background");
+        if (this.readOnly) {
+            this.layout.addStyleName("editor-disabled-widget");
+        }
+        this.layout.addStyleName("model-builderInner-Background");
 
         doLayout();
         initWidget(layout);
@@ -50,19 +67,27 @@
         if (pattern.getFactPattern() != null) {
             FactPattern fact = pattern.getFactPattern();
             if (fact != null) {
-                this.layout.setWidget(r,
-                        0,
-                        addRemoveButton(new FactPatternWidget(modeller,
-                        fact,
-                        true), new ClickListener() {
 
-                    public void onClick(Widget w) {
-                        if (Window.confirm(constants.RemoveThisEntireConditionQ())) {
-                            pattern.setFactPattern(null);
-                            modeller.refreshWidget();
+
+                if (this.readOnly) {
+                    //creates a new read-only FactPatternWidget
+                    FactPatternWidget factPatternWidget = new FactPatternWidget(modeller, fact, false, true);
+                    this.layout.setWidget(r,
+                            0, factPatternWidget);
+                } else {
+                    FactPatternWidget factPatternWidget = new FactPatternWidget(modeller, fact, true);
+                    this.layout.setWidget(r,
+                            0,
+                            addRemoveButton(factPatternWidget, new ClickListener() {
+
+                        public void onClick(Widget w) {
+                            if (Window.confirm(constants.RemoveThisEntireConditionQ())) {
+                                pattern.setFactPattern(null);
+                                modeller.refreshWidget();
+                            }
                         }
-                    }
-                }));
+                    }));
+                }
                 r++;
             }
         }
@@ -88,13 +113,13 @@
         int r = 0;
 
         if (pattern.getFactPattern() == null) {
-            panel.setWidget(r, 0, new ClickableLabel("<br> <font color='red'>" + constants.clickToAddPatterns() + "</font>", click, !this.modeller.lockLHS()));
+            panel.setWidget(r, 0, new ClickableLabel("<br> <font color='red'>" + constants.clickToAddPatterns() + "</font>", click, !(this.modeller.lockLHS() || this.readOnly)));
             r++;
         }
 
 
         panel.setWidget(r, 0, new HTML(lbl));
-        panel.setWidget(r, 1, new ExpressionBuilder(modeller, this.pattern.getExpression()));
+        panel.setWidget(r, 1, new ExpressionBuilder(modeller, this.pattern.getExpression(), this.readOnly));
 
 
         return panel;
@@ -144,14 +169,19 @@
         w.setWidth("100%");
 
         horiz.add(w);
-        if (!modeller.lockLHS()) {
+        if (!(modeller.lockLHS() || this.readOnly)) {
             horiz.add(remove);
         }
-
         return horiz;
     }
 
     public boolean isDirty() {
         return layout.hasDirty();
     }
+
+    protected void calculateReadOnly() {
+        if (this.pattern.factPattern != null) {
+            this.readOnly = !modeller.getSuggestionCompletions().containsFactType(this.pattern.factPattern.factType);
+        }
+    }
 }

Modified: labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleModeller.java
===================================================================
--- labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleModeller.java	2010-03-15 16:00:28 UTC (rev 32096)
+++ labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleModeller.java	2010-03-15 19:11:19 UTC (rev 32097)
@@ -293,6 +293,7 @@
 
         for (int i = 0; i < model.rhs.length; i++) {
             DirtyableVerticalPane widget = new DirtyableVerticalPane();
+            widget.setWidth("100%");
             IAction action = model.rhs[i];
 
             Widget w = null;
@@ -919,6 +920,8 @@
 
         for (int i = 0; i < model.lhs.length; i++) {
             DirtyableVerticalPane vert = new DirtyableVerticalPane();
+            vert.setWidth("100%");
+
             IPattern pattern = model.lhs[i];
             Widget w = null;
             if (pattern instanceof FactPattern) {
@@ -963,6 +966,7 @@
             layout.setWidget(currentLayoutRow, 1, vert);
             layout.getFlexCellFormatter().setHorizontalAlignment(currentLayoutRow, 1, HasHorizontalAlignment.ALIGN_LEFT);
             layout.getFlexCellFormatter().setVerticalAlignment(currentLayoutRow, 1, HasVerticalAlignment.ALIGN_TOP);
+            layout.getFlexCellFormatter().setWidth(currentLayoutRow, 1, "100%");
 
             final int index = i;
             if (!lockLHS()) {

Modified: labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/factPattern/Connectives.java
===================================================================
--- labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/factPattern/Connectives.java	2010-03-15 16:00:28 UTC (rev 32096)
+++ labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/factPattern/Connectives.java	2010-03-15 19:11:19 UTC (rev 32097)
@@ -83,7 +83,7 @@
 
     private Widget connectiveValueEditor(final ISingleFieldConstraint con, String factClass, String fieldName) {
         String typeNumeric = this.modeller.getSuggestionCompletions().getFieldType( factClass, fieldName );
-        return new ConstraintValueEditor(pattern, fieldName, con, this.modeller, typeNumeric);
+        return new ConstraintValueEditor(pattern, fieldName, con, this.modeller, typeNumeric,false);
     }
 
     private Widget connectiveOperatorDropDown(final ConnectiveConstraint con, String fieldName) {

Modified: labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/ActionToolbar.java
===================================================================
--- labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/ActionToolbar.java	2010-03-15 16:00:28 UTC (rev 32096)
+++ labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/ActionToolbar.java	2010-03-15 19:11:19 UTC (rev 32097)
@@ -39,6 +39,7 @@
 import org.drools.guvnor.client.rpc.RuleAsset;
 import org.drools.guvnor.client.rpc.BuilderResult;
 import org.drools.guvnor.client.explorer.ExplorerLayoutManager;
+import org.drools.guvnor.client.modeldriven.ui.RuleModeller;
 import org.drools.guvnor.client.security.Capabilities;
 import org.drools.guvnor.client.packages.PackageBuilderWidget;
 
@@ -220,17 +221,18 @@
 
         if ( isValidatorTypeAsset() ) {
 
-            ToolbarButton workingSets = new ToolbarButton();
-            workingSets.setText( constants.SelectWorkingSets() );
-            workingSets.addListener( new ButtonListenerAdapter() {
-                public void onClick(com.gwtext.client.widgets.Button button,
-                                    EventObject e) {
-                    showWorkingSetsSelection(editor);
-                }
-            } );
-            toolbar.addButton( workingSets );
+            if (editor instanceof RuleModeller){
+                ToolbarButton workingSets = new ToolbarButton();
+                workingSets.setText( constants.SelectWorkingSets() );
+                workingSets.addListener( new ButtonListenerAdapter() {
+                    public void onClick(com.gwtext.client.widgets.Button button,
+                                        EventObject e) {
+                        showWorkingSetsSelection((RuleModeller)editor);
+                    }
+                } );
+                toolbar.addButton( workingSets );
+            }
 
-
             ToolbarButton validate = new ToolbarButton();
             validate.setText( constants.Validate() );
             validate.addListener( new ButtonListenerAdapter() {
@@ -398,8 +400,8 @@
         pop.show();
     }
 
-    protected void showWorkingSetsSelection(Widget w) {
-        final WorkingSetSelectorPopup pop = new WorkingSetSelectorPopup(asset);
+    protected void showWorkingSetsSelection(RuleModeller modeller) {
+        final WorkingSetSelectorPopup pop = new WorkingSetSelectorPopup(modeller,asset);
 
 
         /*

Modified: labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/WorkingSetSelectorPopup.java
===================================================================
--- labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/WorkingSetSelectorPopup.java	2010-03-15 16:00:28 UTC (rev 32096)
+++ labs/jbossrules/branches/factsConstraints_baunax_esteban/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/WorkingSetSelectorPopup.java	2010-03-15 19:11:19 UTC (rev 32097)
@@ -15,6 +15,7 @@
  * limitations under the License.
  */
 
+import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -37,17 +38,21 @@
 import com.google.gwt.user.client.ui.Widget;
 import com.gwtext.client.widgets.tree.TreeNode;
 import com.gwtext.client.widgets.tree.TreePanel;
+import org.drools.guvnor.client.common.ErrorPopup;
+import org.drools.guvnor.client.modeldriven.ui.RuleModeller;
 
 public class WorkingSetSelectorPopup {
 
+    private final RuleModeller modeller;
     private final RuleAsset asset;
     private TreePanel treePanel;
     private Button save;
     private FormStylePopup pop;
     private Constants constants = ((Constants) GWT.create(Constants.class));
 
-    public WorkingSetSelectorPopup(RuleAsset a) {
+    public WorkingSetSelectorPopup(RuleModeller m, RuleAsset a) {
 
+        this.modeller = m;
         this.asset = a;
 
         pop = new FormStylePopup();
@@ -60,37 +65,18 @@
         treePanel.setRootNode(root);
         treePanel.setRootVisible(false);
 
-        RepositoryServiceFactory.getService().listAssets(asset.metaData.packageUUID, new String[] {AssetFormats.WORKING_SET}, 0, -1, "workingsetList", new GenericCallback<TableDataResult>()  {
 
-			public void onSuccess(TableDataResult result) {
-				for (int i = 0; i < result.data.length; i++) {
-					TreeNode node = new TreeNode(result.data[i].getDisplayName());
+        RepositoryServiceFactory.getService().listAssets(asset.metaData.packageUUID, new String[]{AssetFormats.WORKING_SET}, 0, -1, "workingsetList", new GenericCallback<TableDataResult>() {
+
+            public void onSuccess(TableDataResult result) {
+                for (int i = 0; i < result.data.length; i++) {
+                    TreeNode node = new TreeNode(result.data[i].getDisplayName());
                     node.setUserObject(result.data[0].id);
                     node.setChecked(false);
                     root.appendChild(node);
-				}
-			}
+                }
+            }
         });
-        
-//        RepositoryServiceFactory.getService().loadPackageConfig(asset.metaData.packageUUID, new GenericCallback<PackageConfigData>() {
-//        	
-//            public void onSuccess(PackageConfigData t) {
-//                this.createTreeNodes(root, t.workingsets);
-//            }
-//
-//            private void createTreeNodes(TreeNode root, WorkingSetConfigData[] data) {
-//
-//                for (WorkingSetConfigData ws : data) {
-//                    TreeNode node = new TreeNode(ws.name);
-//                    node.setAttribute("workingSet", ws);
-//                    node.setChecked(false);
-//                    if (ws.workingSets != null && ws.workingSets.length > 0) {
-//                        this.createTreeNodes(node, ws.workingSets);
-//                    }
-//                    root.appendChild(node);
-//                }
-//            }
-//        });
 
         save = new Button(constants.SaveAndClose());
         save.addClickListener(new ClickListener() {
@@ -106,70 +92,65 @@
                 //TODO: move this code to a class
 
                 //if there are no WS checked, remove any SCE filter.
-                if (wsUUIDs.length > 0){
+                if (wsUUIDs.length == 0) {
                     SuggestionCompletionCache.getInstance().refreshPackage(asset.metaData.packageName, new Command() {
+
                         public void execute() {
                             LoadingPopup.close();
                             pop.hide();
-
+                            modeller.refreshWidget();
                         }
                     });
                     return;
                 }
 
-                final Set<String> validFacts = new HashSet<String>();
-                RepositoryServiceFactory.getService().loadRuleAssets(wsUUIDs, new GenericCallback<RuleAsset[]>() {
-					public void onSuccess(RuleAsset[] result) {
-						for (RuleAsset asset : result) {
-							WorkingSetConfigData wsConfig = (WorkingSetConfigData) asset.content;
-		                    for (int i = 0; i < wsConfig.validFacts.length; i++) {
-		                        validFacts.add(wsConfig.validFacts[i]);
-		                    }
-		                }
-					}
-				});
                 
-                FactTypeFilter filter = new FactTypeFilter() {
-                    public boolean filter(String originalFact) {
-                        return !validFacts.contains(originalFact);
+                RepositoryServiceFactory.getService().loadRuleAssets(wsUUIDs, new GenericCallback<RuleAsset[]>() {
+
+                    public void onSuccess(RuleAsset[] result) {
+                        final Set<String> validFacts = new HashSet<String>();
+                        for (RuleAsset asset : result) {
+                            WorkingSetConfigData wsConfig = (WorkingSetConfigData) asset.content;
+                            validFacts.addAll(Arrays.asList(wsConfig.validFacts));
+                        }
+
+
+                        FactTypeFilter filter = new FactTypeFilter() {
+
+                            public boolean filter(String originalFact) {
+                                return !validFacts.contains(originalFact);
+                            }
+                        };
+
+                        Command done = new Command() {
+
+                            public void execute() {
+                                LoadingPopup.close();
+                                pop.hide();
+                                modeller.refreshWidget();
+                            }
+                        };
+
+                        SuggestionCompletionCache.getInstance().applyFactFilter(asset.metaData.packageName, filter, done);
+
+
                     }
-                };
 
-                Command done = new Command() {
-                    public void execute() {
+                    @Override
+                    public void onFailure(Throwable t) {
                         LoadingPopup.close();
                         pop.hide();
+                        ErrorPopup.showMessage(constants.ErrorLoadingRules());
                     }
-                };
+                });
 
-                SuggestionCompletionCache.getInstance().applyFactFilter(asset.metaData.packageName,filter,done);
+
             }
         });
         pop.addRow(treePanel);
         pop.addRow(save);
     }
 
-    public void setCommand(final Command checkin) {
-        /*
-        final ClickListener cl = new ClickListener() {
-        public void onClick(Widget w) {
-        checkin.execute();
-        pop.hide();
-        }
-        };
-        save.addClickListener( cl );
-        comment.addKeyboardListener(new KeyboardListenerAdapter() {
-        @Override
-        public void onKeyUp(Widget sender, char keyCode, int modifiers) {
-        if (keyCode == KeyboardListener.KEY_ENTER) {
-        cl.onClick(null);
-        }
-        }
-        });
-         *
-         */
-    }
-
     public void show() {
         treePanel.expandAll();
         pop.show();



More information about the jboss-svn-commits mailing list