Netbeans met GWT and more GWT components

I wrote about my first experience with GWT in my last blog. Yesterday I experimented with GWT application in NetBeans. The new GWT plugin contains GWT project type. It is now easy build, run and debug GWT projects in NetBeans. The code completion with javadoc is also available. Tomas will publish his plugin early, I hope.

On http://gwt.components.googlepages.com/ are more GWT components. My favorite is Auto-Completion Textbox. It allows to add Code completion to Texbox on web page. The AutoCompleteTextBox component extends TextBox class. It adds to TextBox one new useful method:

public void setCompletionItems(CompletionItems items)
The CoompletionItems type is code completion provider:
public interface CompletionItems {
        /\*\*
         \* Returns an array of all completion items matching
         \* @param match The user-entered text all compleition items have to match
         \* @return      Array of strings
         \*/
        public String[] getCompletionItems(String match);
}
I wrote a simple application with AutoCompleteTextBox. The class with GWT EntryPoint is below. It shows code completion for names.
public class Main implements EntryPoint {
    
    class NameCompletionItem implements CompletionItems {
        public String[] getCompletionItems(String match) {
            ArrayList list = new ArrayList();
            
            String values[] =  new String[]{"roumen","radim","xzajo","geertjan","lukas"}; 
            
            String lowerMatch = match.toLowerCase();
            for (int i = 0 ; i < values.length ; i++) {
                String value = values[i];
                if (value.startsWith(lowerMatch)) {
                    list.add(value);
                }
            }
            String retVals [] = new String[list.size()];
            
            for (int i = 0 ; i < list.size() ; i++) {
               retVals[i] = (String) list.get(i); 
            }
            return retVals;
        }
        
        
    }
    public void onModuleLoad() {
        AutoCompletionTexBox textBox = new AutoCompletionTexBox();
        textBox.setCompletionItems(new NameCompletionItem());
        RootPanel.get().add(textBox);
    }
    
}

Conversion between ArrayList and array of Strings doesn't work on client side of GWT (Collection.toArray(Object[] array). The gwt compiler shows an error. Therefore I used the for loop. Screenshot with code completion in browser is below.


Comments:

Post a Comment:
Comments are closed for this entry.
About

xzajo

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today