Subversion Repositories eFlore/Applications.del

Rev

Rev 178 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 178 Rev 204
1
package org.tela_botanica.del.client.vues.rechercheimages;
1
package org.tela_botanica.del.client.vues.rechercheimages;
2
 
2
 
3
import java.util.List;
3
import java.util.List;
4
 
4
 
5
import org.tela_botanica.del.client.cache.CacheClient;
5
import org.tela_botanica.del.client.cache.CacheClient;
6
import org.tela_botanica.del.client.modeles.Image;
6
import org.tela_botanica.del.client.modeles.Image;
7
import org.tela_botanica.del.client.modeles.Protocole;
7
import org.tela_botanica.del.client.modeles.Protocole;
8
import org.tela_botanica.del.client.navigation.evenement.BusEvenementiel;
8
import org.tela_botanica.del.client.navigation.evenement.BusEvenementiel;
9
import org.tela_botanica.del.client.navigation.evenement.changementprotocole.EvenementChangementProtocole;
9
import org.tela_botanica.del.client.navigation.evenement.changementprotocole.EvenementChangementProtocole;
10
import org.tela_botanica.del.client.navigation.evenement.rechercheimage.EvenementRechercheImage;
10
import org.tela_botanica.del.client.navigation.evenement.rechercheimage.EvenementRechercheImage;
11
import org.tela_botanica.del.client.utils.KeyboardKeyListener;
-
 
12
import org.tela_botanica.del.client.utils.MockDatasource;
11
import org.tela_botanica.del.client.utils.MockDatasource;
13
 
12
 
14
import com.google.gwt.event.dom.client.ChangeEvent;
13
import com.google.gwt.event.dom.client.ChangeEvent;
15
import com.google.gwt.event.dom.client.ChangeHandler;
14
import com.google.gwt.event.dom.client.ChangeHandler;
16
import com.google.gwt.event.dom.client.ClickEvent;
15
import com.google.gwt.event.dom.client.ClickEvent;
17
import com.google.gwt.event.dom.client.ClickHandler;
16
import com.google.gwt.event.dom.client.ClickHandler;
-
 
17
import com.google.gwt.event.dom.client.KeyCodes;
-
 
18
import com.google.gwt.event.dom.client.KeyPressEvent;
-
 
19
import com.google.gwt.event.dom.client.KeyPressHandler;
18
import com.google.gwt.user.client.ui.HasWidgets;
20
import com.google.gwt.user.client.ui.HasWidgets;
19
 
21
 
