Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 7 | Rev 9 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7 Rev 8
Line 19... Line 19...
19
*/
19
*/
20
package org.tela_botanica.client;
20
package org.tela_botanica.client;
Line 21... Line 21...
21
 
21
 
22
 
22
 
23
// TODO : traiter latence (augmenter en fonction rapidité saisie + texte vide)
-
 
24
// TODO : traiter Tab (selection)
-
 
Line 25... Line 23...
25
// TODO : revoir traitement keyup, keydown
23
// TODO : traiter latence (augmenter en fonction rapidité saisie + texte vide)
26
// TODO : reactiver le cache (du design à revoir dans ce cas la) 
24
// TODO : traitement espace apres l'espece (%20)
27
 
-
 
28
import com.google.gwt.user.client.HTTPRequest;
25
 
29
import com.google.gwt.user.client.ResponseTextHandler;
26
import com.google.gwt.user.client.HTTPRequest;
30
import com.google.gwt.user.client.ui.ChangeListener;
27
import com.google.gwt.user.client.ResponseTextHandler;
31
import com.google.gwt.user.client.ui.KeyboardListener;
28
import com.google.gwt.user.client.ui.KeyboardListener;
32
import com.google.gwt.user.client.ui.ListBox;
29
import com.google.gwt.user.client.ui.ListBox;
33
import com.google.gwt.user.client.ui.PopupPanel;
30
import com.google.gwt.user.client.ui.PopupPanel;
-
 
31
import com.google.gwt.user.client.ui.RootPanel;
-
 
32
import com.google.gwt.user.client.ui.TextBox;
Line 34... Line 33...
34
import com.google.gwt.user.client.ui.RootPanel;
33
import com.google.gwt.user.client.ui.Widget;
35
import com.google.gwt.user.client.ui.TextBox;
34
import com.google.gwt.user.client.DOM;
Line 36... Line 35...
36
import com.google.gwt.user.client.ui.Widget;
35
import com.google.gwt.user.client.Event; 
37
 
36
 
Line 38... Line 37...
38
import java.util.Vector;
37
import java.util.Vector;
39
import java.util.HashMap;
38
import java.util.HashMap;
Line 40... Line 39...
40
 
39
 
41
 
40
 
42
 
41
 
