Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 2392 Rev 2602
Line 1... Line 1...
1
package org.tela_botanica.client.util;
1
package org.tela_botanica.client.util;
Line 2... Line 2...
2
 
2
 
3
import java.util.ArrayList;
3
import java.util.ArrayList;
4
import java.util.Iterator;
4
import java.util.Iterator;
-
 
5
import java.util.List;
-
 
6
import java.util.Map;
-
 
7
 
5
import java.util.List;
8
import org.tela_botanica.client.cel2;
6
import org.tela_botanica.client.interfaces.Rafraichissable;
9
import org.tela_botanica.client.interfaces.Rafraichissable;
7
import org.tela_botanica.client.modeles.dao.ListeReferentielChampsEtendusDAO;
10
import org.tela_botanica.client.modeles.dao.ListeReferentielChampsEtendusDAO;
-
 
11
import org.tela_botanica.client.modeles.objets.Configuration;
Line 8... Line 12...
8
import org.tela_botanica.client.modeles.objets.Configuration;
12
import org.tela_botanica.client.util.autocompletion.AutoCompletionComboBox;
-
 
13
 
9
 
14
import com.google.gwt.core.client.Callback;
10
import com.google.gwt.core.client.Callback;
15
import com.google.gwt.http.client.Response;
11
import com.google.gwt.user.client.Timer;
16
import com.google.gwt.user.client.Timer;
12
import com.gwtext.client.core.EventCallback;
17
import com.gwtext.client.core.EventCallback;
13
import com.gwtext.client.core.EventObject;
18
import com.gwtext.client.core.EventObject;
Line 24... Line 29...
24
import com.gwtext.client.widgets.ToolTip;
29
import com.gwtext.client.widgets.ToolTip;
25
import com.gwtext.client.widgets.form.ComboBox;
30
import com.gwtext.client.widgets.form.ComboBox;
26
import com.gwtext.client.widgets.form.Field;
31
import com.gwtext.client.widgets.form.Field;
27
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
32
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
Line 28... Line 33...
28
 
33
 
