[jboss-svn-commits] JBL Code SVN: r12850 - in labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client: ruleeditor and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Jun 26 01:28:48 EDT 2007


Author: fmeyer
Date: 2007-06-26 01:28:48 -0400 (Tue, 26 Jun 2007)
New Revision: 12850

Modified:
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/packages/AssetAttachmentFileWidget.java
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/ChoiceList.java
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/DSLRuleEditor.java
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/DefaultRuleContentWidget.java
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/RuleValidatorWrapper.java
Log:
JBRULES-741 - added tab key capture on editors textarea

Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/packages/AssetAttachmentFileWidget.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/packages/AssetAttachmentFileWidget.java	2007-06-26 02:16:29 UTC (rev 12849)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/packages/AssetAttachmentFileWidget.java	2007-06-26 05:28:48 UTC (rev 12850)
@@ -15,8 +15,6 @@
  * limitations under the License.
  */
 
-
-
 import org.drools.brms.client.common.ErrorPopup;
 import org.drools.brms.client.common.FormStyleLayout;
 import org.drools.brms.client.common.HTMLFileManagerFields;

Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/ChoiceList.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/ChoiceList.java	2007-06-26 02:16:29 UTC (rev 12849)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/ChoiceList.java	2007-06-26 05:28:48 UTC (rev 12850)
@@ -1,4 +1,5 @@
 package org.drools.brms.client.ruleeditor;
+
 /*
  * Copyright 2005 JBoss Inc
  * 
@@ -15,8 +16,6 @@
  * limitations under the License.
  */
 
-
-
 import java.util.List;
 
 import org.drools.brms.client.modeldriven.brxml.DSLSentence;
@@ -24,6 +23,7 @@
 import com.google.gwt.user.client.ui.Button;
 import com.google.gwt.user.client.ui.ClickListener;
 import com.google.gwt.user.client.ui.FocusListener;
+import com.google.gwt.user.client.ui.HorizontalPanel;
 import com.google.gwt.user.client.ui.KeyboardListener;
 import com.google.gwt.user.client.ui.ListBox;
 import com.google.gwt.user.client.ui.PopupPanel;
