[jboss-svn-commits] JBL Code SVN: r9966 - in labs/jbossrules/trunk/drools-jbrms/src: main/java/org/drools/brms/client/categorynav and 7 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Mar 5 05:06:38 EST 2007


Author: michael.neale at jboss.com
Date: 2007-03-05 05:06:38 -0500 (Mon, 05 Mar 2007)
New Revision: 9966

Added:
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/common/AutoCompleteTextBoxAsync.java
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/common/CompletionItemsAsync.java
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/common/CompletionItemsAsyncReturn.java
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rulelist/QuickFindWidget.java
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/public/images/find_items.gif
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/public/images/search_large.gif
Modified:
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/RulesFeature.java
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/categorynav/CategoryExplorerWidget.java
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/packages/PackageSnapshotView.java
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/RepositoryService.java
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/RepositoryServiceAsync.java
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/server/JBRMSServiceServlet.java
   labs/jbossrules/trunk/drools-jbrms/src/test/java/org/drools/brms/server/ServiceImplementationTest.java
Log:
JBRULES-721 and JBRULES-639

Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/RulesFeature.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/RulesFeature.java	2007-03-05 10:04:03 UTC (rev 9965)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/RulesFeature.java	2007-03-05 10:06:38 UTC (rev 9966)
@@ -16,6 +16,7 @@
 import org.drools.brms.client.ruleeditor.RuleViewer;
 import org.drools.brms.client.rulelist.AssetItemListViewer;
 import org.drools.brms.client.rulelist.EditItemEvent;
+import org.drools.brms.client.rulelist.QuickFindWidget;
 
 import com.google.gwt.user.client.Command;
 import com.google.gwt.user.client.DeferredCommand;
@@ -24,6 +25,7 @@
 import com.google.gwt.user.client.ui.FlexTable;
 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
 import com.google.gwt.user.client.ui.HasVerticalAlignment;
+import com.google.gwt.user.client.ui.HorizontalPanel;
 import com.google.gwt.user.client.ui.Image;
 import com.google.gwt.user.client.ui.TabPanel;
 import com.google.gwt.user.client.ui.Widget;
@@ -39,8 +41,9 @@
     private TabPanel tab;
     private Map openedViewers = new HashMap();
     private AssetItemListViewer list;
-
     
