| 195 | david | 1 | package org.tela_botanica.client.vues.observation;
 | 
        
           | 185 | david | 2 |   | 
        
           |  |  | 3 | import org.tela_botanica.client.interfaces.Rafraichissable;
 | 
        
           |  |  | 4 | import org.tela_botanica.client.observation.ObservationMediateur;
 | 
        
           |  |  | 5 |   | 
        
           |  |  | 6 | import com.google.gwt.user.client.Event;
 | 
        
           |  |  | 7 | import com.google.gwt.user.client.ui.HTML;
 | 
        
           |  |  | 8 | import com.gwtext.client.core.EventObject;
 | 
        
           |  |  | 9 | import com.gwtext.client.core.Ext;
 | 
        
           |  |  | 10 | import com.gwtext.client.core.ExtElement;
 | 
        
           |  |  | 11 | import com.gwtext.client.widgets.Button;
 | 
        
           |  |  | 12 | import com.gwtext.client.widgets.Panel;
 | 
        
           |  |  | 13 | import com.gwtext.client.widgets.Window;
 | 
        
           |  |  | 14 | import com.gwtext.client.widgets.event.ButtonListenerAdapter;
 | 
        
           |  |  | 15 | import com.gwtext.client.widgets.form.TextArea;
 | 
        
           |  |  | 16 |   | 
        
           |  |  | 17 | public class SaisieMotsClesVue extends Window implements Rafraichissable {
 | 
        
           |  |  | 18 | private ObservationMediateur oMediateur = null ;
 | 
        
           |  |  | 19 |   | 
        
           |  |  | 20 | 	private Object[][] listeMotsPesee = null;
 | 
        
           |  |  | 21 |   | 
        
           |  |  | 22 | 	private String motsAAjouter = "" ;
 | 
        
           |  |  | 23 |   | 
        
           |  |  | 24 | 	private int nbMotsClesMax = 1 ;
 | 
        
           |  |  | 25 |   | 
        
           |  |  | 26 | 	private TextArea motsClesAjout = null;
 | 
        
           |  |  | 27 |   | 
        
           |  |  | 28 | 	private Button validerAjout = null ;
 | 
        
           |  |  | 29 |   | 
        
           |  |  | 30 | 	private Button voirCacherNuage = null;
 | 
        
           |  |  | 31 |   | 
        
           |  |  | 32 | 	private boolean nuageVisible = false ;
 | 
        
           |  |  | 33 |   | 
        
           |  |  | 34 | 	private Panel contenuNuage = null ;
 | 
        
           |  |  | 35 |   | 
        
           |  |  | 36 | 	public SaisieMotsClesVue(ObservationMediateur om) {
 | 
        
           |  |  | 37 | 		super("Entrez vos mots clés");
 | 
        
           |  |  | 38 | 		setCls("fenmotcles");
 | 
        
           |  |  | 39 | 		oMediateur = om ;
 | 
        
           | 201 | david | 40 | 		//setWidth(300);
 | 
        
           | 185 | david | 41 | 		motsClesAjout = new TextArea();
 | 
        
           | 201 | david | 42 | 		//motsClesAjout.setWidth(300);
 | 
        
           | 185 | david | 43 | 		validerAjout = new Button("Valider");
 | 
        
           |  |  | 44 | 		voirCacherNuage= new Button("Afficher les mots clés");
 | 
        
           |  |  | 45 | 		final Rafraichissable r = this ;
 | 
        
           |  |  | 46 |   | 
        
           |  |  | 47 | 		this.setCloseAction(CLOSE);
 | 
        
           |  |  | 48 |   | 
        
           |  |  | 49 | 		validerAjout.addListener(new ButtonListenerAdapter() {
 | 
        
           | 1292 | aurelien | 50 | 			@Override
 | 
        
           | 185 | david | 51 | 			public void onClick(Button button, EventObject e) {
 | 
        
           |  |  | 52 |   | 
        
           |  |  | 53 | 				motsAAjouter = motsClesAjout.getText();
 | 
        
           |  |  | 54 | 				//oMediateur.AjouterMotsClesEnMasse(motsAAjouter);
 | 
        
           |  |  | 55 | 			}
 | 
        
           |  |  | 56 |   | 
        
           |  |  | 57 | 		});
 | 
        
           |  |  | 58 |   | 
        
           |  |  | 59 | 		voirCacherNuage.addListener(new ButtonListenerAdapter() {
 | 
        
           | 1292 | aurelien | 60 | 			@Override
 | 
        
           | 185 | david | 61 | 			public void onClick(Button button, EventObject e) {
 | 
        
           |  |  | 62 |   | 
        
           |  |  | 63 | 				if(nuageVisible) {
 | 
        
           |  |  | 64 |   | 
        
           |  |  | 65 | 					if(contenuNuage != null) {
 | 
        
           |  |  | 66 | 						contenuNuage.clear();
 | 
        
           |  |  | 67 | 					}
 | 
        
           |  |  | 68 | 					voirCacherNuage.setText("Afficher les mots clés");
 | 
        
           |  |  | 69 | 					nuageVisible = false;
 | 
        
           |  |  | 70 | 				}
 | 
        
           |  |  | 71 | 				else {
 | 
        
           |  |  | 72 | 				//	oMediateur.obtenirNuageMotsCles(r);
 | 
        
           |  |  | 73 | 					voirCacherNuage.setText("Cacher les mots clés");
 | 
        
           |  |  | 74 | 					nuageVisible = true;
 | 
        
           |  |  | 75 | 				}
 | 
        
           |  |  | 76 | 			}
 | 
        
           |  |  | 77 |   | 
        
           |  |  | 78 | 		});
 | 
        
           |  |  | 79 |   | 
        
           |  |  | 80 | 		add(motsClesAjout);
 | 
        
           |  |  | 81 | 		add(validerAjout);
 | 
        
           |  |  | 82 | 		add(voirCacherNuage);
 | 
        
           |  |  | 83 |   | 
        
           |  |  | 84 | 		contenuNuage = new Panel();
 | 
        
           |  |  | 85 | 		contenuNuage.setBorder(false);
 | 
        
           |  |  | 86 |   | 
        
           |  |  | 87 | 		add(contenuNuage);
 | 
        
           |  |  | 88 | 	}
 | 
        
           |  |  | 89 |   | 
        
           |  |  | 90 |   | 
        
           |  |  | 91 | 	public boolean renvoyerEtatFiltre() {
 | 
        
           |  |  | 92 | 		// TODO Auto-generated method stub
 | 
        
           |  |  | 93 | 		return false;
 | 
        
           |  |  | 94 | 	}
 | 
        
           |  |  | 95 |   | 
        
           |  |  | 96 |   | 
        
           |  |  | 97 | 	public String renvoyerNomFiltre() {
 | 
        
           |  |  | 98 | 		// TODO Auto-generated method stub
 | 
        
           |  |  | 99 | 		return null;
 | 
        
           |  |  | 100 | 	}
 | 
        
           |  |  | 101 |   | 
        
           |  |  | 102 |   | 
        
           |  |  | 103 | 	public String[] renvoyerValeursAFiltrer() {
 | 
        
           |  |  | 104 | 		// TODO Auto-generated method stub
 | 
        
           |  |  | 105 | 		return null;
 | 
        
           |  |  | 106 | 	}
 | 
        
           |  |  | 107 |   | 
        
           |  |  | 108 |   | 
        
           |  |  | 109 | 	public void valider() {
 | 
        
           |  |  | 110 | 		// TODO Auto-generated method stub
 | 
        
           |  |  | 111 |   | 
        
           |  |  | 112 | 	}
 | 
        
           |  |  | 113 |   | 
        
           |  |  | 114 |   | 
        
           | 1292 | aurelien | 115 | 	@Override
 | 
        
           | 185 | david | 116 | 	public void rafraichir(Object nouvelleDonnees,
 | 
        
           |  |  | 117 | 			boolean repandreRaffraichissement) {
 | 
        
           |  |  | 118 |   | 
        
           |  |  | 119 | 		if(nouvelleDonnees instanceof Integer) {
 | 
        
           |  |  | 120 | 			nbMotsClesMax = (Integer)nouvelleDonnees;
 | 
        
           |  |  | 121 | 			demasquerChargement();
 | 
        
           |  |  | 122 | 		}
 | 
        
           |  |  | 123 |   | 
        
           |  |  | 124 | 		if(nouvelleDonnees instanceof Object[][]) {
 | 
        
           |  |  | 125 |   | 
        
           |  |  | 126 | 			listeMotsPesee = (Object[][])nouvelleDonnees ;
 | 
        
           |  |  | 127 | 			construireNuage();
 | 
        
           |  |  | 128 | 			demasquerChargement();
 | 
        
           |  |  | 129 | 		}
 | 
        
           |  |  | 130 |   | 
        
           |  |  | 131 | 		if(nouvelleDonnees instanceof String) {
 | 
        
           |  |  | 132 |   | 
        
           |  |  | 133 | 			String res = (String)nouvelleDonnees;
 | 
        
           |  |  | 134 | 			if(res.equals("OK")) {
 | 
        
           |  |  | 135 | 				masquerChargement();
 | 
        
           |  |  | 136 | 				oMediateur.obtenirListeObservation();
 | 
        
           |  |  | 137 | 				//oMediateur.obtenirNuageMotsCles(this);
 | 
        
           |  |  | 138 | 			}
 | 
        
           |  |  | 139 | 		}
 | 
        
           |  |  | 140 | 	}
 | 
        
           |  |  | 141 |   | 
        
           |  |  | 142 | 	private void construireNuage() {
 | 
        
           |  |  | 143 |   | 
        
           |  |  | 144 | 		contenuNuage.clear();
 | 
        
           |  |  | 145 |   | 
        
           |  |  | 146 | 		String contenu = "<ul class=\"nuagetag\">" ;
 | 
        
           |  |  | 147 |   | 
        
           |  |  | 148 | 		for(int i = 0; i<listeMotsPesee.length; i++) {
 | 
        
           |  |  | 149 |   | 
        
           |  |  | 150 | 			String classeMotCle = "motcletaille"+calculerPoids((Integer)listeMotsPesee[i][1]) ;
 | 
        
           |  |  | 151 | 			contenu += "<li class=\""+classeMotCle+"\">";
 | 
        
           |  |  | 152 | 			contenu += (String)listeMotsPesee[i][0];
 | 
        
           |  |  | 153 | 			contenu += "</li>";
 | 
        
           |  |  | 154 | 		}
 | 
        
           |  |  | 155 |   | 
        
           |  |  | 156 | 		contenu += "</ul>" ;
 | 
        
           |  |  | 157 |   | 
        
           |  |  | 158 | 		HTML contenuHTML = new HTML(contenu) {
 | 
        
           | 1292 | aurelien | 159 | 			@Override
 | 
        
           | 185 | david | 160 | 			public void onBrowserEvent(Event e) {
 | 
        
           |  |  | 161 |   | 
        
           |  |  | 162 | 				motsAAjouter += " "+e.getTarget().getInnerHTML();
 | 
        
           |  |  | 163 | 				motsClesAjout.setValue(motsAAjouter);
 | 
        
           |  |  | 164 | 			}
 | 
        
           |  |  | 165 | 		};
 | 
        
           |  |  | 166 |   | 
        
           |  |  | 167 | 		contenuHTML.sinkEvents(Event.ONCLICK);
 | 
        
           |  |  | 168 | 		contenuNuage.add(contenuHTML);
 | 
        
           |  |  | 169 |   | 
        
           |  |  | 170 | 		contenuNuage.doLayout();
 | 
        
           |  |  | 171 | 		doLayout();
 | 
        
           |  |  | 172 | 	}
 | 
        
           |  |  | 173 |   | 
        
           |  |  | 174 | 	private int calculerPoids(int poidMot) {
 | 
        
           |  |  | 175 |   | 
        
           |  |  | 176 | 		int poids = (poidMot*10)/nbMotsClesMax;
 | 
        
           |  |  | 177 | 		if(poids < 1) {
 | 
        
           |  |  | 178 | 			return 1;
 | 
        
           |  |  | 179 | 		}
 | 
        
           |  |  | 180 |   | 
        
           |  |  | 181 | 		return poids;
 | 
        
           |  |  | 182 | 	}
 | 
        
           |  |  | 183 |   | 
        
           |  |  | 184 | 	/**
 | 
        
           |  |  | 185 | 	 * Recherche l'élement actuellement affiché et affiche son message de chargement
 | 
        
           |  |  | 186 | 	 */
 | 
        
           |  |  | 187 | 	public void masquerChargement()
 | 
        
           |  |  | 188 | 	{
 | 
        
           |  |  | 189 | 			ExtElement masked = Ext.get(getId()) ;
 | 
        
           |  |  | 190 |   | 
        
           |  |  | 191 |   | 
        
           |  |  | 192 | 			if (masked!=null) {
 | 
        
           |  |  | 193 | 				masked.mask("Chargement") ;
 | 
        
           |  |  | 194 | 			}
 | 
        
           |  |  | 195 |   | 
        
           |  |  | 196 | 	}
 | 
        
           |  |  | 197 |   | 
        
           |  |  | 198 | 	/**
 | 
        
           |  |  | 199 | 	 * Recherche l'élement actuellement affiché et retire son message de chargement si l'était affiché
 | 
        
           |  |  | 200 | 	 */
 | 
        
           |  |  | 201 | 	public void demasquerChargement()
 | 
        
           |  |  | 202 | 	{
 | 
        
           |  |  | 203 | 			ExtElement masked = Ext.get(getId()) ;
 | 
        
           |  |  | 204 |   | 
        
           |  |  | 205 | 			if (masked!=null) {
 | 
        
           |  |  | 206 | 					masked.unmask() ;
 | 
        
           |  |  | 207 | 			}
 | 
        
           |  |  | 208 | 	}
 | 
        
           |  |  | 209 |   | 
        
           |  |  | 210 |   | 
        
           |  |  | 211 | }
 |