@@ -37,19 +37,19 @@
  */
 public class ChoiceList extends PopupPanel {
 
-    private ListBox list;
-    private final DSLSentence[] sentences;    
-    
-    private TextBox filter;
-    
+    private ListBox             list;
+    private final DSLSentence[] sentences;
+    private HorizontalPanel     buttons;
+    private TextBox             filter;
 
-        /**
-     * 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(final DSLSentence[] sen, final DSLRuleEditor self) {
+    /**
+    * 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(final DSLSentence[] sen,
+                      final DSLRuleEditor self) {
         super( true );
-        
+
         this.sentences = sen;
         filter = new TextBox();
         filter.setWidth( "100%" );
@@ -59,16 +59,17 @@
             public void onFocus(Widget w) {
                 filter.setText( "" );
             }
+
             public void onLostFocus(Widget w) {
                 filter.setText( defaultMessage );
             }
-        });
+        } );
         filter.addKeyboardListener( new KeyboardListener() {
 
             public void onKeyDown(Widget arg0,
                                   char arg1,
                                   int arg2) {
-                
+
             }
 
             public void onKeyPress(Widget arg0,
@@ -79,60 +80,68 @@
             public void onKeyUp(Widget arg0,
                                 char arg1,
                                 int arg2) {
-                if (arg1 == KEY_ENTER) {
+                if ( arg1 == KEY_ENTER ) {
                     applyChoice( self );
                 } else {
-                    populateList( ListUtil.filter(sentences, filter.getText()) );
+                    populateList( ListUtil.filter( sentences,
+                                                   filter.getText() ) );
                 }
             }
-            
-        });
+
+        } );
         filter.setFocus( true );
-        
-        
+
         VerticalPanel panel = new VerticalPanel();
         panel.add( filter );
-        
+
         list = new ListBox();
         list.setVisibleItemCount( 5 );
-        
-        populateList( ListUtil.filter( this.sentences, "" ));        
-        
-        
+
+        populateList( ListUtil.filter( this.sentences,
+                                       "" ) );
+
         panel.add( list );
-        
-        Button ok = new Button("ok");
+
+        Button ok = new Button( "ok" );
         ok.addClickListener( new ClickListener() {
-            public void onClick(Widget btn) {                
+            public void onClick(Widget btn) {
                 applyChoice( self );
             }
+        } );
 
+        Button cancel = new Button( "cancel" );
+        cancel.addClickListener( new ClickListener() {
+            public void onClick(Widget btn) {
+                hide();
+            }
+        } );
 
-            
-        });
-        panel.add( ok );        
-        add( panel );      
+        buttons = new HorizontalPanel();
+
+        buttons.add( ok );
+        buttons.add( cancel );
+
+        panel.add( buttons );
+
+        add( panel );
         setStyleName( "ks-popups-Popup" );
-        
+
     }
 
     private void applyChoice(final DSLRuleEditor self) {
         self.insertText( getSelectedItem() );
         hide();
     }
-    
+
     private void populateList(List filtered) {
         list.clear();
-        for (int i = 0; i < filtered.size(); i++) {
-            list.addItem(((DSLSentence)filtered.get( i )).sentence);
-        }        
+        for ( int i = 0; i < filtered.size(); i++ ) {
+            list.addItem( ((DSLSentence) filtered.get( i )).sentence );
+        }
     }
-    
 
-    
     public String getSelectedItem() {
         return list.getItemText( list.getSelectedIndex() );
     }
-    
-    
+
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/DSLRuleEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/DSLRuleEditor.java	2007-06-26 02:16:29 UTC (rev 12849)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/DSLRuleEditor.java	2007-06-26 05:28:48 UTC (rev 12850)
@@ -1,4 +1,5 @@
 package org.drools.brms.client.ruleeditor;
+
 /*
  * Copyright 2005 JBoss Inc
  * 
@@ -15,8 +16,6 @@
  * limitations under the License.
  */
 
-
-
 import org.drools.brms.client.common.ImageButton;
 import org.drools.brms.client.modeldriven.SuggestionCompletionEngine;
 import org.drools.brms.client.modeldriven.brxml.DSLSentence;
@@ -29,133 +28,139 @@
 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.KeyboardListener;
 import com.google.gwt.user.client.ui.KeyboardListenerAdapter;
+import com.google.gwt.user.client.ui.Label;
 import com.google.gwt.user.client.ui.TextArea;
+import com.google.gwt.user.client.ui.TextBox;
 import com.google.gwt.user.client.ui.VerticalPanel;
 import com.google.gwt.user.client.ui.Widget;
 
-
 /**
- * This is a textual rule editor, which provides DSL content assistance.
- * This is similar (but simpler) to the IDE based one.
+ * This is a textual rule editor, which provides DSL content assistance. This is
+ * similar (but simpler) to the IDE based one.
+ * 
  * @author michael neale
  */
+
 public class DSLRuleEditor extends Composite {
-    
-    private TextArea text;
+
+    private TextArea      text;
     final private RuleContentText data;
-    private DSLSentence[] conditions;
-    private DSLSentence[] actions;
-    
+    private DSLSentence[]         conditions;
+    private DSLSentence[]         actions;
 
-    
     public DSLRuleEditor(RuleAsset asset) {
-        
+
         RuleContentText cont = (RuleContentText) asset.content;
-        
+
         this.data = cont;
         text = new TextArea();
-        text.setWidth("100%");
-        text.setHeight("100%");
-        text.setVisibleLines(10);
-        text.setText(data.content);
+        text.setWidth( "100%" );
+        text.setHeight( "100%" );
+        text.setVisibleLines( 10 );
+        text.setText( data.content );
         text.setTitle( "Hint: press control+space for popup assistance, or use one of the icons to the right." );
+
         SuggestionCompletionEngine eng = SuggestionCompletionCache.getInstance().getEngineFromCache( asset.metaData.packageName );
         this.actions = eng.actionDSLSentences;
         this.conditions = eng.conditionDSLSentences;
-      
-        
+
         text.setStyleName( "dsl-text-Editor" );
-        
+
         FlexTable layout = new FlexTable();
-        layout.setWidget( 0, 0, text );
-        
+        layout.setWidget( 0,
+                          0,
+                          text );
+
         text.addChangeListener( new ChangeListener() {
             public void onChange(Widget w) {
                 data.content = text.getText();
             }
-        });
+        } );
 
-
-
         text.addKeyboardListener( new KeyboardListenerAdapter() {
-
-
-
             public void onKeyDown(Widget arg0,
-                                   char arg1,
-                                   int arg2) {
+                                  char arg1,
+                                  int arg2) {
+                if ( arg1 == ' ' && arg2 == MODIFIER_CTRL ) {
+                    showInTextOptions();
+                }
                 
-                if (arg1 == ' ' && arg2 == MODIFIER_CTRL) {
-                    showInTextOptions( ); 
-                } 
-                
+                if ( arg1 == KEY_TAB ) {
+                    insertText( "\t" );
+                    text.setCursorPos( text.getCursorPos() + 1 );
+                    text.cancelKey();
+                }
             }
+        } );
 
+        VerticalPanel vert = new VerticalPanel();
 
-            
-        });
-        
-        VerticalPanel vert = new VerticalPanel();
-        
-        Image lhsOptions = new ImageButton("images/new_dsl_pattern.gif");
+        Image lhsOptions = new ImageButton( "images/new_dsl_pattern.gif" );
         final String msg = "Add a new condition";
         lhsOptions.setTitle( msg );
         lhsOptions.addClickListener( new ClickListener() {
             public void onClick(Widget w) {
                 showSuggestions( conditions );
             }
-        });        
-        
-        Image rhsOptions = new ImageButton("images/new_dsl_action.gif");   
-        final String msg2 =  "Add an action";
+        } );
+
+        Image rhsOptions = new ImageButton( "images/new_dsl_action.gif" );
+        final String msg2 = "Add an action";
         rhsOptions.setTitle( msg2 );
         rhsOptions.addClickListener( new ClickListener() {
             public void onClick(Widget w) {
                 showSuggestions( actions );
             }
-        });   
-        
-        vert.add( lhsOptions );    
+        } );
+
+        vert.add( lhsOptions );
         vert.add( rhsOptions );