+    
+    
 	public static ComponentInfo init() {
 		return new ComponentInfo("Rules", "Find and edit rules.") {
 			public JBRMSFeature createInstance() {
@@ -57,9 +60,10 @@
         tab.setWidth("100%");
         tab.setHeight("100%");        
 
-        FlexTable explorePanel = doExplore();        
+        FlexTable explorePanel = doExplorer();        
         
         tab.add(explorePanel, "Explore");
+
         tab.selectTab(0);
         
 		initWidget(tab);
@@ -68,34 +72,40 @@
     
 
     /** This will setup the explorer tab */
-	private FlexTable doExplore() {
-		FlexTable  table = new FlexTable();
+	private FlexTable doExplorer() {
+		final FlexTable  table = new FlexTable();
         //and the the delegate to open an editor for a rule resource when
         //chosen to
         list = new AssetItemListViewer(new EditItemEvent() {
             public void open(String key) {                  
                 showLoadEditor( key );
-                
             }
         });    
-        //list.loadTableData( null );
         
+        
+        FlexCellFormatter formatter = table.getFlexCellFormatter();
+
+        
         //setup the nav, which will drive the list
 		CategoryExplorerWidget nav = new CategoryExplorerWidget(new CategorySelectHandler() {
             public void selected(final String selectedPath) {
                 Command load = getRuleListLoadingCommand( list,
                                            selectedPath );
+                table.setWidget( 0, 1, list );
                 DeferredCommand.add( load );
                 list.setRefreshCommand(load);                
             }
 
         });		
         
+        final QuickFindWidget quick = new QuickFindWidget(new EditItemEvent() {
+            public void open(String key) {                  
+                showLoadEditor( key );
+            }
+        });
         
-        FlexCellFormatter formatter = table.getFlexCellFormatter();
-        
         table.setWidget( 0, 0, nav );
-		table.setWidget( 0, 1, list);
+		table.setWidget( 0, 1, quick);
         
         formatter.setAlignment( 0, 1, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP );
         formatter.setAlignment( 0, 0, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP );        
@@ -111,25 +121,23 @@
         newRule.setTitle( "Create new rule" );
 
         newRule.addClickListener( new ClickListener() {
-
             public void onClick(Widget w) {
-              int left = 70;
-              int top = 100;
-                
-              NewAssetWizard pop = new NewAssetWizard(new EditItemEvent() {
-                  public void open(String key) {                  
-                      showLoadEditor( key );
-                      
-                  }
-              }, true, null, "Create a new rule");
-              pop.setPopupPosition( left, top );
-              
-              pop.show();
+              showNewAssetWizard();
             }
-            
         });
         
-        table.setWidget( 1, 0, newRule);
+        Image showFinder = new Image("images/find_items.gif");
+        showFinder.setTitle( "Show the name finder." );
+        showFinder.addClickListener( new ClickListener() {
+            public void onClick(Widget w) {
+                table.setWidget( 0, 1, quick );
+            }
+        } );
+        
+        HorizontalPanel actions = new HorizontalPanel();
+        actions.add( showFinder );
+        actions.add( newRule );
+        table.setWidget( 1, 0, actions);
         formatter.setHeight( 1, 0, "5%" );
         formatter.setAlignment( 1, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_TOP);
         formatter.setStyleName( 1, 0, "new-asset-Icons" );
@@ -157,6 +165,23 @@
         showLoadEditor( openedViewers, tab, uuid, false );
     }
 
+    private void showNewAssetWizard() {
+        int left = 70;
+          int top = 100;
+            
+          NewAssetWizard pop = new NewAssetWizard(new EditItemEvent() {
+              public void open(String key) {                  
+                  showLoadEditor( key );
+                  
+              }
+          }, true, null, "Create a new rule");
+          pop.setPopupPosition( left, top );
+          
+          pop.show();
+    }
+
+
+
     /**
      * This will show the rule viewer. If it was previously opened, it will show that dialog instead
      * of opening it again.

Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/categorynav/CategoryExplorerWidget.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/categorynav/CategoryExplorerWidget.java	2007-03-05 10:04:03 UTC (rev 9965)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/categorynav/CategoryExplorerWidget.java	2007-03-05 10:06:38 UTC (rev 9966)
@@ -83,7 +83,8 @@
                                                  it.addItem( new PendingItem() );
                                                  navTreeWidget.addItem( it );
                                              }
-                                             if (!empty) navTreeWidget.setSelectedItem( navTreeWidget.getItem( 0 ) );
+                                             //MN: disabling this to get rid of default selection
+                                             //if (!empty) navTreeWidget.setSelectedItem( navTreeWidget.getItem( 0 ) );
 
                                          }
 

Added: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/common/AutoCompleteTextBoxAsync.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/common/AutoCompleteTextBoxAsync.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/common/AutoCompleteTextBoxAsync.java	2007-03-05 10:06:38 UTC (rev 9966)
@@ -0,0 +1,252 @@
+package org.drools.brms.client.common;
+
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.ui.KeyboardListener;
+import com.google.gwt.user.client.ui.ListBox;
+import com.google.gwt.user.client.ui.PopupPanel;
+import com.google.gwt.user.client.ui.RootPanel;
+import com.google.gwt.user.client.ui.TextBox;
+import com.google.gwt.user.client.ui.Widget;
+
+/**
+ * This nifty utility provides auto completion. Drop in replacement for a text box.
+ * I recall lifting it from somewhere on http://del.icio.us/michaelneale/GWT, plus some 
+ * small tweaks. 
+ * 
+ * If this gives any back chat, I will shut it down and we can just use a regular text box.
+ * 
+ */
+public class AutoCompleteTextBoxAsync extends TextBox
+    implements KeyboardListener {
+
+  protected CompletionItemsAsync items = null;
+  protected boolean popupAdded = false;
+  protected boolean visible = false;
+  protected PopupPanel choicesPopup = new PopupPanel(true);
+  protected ListBox choices = new ListBox() {
+    public void onBrowserEvent(Event event) {
+      if (Event.ONCLICK == DOM.eventGetType(event)) {
+        complete();
+      }
+    }
+  };
+
+  /**
+   * Default Constructor
+   */
+  public AutoCompleteTextBoxAsync(CompletionItemsAsync comp)
+  {
+    super();
+    this.addKeyboardListener(this);
+    choices.sinkEvents(Event.ONCLICK);
+    this.setStyleName("AutoCompleteTextBox");
+
+    choicesPopup.add(choices);
+    choicesPopup.addStyleName("AutoCompleteChoices");
+
+    choices.setStyleName("list");
+    this.items = comp;
+  }
+
+  /**
+   * Sets an "algorithm" returning completion items
+   * You can define your own way how the textbox retrieves
+autocompletion items
+   * by implementing the CompletionItems interface and setting the
+according object
+   * @see SimpleAutoCompletionItem
+   * @param items CompletionItem implementation
+   */
+  public void setCompletionItems(CompletionItemsAsync items)
+  {
+    this.items = items;
+  }
+
+  /**
+   * Returns the used CompletionItems object
+   * @return CompletionItems implementation
+   */
+  public CompletionItemsAsync getCompletionItems()
+  {
+    return this.items;
+  }
+
+  /**
+   * Handle events that happen when keys are pressed.
+   */
+  public void onKeyDown(Widget arg0, char arg1, int arg2) {
+    if(arg1 == KEY_ENTER)
+    {
+      enterKey(arg0, arg1, arg2);
+    }
+    else if(arg1 == KEY_TAB)
+    {
+      tabKey(arg0, arg1, arg2);
+    }
+    else if(arg1 == KEY_DOWN)
+    {
+      downKey(arg0, arg1, arg2);
+    }
+    else if(arg1 == KEY_UP)
+    {
+      upKey(arg0, arg1, arg2);
+    }
+    else if(arg1 == KEY_ESCAPE)
+    {
+      escapeKey(arg0, arg1, arg2);
+    }
+  }
+
+  /**
+   * Not used at all
+   */
+  public void onKeyPress(Widget arg0, char arg1, int arg2) {
+  }
+
+  /**
+   * Handle events that happen when keys are released.
+   */
+  public void onKeyUp(Widget arg0, char arg1, int arg2) {
+    switch(arg1) {
+      case KEY_ALT:
+      case KEY_CTRL:
+      case KEY_DOWN:
+      case KEY_END:
+      case KEY_ENTER:
+      case KEY_ESCAPE:
+      case KEY_HOME:
+      case KEY_LEFT:
+      case KEY_PAGEDOWN:
+      case KEY_PAGEUP:
+      case KEY_RIGHT:
+      case KEY_SHIFT:
+      case KEY_TAB:
+      case KEY_UP:
+        break;
+      default:
+        otherKey(arg0, arg1, arg2);
+        break;
+    }
+  }
+
+  // The down key was pressed.
+  protected void downKey(Widget arg0, char arg1, int arg2) {
+    int selectedIndex = choices.getSelectedIndex();
+    selectedIndex++;
+    if (selectedIndex >= choices.getItemCount())
+    {
+      selectedIndex = 0;
+    }
+    choices.setSelectedIndex(selectedIndex);
+  }
+
+  // The up key was pressed.
+  protected void upKey(Widget arg0, char arg1, int arg2) {
+    int selectedIndex = choices.getSelectedIndex();
+    selectedIndex--;
+    if(selectedIndex < 0)
+    {
+      selectedIndex = choices.getItemCount() - 1;
+    }
+    choices.setSelectedIndex(selectedIndex);
+  }
+
+  // The enter key was pressed.
+  protected void enterKey(Widget arg0, char arg1, int arg2) {
+    complete();
+  }
+
+  // The tab key was pressed.
+  protected void tabKey(Widget arg0, char arg1, int arg2) {
+    complete();
+  }
+
+  // The escape key was pressed.
+  protected void escapeKey(Widget arg0, char arg1, int arg2) {
+    choices.clear();
+    choicesPopup.hide();
+    this.visible = false;
+  }
+
+  // Any other non-special key was pressed.
+  protected void otherKey(Widget arg0, char arg1, int arg2) {
+    // Update the existing choices in the list box to reflect the user's entry.
+    updateChoices(this.getText());
+
+    // If any text was entered, start an async callback.
+    if (this.getText().length() > 0 && items != null) {
+      items.getCompletionItems(this.getText(), new CompletionItemsAsyncReturn() {
+        public void itemReturn(String[] matches) {
+          updateChoices(matches, getText());
+        }
+      });
+    }
+  }
+
+  // Hides/shows the choice box as needed.
+  // Assumes all choices are currently valid.
+  protected void hideChoicesIfNeeded(String text) {
+    // Hide the list box under any of these conditions:
+    // - the text box is empty
+    // - there are no matching choices
+    // - there is only one choice that exactly matches the text box entry
+    // Show the list box under any other condition.
+    if (0 == text.length() || 0 == choices.getItemCount() ||
+      (1 == choices.getItemCount() &&
+choices.getItemText(0).equals(text))) {
+      choices.clear();
+      choicesPopup.hide();
+      visible = false;
+    } else {
+      choices.setSelectedIndex(0);
+      choices.setVisibleItemCount(choices.getItemCount() + 1);
+
+      if(!popupAdded) {
+        RootPanel.get().add(choicesPopup);
+        popupAdded = true;
+      }
+      choicesPopup.show();
+      visible = true;
+      choicesPopup.setPopupPosition(this.getAbsoluteLeft(),
+        this.getAbsoluteTop() + this.getOffsetHeight());
+      choices.setWidth(this.getOffsetWidth() + "px");
+    }
+  }
+
+  // Removes all items in the choices menu that do not start with the specified text.
+  protected void updateChoices(String text) {
+    int i = 0;
+    while (i < choices.getItemCount()) {
+      if (choices.getItemText(i).toLowerCase().startsWith(text.toLowerCase())) {
+        ++i;
+      } else {
+        choices.removeItem(i);
+      }
+    }
+    hideChoicesIfNeeded(text);
+  }
+
+  // Update the choices menu using the provided matches and entered text.
+  protected void updateChoices(String[] matches, String text) {
+    choices.clear();
+    for(int i = 0; i < matches.length; i++)
+    {
+      choices.addItem((String) matches[i]);
+    }
+    updateChoices(text);
+  }
+
+  // add selected item to textbox
+  protected void complete()
+  {
+    if(this.visible && choices.getItemCount() > 0)
+    {
+      this.setText(choices.getItemText(choices.getSelectedIndex()));
+    }
+    choices.clear();
+    choicesPopup.hide();
+    this.visible = false;
+  }
+
+} 


Property changes on: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/common/AutoCompleteTextBoxAsync.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/common/CompletionItemsAsync.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/common/CompletionItemsAsync.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/common/CompletionItemsAsync.java	2007-03-05 10:06:38 UTC (rev 9966)
@@ -0,0 +1,11 @@
+package org.drools.brms.client.common;
+
+public interface CompletionItemsAsync {
+    /**
+     * Makes a call to find all completion items matching.
+     * @param match The user-entered text all completion items have to match
+     * @param asyncReturn  The object invoked when the async call returns correctly
+     */
+    public void getCompletionItems(String match, CompletionItemsAsyncReturn asyncReturn);
+
+} 


Property changes on: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/common/CompletionItemsAsync.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/common/CompletionItemsAsyncReturn.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/common/CompletionItemsAsyncReturn.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/common/CompletionItemsAsyncReturn.java	2007-03-05 10:06:38 UTC (rev 9966)
@@ -0,0 +1,10 @@
+package org.drools.brms.client.common;
+
+public interface CompletionItemsAsyncReturn {
+    /**
+     * Handles an array of items. Called by <code>CompletionItemsAsync.getCompletionItems</code>
+     * @param items The array of compleition items
+     */
+    public void itemReturn(String[] items); 
+    
+}


Property changes on: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/common/CompletionItemsAsyncReturn.java
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/packages/PackageSnapshotView.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/packages/PackageSnapshotView.java	2007-03-05 10:04:03 UTC (rev 9965)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/packages/PackageSnapshotView.java	2007-03-05 10:06:38 UTC (rev 9966)
@@ -162,7 +162,7 @@
         }
         
         right.setWidth( "100%" );
-        right.setHeight( "100%" );
+        //right.setHeight( "100%" );
         right.addRow( table );
         table.setWidth( "100%" );
         right.setStyleName( SortableTable.styleList );

Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/RepositoryService.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/RepositoryService.java	2007-03-05 10:04:03 UTC (rev 9965)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/RepositoryService.java	2007-03-05 10:06:38 UTC (rev 9966)
@@ -164,4 +164,16 @@
      */
     public void copyOrRemoveSnapshot(String packageName, String snapshotName, boolean delete, String newSnapshotName) throws SerializableException;
     
+    
+    /**
+     * This will quickly return a list of asset names/descriptions.
+     * This list will be limited, and it will be flagged if more are found then can be shown.
+     * Returning an extra empty row means there are more to come... 
+     * 
+     * The id of a row is the UUID, the first value is the name, the next the description.
+     * Finally, if there is "more" rows, a row will be returned which has "MORE" as its ID.
+     * 
+     */
+    public TableDataResult quickFindAsset(String searchText, int maxMatches);
+    
 }

Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/RepositoryServiceAsync.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/RepositoryServiceAsync.java	2007-03-05 10:04:03 UTC (rev 9965)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/RepositoryServiceAsync.java	2007-03-05 10:06:38 UTC (rev 9966)
@@ -37,6 +37,7 @@
     public void listSnapshots(java.lang.String p0, AsyncCallback cb);
     public void createPackageSnapshot(java.lang.String p0, java.lang.String p1, boolean p2, java.lang.String p3, AsyncCallback cb);
     public void copyOrRemoveSnapshot(java.lang.String p0, java.lang.String p1, boolean p2, java.lang.String p3, AsyncCallback cb);
+    public void quickFindAsset(java.lang.String p0, int p2, AsyncCallback cb);
     public void changeState(java.lang.String p0, java.lang.String p1, boolean p2, AsyncCallback cb);
-
+    
 }

Added: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rulelist/QuickFindWidget.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rulelist/QuickFindWidget.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rulelist/QuickFindWidget.java	2007-03-05 10:06:38 UTC (rev 9966)
@@ -0,0 +1,179 @@
+package org.drools.brms.client.rulelist;
+
+import org.drools.brms.client.common.AutoCompleteTextBoxAsync;
+import org.drools.brms.client.common.CompletionItemsAsync;
+import org.drools.brms.client.common.CompletionItemsAsyncReturn;
+import org.drools.brms.client.common.FormStyleLayout;
+import org.drools.brms.client.common.GenericCallback;
+import org.drools.brms.client.common.LoadingPopup;
+import org.drools.brms.client.rpc.RepositoryServiceFactory;
+import org.drools.brms.client.rpc.TableDataResult;
+import org.drools.brms.client.rpc.TableDataRow;
+
+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.HorizontalPanel;
+import com.google.gwt.user.client.ui.KeyboardListener;
+import com.google.gwt.user.client.ui.Label;
+import com.google.gwt.user.client.ui.TextBox;
+import com.google.gwt.user.client.ui.Widget;
+
+/**
+ * This is for quickly finding an asset by name. Partial completion is allowed.
+ * This also uses some auto completion magic.
+ * @author Michael Neale
+ */
+public class QuickFindWidget extends Composite {
+
+    private final FormStyleLayout layout;
+    private final FlexTable listPanel;
+    private final TextBox searchBox;
+    private EditItemEvent editEvent;
+    private String[] shortListItems;
+    
+    
+    public QuickFindWidget(EditItemEvent editEvent) {
+        layout = new FormStyleLayout("images/search_large.gif", "Find rules");
+        
+        
+        
+        searchBox = new AutoCompleteTextBoxAsync(new CompletionItemsAsync() {
+
+            public void getCompletionItems(String match,
+                                           CompletionItemsAsyncReturn asyncReturn) {
+                loadShortList(match, asyncReturn);
+                
+            }
+
+            
+        });
+        
+        this.editEvent = editEvent;
+        HorizontalPanel srch = new HorizontalPanel();
+        Button go = new Button("Go");
+        go.addClickListener( new ClickListener() {
+            public void onClick(Widget w) {
+               updateList();
+            }
+        } );
+        
+        srch.add( searchBox );
+        srch.add( go ); 
+        layout.addAttribute( "Find items with a name matching:", srch );
+        layout.addRow( new HTML("<hr/>") );
+        
+        listPanel = new FlexTable();
+        listPanel.setWidget( 0, 0, new HTML("Enter the name or part of a name. Alternatively, use the categories to browse.") );
+        layout.addRow(listPanel);
+        
+        listPanel.setStyleName( "editable-Surface" );
+        
+        
+        searchBox.addKeyboardListener( getKeyboardListener());
+        
+        initWidget( layout );
+    }
+
+    /**
+     * This will load a list of items as they are typing.
+     */
+    protected String[] loadShortList(String match, final CompletionItemsAsyncReturn returnItems) {
+        RepositoryServiceFactory.getService().quickFindAsset( match, 5, new GenericCallback() {
+
+
+            public void onSuccess(Object data) {
+                TableDataResult result = (TableDataResult) data;
+                String[] items = new String[result.data.length];
+                for ( int i = 0; i < result.data.length; i++ ) {
+                    if (!result.data[i].id.equals( "MORE" )) {
+                        items[i] = result.data[i].values[0];
+                    }
+                }
+                returnItems.itemReturn( items ); 
+            }
+            
+        });
+        return shortListItems;
+    }
+
+    private KeyboardListener getKeyboardListener() {
+        return new KeyboardListener() {
+            public void onKeyDown(Widget arg0,
+                                  char arg1,
+                                  int arg2) {
+            }
+
+            public void onKeyPress(Widget arg0,
+                                   char arg1,
+                                   int arg2) {
+            }
+
+            public void onKeyUp(Widget arg0,
+                                char arg1,
+                                int arg2) {
+                if (arg1 == KEY_ENTER) {
+                    
+                    updateList();
+                }
+            }
+            
+        };
+    }
+
+    protected void updateList() {
+
+        LoadingPopup.showMessage( "Searching..." );
+        RepositoryServiceFactory.getService().quickFindAsset( searchBox.getText(), 15, new GenericCallback() {
+            public void onSuccess(Object data) {
+                TableDataResult result = (TableDataResult) data;
+                populateList(result);
+                
+            }
+        });
+        
+    }
+
+    protected void populateList(TableDataResult result) {
+        
+        
+        FlexTable data = new FlexTable();
+        
+        //if its only one, just open it...
+        if (result.data.length == 1) {
+            editEvent.open( result.data[0].id );
+        }
+        
+        for ( int i = 0; i < result.data.length; i++ ) {
+            
+            final TableDataRow row = result.data[i];
+            if (row.id.equals( "MORE" )) {
+                data.setWidget( i, 0, new HTML("<i>There are more items... try narrowing the search terms..</i>") );
+                data.getFlexCellFormatter().setColSpan( i, 0, 3 );
+            } else {
+                data.setWidget( i, 0, new Label(row.values[0]) );
+                data.setWidget( i, 1, new Label(row.values[1]) );
+                Button open = new Button("Open");
+                open.addClickListener( new ClickListener() {
+                    public void onClick(Widget w) {
+                        editEvent.open( row.id );
+                    }
+                } );
+                
+                data.setWidget( i, 2, open );
+            }
+            
+
+        }
+        
+        data.setWidth( "100%" );
+        listPanel.setWidget( 0, 0, data);
+        
+        LoadingPopup.close();
+        
+    }
+    
+    
+}


Property changes on: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rulelist/QuickFindWidget.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/public/images/find_items.gif
===================================================================
(Binary files differ)


Property changes on: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/public/images/find_items.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/public/images/search_large.gif
===================================================================
(Binary files differ)


Property changes on: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/public/images/search_large.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/server/JBRMSServiceServlet.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/server/JBRMSServiceServlet.java	2007-03-05 10:04:03 UTC (rev 9965)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/server/JBRMSServiceServlet.java	2007-03-05 10:06:38 UTC (rev 9966)
@@ -8,6 +8,8 @@
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.jcr.RepositoryException;
 import javax.servlet.http.HttpSession;
@@ -505,6 +507,47 @@
         }
         
     }