Line 43... Line 42...
43
public class AutoCompleteAsyncTextBox extends TextBox
42
public class AutoCompleteAsyncTextBox extends TextBox
44
    implements KeyboardListener, ChangeListener, SourcesAutoCompleteAsyncTextBoxEvents {
43
    implements KeyboardListener, SourcesAutoCompleteAsyncTextBoxEvents {
-
 
44
   
-
 
45
  private String searchUrl = null; 
-
 
46
  private AutoCompleteAsyncTextBoxListenerCollection autoCompleteAsyncTextBoxListeners=null;  
-
 
47
    
-
 
48
  private HashMap cache = new HashMap();
-
 
49
  private boolean searching = false;
45
   
50
  private ResponseTextHandler responseTextHandler=null;
46
  private String searchUrl = null; 
51
		  
47
  private AutoCompleteAsyncTextBoxListenerCollection autoCompleteAsyncTextBoxListeners=null;  
52
  protected PopupPanel choicesPopup = new PopupPanel(true);
48
    
53
  protected ListBox choices = new ListBox() {
Line -... Line 54...
-
 
54
	  public void onBrowserEvent(Event event) {
49
  private HashMap cache = new HashMap();
55
		  if (Event.ONCLICK == DOM.eventGetType(event)) {
50
  private boolean searching = false;
56
			  complete();
51
  private ResponseTextHandler responseTextHandler=null;
57
		  }
52
		  
58
	  } 
53
  protected PopupPanel choicesPopup = new PopupPanel(true);
59
  };
54
  protected ListBox choices = new ListBox();
60
  protected Vector items = new Vector(); 
55
  protected Vector items = new Vector(); 
61
  protected boolean popupAdded = false;
56
  protected boolean popupAdded = false;
62
  protected boolean visible = false;
57
  protected boolean visible = false;
63
  protected String currentValue = null;
58
  protected String currentValue = null;
64
  
59
   
65
   
Line 60... Line 66...
60
   
66
   
61
  /**
67
  /**
Line 110... Line 116...
110
  
116
  
111
  /**
117
  /**
112
   * Not used at all
118
   * Not used at all
113
   */
119
   */
-
 
120
  public void onKeyDown(Widget arg0, char arg1, int arg2) {
-
 
121
	  
-
 
122
	  
-
 
123
	  if(arg1 == KEY_ENTER)
-
 
124
	    {
-
 
125
	      enterKey(arg0, arg1, arg2);
-
 
126
	    }
-
 
127
	    else if(arg1 == KEY_DOWN)
-
 
128
	    {
-
 
129
	      downKey(arg0, arg1, arg2);
-
 
130
	    }
-
 
131
	    else if(arg1 == KEY_UP)
-
 
132
	    {
-
 
133
	      upKey(arg0, arg1, arg2);
-
 
134
	    }
-
 
135
	    else if(arg1 == KEY_ESCAPE)
-
 
136
	    {
114
  public void onKeyDown(Widget arg0, char arg1, int arg2) {
137
	      escapeKey(arg0, arg1, arg2);
Line -... Line 138...
-
 
138
	    }
-
 
139
	  	
115
  }
140
	  
116
 
141
  }	 
117
  /**
142
  /**
118
   * Not used at all
143
   * Not used at all (probleme avec ie, qui ne comprend pas les touches meta)
Line -... Line 144...
-
 
144
   */
-
 
145
  public void onKeyPress(Widget arg0, char arg1, int arg2) {
-
 
146
	
119
   */
147
 
-
 
148
  }
120
  public void onKeyPress(Widget arg0, char arg1, int arg2) {
149
  
121
	 
150
  // The down key was pressed.
122
	    if(arg1 == KEY_DOWN)
151
  protected void downKey(Widget arg0, char arg1, int arg2) {
123
	    {
152
	  
124
	      int selectedIndex = choices.getSelectedIndex();
153
	    int selectedIndex = choices.getSelectedIndex();
125
	      selectedIndex++;
154
	    selectedIndex++;
126
	      if(selectedIndex >= choices.getItemCount())
155
	    if (selectedIndex >= choices.getItemCount())
127
	      {
156
	    {
128
	        selectedIndex = 0;
-
 
129
	      }
-
 
130
	      choices.setSelectedIndex(selectedIndex);
157
	      selectedIndex = 0;
Line 131... Line 158...
131
	           
158
	    }
132
	      return;
159
	    choices.setSelectedIndex(selectedIndex);
133
	    }
160
 }
134
	       
161
 
135
	    if(arg1 == KEY_UP)
162
  // The up key was pressed.
136
	    {
163
  protected void upKey(Widget arg0, char arg1, int arg2) {
137
	      int selectedIndex = choices.getSelectedIndex();
164
    int selectedIndex = choices.getSelectedIndex();
138
	      selectedIndex--;
165
    selectedIndex--;
139
	      if(selectedIndex < 0)
166
    if(selectedIndex < 0)
140
	      {
-
 
141
	        selectedIndex = choices.getItemCount() - 1 ;
-
 
142
	      }
-
 
143
	      choices.setSelectedIndex(selectedIndex);
-
 
144
	           
-
 
145
	      return;        
-
 
146
	    }
-
 
147
	  
-
 
148
	  
-
 
149
  }
-
 
150
 
-
 
151
  /**
-
 
152
   * A key was released, start autocompletion
-
 
153
   */
-
 
154
  public void onKeyUp(Widget arg0, char arg1, int arg2) {
-
 
155
 
-
 
156
 
-
 
157
	 if(arg1 == KEY_DOWN)
-
 
158
	 {
-
 
159
		 return;
-
 
160
 
-
 
161
	 }
-
 
162
	 
-
 
163
 
-
 
164
	 if(arg1 == KEY_UP)
167
    {
Line 165... Line 168...
165
	 {
168
      selectedIndex = choices.getItemCount() - 1;
166
		 return;
169
    }
167
 
170
    choices.setSelectedIndex(selectedIndex);
168
	 }
171
  } 
169
 
172
 
170
    if(arg1 == KEY_ENTER)
173
  // The enter key was pressed.
171
    {
174
  protected void enterKey(Widget arg0, char arg1, int arg2) {
172
      if(visible)
175
      if(visible)
173
      {
176
      {
174
        complete();
177
        complete();
175
      }
178
      }
176
      else {
179
      else {
177
    	 // Validation de l'entree : 
180
    	 // Validation de l'entree : appel asynchrone  
178
          if (autoCompleteAsyncTextBoxListeners!= null) {
181
          if (autoCompleteAsyncTextBoxListeners!= null) {
Line 179... Line -...
179
              autoCompleteAsyncTextBoxListeners.fireTextBoxEnter(this,this.getText(),currentValue);
-
 
180
          }
182
              autoCompleteAsyncTextBoxListeners.fireTextBoxEnter(this,this.getText(),currentValue);
Line 181... Line 183...
181
    	  currentValue=null;
183
          }
182
    	  this.setText("");
-
 
-
 
184
    	  currentValue=null;
183
      }
185
    	  this.setText("");
184
           
186
      }
185
      return;
187
 
186
    }
188
  }
Line 187... Line -...
187
       
-
 
188
    if(arg1 == KEY_ESCAPE)
189
 
Line -... Line 190...
-
 
190
//The escape key was pressed.
-
 
191
  protected void escapeKey(Widget arg0, char arg1, int arg2) {
-
 
192
    choices.clear();
-
 
193
    items.clear();
189
    {
194
    choicesPopup.hide();
190
      choices.clear();
195
    visible = false;
Line -... Line 196...
-
 
196
 
191
      items.clear();
197
  } 
192
      choicesPopup.hide();
198
 
-
 
199
 
193
      visible = false;
200
  // Any other non-special key was pressed.
Line 194... Line 201...
194
           
201
  protected void otherKey(Widget arg0, char arg1, int arg2) {
195
      return;
202
   
196
    }
203
	
Line 210... Line 217...
210
      else {
217
		      else {
Line 211... Line 218...
211
     
218
		     
212
    	  this.doFetchURL(text);
219
		    	  this.doFetchURL(text);
213
      }
220
		      }
-
 
221
		 }
-
 
222
   
-
 
223
	
-
 
224
	    
-
 
225
    
-
 
226
  } 
-
 
227
  
-
 
228
  public void onKeyUp(Widget arg0, char arg1, int arg2) {
-
 
229
	  
-
 
230
	  switch(arg1) {
-
 
231
      case KEY_ALT:
-
 
232
      case KEY_CTRL:
-
 
233
      case KEY_DOWN:
-
 
234
      case KEY_END:
-
 
235
      case KEY_ENTER:
-
 
236
      case KEY_ESCAPE:
-
 
237
      case KEY_HOME:
-
 
238
      case KEY_LEFT:
-
 
239
      case KEY_PAGEDOWN:
-
 
240
      case KEY_PAGEUP:
-
 
241
      case KEY_RIGHT:
-
 
242
      case KEY_SHIFT:
-
 
243
      case KEY_TAB:
-
 
244
      case KEY_UP:
-
 
245
        break;
-
 
246
      default:
-
 
247
        otherKey(arg0, arg1, arg2);
-
 
248
        break;
-
 
249
    }
214
    }
250
 
Line 215... Line 251...
215
  }
251
  }
