[jboss-svn-commits] JBL Code SVN: r6312 - in labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client: . breditor

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Sep 20 06:19:11 EDT 2006


Author: michael.neale at jboss.com
Date: 2006-09-20 06:19:07 -0400 (Wed, 20 Sep 2006)
New Revision: 6312

Modified:
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/Packages.java
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/breditor/BREditor.java
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/breditor/ChoiceList.java
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/breditor/EditableLine.java
Log:
got DSL editor working

Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/Packages.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/Packages.java	2006-09-20 09:31:19 UTC (rev 6311)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/Packages.java	2006-09-20 10:19:07 UTC (rev 6312)
@@ -82,9 +82,6 @@
         panel.add( fPopupButton );
         panel.add( new BREditor() );
         
-        EditableLine line = new EditableLine(new Widget[] {new Label("this is pretty "), new TextBox()});
-        panel.add( line );
-        
         panel.setSpacing( 8 );
         initWidget( panel );
     }

Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/breditor/BREditor.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/breditor/BREditor.java	2006-09-20 09:31:19 UTC (rev 6311)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/breditor/BREditor.java	2006-09-20 10:19:07 UTC (rev 6312)
@@ -7,9 +7,7 @@
 import com.google.gwt.user.client.ui.Composite;
 import com.google.gwt.user.client.ui.FlexTable;
 import com.google.gwt.user.client.ui.Image;
-import com.google.gwt.user.client.ui.Label;
 import com.google.gwt.user.client.ui.Panel;
-import com.google.gwt.user.client.ui.TextBox;
 import com.google.gwt.user.client.ui.VerticalPanel;
 import com.google.gwt.user.client.ui.Widget;
 
@@ -25,8 +23,16 @@
     
     
     private Panel panel;
+    
+    /** these lists contain the guts of the rule */
     private List lhs = new ArrayList(); //these will be populated with EditableLine widget
     private List rhs = new ArrayList();
+    
+    /** these lists contain the "popup data" for the content assistance */
+    private List lhsSuggestions = new ArrayList();
+    private List rhsSuggestions = new ArrayList();
+    
+    
     private FlexTable table = null;
     private boolean editMode = false;
     
@@ -45,17 +51,7 @@
         table.setText( 0, DESC_COLUMN, "IF" );
         
         //DSL suggestions/pick list
-        final ChoiceList listPopup = new ChoiceList(new ClickListener() {
-            public void onClick(Widget popup) {
-                //need up add to the LHS list
-                ChoiceList c = (ChoiceList) popup;
-                EditableLine editLine = new EditableLine(new Label[] {new Label(c.getSelectedItem())} );
-                if (editMode) editLine.makeEditable();
-                
-                lhs.add( editLine );
-                refreshLayoutTable();
-            }            
-        });
+        final ChoiceList lhsSuggestionPopup = getLHSChoiceList();
         
         //button to add a new item for lhs (using the choice list).
         Image addLhs = new Image("images/new_item.gif");
@@ -63,8 +59,8 @@
             public void onClick(Widget sender) {
                 int left = sender.getAbsoluteLeft() + 10;
                 int top = sender.getAbsoluteTop() + 10;
-                listPopup.setPopupPosition( left, top );
-                listPopup.show();                
+                lhsSuggestionPopup.setPopupPosition( left, top );
+                lhsSuggestionPopup.show();                
             }            
         });
         
@@ -89,15 +85,61 @@
         rowOffset = lhs.size() + 1;        
         table.setText( rowOffset, DESC_COLUMN, "THEN" );
         
+        final ChoiceList rhsSuggestionPopup = getRhsChoiceList();
+        
         //the new button for the RHS
-        table.setWidget( rowOffset, ACTION_COLUMN, new Image("images/new_item.gif") );
+        Image newRhsPopup = new Image("images/new_item.gif");
+        newRhsPopup.addClickListener( new ClickListener() {
+
+            public void onClick(Widget sender) {
+                int left = sender.getAbsoluteLeft() + 10;
+                int top = sender.getAbsoluteTop() + 10;
+                rhsSuggestionPopup.setPopupPosition( left, top );
+                rhsSuggestionPopup.show();              
+            }
+            
+        });
+        table.setWidget( rowOffset, ACTION_COLUMN, newRhsPopup );
         
         rowOffset++;
         
         //setup RHS
         displayEditorWidgets( rowOffset, rhs );
     }
