Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 2 | Rev 6 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 4
Line 21... Line 21...
21
 
21
 
22
 
22
 
23
// TODO : traiter latence (augmenter en fonction rapidité saisie + texte vide)
23
// TODO : traiter latence (augmenter en fonction rapidité saisie + texte vide)
-
 
24
// TODO : traiter Tab (selection)
Line 24... Line -...
24
// TODO : traiter Tab (selection)
-
 
25
// TODO : revoir traitement keyup, keydown
-
 
26
 
-
 
27
import com.google.gwt.json.client.JSONArray;
-
 
28
import com.google.gwt.json.client.JSONParser;
25
// TODO : revoir traitement keyup, keydown
29
import com.google.gwt.json.client.JSONString;
26
// TODO : reactiver le cache (du design à revoir dans ce cas la) 
30
import com.google.gwt.json.client.JSONValue;
27
 
31
import com.google.gwt.user.client.HTTPRequest;
28
import com.google.gwt.user.client.HTTPRequest;
32
import com.google.gwt.user.client.ResponseTextHandler;
29
import com.google.gwt.user.client.ResponseTextHandler;
Line 49... Line 46...
49
  private String searchUrl = null; 
46
  private String searchUrl = null; 
50
  private AutoCompleteAsyncTextBoxListenerCollection autoCompleteAsyncTextBoxListeners=null;  
47
  private AutoCompleteAsyncTextBoxListenerCollection autoCompleteAsyncTextBoxListeners=null;  
Line 51... Line 48...
51
    
48
    
52
  private HashMap cache = new HashMap();
49
  private HashMap cache = new HashMap();
-
 
50
  private boolean searching = false;
Line 53... Line 51...
53
  private boolean searching = false;
51
  private ResponseTextHandler responseTextHandler=null;
54
		  
52
		  
55
  protected PopupPanel choicesPopup = new PopupPanel(true);
53
  protected PopupPanel choicesPopup = new PopupPanel(true);
56
  protected ListBox choices = new ListBox();
54
  protected ListBox choices = new ListBox();
57
  protected Vector items = new Vector(); 
55
  protected Vector items = new Vector(); 
-
 
56
  protected boolean popupAdded = false;
-
 
57
  protected boolean visible = false;
Line 58... Line 58...
58
  protected boolean popupAdded = false;
58
  protected int current = -1;
59
  protected boolean visible = false;
59
   
60
   
60
   
61
  /**
61
  /**
62
   * Default Constructor
62
   * Default Constructor
63
   *
63
   *
64
   */
64
   */
-
 
65
  public AutoCompleteAsyncTextBox(ResponseTextHandler rsp)
65
  public AutoCompleteAsyncTextBox()
66
  {
66
  {
67
    super();
67
    super();
68
    responseTextHandler=rsp;
Line 68... Line 69...
68
    this.addKeyboardListener(this);
69
    this.addKeyboardListener(this);
Line 94... Line 95...
94
  
95
  
95
  private void doFetchURL(String match) {
96
  private void doFetchURL(String match) {
96
	  /*
97
	  /*
97
	   * Here we fetch the URL and call the handler
98
	   * Here we fetch the URL and call the handler
-
 
99
	   */	  
-
 
100
	 
Line 98... Line 101...
98
	   */	  
101
	  String rematch=match.replaceFirst(" ","/");
99
	  
102
	  
100
	  if (this.searchUrl!=null && searching==false) {
103
	  if (this.searchUrl!=null && searching==false) {
101
		  searching=true;
-
 
102
	      HTTPRequest.asyncGet(this.searchUrl + match, 
-
 
103
	  		    new ResponseTextHandler(){
-
 
104
	    	  		public void onCompletion(String str) {
-
 
105
	    		  
-
 
106
	    	  			JSONValue jsonValue= JSONParser.parse(str);
-
 
107
	    	  			JSONArray jsonArray;
-
 
108
	    	  			JSONString jsonString;
-
 
109
 
-
 
110
	    	  			if ((jsonArray = jsonValue.isArray()) != null) {
-
 
111
	    	  				for (int i = 0; i < jsonArray.size(); ++i) {
-
 
112
	    	  					if ((jsonString = (jsonArray.get(i)).isString()) != null) {
-
 
113
	    	  						addItem(jsonString.stringValue());
-
 
114
	    	  					}
-
 
115
	    	  				}
-
 
116
	    	  			}
-
 
117
 
-
 
118
	    	  			displayList();
-
 
119
	    		            
-
 
120
 
-
 
121
	    		  
-
 
122
	    		  }	  
-
 
123
	    			
-
 
124
	    			  
-
 
Line 125... Line 104...
125
 
104
		  searching=true;
126
	  		    });
105
	      HTTPRequest.asyncGet(this.searchUrl + rematch, responseTextHandler );
Line 195... Line 174...
195
        complete();
174
        complete();
196
      }
175
      }
197
      else {
176
      else {
198
    	 // Validation de l'entree : 
177
    	 // Validation de l'entree : 
199
          if (autoCompleteAsyncTextBoxListeners!= null) {
178
          if (autoCompleteAsyncTextBoxListeners!= null) {
200
              autoCompleteAsyncTextBoxListeners.fireTextBoxEnter(this, this.getText());
179
              autoCompleteAsyncTextBoxListeners.fireTextBoxEnter(this,current, this.getText());
201
          }
180
          }
202
    	  
-
 
-
 
181
    	  current=-1;
203
    	  this.setText("");
182
    	  this.setText("");
204
      }
183
      }
Line 205... Line 184...
205
           
184
           
206
      return;
185
      return;
Line 222... Line 201...
222
    
201
    
223
    if(text.length() > 0)
202
    if(text.length() > 0)
224
    {
203
    {
Line 225... Line 204...
225
      items.clear();
204
      items.clear();
226
      
205
      
227
      if (getFromCache(text)!=null) {
206
/*      if (getFromCache(text)!=null) {
228
    	  items=getFromCache(text);
207
    	  items=getFromCache(text);
229
    	  displayList();
208
    	  displayList();
230
      }
209
      }
231
      else {
210
      else {*/
232
    	  this.doFetchURL(text);
211
    	  this.doFetchURL(text);
233
      }
212
      //}
Line 234... Line 213...
234
    }
213
    }
Line 241... Line 220...
241
    	
220
    	
242
    	searching=false;
221
    	searching=false;
243
	    if(this.items.size() > 0)
222
	    if(this.items.size() > 0)
Line 244... Line 223...
244
	    {
223
	    {
Line 245... Line 224...
245
	    	
224
	    	
Line 246... Line 225...
246
	      addToCache(this.getText(),(Vector) items.clone());
225
	      //addToCache(this.getText(),(Vector) items.clone());
247
	      
226
	      
Line 296... Line 275...
296
  protected void complete()
275
  protected void complete()
297
  {
276
  {
298
    if(choices.getItemCount() > 0)
277
    if(choices.getItemCount() > 0)
299
    {
278
    {
300
      this.setText(choices.getItemText(choices.getSelectedIndex()));
279
      this.setText(choices.getItemText(choices.getSelectedIndex()));
-
 
280
      current=choices.getSelectedIndex();
301
    }
281
    }
Line 302... Line 282...
302
 
282
 
303
    visible=false;
283
    visible=false;
304
    items.clear();
284
    items.clear();