-        layout.setWidget( 0, 1, vert );
-        
-        layout.getCellFormatter().setWidth( 0, 0, "95%" );
-        layout.getCellFormatter().setWidth( 0, 1, "5%" );
-        
+
+        layout.setWidget( 0,
+                          1,
+                          vert );
+
+        layout.getCellFormatter().setWidth( 0,
+                                            0,
+                                            "95%" );
+        layout.getCellFormatter().setWidth( 0,
+                                            1,
+                                            "5%" );
+
         layout.setWidth( "100%" );
         layout.setHeight( "100%" );
-        
-        
+
         initWidget( layout );
     }
-    
+
     protected void showInTextOptions() {
-        String prev = text.getText().substring( 0, this.text.getCursorPos() );
-        if (prev.indexOf( "then" ) > -1) {
-            showSuggestions(this.actions);
+        String prev = text.getText().substring( 0,
+                                                this.text.getCursorPos() );
+        if ( prev.indexOf( "then" ) > -1 ) {
+            showSuggestions( this.actions );
         } else {
-            showSuggestions(this.conditions);
+            showSuggestions( this.conditions );
         }
     }
-    
 
     private void showSuggestions(DSLSentence[] items) {
-        ChoiceList choice = new ChoiceList(items, this);
-        choice.setPopupPosition( text.getAbsoluteLeft() + 20, text.getAbsoluteTop() + 20 );
-        choice.show();        
+        ChoiceList choice = new ChoiceList( items,
+                                            this );
+        choice.setPopupPosition( text.getAbsoluteLeft() + 20,
+                                 text.getAbsoluteTop() + 20 );
+        choice.show();
     }
-    
-  
-    
+
     void insertText(String ins) {
         int i = text.getCursorPos();
-        String left = text.getText().substring( 0, i );
-        String right = text.getText().substring( i, text.getText().length() );
+        String left = text.getText().substring( 0,
+                                                i );
+        String right = text.getText().substring( i,
+                                                 text.getText().length() );
         text.setText( left + ins + right );
         this.data.content = text.getText();
-    }    
+    }
 