Line 233... Line 269...
233
	      }
269
	      }
Line 234... Line 270...
234
	      
270
	      
235
	           
271
	           
236
	      // if there is only one match and it is what is in the
272
	      // if there is only one match and it is what is in the
237
	      // text field anyways there is no need to show autocompletion
273
	      // text field anyways there is no need to show autocompletion
238
	      if(items.size() == 1 && (((String []) items.get(0))[0]).compareTo(this.getText()) == 0)
274
	    //  if(items.size() == 1 && (((String []) items.get(0))[0]).compareTo(this.getText()) == 0)
239
	      {
275
	     // {
240
	        choicesPopup.hide();
276
	       // choicesPopup.hide();
241
	      } else {
277
	     // } else {
Line 242... Line 278...
242
	        choices.setSelectedIndex(0);
278
	        choices.setSelectedIndex(0);
243
	        choices.setVisibleItemCount(items.size());
279
	        choices.setVisibleItemCount(items.size());
Line 249... Line 285...
249
	        }
285
	        }
250
	        choicesPopup.show();
286
	        choicesPopup.show();
251
	        visible = true;
287
	        visible = true;
252
	        choicesPopup.setPopupPosition(this.getAbsoluteLeft(),
288
	        choicesPopup.setPopupPosition(this.getAbsoluteLeft(),
253
	        this.getAbsoluteTop() + this.getOffsetHeight());
289
	        this.getAbsoluteTop() + this.getOffsetHeight());
254
	        //choicesPopup.setWidth(this.getOffsetWidth() + "px");
290
	        choicesPopup.setWidth(this.getOffsetWidth() + "px");
255
	        choices.setWidth(this.getOffsetWidth() + "px");
291
	        choices.setWidth(this.getOffsetWidth() + "px");
256
	      }
292
	    //  }
Line 257... Line 293...
257
	
293
	
258
	    } else {
294
	    } else {
259
	      visible = false;
295
	      visible = false;
260
	      choicesPopup.hide();
296
	      choicesPopup.hide();
Line 266... Line 302...
266
   */
302
   */
267
  public void onChange(Widget arg0) {
303
  public void onChange(Widget arg0) {
268
    complete();
304
    complete();
269
  }
305
  }
Line -... Line 306...
-
 
306
  
270
 
307
 
271
  public void onClick(Widget arg0) {
308
  public void onClick(Widget arg0) {
272
    complete();
309
    complete();
Line 273... Line 310...
273
  }
310
  }