Subversion Repositories eFlore/Applications.cel

Rev

Rev 798 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 798 Rev 815
1
package org.tela_botanica.client.util;
1
package org.tela_botanica.client.util;
2
 
2
 
3
import java.util.Iterator;
3
import java.util.Iterator;
4
 
4
 
5
import org.tela_botanica.client.interfaces.Rafraichissable;
5
import org.tela_botanica.client.interfaces.Rafraichissable;
6
import org.tela_botanica.client.modeles.ListeReferentielPerso;
6
import org.tela_botanica.client.modeles.ListeReferentielPerso;
7
import org.tela_botanica.client.modeles.ListeReferentielPerso.TypesReferentiels;
7
import org.tela_botanica.client.modeles.ListeReferentielPerso.TypesReferentiels;
8
import org.tela_botanica.client.observation.ObservationMediateur;
8
import org.tela_botanica.client.observation.ObservationMediateur;
9
 
9
 
10
import com.gwtext.client.core.EventCallback;
10
import com.gwtext.client.core.EventCallback;
11
import com.gwtext.client.core.EventObject;
11
import com.gwtext.client.core.EventObject;
12
import com.gwtext.client.core.ListenerConfig;
12
import com.gwtext.client.core.ListenerConfig;
13
import com.gwtext.client.data.ArrayReader;
13
import com.gwtext.client.data.ArrayReader;
14
import com.gwtext.client.data.FieldDef;
14
import com.gwtext.client.data.FieldDef;
15
import com.gwtext.client.data.MemoryProxy;
15
import com.gwtext.client.data.MemoryProxy;
16
import com.gwtext.client.data.Record;
16
import com.gwtext.client.data.Record;
17
import com.gwtext.client.data.RecordDef;
17
import com.gwtext.client.data.RecordDef;
18
import com.gwtext.client.data.Store;
18
import com.gwtext.client.data.Store;
19
import com.gwtext.client.data.StringFieldDef;
19
import com.gwtext.client.data.StringFieldDef;
20
import com.gwtext.client.widgets.form.ComboBox;
20
import com.gwtext.client.widgets.form.ComboBox;
21
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
21
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
22
 
22
 