-
-
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/DefaultRuleContentWidget.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/DefaultRuleContentWidget.java	2007-06-26 02:16:29 UTC (rev 12849)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/DefaultRuleContentWidget.java	2007-06-26 05:28:48 UTC (rev 12850)
@@ -1,4 +1,5 @@
 package org.drools.brms.client.ruleeditor;
+
 /*
  * Copyright 2005 JBoss Inc
  * 
@@ -15,49 +16,70 @@
  * limitations under the License.
  */
 
-
-
 import org.drools.brms.client.common.DirtyableComposite;
-import org.drools.brms.client.rpc.MetaData;
 import org.drools.brms.client.rpc.RuleAsset;
 import org.drools.brms.client.rpc.RuleContentText;
 
 import com.google.gwt.user.client.ui.ChangeListener;
+import com.google.gwt.user.client.ui.FocusListener;
+import com.google.gwt.user.client.ui.KeyboardListenerAdapter;
 import com.google.gwt.user.client.ui.TextArea;
 import com.google.gwt.user.client.ui.Widget;
 
-
 /**
  * This is the default rule editor widget (just text editor based) - more to come later.
  * @author michael neale
  */
 public class DefaultRuleContentWidget extends DirtyableComposite {
-	
-	private TextArea text;
-	final private RuleContentText data;
 
-    final private RuleAsset asset;
-    
-	public DefaultRuleContentWidget(RuleAsset a) {
+    private TextArea              text;
+    final private RuleContentText data;
+
+    final private RuleAsset       asset;
+
+    public DefaultRuleContentWidget(RuleAsset a) {
         asset = a;
         data = (RuleContentText) asset.content;
-        
-		text = new TextArea();
-		text.setWidth("100%");
-		text.setHeight("100%");
-		text.setVisibleLines(10);
-		text.setText(data.content);
-        
+
+        text = new TextArea();
+        text.setWidth( "100%" );
+        text.setHeight( "100%" );
+        text.setVisibleLines( 10 );
+        text.setText( data.content );
+
         text.setStyleName( "default-text-Area" );
-        
+
         text.addChangeListener( new ChangeListener() {
             public void onChange(Widget w) {
                 data.content = text.getText();
                 makeDirty();
             }
-        }); 
-        
-		initWidget(text);
-	}
+        } );
 
+        text.addKeyboardListener( new KeyboardListenerAdapter() {
+            public void onKeyDown(Widget arg0,
+                                  char arg1,
+                                  int arg2) {
+
+                if ( arg1 == KEY_TAB ) {
+                    insertText( "\t" );
+                    text.setCursorPos( text.getCursorPos() + 1 );
+                    text.cancelKey();
+                }
+            }
+        } );
+
+        initWidget( text );
+    }
+
+    void insertText(String ins) {
+        int i = text.getCursorPos();
+        String left = text.getText().substring( 0,
+                                                i );
+        String right = text.getText().substring( i,
+                                                 text.getText().length() );
+        text.setText( left + ins + right );
+        this.data.content = text.getText();
+    }
+
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/RuleValidatorWrapper.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/RuleValidatorWrapper.java	2007-06-26 02:16:29 UTC (rev 12849)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/RuleValidatorWrapper.java	2007-06-26 05:28:48 UTC (rev 12850)
@@ -29,7 +29,6 @@
 
 import com.google.gwt.user.client.ui.Button;
 import com.google.gwt.user.client.ui.ClickListener;
-import com.google.gwt.user.client.ui.Composite;
 import com.google.gwt.user.client.ui.FlexTable;
 import com.google.gwt.user.client.ui.HTML;
 import com.google.gwt.user.client.ui.HasHorizontalAlignment;




More information about the jboss-svn-commits mailing list