+
+    public TableDataResult quickFindAsset(String searchText, int max) {
+        
+        RulesRepository repo = getRulesRepository();
+        String search = Pattern.compile("*", Pattern.LITERAL).matcher(searchText).replaceAll(Matcher.quoteReplacement("%"));
+        
+        if (!search.endsWith( "%" )) {
+            search += "%";
+        }
+        
+        
+        TableDataResult result = new TableDataResult();
+        
+        List resultList = new ArrayList();        
+        
+        long start = System.currentTimeMillis();        
+        AssetItemIterator it = repo.findAssetsByName( search );
+        System.out.println(System.currentTimeMillis() - start);
+        for(int i = 0; i < max; i++) {
+            if (!it.hasNext()) {
+                break;
+            } 
+            
+            AssetItem item = (AssetItem) it.next();
+            TableDataRow row = new TableDataRow();
+            row.id = item.getUUID();
+            row.values = new String[] { item.getName(), item.getDescription() };
+            resultList.add( row );
+           
+        }
+        
+        if (it.hasNext()) {
+            TableDataRow empty = new TableDataRow();
+            empty.id = "MORE";
+            resultList.add( empty );
+        }
+        
+        result.data = (TableDataRow[]) resultList.toArray( new TableDataRow[resultList.size()] );
+        return result;
+        
+    }
     
 
 

Modified: labs/jbossrules/trunk/drools-jbrms/src/test/java/org/drools/brms/server/ServiceImplementationTest.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/test/java/org/drools/brms/server/ServiceImplementationTest.java	2007-03-05 10:04:03 UTC (rev 9965)
+++ labs/jbossrules/trunk/drools-jbrms/src/test/java/org/drools/brms/server/ServiceImplementationTest.java	2007-03-05 10:06:38 UTC (rev 9966)
@@ -390,7 +390,18 @@
       assertEquals(5, res.data.length);
       
 
+      TableDataResult result = impl.quickFindAsset( "testListByForma", 5 );
+      assertEquals(5, result.data.length);
       
+      assertNotNull(result.data[0].id);
+      assertTrue(result.data[0].values[0].startsWith( "testListByFormat" ));
+      
+      result = impl.quickFindAsset( "testListByForma", 3 );
+      assertEquals(4, result.data.length);
+      
+      assertEquals("MORE", result.data[3].id);
+      
+      
   }
   
   public String[] arr(String s) {




More information about the jboss-svn-commits mailing list