23
public abstract class AutoCompletionRefComboBox extends ComboBox implements Rafraichissable {
23
public abstract class AutoCompletionRefComboBox extends ComboBox implements Rafraichissable {
24
	
24
	
25
	// TODO: faire un enum
25
	// TODO: faire un enum
26
	private final int KEY_ALT = 18;
26
	private final int KEY_ALT = 18;
27
	private final int KEY_BACKSPACE = 8;
27
	private final int KEY_BACKSPACE = 8;
28
	private final int KEY_CTRL = 17;
28
	private final int KEY_CTRL = 17;
29
	private final int KEY_DELETE = 46;
29
	private final int KEY_DELETE = 46;
30
	private final int KEY_DOWN = 40;
30
	private final int KEY_DOWN = 40;
31
	private final int KEY_END = 35;
31
	private final int KEY_END = 35;
32
	private final int KEY_ENTER = 13;
32
	private final int KEY_ENTER = 13;
33
	private final int KEY_ESCAPE = 27;
33
	private final int KEY_ESCAPE = 27;
34
	private final int KEY_HOME = 36;
34
	private final int KEY_HOME = 36;
35
	private final int KEY_LEFT = 37;
35
	private final int KEY_LEFT = 37;
36
	private final int KEY_PAGEDOWN = 34;
36
	private final int KEY_PAGEDOWN = 34;
37
	private final int KEY_PAGEUP = 33;
37
	private final int KEY_PAGEUP = 33;
38
	private final int KEY_RIGHT = 39;
38
	private final int KEY_RIGHT = 39;
39
	private final int KEY_SHIFT = 16;
39
	private final int KEY_SHIFT = 16;
40
	private final int KEY_TAB = 9;
40
	private final int KEY_TAB = 9;
41
	private final int KEY_UP = 38;
41
	private final int KEY_UP = 38;
42
	
42
	
43
	private ObservationMediateur oMediateur = null;
43
	private ObservationMediateur oMediateur = null;
44
	private TypesReferentiels typeRef = null;
44
	private TypesReferentiels typeRef = null;
45
	private boolean selectionValeur = false;
45
	private boolean selectionValeur = false;
46
	private boolean estModifie = false;
46
	private boolean estModifie = false;
47
	
47
	
48
	final String resultTplRefPerso = "<div class=\"search-item-ref\">{element_referentiel}</div>";  
48
	final String resultTplRefPerso = "<div class=\"search-item-ref\">{element_referentiel}</div>";  
49
	
49
	
50
	public AutoCompletionRefComboBox(String label, String nom, ObservationMediateur oMediateur, TypesReferentiels typeRef) {
50
	public AutoCompletionRefComboBox(String label, String nom, ObservationMediateur oMediateur, TypesReferentiels typeRef) {
51
		
51
		
52
		// Accesskey pour debugging
52
		// Accesskey pour debugging
53
		super(label,nom);  
53
		super(label,nom);  
54
		
54
		
55
		this.oMediateur = oMediateur;
55
		this.oMediateur = oMediateur;
56
		this.typeRef = typeRef;
56
		this.typeRef = typeRef;
57
 
57
 
58
		setTpl(resultTplRefPerso);
58
		setTpl(resultTplRefPerso);
59
		setMode(ComboBox.REMOTE);
59
		setMode(ComboBox.REMOTE);
60
		setItemSelector("div.search-item-ref");
60
		setItemSelector("div.search-item-ref");
61
		setTypeAhead(true);  
61
		setTypeAhead(true);  
62
		setLoadingText("Recherche...");  
62
		setLoadingText("Recherche...");  
63
		setHideTrigger(true);
63
		setHideTrigger(true);
64
		
64
		
65
	    ListenerConfig listenerConfigAutocompletion=new ListenerConfig();
65
	    ListenerConfig listenerConfigAutocompletion=new ListenerConfig();
66
	    listenerConfigAutocompletion.setDelay(200);
66
	    listenerConfigAutocompletion.setDelay(200);
67
	    listenerConfigAutocompletion.setStopPropagation(false);
67
	    listenerConfigAutocompletion.setStopPropagation(false);
68
	    listenerConfigAutocompletion.setStopEvent(false);
68
	    listenerConfigAutocompletion.setStopEvent(false);
69
		
69
		
70
		addKeyPressListener(new EventCallback() {
70
		addKeyPressListener(new EventCallback() {
71
 
71
 
72
			public void execute(EventObject e) {
72
			public void execute(EventObject e) {
73
 
73
 
74
				switch(e.getKey()) {
74
				switch(e.getKey()) {
75
  	    	      
75
  	    	      
76
				case KEY_ALT:
76
				case KEY_ALT:
77
  	    	      case KEY_CTRL:
77
  	    	      case KEY_CTRL:
78
  	    	      case KEY_DOWN:
78
  	    	      case KEY_DOWN:
79
  	    	      case KEY_END:
79
  	    	      case KEY_END:
80
  	    	      case KEY_ESCAPE:
80
  	    	      case KEY_ESCAPE:
81
  	    	      case KEY_HOME:
81
  	    	      case KEY_HOME:
82
  	    	      case KEY_LEFT:
82
  	    	      case KEY_LEFT:
83
  	    	      case KEY_PAGEDOWN:
83
  	    	      case KEY_PAGEDOWN:
84
  	    	      case KEY_PAGEUP:
84
  	    	      case KEY_PAGEUP:
85
  	    	      case KEY_RIGHT:
85
  	    	      case KEY_RIGHT:
86
  	    	      case KEY_SHIFT:
86
  	    	      case KEY_SHIFT:
87
  	    	      case KEY_TAB:
87
  	    	      case KEY_TAB:
88
  	    	      case KEY_UP:
88
  	    	      case KEY_UP:
89
	    	    	
89
	    	    	
90
	    	        break;
90
	    	        break;
91
				
91
				
92
  	    	    case KEY_ENTER:	
92
  	    	    case KEY_ENTER:	
93
  	    	    	if (selectionValeur) {
93
  	    	    	if (selectionValeur) {
94
  	    	    		estModifie= true;
94
  	    	    		estModifie= true;
95
  	    	    		selectionValeur=false;
95
  	    	    		selectionValeur=false;
96
  	    	    		onModificationValeur();
96
  	    	    		onModificationValeur();
97
   	    	    	}
97
   	    	    	}
98
   	    	    	else {
98
   	    	    	else {
99
  	    	    		onValidationSaisie();
99
  	    	    		onValidationSaisie();
100
  	    	    	}
100
  	    	    	}
101
  	    	    break;
101
  	    	    break;
102
  	    	       
102
  	    	       
103
  	    	      default:
103
  	    	      default:
104
  	    	    	estModifie = true;
104
  	    	    	estModifie = true;
-
 
105
	    	      	onModificationValeur();
105
  	    	      	obtenirReferentiel();
106
  	    	      	obtenirReferentiel();
106
				}
107
				}
107
			}
108
			}
108
	    },listenerConfigAutocompletion);
109
	    },listenerConfigAutocompletion);
109
		
110
		
110
		
111
		
111
		// Listener completion 
112
		// Listener completion 
112
		addListener(new ComboBoxListenerAdapter() {  
113
		addListener(new ComboBoxListenerAdapter() {  
113
             public void onSelect(ComboBox comboBox, Record record, int index) {  
114
             public void onSelect(ComboBox comboBox, Record record, int index) {  
114
            	 setValue(record.getAsString("element_referentiel"));
115
            	 setValue(record.getAsString("element_referentiel"));
115
            	 selectionValeur=true;
116
            	 selectionValeur=true;
116
                 collapse();
117
                 collapse();
117
             }  
118
             }  
118
         });
119
         });
119
		
120
		
120
	}
121
	}
121
 
122
 
122
	public void rafraichir(Object nouvelleDonnees,
123
	public void rafraichir(Object nouvelleDonnees,
123
			boolean repandreRaffraichissement) {
124
			boolean repandreRaffraichissement) {
124
		
125
		
125
		ListeReferentielPerso referentielPerso = (ListeReferentielPerso)nouvelleDonnees;
126
		ListeReferentielPerso referentielPerso = (ListeReferentielPerso)nouvelleDonnees;
126
		
127
		
127
		int i = 0;
128
		int i = 0;
128
		Object[][] refData = new Object[referentielPerso.size()][1];
129
		Object[][] refData = new Object[referentielPerso.size()][1];
129
		
130
		
130
		for (Iterator it = referentielPerso.keySet().iterator(); it.hasNext();) 
131
		for (Iterator it = referentielPerso.keySet().iterator(); it.hasNext();) 
131
		{
132
		{
132
			String ref= referentielPerso.get(it.next());
133
			String ref= referentielPerso.get(it.next());
133
			refData[i][0]= ref;
134
			refData[i][0]= ref;
134
			
135
			
135
			i++;
136
			i++;
136
		}
137
		}
137
		
138
		
138
		FieldDef defStation = new StringFieldDef("element_referentiel");
139
		FieldDef defStation = new StringFieldDef("element_referentiel");
139
		FieldDef[] defTab = {defStation};
140
		FieldDef[] defTab = {defStation};
140
		
141
		
141
		RecordDef rd = new RecordDef(defTab);
142
		RecordDef rd = new RecordDef(defTab);
142
		
143
		
143
		final MemoryProxy dataProxy = new MemoryProxy(refData);
144
		final MemoryProxy dataProxy = new MemoryProxy(refData);
144
		final ArrayReader reader = new ArrayReader(rd);		
145
		final ArrayReader reader = new ArrayReader(rd);		
145
						
146
						
146
		Store store=new Store(dataProxy,reader);
147
		Store store=new Store(dataProxy,reader);
147
		
148
		
148
		setStore(store);
149
		setStore(store);
149
		store.load();
150
		store.load();
150
	}
151
	}
151
	
152
	
152
	private void obtenirReferentiel() {
153
	private void obtenirReferentiel() {
153
		
154
		
154
		String valeurChamp = getValue();
155
		String valeurChamp = getValue();
155
		
156
		
156
		if(valeurChamp == null) {
157
		if(valeurChamp == null) {
157
			valeurChamp = "";
158
			valeurChamp = "";
158
		}
159
		}
159
		
160
		
160
		oMediateur.obtenirListeReferentielPerso(this, typeRef, valeurChamp);
161
		oMediateur.obtenirListeReferentielPerso(this, typeRef, valeurChamp);
161
	}
162
	}
162
	
163
	
163
	public abstract void onValidationSaisie();
164
	public abstract void onValidationSaisie();
164
	public abstract void onModificationValeur();
165
	public abstract void onModificationValeur();
165
 
166
 
166
}
167
}