20
public class RechercheImagePresenteur {
22
public class RechercheImagePresenteur {
21
 
23
 
22
	private final MockDatasource dataSource = MockDatasource.getInstance();
24
	private final MockDatasource dataSource = MockDatasource.getInstance();
23
	private final RechercheImageVue vue = new RechercheImageVue();
25
	private final RechercheImageVue vue = new RechercheImageVue();
24
	private String protocoleParDefaut = Protocole.IDENTIFICATION_AUTOMATIQUE;
26
	private String protocoleParDefaut = Protocole.IDENTIFICATION_AUTOMATIQUE;
25
	private List<Protocole> protocoles;
27
	private List<Protocole> protocoles;
26
 
28
 
27
	public RechercheImagePresenteur() {
29
	public RechercheImagePresenteur() {
28
 
30
 
29
		if (CacheClient.getInstance().getProtocoleCourant() == null) {
31
		if (CacheClient.getInstance().getProtocoleCourant() == null) {
30
			CacheClient.getInstance().setProtocoleCourant(dataSource.getProtocole(protocoleParDefaut));
32
			CacheClient.getInstance().setProtocoleCourant(dataSource.getProtocole(protocoleParDefaut));
31
		}
33
		}
32
	}
34
	}
33
 
35
 
34
	public void go(HasWidgets composite) {
36
	public void go(HasWidgets composite) {
35
		composite.add(vue);
37
		composite.add(vue);
36
		gererEvenements();
38
		gererEvenements();
37
		chargerProtocoles();
39
		chargerProtocoles();
38
	}
40
	}
39
 
41
 
40
	private void chargerProtocoles() {
42
	private void chargerProtocoles() {
41
		protocoles = dataSource.getProtocoles();
43
		protocoles = dataSource.getProtocoles();
42
		for (Protocole protocole : protocoles) {
44
		for (Protocole protocole : protocoles) {
43
			vue.getListeProtocoles().addItem(protocole.getNom());
45
			vue.getListeProtocoles().addItem(protocole.getNom());
44
		}
46
		}
45
		vue.getListeProtocoles().setSelectedIndex(protocoles.indexOf(CacheClient.getInstance().getProtocoleCourant()));
47
		vue.getListeProtocoles().setSelectedIndex(protocoles.indexOf(CacheClient.getInstance().getProtocoleCourant()));
46
	}
48
	}
47
 
-
 
48
	@SuppressWarnings("deprecation")
49
 
49
	public void gererEvenements() {
50
	public void gererEvenements() {
50
 
51
 
51
		vue.getBoutonChercher().addClickHandler(new ClickHandler() {
52
		vue.getBoutonChercher().addClickHandler(new ClickHandler() {
52
 
53
 
53
			@Override
54
			@Override
54
			public void onClick(ClickEvent event) {
55
			public void onClick(ClickEvent event) {
55
				chargerImages();
56
				chargerImages();
56
			}
57
			}
57
		});
58
		});
58
 
-
 
59
		// TODO : remplacer par KeyUp, KeyDown ... etc.
59
 
60
		vue.getTextBox().addKeyboardListener(new KeyboardKeyListener() {
-
 
61
 
60
		vue.getTextBox().addKeyPressHandler(new KeyPressHandler() {
-
 
61
 
62
			@Override
62
			public void onKeyPress(KeyPressEvent event) {
-
 
63
				if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
63
			public void onEnterKeyUp() {
64
					chargerImages();
64
				chargerImages();
65
				}
65
			}
66
			}
66
		});
67
		});
67
 
68
 
68
		vue.getListeProtocoles().addChangeHandler(new ChangeHandler() {
69
		vue.getListeProtocoles().addChangeHandler(new ChangeHandler() {
69
 
70
 
70
			@Override
71
			@Override
71
			public void onChange(ChangeEvent event) {
72
			public void onChange(ChangeEvent event) {
72
				Protocole protocoleCourant = protocoles.get(vue.getListeProtocoles().getSelectedIndex());
73
				Protocole protocoleCourant = protocoles.get(vue.getListeProtocoles().getSelectedIndex());
73
				EvenementChangementProtocole evenement = new EvenementChangementProtocole(protocoleCourant);
74
				EvenementChangementProtocole evenement = new EvenementChangementProtocole(protocoleCourant);
74
				BusEvenementiel.getInstance().fireEvent(evenement);
75
				BusEvenementiel.getInstance().fireEvent(evenement);
75
			}
76
			}
76
		});
77
		});
77
	}
78
	}
78
 
79
 
79
	private void chargerImages() {
80
	private void chargerImages() {
80
		List<Image> imagesFromDatabase = dataSource.getImages();
81
		List<Image> imagesFromDatabase = dataSource.getImages();
81
		EvenementRechercheImage evenementRechercheImage = new EvenementRechercheImage(imagesFromDatabase);
82
		EvenementRechercheImage evenementRechercheImage = new EvenementRechercheImage(imagesFromDatabase);
82
		BusEvenementiel.getInstance().fireEvent(evenementRechercheImage);
83
		BusEvenementiel.getInstance().fireEvent(evenementRechercheImage);
83
	}
84
	}
84
 
85
 
85
	public RechercheImageVue getVue() {
86
	public RechercheImageVue getVue() {
86
		return vue;
87
		return vue;
87
	}
88
	}
88
 
89
 
89
}
90
}