+
+    private ChoiceList getRhsChoiceList() {
+        final ChoiceList rhsSuggestionPopup = new ChoiceList(rhsSuggestions);
+        rhsSuggestionPopup.setOKClickListener( new ClickListener() {
+            public void onClick(Widget popup) {
+                //need up add to the LHS list
+                ChoiceList c = (ChoiceList) popup;
+                EditableLine editLine = new EditableLine(c.getSelectedItem());
+                if (editMode) editLine.makeEditable();
+                
+                rhs.add( editLine );
+                refreshLayoutTable();
+            }            
+        } );
+        return rhsSuggestionPopup;
+    }
+
+    private ChoiceList getLHSChoiceList() {
+        final ChoiceList lhsSuggestionPopup = new ChoiceList(lhsSuggestions);
+        lhsSuggestionPopup.setOKClickListener( new ClickListener() {
+            public void onClick(Widget popup) {
+                //need up add to the LHS list
+                ChoiceList c = (ChoiceList) popup;
+                EditableLine editLine = new EditableLine(c.getSelectedItem());
+                if (editMode) editLine.makeEditable();
+                
+                lhs.add( editLine );
+                refreshLayoutTable();
+            }            
+        } );
+        return lhsSuggestionPopup;
+    }
     
+
     private void switchModes(List list, boolean readOnly) {  
         
         
@@ -202,15 +244,21 @@
     /**
      * This will setup the data
      * TODO: this is only mockup data.
+     * TODO: When populading the lhs and rhs lists, need to have "{" stuffed in there
+     * so that the text fields will be created for you. When reading the value out of the 
+     * EditableLine, they will be removed (as they won't actually show up on screen, 
+     * they are just place holders).
      */
     private void initData() {
-        
-        Widget[] w = new Widget[] {new Label("hello cruel "), new TextBox()};
-        Widget[] w2 = new Widget[] {new Label("hello cruel "), new TextBox()};
-        Widget[] w3 = new Widget[] {new Label("hello cruel "), new TextBox()};
-        lhs.add( new EditableLine(w));
-        lhs.add( new EditableLine(w2));
-        rhs.add( new EditableLine(w3));
+
+        lhsSuggestions.add( "Hello {world}" );
+        lhsSuggestions.add( "Goodbye {world}" );
+        rhsSuggestions.add( "Log '{message}'" );
+        rhsSuggestions.add( "Do nothing" );
+
+        lhs.add( new EditableLine("this is a {bam}"));
+        lhs.add( new EditableLine("this is a {bam}"));
+        rhs.add( new EditableLine("this is a {bam}"));
     }
 
     /** Adjust items up and down in a list.

Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/breditor/ChoiceList.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/breditor/ChoiceList.java	2006-09-20 09:31:19 UTC (rev 6311)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/breditor/ChoiceList.java	2006-09-20 10:19:07 UTC (rev 6312)
@@ -1,5 +1,7 @@
 package org.drools.brms.client.breditor;
 
+import java.util.List;
+
 import com.google.gwt.user.client.ui.Button;
 import com.google.gwt.user.client.ui.ClickListener;
 import com.google.gwt.user.client.ui.ListBox;
@@ -7,22 +9,33 @@
 import com.google.gwt.user.client.ui.VerticalPanel;
 import com.google.gwt.user.client.ui.Widget;
 
+/**
+ * This is a popup list for "content assistance" - although on the web, 
+ * its not assistance - its mandatory ;)
+ */
 public class ChoiceList extends PopupPanel {
 
     private ListBox list;    
     private ClickListener okClickListener;
     
-    public ChoiceList(ClickListener okClickListener) {
+    public void setOKClickListener(ClickListener listener) {
+        this.okClickListener = listener;
+    }
+    
+    /**
+     * Pass in a list of suggestions for the popup lists.
+     * Set a click listener to get notified when the OK button is clicked.
+     */
+    public ChoiceList(List data) {
         super( true );
-        this.okClickListener = okClickListener;
         
         list = new ListBox();
         list.setVisibleItemCount( 5 );
-        list.addItem( "There is a person {bob} who is blah" );
-        list.addItem( "There is a cheese {bob} who is {type}" );
-        list.addItem( "- age is less then {number}" );
-        list.addItem( "- likes doing '{number}'" );
         
+        for (int i = 0; i < data.size(); i++) {
+            list.addItem((String) data.get( i ));
+        }        
+        
         VerticalPanel panel = new VerticalPanel();
         panel.add( list );
         

Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/breditor/EditableLine.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/breditor/EditableLine.java	2006-09-20 09:31:19 UTC (rev 6311)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/breditor/EditableLine.java	2006-09-20 10:19:07 UTC (rev 6312)
@@ -1,8 +1,10 @@
 package org.drools.brms.client.breditor;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import com.google.gwt.user.client.ui.Composite;
 import com.google.gwt.user.client.ui.HorizontalPanel;
-import com.google.gwt.user.client.ui.Image;
 import com.google.gwt.user.client.ui.Label;
 import com.google.gwt.user.client.ui.Panel;
 import com.google.gwt.user.client.ui.TextBox;
@@ -20,8 +22,9 @@
      */
     private Widget[] widgets;
     
-    public EditableLine(Widget[] items) {
-        widgets = items;
+    public EditableLine(String dslLine) {
+        widgets = makeWidgets( dslLine );
+        //widgets = items;
         panel = new HorizontalPanel();
         initWidget( panel ); 
         makeReadOnly();
@@ -57,8 +60,100 @@
     }
 
 
+    /** 
+     * This will take a DSL line item, and split it into widget thingamies for displaying.
+     * One day, if this is too complex, this will have to be done on the server side.
+     */
+    public static Widget[] makeWidgets(String dslLine) {
+        List widgets = new ArrayList();
+        char[] chars = dslLine.toCharArray();
+        TextBox currentBox = null;
+        Label currentLabel = null;
+        for ( int i = 0; i < chars.length; i++ ) {
+            char c = chars[i];
+            if (c == '{') {
+                currentLabel = null;
+                currentBox = new TextBox();
+                currentBox.setVisibleLength( 3 );
+                widgets.add( currentBox );
+            } else if (c == '}') {
+                currentBox = null;
+            } else {
+                if (currentBox == null && currentLabel == null) {
+                    currentLabel = new Label();
+                    widgets.add( currentLabel );
+                }
+                if (currentLabel != null) {
+                    currentLabel.setText( currentLabel.getText() + c );
+                } else if (currentBox != null) {
+                    currentBox.setText( currentBox.getText() + c );
+                }
+                
+            }
+        }
+        Widget[] result = new Widget[widgets.size()];
+        for(int i=0; i < result.length; i++) {
+            result[i] = (Widget) widgets.get( i );
+        }
+        return result;
+    }
+
+
+    /** 
+     * This represents a little element of a DSL line - ie a label or a text box widget
+     * or whatever it grows up into being.
+     *
+     */
+    static interface DSLLineAtom {
     
+        Widget getWidget();
+        String getValue();
+    }
 
-
+//    /**
+//     * This represents the read only part of a DSL line item. 
+//     */
+//    static class DSLText implements DSLLineAtom {
+//
+//        private Label label;
+//        private String value;
+//
+//        public Widget getWidget() {
+//            if (label == null) 
+//                this.label = new Label(value);
+//            return this.label;
+//        }
+//
+//        public DSLText(String txt) {
+//            this.value = txt;
+//        }
+//        
+//        public String getValue() {
+//            
+//            return this.value;
+//        }
+//        
+//    }
+//    
+//    static class DSLTextBox implements DSLLineAtom {
+//
+//        private TextBox textBox;
+//
+//        public String getValue() {
+//            return this.value;
+//        }
+//
+//        public DSLTextBox(String initialValue) {
+//            
+//        }
+//        
+//        public Widget getWidget() {
+//            if (this.textBox == null) {
+//                  this.textBox = new TextBox();
+//            }
+//            return this.textBox;
+//        }
+//        
+//    }
      
 }




More information about the jboss-svn-commits mailing list