29
public class ChampSaisieEtendu extends ComboBox implements Rafraichissable {
-
 
30
		// TODO: faire un enum
-
 
31
		private final int KEY_ALT = 18;
-
 
32
		private final int KEY_BACKSPACE = 8;
-
 
33
		private final int KEY_CTRL = 17;
-
 
34
		private final int KEY_DELETE = 46;
-
 
35
		private final int KEY_DOWN = 40;
-
 
36
		private final int KEY_END = 35;
-
 
37
		private final int KEY_ENTER = 13;
-
 
38
		private final int KEY_ESCAPE = 27;
-
 
39
		private final int KEY_HOME = 36;
-
 
40
		private final int KEY_LEFT = 37;
-
 
41
		private final int KEY_PAGEDOWN = 34;
-
 
42
		private final int KEY_PAGEUP = 33;
-
 
43
		private final int KEY_RIGHT = 39;
-
 
44
		private final int KEY_SHIFT = 16;
-
 
45
		private final int KEY_TAB = 9;
-
 
46
		private final int KEY_UP = 38;
-
 
47
		
-
 
48
		private boolean selectionValeur = false;
-
 
Line 49... Line 34...
49
		private boolean estModifie = false;
34
public class ChampSaisieEtendu extends AutoCompletionComboBox {
50
		
35
		
51
		private String cle = null;
-
 
52
		private String label = null;
-
 
53
				
-
 
54
		private Timer timer = null;
-
 
55
		
-
 
56
		final String resultTplRefPerso = "<div class=\"search-item-ref\">{valeur}</div>"; 
-
 
57
		
-
 
58
		private List<String> cacheValeurs;
-
 
Line 59... Line 36...
59
		private Record rdSelectionne = null;
36
		private String cle = null;
60
		private String valeurBrute = "";
37
		private String label = null;
Line 61... Line 38...
61
		
38
		
62
		private String description = null;
-
 
63
		private ToolTip tpDesc = null;
-
 
Line -... Line 39...
-
 
39
		private String description = null;
64
		
40
		private ToolTip tpDesc = null;
65
		public ChampSaisieEtendu(String label, String cle) {
41
		
Line 66... Line -...
66
 
-
 
67
			super(label,cle);  
-
 
68
 
-
 
69
			this.cle =cle;
-
 
70
			this.label = label;
-
 
71
			
-
 
72
			setTpl(resultTplRefPerso);
-
 
73
			setMode(ComboBox.REMOTE);
-
 
74
			setItemSelector("div.search-item-ref");
-
 
75
			setTypeAhead(false);  
-
 
76
			setLoadingText("Recherche...");  
-
 
77
			setHideTrigger(true);
-
 
78
			setValidateOnBlur(false);
-
 
79
			
-
 
80
		    ListenerConfig listenerConfigAutocompletion=new ListenerConfig();
-
 
81
		    listenerConfigAutocompletion.setDelay(200);
-
 
82
		    listenerConfigAutocompletion.setStopPropagation(false);
-
 
83
		    listenerConfigAutocompletion.setStopEvent(false);
-
 
84
		    initStoreVide();
-
 
85
			
-
 
86
		    if(Configuration.saisieChampsEtendusActivee()) {
-
 
87
				addKeyPressListener(new EventCallback() {
-
 
88
	
-
 
89
					@Override
-
 
90
					public void execute(EventObject e) {
-
 
91
	
-
 
92
						switch(e.getKey()) {
-
 
93
		  	    	      
-
 
94
						  case KEY_ALT:
-
 
95
		  	    	      case KEY_CTRL:
-
 
96
		  	    	      case KEY_END:
-
 
97
		  	    	      case KEY_ESCAPE:
-
 
98
		  	    	      case KEY_HOME:
-
 
99
		  	    	      case KEY_LEFT:
-
 
100
		  	    	      case KEY_PAGEDOWN:
-
 
101
		  	    	      case KEY_PAGEUP:
-
 
102
		  	    	      case KEY_RIGHT:
-
 
103
		  	    	      case KEY_SHIFT:
-
 
104
		  	    	      case KEY_TAB:
-
 
105
		  	    	      case KEY_UP:
-
 
106
			    	    	
-
 
107
			    	        break;
-
 
108
			    	        
-
 
109
		  	    	      case KEY_ENTER:
-
 
110
		  	    	    	  if(rdSelectionne != null) {
-
 
111
		  	    	    		  setValue(rdSelectionne.getAsString("valeur"));
-
 
112
		  	    	    		  selectionValeur=true;
-
 
113
		  	    	    		  valeurBrute = rdSelectionne.getAsString("valeur");
-
 
114
		  	    	    	  }
-
 
115
			              break;
-
 
116
			    	        
-
 
117
		  	    	      case KEY_DOWN:
-
 
118
		  	    	    	  if(getValueAsString().isEmpty() && !isExpanded()) {
-
 
119
		  	    	    		  obtenirListeValeurs("*");
-
 
120
		  	    	    	  }
-
 
121
		  	    	      break;
-
 
122
							  	    	       
-
 
123
		  	    	      default:
-
 
124
		  	    	    	if(timer != null) {
-
 
125
			    	    		timer.cancel();
-
 
126
			    	    	}
-
 
127
			    	    	timer = new Timer() {
-
 
128
								
-
 
129
								@Override
-
 
130
								public void run() {
-
 
131
				  	    	      	obtenirListeValeurs();
-
 
132
								}
-
 
133
							};
-
 
134
							timer.schedule(300);
-
 
135
							valeurBrute = getValueAsString();
-
 
136
							setValue(valeurBrute);
-
 
137
						}
-
 
138
					}
-
 
139
			    },listenerConfigAutocompletion);
-
 
140
		    }
-
 
141
			
-
 
142
			addListener(new ComboBoxListenerAdapter() {  
-
 
143
	            @Override
-
 
144
				public void onSelect(ComboBox comboBox, Record record, int index) {  
-
 
145
	            	rdSelectionne = record;
-
 
146
	            	setRawValue(rdSelectionne.getAsString("valeur"));
-
 
147
	            }
-
 
148
	            
-
 
149
	            @Override
-
 
150
				public void onBlur(Field field) {  
-
 
151
	            	if(rdSelectionne != null && !rdSelectionne.getAsString("valeur").equals(valeurBrute)) {
42
		public ChampSaisieEtendu(String label, String cle, String urlRequete) {
152
	            		setRawValue(valeurBrute);
43
 
153
	            	}
44
			super(label, urlRequete);  
154
	            }
45
			this.cle =cle;
155
	         });
46
			this.label = label;
156
			
-
 
157
			// A activer pour télécharger la description
47
			
158
			// si jamais on le décide
48
			// A activer pour télécharger la description
159
			addListener(new ComboBoxListenerAdapter() {
49
			// si jamais on le décide
160
				@Override
50
			addListener(new ComboBoxListenerAdapter() {
161
				public void onRender(Component component) {
51
				@Override
Line 199... Line 89...
199
					tpDesc.show();
89
					tpDesc.show();
200
				}
90
				}
201
			}
91
			}
202
		}
92
		}
Line 203... Line -...
203
		
-
 
204
		@Override
-
 
205
		public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) {
-
 
206
			
-
 
207
			@SuppressWarnings("unchecked")
-
 
208
			ArrayList<String> valeurs = (ArrayList<String>)nouvelleDonnees;
93
		
209
			cacheValeurs = valeurs;
-
 
210
 
94
		public String getCle() {
211
			int i = 0;
-
 
212
			Object[][] refData = new Object[valeurs.size()][1];
-
 
213
			
-
 
214
			for (Iterator<String> it = valeurs.iterator(); it.hasNext();) 
-
 
215
			{
-
 
216
				refData[i][0]= it.next();
-
 
217
				i++;
-
 
218
			}
-
 
219
			
-
 
220
			FieldDef defValeur = new StringFieldDef("valeur");
-
 
221
			FieldDef[] defTab = {defValeur};
-
 
222
			
-
 
223
			RecordDef rd = new RecordDef(defTab);
-
 
224
			
-
 
225
			final MemoryProxy dataProxy = new MemoryProxy(refData);
-
 
226
			final ArrayReader reader = new ArrayReader(rd);		
-
 
227
							
-
 
228
			Store store = new Store(dataProxy,reader);
-
 
229
			
-
 
230
			setStore(store);
-
 
231
			store.load();
-
 
232
		}
-
 
233
		
-
 
234
		private void obtenirListeValeurs() {
-
 
235
			String valeurChamp = getRawValue();
-
 
236
			obtenirListeValeurs(valeurChamp);
-
 
237
		}
-
 
238
		
-
 
239
		private void obtenirListeValeurs(String valeurChamp) {
-
 
240
			if(valeurChamp == null) {
-
 
241
				valeurChamp = "";
-
 
242
			} else {
-
 
243
				valeurChamp += "*";
-
 
244
			}
-
 
245
			ListeReferentielChampsEtendusDAO lrceDao = new ListeReferentielChampsEtendusDAO(null);
-
 
246
			lrceDao.obtenirListeValeursChampEtendu(this, cle, valeurChamp);
95
			return cle;
Line 247... Line 96...
247
		}
96
		}
248
		
-
 
249
		public void setLargeurChamp() {
-
 
250
			// Correction un peu moche pour améliorer l'affichage du champ
-
 
251
			String idElementEnfant = Ext.get(("x-form-el-"+cle)).getFirstChild().getId();
97
		
252
			Ext.get(idElementEnfant).setWidth("90%", false);
98
		public String getLabel() {
253
			Ext.get(cle).setWidth("100%", false);
99
			return label;
254
		}
100
		}
255
		
-
 
256
		private void initStoreVide() {
-
 
257
			Object[][] refData = new Object[0][1];
101
 
258
			
-
 
259
			FieldDef defValeur = new StringFieldDef("valeur");
-
 
260
			FieldDef[] defTab = {defValeur};
-
 
261
			
-
 
262
			RecordDef rd = new RecordDef(defTab);
102
		@Override
263
			
-
 
264
			final MemoryProxy dataProxy = new MemoryProxy(refData);
-
 
265
			final ArrayReader reader = new ArrayReader(rd);		
-
 
266
							
-
 
267
			Store store = new Store(dataProxy,reader);
-
 
268
			
-
 
269
			setStore(store);
103
		protected Map<String, String> parserResultatRequete(Response response) {
270
			store.load();
104
			return ListeReferentielChampsEtendusDAO.parserRetourListeValeursChampsEtendus(response);
271
		}
105
		}
272
		
106
 
273
		@Override
107
		@Override
274
		public void setValue(String valeur) {
-
 
275
			valeurBrute = valeur;
108
		protected void onModificationValeur() {
Line -... Line 109...
-
 
109
			// TODO Auto-generated method stub	
276
			super.setValue(valeur);
110
		}
277
		}
111
		
278
		
112
		@Override
279
		public String getCle() {
113
		protected void onSelectionValeur() {
-
 
114
			// TODO Auto-generated method stub	
280
			return cle;
115
		}
281
		}
116
 
-
 
117
		@Override
282
		
118
		protected void onValidationSaisie() {
283
		public String getLabel() {
119
			// TODO Auto-generated method stub
284
			return label;
120