/trunk/src/org/tela_botanica/client/EntryView.java |
---|
New file |
0,0 → 1,635 |
/** |
David Delon david.delon@clapas.net 2007 |
*/ |
/* |
* EntryView.java (Composite de Panel) |
* |
* Cas d'utilisation : |
* Saisie assistee (completion nom et completion commune) de releves. |
* L'identification n'est pas obligatoire |
* |
* 1 : L'utilisateur saisit a minima un nom de plante |
* 1: Le nom de plante provient d'une application externe : il est deduit du nuremo nomenclatural transmis en historique |
* 2 : Le programme assiste la saisie de nom de plante ou de localite par interrogation du systeme distant |
* 3 : L'utilisateur choisi le type de mise (ajout ou modification) |
* 3 : L'utilisateur valide sa saisie |
* 4 : Le programme transmet au systeme distant la nouvelle saisie pour l'identifiant en cours |
* 5 : Le programme transmet au systeme local un evenement annoncant une nouvelle saisie |
* |
* |
* Affichage detail d'un observation |
* 1 : Le programme affiche les donnees d'inventaire pour l'identifiant enregistre et pour le numero d'ordre transmis |
* |
*/ |
// TODO : onvalidate dans mediator |
package org.tela_botanica.client; |
import java.util.Date; |
import net.mygwt.ui.client.Style; |
import net.mygwt.ui.client.event.BaseEvent; |
import net.mygwt.ui.client.event.SelectionListener; |
import net.mygwt.ui.client.widget.Button; |
import net.mygwt.ui.client.widget.ContentPanel; |
import net.mygwt.ui.client.widget.WidgetContainer; |
import net.mygwt.ui.client.widget.layout.BorderLayoutData; |
import net.mygwt.ui.client.widget.layout.FlowLayout; |
import com.google.gwt.json.client.JSONArray; |
import com.google.gwt.json.client.JSONParser; |
import com.google.gwt.json.client.JSONString; |
import com.google.gwt.json.client.JSONValue; |
import com.google.gwt.user.client.HTTPRequest; |
import com.google.gwt.user.client.History; |
import com.google.gwt.user.client.ResponseTextHandler; |
import com.google.gwt.user.client.ui.ChangeListener; |
import com.google.gwt.user.client.ui.Grid; |
import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
import com.google.gwt.user.client.ui.HasVerticalAlignment; |
import com.google.gwt.user.client.ui.HorizontalPanel; |
import com.google.gwt.user.client.ui.KeyboardListener; |
import com.google.gwt.user.client.ui.Label; |
import com.google.gwt.user.client.ui.PopupPanel; |
import com.google.gwt.user.client.ui.TextBox; |
import com.google.gwt.user.client.ui.VerticalPanel; |
import com.google.gwt.user.client.ui.Widget; |
public class EntryView { |
private ContentPanel panel=null; |
private NameAssistant nameAssistant = null; |
private LocationAssistant locationAssistant = null; |
private TextBox date = new TextBox(); |
private TextBox lieudit = new TextBox(); |
private TextBox station = new TextBox(); |
private TextBox milieu = new TextBox(); |
private TextBox comment = new TextBox(); |
private Button dateSelector = new Button("..."); |
boolean visible=false; |
private Mediator mediator=null; |
private String user= null; |
private String ordre =null; |
private CalendarWidget calendar = null; // Lazy instantiation |
private PopupPanel choicesPopup = null; // Lazy instantiation |
public EntryView(final Mediator med) { |
Grid observation = new Grid(5,4); |
// Formatage affichage |
for (int i=0; i<5;i++) { |
observation.getCellFormatter().setWidth(i, 0, "3%"); |
observation.getCellFormatter().setWidth(i, 1, "47%"); |
observation.getCellFormatter().setWidth(i, 2, "3%"); |
observation.getCellFormatter().setWidth(i, 3, "47%"); |
} |
mediator=med; |
user=mediator.getUser(); |
// Declaration des elements du dialogue de saisie aupres du mediator |
mediator.registerDate(date); |
mediator.registerComment(comment); |
mediator.registerStation(station); |
mediator.registerMilieu(milieu); |
mediator.registerLieudit(lieudit); |
panel= new ContentPanel(Style.HEADER); |
panel.setLayout(new FlowLayout()); |
panel.setText("Nouvelle observation"); |
VerticalPanel outer = new VerticalPanel(); |
// Name assistant et location assistant : widget auto-completion sur nom scientifique ou commune |
nameAssistant = new NameAssistant(mediator); |
locationAssistant = new LocationAssistant(mediator); |
// Saisie Commune |
observation.setHTML(0,0,"Commune: "); |
observation.setWidget(0,1,locationAssistant); |
locationAssistant.setWidth("100%"); |
// Saisie lieu-dit |
observation.setHTML(0,2,"Lieu-dit: "); |
observation.setWidget(0,3,lieudit); |
lieudit.setWidth("100%"); |
lieudit.addKeyboardListener( new KeyboardListener() { |
public void onKeyDown(Widget arg0, char arg1, int arg2) { |
if(arg1 == KEY_ENTER) |
{ |
onValidateTextBox(lieudit); |
} |
} |
public void onKeyUp(Widget arg0, char arg1, int arg2) { } |
public void onKeyPress(Widget arg0, char arg1, int arg2) { } |
} |
); |
// Saisie (station) |
observation.setHTML(1,0,"Station: "); |
observation.setWidget(1,1,station); |
station.setWidth("100%"); |
// Validation par entree sur cette zone de texte |
station.addKeyboardListener( new KeyboardListener() { |
public void onKeyDown(Widget arg0, char arg1, int arg2) { |
if(arg1 == KEY_ENTER) |
{ |
onValidateTextBox(station); |
} |
} |
public void onKeyUp(Widget arg0, char arg1, int arg2) { } |
public void onKeyPress(Widget arg0, char arg1, int arg2) { } |
} |
); |
// Saisie (station) |
observation.setHTML(1,2,"Milieu: "); |
observation.setWidget(1,3,milieu); |
milieu.setWidth("100%"); |
// Validation par entree sur cette zone de texte |
milieu.addKeyboardListener( new KeyboardListener() { |
public void onKeyDown(Widget arg0, char arg1, int arg2) { |
if(arg1 == KEY_ENTER) |
{ |
onValidateTextBox(milieu); |
} |
} |
public void onKeyUp(Widget arg0, char arg1, int arg2) { } |
public void onKeyPress(Widget arg0, char arg1, int arg2) { } |
} |
); |
// Selecteur de Date |
// Releve |
dateSelector.addSelectionListener( |
new SelectionListener() { |
public void widgetSelected(BaseEvent be) { |
if (visible) { |
visible=false; |
choicesPopup.hide(); |
} |
else { |
visible=true; |
if (calendar==null) { // Lazy instantiation |
calendar = new CalendarWidget(); |
choicesPopup = new PopupPanel(true); |
choicesPopup.add(calendar); |
calendar.addChangeListener(new ChangeListener() { |
public void onChange(Widget sender) { |
Date dateSelected=calendar.getDate(); |
date.setText(dateSelected.getDate()+"/"+(dateSelected.getMonth()+1)+"/"+(dateSelected.getYear()+1900)); |
visible=false; |
choicesPopup.hide(); |
} |
}); |
} |
choicesPopup.show(); |
choicesPopup.setPopupPosition(dateSelector.getAbsoluteLeft(), |
dateSelector.getAbsoluteTop() - dateSelector.getOffsetHeight() - choicesPopup.getOffsetHeight()); |
choicesPopup.setWidth(dateSelector.getOffsetWidth() + "px"); |
} |
} |
}); |
// Saisie Espece |
observation.setHTML(3,0,"Espèce: "); |
observation.setWidget(3,1,nameAssistant); |
nameAssistant.setWidth("100%"); |
observation.setHTML(2,0,"Date: "); |
HorizontalPanel datePanel = new HorizontalPanel(); |
datePanel.add(date); |
datePanel.add(dateSelector); |
observation.setWidget(2,1,datePanel); |
// Saisie date |
// Validation par entree sur cette zone de texte |
date.addKeyboardListener( new KeyboardListener() { |
public void onKeyDown(Widget arg0, char arg1, int arg2) { |
if(arg1 == KEY_ENTER) |
{ |
onValidateTextBox(date); |
} |
} |
public void onKeyUp(Widget arg0, char arg1, int arg2) { } |
public void onKeyPress(Widget arg0, char arg1, int arg2) { } |
} |
); |
// Saisie Commentaire |
observation.setHTML(4,0,"Notes: "); |
observation.setWidget(4,1,comment); |
comment.setWidth("100%"); |
// Validation par entree sur cette zone de texte |
comment.addKeyboardListener( new KeyboardListener() { |
public void onKeyDown(Widget arg0, char arg1, int arg2) { |
if(arg1 == KEY_ENTER) |
{ |
onValidateTextBox(comment); |
} |
} |
public void onKeyUp(Widget arg0, char arg1, int arg2) { } |
public void onKeyPress(Widget arg0, char arg1, int arg2) { } |
} |
); |
Button validButton=new Button("OK", |
new SelectionListener() { |
public void widgetSelected(BaseEvent be) { |
// Numero ordre vide : ajout d'une observation |
if (ordre==null) { |
mediator.onAddInventoryItem(); |
panel.setText("Nouvelle observation"); |
} |
else { |
mediator.onModifyInventoryItem(ordre); |
panel.setText("Modification de l'observation n°: "+ordre); |
} |
} |
} |
); |
observation.setWidget(4,3,validButton); |
HorizontalPanel actionPanel= new HorizontalPanel(); |
// actionPanel.add(validButton); |
observation.setWidth("100%"); |
outer.add(observation); |
outer.setCellWidth(observation, "100%"); |
outer.setSpacing(10); |
outer.setHorizontalAlignment(HorizontalPanel.ALIGN_CENTER); |
outer.add(actionPanel); |
outer.setWidth("100%"); |
panel.add(outer); |
HorizontalPanel inner=new HorizontalPanel(); |
Button newButton=new Button("Clear", |
// Init |
new SelectionListener() { |
public void widgetSelected(BaseEvent be) { |
clear(); |
} |
} |
); |
inner.add(newButton); |
inner.setWidth("100%"); |
panel.getHeader().addWidget(inner); |
WidgetContainer center=mediator.getCenterContainer(); |
BorderLayoutData centerData = new BorderLayoutData(Style.NORTH, .27f, 150, 300); |
center.add(panel,centerData); |
// Initialisation si provenance d'un lien |
if (History.getToken().length()>0) { |
final String anum=History.getToken(); |
HTTPRequest.asyncGet(mediator.getServiceBaseUrl() + "/Name/" + anum, |
new ResponseTextHandler() { |
public void onCompletion(String strcomplete) { |
JSONValue jsonValue = JSONParser.parse(strcomplete); |
JSONArray jsonArray; |
if ((jsonArray = jsonValue.isArray()) != null) { |
String aname = Util.toCelString(((JSONString) jsonArray.get(0)).toString()); |
// Nom |
if (aname.compareTo("null")!=0) { |
nameAssistant.setText(aname); |
// Numero nomenclatural |
nameAssistant.setValue(anum); |
} |
} |
} |
}); |
} |
} |
void clear() { |
nameAssistant.setText(""); |
nameAssistant.setValue(null); |
locationAssistant.setText(""); |
locationAssistant.setValue(null); // Null ? |
date.setText(""); |
lieudit.setText(""); |
station.setText(""); |
milieu.setText(""); |
comment.setText(""); |
ordre=null; |
panel.setText("Nouvelle observation"); |
} |
/* |
* Numero d'ordre du releve affiche + mise à jour bouton |
* |
*/ |
public void setOrdre(String ordre) { |
this.ordre = ordre; |
if (ordre==null) { |
panel.setText("Nouvelle observation"); |
} |
else { |
panel.setText("Modification de l'observation n°: "+ordre); |
} |
} |
/* |
* Numero d'ordre du releve affiche |
* |
*/ |
public String getOrdre() { |
return this.ordre; |
} |
// Validation par entree sur cette zone de texte |
private void onValidateTextBox(TextBox textbox) { |
if (ordre==null) { |
// Numero ordre vide : ajout d'une observation |
mediator.onAddInventoryItem(); |
textbox.setText(""); |
panel.setText("Nouvelle observation"); |
} |
else { |
// Modification d'une observation |
mediator.onModifyInventoryItem(ordre); |
panel.setText("Modification de l'observation n°: "+ordre); |
} |
} |
/** |
* Mise a jour de l'affichage a partir de donnees deja saisie |
* |
*/ |
public void update() { |
HTTPRequest.asyncGet(mediator.getServiceBaseUrl() + "/Inventory/" + user + "/" + ordre, |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
JSONValue jsonValue = JSONParser.parse(str); |
JSONArray jsonArray; |
if ((jsonArray = jsonValue.isArray()) != null) { |
// Nom saisi |
nameAssistant.setText(Util.toCelString(((JSONString) jsonArray.get(0)).toString())); |
// Numero nomenclatural |
String ann=((JSONString) jsonArray .get(3)).stringValue(); |
if (ann.compareTo("0")!=0) { |
nameAssistant.setValue(ann); |
mediator.getInfoPopup().setImageUrl(ann); |
} |
else { |
nameAssistant.setValue(null); |
} |
// Commune |
String aloc=Util.toCelString(((JSONString) jsonArray .get(6)).toString()); |
if (aloc.compareTo("000null")!=0) { |
locationAssistant.setText(aloc); |
} |
else { |
locationAssistant.setText(""); |
} |
// Departement |
String adep=Util.toCelString(((JSONString) jsonArray .get(7)).toString()); |
if (adep.compareTo("000null")!=0) { |
locationAssistant.setValue(adep); |
} |
else { |
locationAssistant.setValue(null); |
} |
String adate=((JSONString) jsonArray .get(9)).stringValue(); |
// Date |
if (adate.compareTo("0000-00-00 00:00:00")!=0) { |
date.setText(adate); |
} |
else { |
date.setText(""); |
} |
String alieudit=Util.toCelString(((JSONString) jsonArray .get(10)).toString()); |
// Lieudit |
if (alieudit.compareTo("000null")!=0) { |
lieudit.setText(alieudit); |
} |
else { |
lieudit.setText(""); |
} |
String astation=Util.toCelString(((JSONString) jsonArray .get(11)).toString()); |
// Station |
if (astation.compareTo("000null")!=0) { |
station.setText(astation); |
} |
else { |
station.setText(""); |
} |
String amilieu=Util.toCelString(((JSONString) jsonArray .get(12)).toString()); |
// Milieu |
if (amilieu.compareTo("000null")!=0) { |
milieu.setText(amilieu); |
} |
else { |
milieu.setText(""); |
} |
String acomment=Util.toCelString(((JSONString) jsonArray .get(13)).toString()); |
// Notes |
if (acomment.compareTo("null")!=0) { |
comment.setText(acomment); |
} |
else { |
comment.setText(""); |
} |
} |
} |
}); |
} |
public void setUser(String user) { |
this.user = user; |
} |
} |
/* +--Fin du code ---------------------------------------------------------------------------------------+ |
* $Log$ |
* Revision 1.2 2008-01-30 08:55:40 ddelon |
* fin mise en place mygwt |
* |
* Revision 1.1 2008-01-02 21:26:04 ddelon |
* mise en place mygwt |
* |
* Revision 1.8 2007-12-22 14:48:53 ddelon |
* Documentation et refactorisation |
* |
* Revision 1.7 2007-09-17 19:25:34 ddelon |
* Documentation |
* |
* Revision 1.6 2007-06-06 13:29:30 ddelon |
* v0.09 |
* |
* Revision 1.5 2007-05-22 14:27:08 ddelon |
* reglage modification |
* |
* Revision 1.4 2007-05-21 21:01:35 ddelon |
* Modification comportement boutons |
* |
* |
*/ |
/trunk/src/org/tela_botanica/client/InventoryFilterView.java |
---|
New file |
0,0 → 1,71 |
/** |
David Delon david.delon@clapas.net 2007 |
*/ |
/* |
* InventoryFilterView.java : filtrage des releves (par communes, lieu-dit, dates ....) |
* |
* |
* 1: Le programme initialise les filtres communes, lieu-dit et dates) |
*/ |
package org.tela_botanica.client; |
//TODO : regler taille |
import net.mygwt.ui.client.Style; |
import net.mygwt.ui.client.widget.ExpandBar; |
import net.mygwt.ui.client.widget.ExpandItem; |
import net.mygwt.ui.client.widget.WidgetContainer; |
/** |
*/ |
public class InventoryFilterView { |
private LocationFilterView locationFilterView = null; |
private DateFilterView dateFilterView = null; |
private ExpandBar expandBar=null; |
private Mediator mediator=null; |
public InventoryFilterView(Mediator med) { |
mediator=med; |
expandBar = new ExpandBar(Style.SINGLE | Style.HEADER); |
expandBar.setSize(300, 300); |
locationFilterView = new LocationFilterView(mediator,this); |
dateFilterView = new DateFilterView(mediator,this); |
WidgetContainer west=mediator.getWestContainer(); |
west.add(expandBar); |
} |
public ExpandBar getExpandBar() { |
return expandBar; |
} |
} |
/* +--Fin du code ---------------------------------------------------------------------------------------+ |
* $Log$ |
* Revision 1.1 2008-01-02 21:26:04 ddelon |
* mise en place mygwt |
* |
* Revision 1.7 2007-09-17 19:25:34 ddelon |
* Documentation |
* |
* |
*/ |
/trunk/src/org/tela_botanica/client/AutoCompleteAsyncTextBoxListenerCollection.java |
---|
New file |
0,0 → 1,38 |
package org.tela_botanica.client; |
import java.util.Iterator; |
import java.util.Vector; |
import com.google.gwt.user.client.ResponseTextHandler; |
public class AutoCompleteAsyncTextBoxListenerCollection extends Vector { |
private static final long serialVersionUID = -2767605614048989439L; |
/** |
* Fires a Text enter event to all listeners. |
* |
* @param sender the widget sending the event |
* @param text the text sent |
*/ |
public void fireTextBoxEnter(SourcesAutoCompleteAsyncTextBoxEvents sender, String text, String value) { |
for (Iterator it = iterator(); it.hasNext();) { |
AutoCompleteAsyncTextBoxListener listener = (AutoCompleteAsyncTextBoxListener) it.next(); |
listener.onValidate(sender, text, value); |
} |
} |
/** |
* Fires a Text complete event to all listeners. |
* |
* @param sender the widget sending the event |
* @param text the text sent |
*/ |
public void fireTextBoxComplete(ResponseTextHandler sender, String text, String value) { |
for (Iterator it = iterator(); it.hasNext();) { |
AutoCompleteAsyncTextBoxListener listener = (AutoCompleteAsyncTextBoxListener) it.next(); |
listener.onComplete(sender, text, value); |
} |
} |
} |
/trunk/src/org/tela_botanica/client/LocationAssistant.java |
---|
New file |
0,0 → 1,86 |
package org.tela_botanica.client; |
import java.util.EventListener; |
import com.google.gwt.json.client.JSONArray; |
import com.google.gwt.json.client.JSONParser; |
import com.google.gwt.json.client.JSONString; |
import com.google.gwt.json.client.JSONValue; |
import com.google.gwt.user.client.ResponseTextHandler; |
import com.google.gwt.user.client.ui.Composite; |
import com.google.gwt.user.client.ui.HorizontalPanel; |
import org.tela_botanica.client.AutoCompleteAsyncTextBox; |
/** |
* Affiche une liste de localite qui peuvent etre selectionnees, retourne la valeur de la localite selectionne et une code associe |
* (gettext et getvalue pour le code associe) |
* Utilise un assistant de saisie asynchrone. |
*/ |
public class LocationAssistant extends Composite implements EventListener, ResponseTextHandler { |
private AutoCompleteAsyncTextBox autoCompletebox = new AutoCompleteAsyncTextBox(this); |
private HorizontalPanel panel = new HorizontalPanel(); |
private Mediator mediator = null; |
public LocationAssistant(Mediator med) { |
mediator=med; |
mediator.registerLocationAssistant(this); |
// autoCompletebox.setFocus(true); |
autoCompletebox.setSearchUrl(mediator.getServiceBaseUrl()+"/LocationSearch/"); |
panel.add(autoCompletebox); |
autoCompletebox.setWidth("100%"); |
initWidget(panel); |
autoCompletebox.addAutoCompleteAsyncTextBoxListener(mediator); |
} |
public void onCompletion(String str) { |
JSONValue jsonValue= JSONParser.parse(str); |
JSONArray jsonArray; |
JSONArray jsonArrayNested; |
if ((jsonArray = jsonValue.isArray()) != null) { |
for (int i = 0; i < jsonArray.size(); ++i) { |
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) { |
autoCompletebox.addItem(((JSONString) jsonArrayNested.get(0)).stringValue(),((JSONString) jsonArrayNested.get(1)).stringValue()); |
} |
} |
} |
autoCompletebox.displayList(); |
} |
public String getText() { |
return autoCompletebox.getText(); |
} |
public void setText(String str) { |
autoCompletebox.setText(str); |
} |
public void setValue(String value) { |
autoCompletebox.setValue(value); |
} |
public String getValue() { |
return autoCompletebox.getValue(); |
} |
} |
/trunk/src/org/tela_botanica/client/Mediator.java |
---|
New file |
0,0 → 1,691 |
package org.tela_botanica.client; |
// TODO : sortie User vers une classe ... |
// TODO : sortie les boutons supprimer et exporter et inclure ici : vraiment ? |
// TODO : optimisation, ne pas rechercher stations ou date si non affichés |
import net.mygwt.ui.client.Style; |
import net.mygwt.ui.client.widget.Viewport; |
import net.mygwt.ui.client.widget.WidgetContainer; |
import net.mygwt.ui.client.widget.layout.BorderLayout; |
import net.mygwt.ui.client.widget.layout.BorderLayoutData; |
import net.mygwt.ui.client.widget.layout.FillLayout; |
import com.google.gwt.i18n.client.Dictionary; |
import com.google.gwt.json.client.JSONArray; |
import com.google.gwt.json.client.JSONBoolean; |
import com.google.gwt.json.client.JSONParser; |
import com.google.gwt.json.client.JSONString; |
import com.google.gwt.json.client.JSONValue; |
import com.google.gwt.user.client.HTTPRequest; |
import com.google.gwt.user.client.ResponseTextHandler; |
import com.google.gwt.user.client.ui.TextBox; |
public class Mediator implements AutoCompleteAsyncTextBoxListener { |
// General |
private WidgetContainer west = null; |
private WidgetContainer south = null; |
private WidgetContainer center = null; |
private WidgetContainer north = null; |
private String serviceBaseUrl = getServiceBaseUrlFromDictionnary(); // Recherche url de base des services distants |
// Utilisateur |
private ConnexionView connexionView=null; // Information de connexion |
private String user = null; // Identifiant utilisateur connecte ou bien identifiant de session en cours |
private boolean connected=false; // Positionne a vrai si identification reussie |
// Filtres sur les releves |
private InventoryFilterView inventoryFilterView=null; // Containeur filtre date, lieu, lieu-dit ... |
private LocationFilterView locationFilterView=null; // Filtre sur lieu de releve |
private DateFilterView dateFilterView = null; // Filtre sur date d'observation |
// Saisie d'une observation |
private EntryView entryView=null; // Formulaire de saisie observation |
private NameAssistant nameAssistant=null; // Assistant de saisie nom scientifique |
private LocationAssistant locationAssistant=null; // Assistant de saisie nom de commune |
private TextBox date = null; // date observation |
private TextBox station = null; // station observation |
private TextBox milieu = null; // milieu observation |
private TextBox lieudit = null; // lieu dit observation |
private TextBox comment = null; // commentaire observation |
private InventoryItem inventoryItem=null; // Une observation saisie |
// Liste de releves saisis |
private InventoryListView inventoryListView = null; // Liste de releves |
// Actions sur les releves |
private ActionView actionView=null; // Action sur les observations |
private SearchPanel searchPanel = null; // Recherche dans les relevés saisis |
// Informations |
private InfoPopup infoPopup=null; // Information complementaire sur un taxon (photo, repartition) |
Mediator() { |
// Recherche identifiant utilisateur connecte |
HTTPRequest.asyncGet(serviceBaseUrl + "/User/", |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
JSONValue jsonValue = JSONParser.parse(str); |
JSONArray jsonArray; |
if ((jsonArray = jsonValue.isArray()) != null) { |
user = ((JSONString) jsonArray.get(0)).stringValue(); // Identifiant utilisateur ou identifiant de session si non connecte |
connected = ((JSONBoolean) jsonArray.get(1)).booleanValue(); // Drapeau leve si utilisateur identifie |
} |
_Mediator(); |
} |
}); |
} |
// Fin initialisation |
private void _Mediator() { |
// Navigateur |
Viewport viewport = new Viewport(); |
// viewport.setStyleName("my-border-layout"); |
// viewport.setBorders(true); |
viewport.setLayout(new BorderLayout()); |
center = new WidgetContainer(); |
center.setLayout(new BorderLayout()); |
// center.setBorders(true); |
west = new WidgetContainer(); |
west.setLayout(new FillLayout()); |
// west.setBorders(true); |
south = new WidgetContainer(); |
south.setLayout(new FillLayout()); |
// south.setBorders(true); |
north = new WidgetContainer(); |
north.setLayout(new FillLayout()); |
// north.setBorders(true); |
inventoryListView = new InventoryListView(this); // Liste de releves |
connexionView = new ConnexionView(this); // Identifiant de connection |
inventoryFilterView = new InventoryFilterView(this); // Ensemble de filtres sur liste de releves |
entryView = new EntryView(this); // Formulaire de saisie |
actionView = new ActionView(this); // Action sur releves saisis |
// searchPanel = new SearchPanel(this); // Recherche dans releves |
//applicationPanel.add(searchPanel); |
BorderLayoutData westData = new BorderLayoutData(Style.WEST, 200, 150, 300); |
westData.resizeable = true; |
viewport.add(west, westData); |
BorderLayoutData centerData = new BorderLayoutData(Style.CENTER, 400, 400, 800); |
viewport.add(center, centerData); |
BorderLayoutData northData = new BorderLayoutData(Style.NORTH, 20, 20, 20); |
viewport.add(north, northData); |
BorderLayoutData southData = new BorderLayoutData(Style.SOUTH, 400, 400, 800); |
// viewport.add(south, southData); |
viewport.layout(); |
onInit(); |
// Methodes Private |
} |
/** |
* Recuperation du prefixe d'appel des services |
* @return prefix appel des service |
*/ |
private String getServiceBaseUrlFromDictionnary() { |
Dictionary theme = Dictionary.getDictionary("Parameters"); |
return theme.get("serviceBaseUrl"); |
} |
// Methodes Public |
// Actions declanchee par le systeme |
/** |
* Action initialisation premier affichage |
*/ |
public void onInit() { |
locationFilterView.setIDLocation("all"); // Mise a jour filtre localite |
locationFilterView.setLocation("all"); // Mise a jour filtre localite |
locationFilterView.setLieudit("all"); // Mise a jour filtre localite |
locationFilterView.update(); // Mise a jour affichage |
dateFilterView.setYear("all"); |
dateFilterView.setMonth("all"); |
dateFilterView.setDay("all"); |
dateFilterView.update(); |
this.onLocationSelected("all","all","all"); |
} |
// Actions sur formulaire de saisie |
/** |
* Action lancee par la completion d'un nom dans un assistant de saisie |
* Recherche d'information complementaires .... |
* |
* @return void |
*/ |
public void onComplete(ResponseTextHandler sender, String str, String value) { |
if (sender instanceof NameAssistant) { |
onNameCompleted(value); |
} |
} |
/** |
* Action suivant la completion d'un nom : affichage popup information |
* |
*/ |
public void onNameCompleted(String value) { |
if (infoPopup==null) { |
infoPopup = new InfoPopup(this); |
} |
infoPopup.setImageUrl(value); |
} |
/** |
* Action prealable a l'ajout d'une observation : controle presence champs requis et lancement mise a jour |
* |
*/ |
public void onAddInventoryItem() { |
// Lazy instantiation |
if (inventoryItem==null) { |
inventoryItem=new InventoryItem(this); |
} |
inventoryItem.setContent(nameAssistant.getText(),nameAssistant.getValue(),locationAssistant.getText(),locationAssistant.getValue(),date.getText(),lieudit.getText(),station.getText(), milieu.getText(), comment.getText(),"null"); |
inventoryItem.addelement(); |
} |
/** |
* Action prealable a la modification d'une observation : controle presence champs requis et lancement mise a jour |
* |
*/ |
public void onModifyInventoryItem(String ordre) { |
// Lazy instantiation |
if (inventoryItem==null) { |
inventoryItem=new InventoryItem(this); |
} |
inventoryItem.setContent(nameAssistant.getText(),nameAssistant.getValue(),locationAssistant.getText(),locationAssistant.getValue(),date.getText(),lieudit.getText(),station.getText(), milieu.getText(), comment.getText(),ordre); |
inventoryItem.updateElement(); |
} |
/** |
* Action lancee par la selection d'un nom dans un assistant de saisie. Lance |
* la recherche d'informations complementaires (famille, numero |
* nomenclaturaux etc) et met a jour l'inventaire (addelement()) |
* |
* @return void |
*/ |
public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender, |
String str, String value) { |
if (entryView.getOrdre()==null) { // Nouvelle observation |
onAddInventoryItem(); |
} |
else { |
onModifyInventoryItem(entryView.getOrdre()); // Modification d'une observation |
entryView.setOrdre(null); |
} |
} |
// Action portant sur la liste des observations |
/** |
* Action suite ajout, modification, suppression d'un element inventaire |
*/ |
public void onInventoryUpdated(String id_location,String loc, String lieu) { |
if (id_location.compareTo("")==0) { |
id_location="000null"; |
} |
if (loc.compareTo("")==0) { |
loc="000null"; |
} |
if (lieu.compareTo("")==0) { |
lieu="000null"; |
} |
locationFilterView.setIDLocation(id_location); // Mise a jour filtre localite |
locationFilterView.setLocation(loc); // Mise a jour filtre localite |
locationFilterView.setLieudit(lieu); // Mise a jour filtre localite |
locationFilterView.update(); // Mise a jour affichage |
dateFilterView.setYear("all"); |
dateFilterView.setMonth("all"); |
dateFilterView.setDay("all"); |
dateFilterView.update(); |
this.onLocationSelected(id_location,loc,lieu); // Selection localite |
} |
/** |
* Action sur selection d'une observation : affichage du detail |
*/ |
public void onInventoryItemSelected(String ordre) { |
entryView.setOrdre(ordre); // Mise a jour du formulaire de saisie avec l'element selectionne |
entryView.update(); |
} |
/** |
* Action sur deselection d'une observation : remise a zero |
*/ |
public void onInventoryItemUnselected() { |
entryView.setOrdre(null); // Mise a jour du formulaire de saisie avec l'element selectionne |
} |
// Action sur Filtrage |
// Filtre identification |
/** |
* Action sur login : initialisation filtres pour cette utilisateur |
* @param user |
*/ |
public void onLogin(String user) { |
this.user=user; |
connexionView.getSignLabel().setText(user+ " (deconnexion)"); |
inventoryListView.setUser(user); |
dateFilterView.setUser(user); |
entryView.setUser(user); |
locationFilterView.setUser(user); |
this.onInit(); |
} |
/** |
* Action sur logoff |
* @param user |
*/ |
public void onLogoff(String user) { |
this.user=user; |
connexionView.getSignLabel().setText("Connexion"); |
inventoryListView.setUser(user); |
dateFilterView.setUser(user); |
entryView.setUser(user); |
locationFilterView.setUser(user); |
this.onInit(); |
} |
// Filtre recherche contenu |
/** |
* Action sur recherche : affichage de la liste des taxons correspondants |
*/ |
public void onSearch(String search) { |
if (search.trim().compareTo("")==0) { |
search="all"; |
} |
inventoryListView.setSearch(search); |
inventoryListView.updateCount(); |
} |
// Filtre selection lieu |
/** |
* Action sur selection d'un lieu : affichage de la liste des taxons correspondants au filtrage |
*/ |
public void onLocationSelected(String id_loc, String loc,String lieu) { |
// Positionnement Filtre affichage |
inventoryListView.setIdLocation(id_loc); |
inventoryListView.setLocation(loc); |
inventoryListView.setLieudit(lieu); |
inventoryListView.updateCount(); |
// Affichage des filtres |
inventoryListView.displayFilter(); |
} |
// Filtre date d'observation |
/** |
* Action sur selection d'une date : affichage de la liste des taxons correspondants |
*/ |
public void onDateSelected(String year,String month,String day) { |
inventoryListView.setYear(year); |
inventoryListView.setMonth(month); |
inventoryListView.setDay(day); |
inventoryListView.updateCount(); |
inventoryListView.displayFilter(); |
} |
// Declaration, enregistrement |
/** |
* Declaration date : date observation |
* @param date |
*/ |
public void registerDate(TextBox date) { |
this.date=date; |
} |
/** |
* Declaration lieu dit : lieu dit d'observation |
* |
* @param lieudit |
*/ |
public void registerLieudit(TextBox lieudit) { |
this.lieudit=lieudit; |
} |
/** |
* Declaration station : station d'observation |
* |
* @param station |
*/ |
public void registerStation(TextBox station) { |
this.station=station; |
} |
/** |
* Declaration milieu : milieu d'observation |
* |
* @param milieu |
*/ |
public void registerMilieu(TextBox milieu) { |
this.milieu=milieu; |
} |
/** |
* Declaration commentaire b |
* @param commentaire |
*/ |
public void registerComment(TextBox comment) { |
this.comment=comment; |
} |
/** |
* Declaration NameAssistant : completion nom scientifique |
* @param nameassistant |
*/ |
public void registerNameAssistant(NameAssistant nameAssistant) { |
this.nameAssistant=nameAssistant; |
} |
/** |
* Declaration DateFilterView : filtre date observation |
* @param locationList |
*/ |
public void registerDateFilterView(DateFilterView dateFilterView) { |
this.dateFilterView=dateFilterView; |
} |
/** |
* Declaration LocationAssistant : completion commune |
* @param locationassistant |
*/ |
public void registerLocationAssistant(LocationAssistant locationAssistant) { |
this.locationAssistant=locationAssistant; |
} |
/** |
* Declaration LocationFilterView : filtre lieu observation |
* @param locationList |
*/ |
public void registerLocationFilterView(LocationFilterView locationFilterView) { |
this.locationFilterView=locationFilterView; |
} |
// Accesseurs et setteurs |
/** |
* Accesseur Url de base |
* @return Url de base |
*/ |
public String getServiceBaseUrl() { |
return serviceBaseUrl; |
} |
/** |
* Accesseur Utilisateur |
* @return utilisateur connecte ou identifiant de session |
*/ |
public String getUser() { |
return user; |
} |
public void setUser(String user) { |
this.user=user; |
} |
public WidgetContainer getCenterContainer() { |
return center; |
} |
public WidgetContainer getNorthContainer() { |
return north; |
} |
public WidgetContainer getWestContainer() { |
return west; |
} |
public WidgetContainer getSouthContainer() { |
return south; |
} |
public InventoryListView getInventoryListView() { |
return inventoryListView; |
} |
public LocationFilterView getLocationFilterView() { |
return locationFilterView; |
} |
public NameAssistant getNameAssistant() { |
return nameAssistant; |
} |
public LocationAssistant getLocationAssistant() { |
return locationAssistant; |
} |
public InventoryItem getInventoryItem() { |
return inventoryItem; |
} |
public EntryView getEntryView() { |
return entryView; |
} |
public InventoryFilterView getInventoryFilterView() { |
return inventoryFilterView; |
} |
public InfoPopup getInfoPopup() { |
if (infoPopup==null) { |
infoPopup = new InfoPopup(this); |
} |
return infoPopup; |
} |
public void setConnected(boolean connected) { |
this.connected=connected; |
} |
public boolean getConnected() { |
return this.connected; |
} |
public ActionView getActionView() { |
return this.actionView; |
} |
} |
/trunk/src/org/tela_botanica/client/CarnetEnLigneModele.java |
---|
New file |
0,0 → 1,66 |
package org.tela_botanica.client; |
/** |
* Modele generique permettant la validation, l'acces aux donnees distantes et la présentation des donnees en retour |
* Ne previent pas les vues. Est appelle par le mediateur qui traite le resultat. |
*/ |
import org.tela_botanica.client.interfaces.iRetourUtilisateur; |
import org.tela_botanica.client.modeles.Utilisateur; |
import org.tela_botanica.client.modeles.UtilisateurAsynchroneDAO; |
import com.google.gwt.i18n.client.Dictionary; |
public class CarnetEnLigneModele { |
private final String baseURL; // Url d'appel aux services |
/** |
* Constructeur |
*/ |
public CarnetEnLigneModele() { |
baseURL=Dictionary.getDictionary("Parameters").get("serviceBaseUrl"); |
} |
/** |
* |
* @param retour |
*/ |
public void getUtilisateurAsynchroneDAO(final iRetourUtilisateur retour) { |
new UtilisateurAsynchroneDAO().getUtilisateur(baseURL,retour ); |
} |
/** |
* |
* @param retour |
*/ |
public Utilisateur getUtilisateurSynchroneDAO() { |
return new Utilisateur("David Delon synchrone",true); |
} |
public void deconnecterUtilisateur(final iRetourUtilisateur retour, String user) { |
new UtilisateurAsynchroneDAO().deconnecterUtilisateur(baseURL,retour,user ); |
} |
public void connecterUtilisateur(final iRetourUtilisateur retour, String login , String password) { |
new UtilisateurAsynchroneDAO().connecteUtilisateur(baseURL,retour,login, password ); |
} |
} |
/trunk/src/org/tela_botanica/client/SourcesAutoCompleteAsyncTextBoxEvents.java |
---|
New file |
0,0 → 1,7 |
package org.tela_botanica.client; |
public interface SourcesAutoCompleteAsyncTextBoxEvents { |
public void addAutoCompleteAsyncTextBoxListener(AutoCompleteAsyncTextBoxListener listener); |
} |
/trunk/src/org/tela_botanica/client/ActionView.java |
---|
New file |
0,0 → 1,117 |
/** |
David Delon david.delon@clapas.net 2007 |
*/ |
/* |
* ActionView.java : affichage actions sur releves saisie ou affiches (suppression, export etc...) |
* |
* TODO : appel de fonction du mediator, au lieu de passer par les methode de la classe de gestion d'affichage des releves (voir les TODO dans le |
* corps de ce programme) |
* |
* 1: Le programme affiche les boutons commandant les actions sur les releves et arme les actions correspondantes |
* - Transmission d'elements (vers tela botanica) |
* - Suppression d'elements selectionnes |
* - Export vers tableur |
* - Selection / Deselection des releves affiches |
*/ |
package org.tela_botanica.client; |
import net.mygwt.ui.client.Style; |
import net.mygwt.ui.client.event.BaseEvent; |
import net.mygwt.ui.client.event.SelectionListener; |
import net.mygwt.ui.client.widget.Button; |
import net.mygwt.ui.client.widget.IconButton; |
import net.mygwt.ui.client.widget.WidgetContainer; |
import net.mygwt.ui.client.widget.layout.BorderLayoutData; |
import com.google.gwt.user.client.Window; |
import com.google.gwt.user.client.ui.HTML; |
import com.google.gwt.user.client.ui.HorizontalPanel; |
public class ActionView { |
private Mediator mediator=null; |
private HTML exportButton=null; |
public ActionView(final Mediator med) { |
mediator=med; |
HorizontalPanel panel = new HorizontalPanel(); |
HorizontalPanel buttons = new HorizontalPanel(); |
buttons.setSpacing(3); |
// Transmission d'elements |
Button transButton= new Button("Transmettre Tela Botanica", |
new SelectionListener() { |
public void widgetSelected(BaseEvent be) { |
if (mediator.getConnected()) { |
mediator.getInventoryListView().transmitElement(); |
} |
else { |
Window.alert("Identifiez-vous pour transmettre"); |
} |
} |
} |
); |
buttons.add(transButton); |
// Suppression d'elements |
Button delButton = new Button("Suppression", |
new SelectionListener() { |
public void widgetSelected(BaseEvent be) { |
// TODO : une action dans le mediator |
mediator.getInventoryListView().deleteElement(); |
} |
} |
); |
buttons.add(delButton); |
// Export (renseigne lors de l'affichage des releves ) |
exportButton=new HTML(); |
buttons.add(exportButton); |
panel.add(buttons); |
WidgetContainer center=mediator.getCenterContainer(); |
BorderLayoutData centerData = new BorderLayoutData(Style.SOUTH, .05f, 100, 300); |
center.add(panel,centerData); |
} |
public HTML getExportButton() { |
return exportButton; |
} |
} |
/* +--Fin du code ---------------------------------------------------------------------------------------+ |
* $Log$ |
* Revision 1.2 2008-01-30 08:55:40 ddelon |
* fin mise en place mygwt |
* |
* Revision 1.1 2008-01-02 21:26:05 ddelon |
* mise en place mygwt |
* |
* Revision 1.5 2007-12-22 14:48:53 ddelon |
* Documentation et refactorisation |
* |
* Revision 1.5 2007-09-17 19:25:34 ddelon |
* Documentation |
* |
* |
*/ |
/trunk/src/org/tela_botanica/client/LocationFilterView.java |
---|
New file |
0,0 → 1,467 |
/* |
* Copyright 2006 Google Inc. |
* |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
* use this file except in compliance with the License. You may obtain a copy of |
* the License at |
* |
* http://www.apache.org/licenses/LICENSE-2.0 |
* |
* Unless required by applicable law or agreed to in writing, software |
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
* License for the specific language governing permissions and limitations under |
* the License. |
*/ |
package org.tela_botanica.client; |
import com.google.gwt.http.client.URL; |
import com.google.gwt.json.client.JSONArray; |
import com.google.gwt.json.client.JSONParser; |
import com.google.gwt.json.client.JSONString; |
import com.google.gwt.json.client.JSONValue; |
import com.google.gwt.user.client.HTTPRequest; |
import com.google.gwt.user.client.ResponseTextHandler; |
import net.mygwt.ui.client.data.Model; |
import net.mygwt.ui.client.viewer.IAsyncContentCallback; |
import net.mygwt.ui.client.viewer.IAsyncTreeContentProvider; |
import net.mygwt.ui.client.viewer.IElementComparer; |
import net.mygwt.ui.client.viewer.ISelectionChangedListener; |
import net.mygwt.ui.client.viewer.ModelLabelProvider; |
import net.mygwt.ui.client.viewer.SelectionChangedEvent; |
import net.mygwt.ui.client.viewer.TreeViewer; |
import net.mygwt.ui.client.viewer.Viewer; |
import net.mygwt.ui.client.widget.ExpandBar; |
import net.mygwt.ui.client.widget.ExpandItem; |
import net.mygwt.ui.client.widget.tree.Tree; |
public class LocationFilterView { |
private static final String VALUE_UNKNOWN = "Inconnu"; |
private String user; |
private String serviceBaseUrl = null; |
private String id_location = "all"; |
private String location = "all"; |
private String lieudit = "all"; |
private Mediator mediator = null; |
private SALB[] salbs=null; |
private TALB[] talbs=null; |
private FALB[] falbs=null; |
private Model root = null; |
private RALB ralb = null; |
private Tree tree = null; |
private TreeViewer viewer=null; |
public LocationFilterView(Mediator med,InventoryFilterView inventoryFilterView) { |
mediator=med; |
user=mediator.getUser(); |
serviceBaseUrl = mediator.getServiceBaseUrl(); |
mediator.registerLocationFilterView(this); |
initTree(); |
ExpandItem locationfilter = new ExpandItem(); |
locationfilter.setText("Lieux"); |
ExpandBar expandBar=inventoryFilterView.getExpandBar(); |
locationfilter.getContainer().add(tree); |
expandBar.add(locationfilter); |
locationfilter.setExpanded(true); |
} |
// Initialisation noeud de base |
void initTree() { |
// Enregistrement Mise à jour asynchrone |
IAsyncTreeContentProvider cp = new IAsyncTreeContentProvider() { |
public Object[] getElements(Object input) { |
Model m = (Model) input; |
return m.getChildren().toArray(); |
} |
public Object getParent(Object element) { |
return ((Model) element).getParent(); |
} |
public boolean hasChildren(Object parent) { |
if (parent instanceof FALB) { // Station |
return false; |
} |
else { |
if (parent instanceof SALB) { // Departement |
if (((SALB)parent).toString().compareTo(VALUE_UNKNOWN)==0) |
return false; |
else |
return true; |
} |
else { |
return true; |
} |
} |
} |
public void getChildren(final Object parent, final IAsyncContentCallback callback) { |
if (parent instanceof SALB) { |
// Departement + commune |
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryLocationList/" + user + "/" |
+ ((SALB) parent).getAsString("path"), |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
JSONValue jsonValue = JSONParser.parse(str); |
JSONArray jsonArray; |
JSONArray jsonArrayNested; |
int i=0; |
if ((jsonArray = jsonValue.isArray()) != null) { |
int arraySize = jsonArray.size(); |
talbs=new TALB[arraySize]; |
for (i = 0; i < arraySize; ++i) { |
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) { |
String dep=Util.toCelString(((JSONString)jsonArrayNested.get(0)).toString()); |
if (dep.compareTo("000null")==0) dep=VALUE_UNKNOWN; |
talbs[i]=new TALB((SALB) parent,dep); |
} |
} |
callback.setElements(talbs); |
} |
} |
}); |
} |
else if (parent instanceof TALB) { |
// Commune + station |
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryLocationList/" + user + "/" |
+ ((TALB) parent).getAsString("path") , |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
JSONValue jsonValue = JSONParser.parse(str); |
JSONArray jsonArray; |
JSONArray jsonArrayNested; |
int i=0; |
if ((jsonArray = jsonValue.isArray()) != null) { |
int arraySize = jsonArray.size(); |
falbs=new FALB[arraySize]; |
for (i = 0; i < arraySize; ++i) { |
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) { |
String com=Util.toCelString(((JSONString)jsonArrayNested.get(0)).toString()); |
if (com.compareTo("000null")==0) com=VALUE_UNKNOWN; |
falbs[i]=new FALB((TALB) parent, com); |
} |
} |
callback.setElements(falbs); |
} |
} |
}); |
} |
else if (parent instanceof RALB) { |
// Rafraichissement Racine |
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryLocationList/" + user , |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
JSONValue jsonValue = JSONParser.parse(str); |
JSONArray jsonArray; |
JSONArray jsonArrayNested; |
int i=0; |
if ((jsonArray = jsonValue.isArray()) != null) { |
int arraySize = jsonArray.size(); |
salbs=new SALB[arraySize]; |
for (i = 0; i < arraySize; ++i) { |
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) { |
String all=Util.toCelString(((JSONString)jsonArrayNested.get(0)).toString()); |
if (all.compareTo("000null")==0) all=VALUE_UNKNOWN; |
salbs[i]=new SALB(all); |
} |
} |
callback.setElements(salbs); |
Model m=new Model(); |
m.set("name",id_location); |
viewer.setExpanded(m,true); |
} |
} |
}); |
} |
} |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
} |
}; |
tree = new Tree(); |
viewer = new TreeViewer(tree); |
viewer.setContentProvider(cp); |
viewer.setLabelProvider(new ModelLabelProvider()); |
viewer.setComparer(new IElementComparer() { |
public boolean equals(Object a, Object b) { |
if ((a==null) || b==null) |
return false; |
if (((Model) a).getAsString("name").compareTo(((Model) b).getAsString("name"))==0) { |
return true; |
} |
else return false; |
} |
} |
); |
viewer.addSelectionListener(new ISelectionChangedListener() { |
public void selectionChanged(SelectionChangedEvent se) { |
Model m = (Model) se.getSelection().getFirstElement(); |
// Info.show("Selection Changed", "{0} was selected", m.getAsString("path")); |
if (m instanceof TALB) { // Commune |
location=m.getAsString("name"); |
if (location.compareTo(VALUE_UNKNOWN)==0) location="000null"; |
id_location=m.getAsString("salb"); |
if (id_location.compareTo(VALUE_UNKNOWN)==0) id_location="000null"; |
lieudit="all"; |
mediator.onLocationSelected(id_location,location,lieudit); |
} |
else |
if (m instanceof FALB) { // Station |
id_location=m.getAsString("salb"); |
if (id_location.compareTo(VALUE_UNKNOWN)==0) id_location="000null"; |
location=m.getAsString("talb"); |
if (location.compareTo(VALUE_UNKNOWN)==0) location="000null"; |
lieudit=m.getAsString("name"); |
if (lieudit.compareTo(VALUE_UNKNOWN)==0) lieudit="000null"; |
mediator.onLocationSelected(id_location,location,lieudit); |
} |
else |
if (m instanceof SALB) { // Departement |
id_location=m.getAsString("name"); |
if (id_location.compareTo(VALUE_UNKNOWN)==0) id_location="000null"; |
location="all"; |
lieudit="all"; |
mediator.onLocationSelected(id_location,location,lieudit); |
} |
if (m instanceof RALB) { // Pays |
id_location="all"; |
location="all"; |
lieudit="all"; |
mediator.onLocationSelected(id_location,location,lieudit); |
} |
} |
}); |
// Initialisation premier niveau (doublon obligatoire avec rafraichissement asynchrone) |
root = new Model(); |
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryLocationList/" + user , |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
JSONValue jsonValue = JSONParser.parse(str); |
JSONArray jsonArray; |
JSONArray jsonArrayNested; |
int i=0; |
if ((jsonArray = jsonValue.isArray()) != null) { |
int arraySize = jsonArray.size(); |
salbs=new SALB[arraySize]; |
ralb = new RALB("France"); |
for (i = 0; i < arraySize; ++i) { |
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) { |
String all=Util.toCelString(((JSONString)jsonArrayNested.get(0)).toString()); |
if (all.compareTo("000null")==0) all=VALUE_UNKNOWN; |
salbs[i]=new SALB(all); |
ralb.add(salbs[i]); |
} |
} |
root.add(ralb); |
viewer.setInput(root); |
} |
} |
}); |
} |
public void setLocation(String location) { |
this.location = location; |
} |
public void setIDLocation(String id_location) { |
this.id_location = id_location; |
} |
public void setLieudit(String lieudit) { |
this.lieudit = lieudit; |
} |
public void setUser(String user) { |
this.user = user; |
} |
private class RALB extends Model { // Root Administrative level boundaries (pays) |
public RALB(String name) { |
set("name", name); |
set("path", URL.encodeComponent(name)); |
} |
public String toString() { |
return getAsString("name"); |
} |
} |
private class SALB extends Model { // Second Administrative level boundaries (departerment) |
public SALB(String name) { |
set("name", name); |
set("path", URL.encodeComponent(name)); |
} |
public String toString() { |
return getAsString("name"); |
} |
} |
private class TALB extends Model { // Tierce Administrative level boundaries (Commune) |
public TALB(SALB parent, String name) { |
set("name", name); |
set("salb", parent.get("name")); |
set("path", parent.get("path")+"/"+URL.encodeComponent(name)); |
} |
public String toString() { |
return getAsString("name"); |
} |
} |
private class FALB extends Model { // Forth Administrative level boundaries (Station) |
public FALB(TALB parent,String name) { |
set("name", name); |
set("salb", parent.get("salb")); |
set("talb", parent.get("name")); |
set("path", parent.get("path")+"/"+URL.encodeComponent(name)); |
} |
public String toString() { |
return getAsString("name"); |
} |
} |
public void update() { |
Model m=new Model(); |
m.set("name",id_location); |
if (viewer.findItem(m)!=null) { |
viewer.refresh(m); // Rafraichissement branche departemental |
} |
else { // Pas de branche departementale ? : rafraichissement total |
Model r=new Model(); |
r.set("name","France"); |
viewer.refresh(r); |
} |
} |
} |
/trunk/src/org/tela_botanica/client/NameAssistant.java |
---|
New file |
0,0 → 1,87 |
package org.tela_botanica.client; |
import java.util.EventListener; |
import com.google.gwt.json.client.JSONArray; |
import com.google.gwt.json.client.JSONParser; |
import com.google.gwt.json.client.JSONString; |
import com.google.gwt.json.client.JSONValue; |
import com.google.gwt.user.client.ResponseTextHandler; |
import com.google.gwt.user.client.ui.Composite; |
import com.google.gwt.user.client.ui.HorizontalPanel; |
import org.tela_botanica.client.AutoCompleteAsyncTextBox; |
/** |
* Affiche une liste de nom pour selection. Son retournes le nom selectionne (gettext()) et un code associe (getvalue()). |
*/ |
public class NameAssistant extends Composite implements EventListener, ResponseTextHandler { |
private AutoCompleteAsyncTextBox autoCompletebox = new AutoCompleteAsyncTextBox(this); |
private HorizontalPanel panel = new HorizontalPanel(); |
private Mediator mediator = null; |
public NameAssistant(Mediator med) { |
mediator=med; |
mediator.registerNameAssistant(this); |
autoCompletebox.setSearchUrl(mediator.getServiceBaseUrl()+"/NameSearch/"); |
panel.add(autoCompletebox); |
autoCompletebox.setWidth("100%"); |
initWidget(panel); |
autoCompletebox.addAutoCompleteAsyncTextBoxListener(mediator); |
} |
public void onCompletion(String str) { |
JSONValue jsonValue= JSONParser.parse(str); |
JSONArray jsonArray; |
JSONArray jsonArrayNested; |
if ((jsonArray = jsonValue.isArray()) != null) { |
for (int i = 0; i < jsonArray.size(); ++i) { |
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) { |
autoCompletebox.addItem(Util.toCelString(((JSONString) jsonArrayNested.get(0)).toString()),Util.toCelString(((JSONString) jsonArrayNested.get(1)).toString())); |
} |
} |
} |
autoCompletebox.displayList(); |
} |
public void setText(String str) { |
autoCompletebox.setText(str); |
} |
public String getText() { |
return autoCompletebox.getText(); |
} |
public String getValue() { |
return autoCompletebox.getValue(); |
} |
public void setValue(String value) { |
autoCompletebox.setValue(value); |
} |
} |
/trunk/src/org/tela_botanica/client/InventoryItem.java |
---|
New file |
0,0 → 1,274 |
package org.tela_botanica.client; |
import com.google.gwt.http.client.URL; |
import com.google.gwt.json.client.JSONArray; |
import com.google.gwt.json.client.JSONParser; |
import com.google.gwt.json.client.JSONString; |
import com.google.gwt.json.client.JSONValue; |
import com.google.gwt.user.client.HTTPRequest; |
import com.google.gwt.user.client.ResponseTextHandler; |
public class InventoryItem { |
// TODO : Singleton ? |
private String name=null; |
private String nomenclaturalNumber=null; |
private String location=null; |
private String location_id=null; |
private String date=null; |
private String lieudit=null; |
private String station=null; |
private String milieu=null; |
private String comment=null; |
private String ordre=null; |
private Mediator mediator = null; |
private String serviceBaseUrl = null; |
// Constructeur |
// Constructeur sur saisie |
public InventoryItem(Mediator med) { |
mediator=med; |
serviceBaseUrl = mediator.getServiceBaseUrl(); |
} |
// Alimentation contenu depuis saisie |
public void setContent(String name,String nomenclaturalNumber, String location, String location_id, String date, String lieudit, String station, String milieu, String comment,String ordre) { |
this.name=name; |
this.nomenclaturalNumber=nomenclaturalNumber; |
// Suppresion indication departementale (on pourrait faire mieux !!) |
int pos=location.indexOf(" (" ); |
if (pos>=0) { |
this.location=location.substring(0,pos); |
} |
else { |
this.location=location; |
} |
this.location_id=location_id; |
if (location.compareTo("")==0) this.location_id=""; |
if (location_id==null) this.location_id=""; |
this.date=date; |
this.lieudit=lieudit; |
this.station=station; |
this.milieu=milieu; |
this.comment=comment; |
this.ordre=ordre; |
} |
public boolean isValid() { |
// TODO : controle date |
if (name.compareTo("")==0) { |
return false; |
} |
else { |
return true; |
} |
} |
/** |
* Lancement de la creation d'une ligne d'inventaire (appele par Mediator.onAddInventoryItem()) |
* |
*/ |
public void addelement() { |
if (isValid()) { |
// Creation d'un nom faisant parti du referentiel : recherche du nom valide correspondant |
if (nomenclaturalNumber !=null) { |
HTTPRequest.asyncGet(serviceBaseUrl + "/NameValid/" + nomenclaturalNumber, |
new ResponseTextHandler() { |
public void onCompletion(String strcomplete) { |
JSONValue jsonValue = JSONParser.parse(strcomplete); |
JSONArray jsonArray; |
if ((jsonArray = jsonValue.isArray()) != null) { |
// Nom retenu, Num Nomen nom retenu, Num Taxon, |
// Famille |
addElement(name, nomenclaturalNumber, |
Util.toCelString(((JSONString) jsonArray.get(0)) |
.toString()), |
((JSONString) jsonArray.get(1)) |
.stringValue(), |
((JSONString) jsonArray.get(2)) |
.stringValue(), |
Util.toCelString(((JSONString) jsonArray.get(3)) |
.toString()), |
location,location_id,date,lieudit,station,milieu,comment); |
} |
} |
}); |
} |
// Saisie libre |
else { |
addElement(name, " ", " ", " ", " ", " ",location,location_id,date,lieudit,station,milieu,comment); |
} |
} |
else { |
// TODO : message d'erreur |
return; |
} |
} |
/** |
* Ajoute effectif d'un element a l'inventaire (appel interne) |
* |
* @param nom_sel : |
* nom selectionne |
* @param num_nom_sel : |
* numero nomenclatural nom selectionne |
* @param nom_ret : |
* nom retenu |
* @param num_nom_ret : |
* numero nomenclaturel nom retenu |
* @param num_taxon : |
* numero taxonomique |
* @param famille : |
* famille |
*/ |
private void addElement(String nom_sel, String num_nom_sel, String nom_ret, |
String num_nom_ret, String num_taxon, String famille,final String loc, String id_location,String dat, String lieu, String sta, String mil, String comment) { |
HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/", "identifiant=" |
+ mediator.getUser() + "&nom_sel=" + URL.encodeComponent(nom_sel) + "&num_nom_sel=" + num_nom_sel |
+ "&nom_ret=" + URL.encodeComponent(nom_ret) + "&num_nom_ret=" + num_nom_ret |
+ "&num_taxon=" + num_taxon + "&famille=" + URL.encodeComponent(famille) + "&location=" + URL.encodeComponent(loc) + "&id_location=" + id_location + "&date_observation=" + dat |
+ "&lieudit="+ URL.encodeComponent(lieu) + "&station="+ URL.encodeComponent(sta) +"&milieu="+ URL.encodeComponent(mil) + "&commentaire="+ URL.encodeComponent(comment), |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
mediator.onInventoryUpdated(location_id,location,"all"); |
} |
}); |
} |
/** |
* Lancement de la mise a jour d'une ligne d'inventaire (appele par Mediator.onModifyInventoryItem()) |
* |
*/ |
public void updateElement() { |
if (isValid()) { |
// Modification d'un nom faisant parti du referentiel : recherche du nom valide correspondant |
if (nomenclaturalNumber !=null) { |
HTTPRequest.asyncGet(serviceBaseUrl + "/NameValid/" + nomenclaturalNumber, |
new ResponseTextHandler() { |
public void onCompletion(String strcomplete) { |
JSONValue jsonValue = JSONParser.parse(strcomplete); |
JSONArray jsonArray; |
if ((jsonArray = jsonValue.isArray()) != null) { |
// Nom retenu, Num Nomen nom retenu, Num Taxon, Famille |
updateElement(ordre,name, nomenclaturalNumber, |
Util.toCelString(((JSONString) jsonArray.get(0)) |
.toString()), |
((JSONString) jsonArray.get(1)) |
.stringValue(), |
((JSONString) jsonArray.get(2)) |
.stringValue(), |
Util.toCelString(((JSONString) jsonArray.get(3)) |
.toString()), |
location,location_id,date,lieudit,station, milieu,comment); |
} |
} |
}); |
} |
// Modification d'un nom ne faisant pas parti du referentiel (saisie libre) |
else { |
updateElement(ordre,name, " ", " ", " ", " ", " ",location,location_id,date,lieudit,station, milieu, comment); |
} |
} |
else { |
// TODO : message d'erreur |
return; |
} |
} |
/** |
* Modification effective d'un element de l'inventaire (appel interne) |
* |
* @param ordre : numero d'ordre |
* @param nom_sel : |
* nom selectionne |
* @param num_nom_sel : |
* numero nomenclatural nom selectionne |
* @param nom_ret : |
* nom retenu |
* @param num_nom_ret : |
* numero nomenclaturel nom retenu |
* @param num_taxon : |
* numero taxonomique |
* @param famille : |
* famille |
*/ |
private void updateElement(String ordre, String nom_sel, String num_nom_sel, String nom_ret, |
String num_nom_ret, String num_taxon, String famille,final String loc, String id_location,String dat, String lieu, String sta, String mil, String comment) { |
HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/" + mediator.getUser() + "/" +ordre + "/", |
"&nom_sel=" + URL.encodeComponent(nom_sel) + "&num_nom_sel=" + num_nom_sel |
+ "&nom_ret=" + URL.encodeComponent(nom_ret) + "&num_nom_ret=" + num_nom_ret |
+ "&num_taxon=" + num_taxon + "&famille=" + URL.encodeComponent(famille) + "&location=" + URL.encodeComponent(loc) + "&id_location=" + id_location + "&date_observation=" + dat |
+ "&lieudit="+ URL.encodeComponent(lieu) + "&station="+ URL.encodeComponent(sta) + "&milieu="+ URL.encodeComponent(mil) + "&commentaire="+ URL.encodeComponent(comment), |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
mediator.onInventoryUpdated(location_id,location,"all"); |
} |
}); |
} |
} |
/trunk/src/org/tela_botanica/client/Util.java |
---|
New file |
0,0 → 1,12 |
package org.tela_botanica.client; |
public class Util { |
public Util() { |
} |
public static String toCelString(String str) { |
return str.substring(1,str.length()-1); |
// |
} |
} |
/trunk/src/org/tela_botanica/client/AutoCompleteAsyncTextBox.java |
---|
New file |
0,0 → 1,364 |
/* |
Auto-Completion Textbox for GWT |
Copyright (C) 2006 Oliver Albers http://gwt.components.googlepages.com/ |
This library is free software; you can redistribute it and/or |
modify it under the terms of the GNU Lesser General Public |
License as published by the Free Software Foundation; either |
version 2.1 of the License, or (at your option) any later version. |
This library is distributed in the hope that it will be useful, |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
Lesser General Public License for more details. |
You should have received a copy of the GNU Lesser General Public |
License along with this library; if not, write to the Free Software |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
*/ |
package org.tela_botanica.client; |
// TODO : traiter latence (augmenter en fonction rapidit� saisie + texte vide) |
// TODO : traitement espace apres l'espece (%20) |
// TODO : Utiliser Suggestbox et les Associating Data Transfer Objects (DTOs) with Suggestion Objects |
import com.google.gwt.user.client.HTTPRequest; |
import com.google.gwt.user.client.ResponseTextHandler; |
import com.google.gwt.user.client.ui.KeyboardListener; |
import com.google.gwt.user.client.ui.ListBox; |
import com.google.gwt.user.client.ui.PopupPanel; |
import com.google.gwt.user.client.ui.TextBox; |
import com.google.gwt.user.client.ui.Widget; |
import com.google.gwt.user.client.DOM; |
import com.google.gwt.user.client.Event; |
import java.util.Vector; |
import java.util.HashMap; |
public class AutoCompleteAsyncTextBox extends TextBox |
implements KeyboardListener, SourcesAutoCompleteAsyncTextBoxEvents { |
private String searchUrl = null; |
private AutoCompleteAsyncTextBoxListenerCollection autoCompleteAsyncTextBoxListeners=null; |
private HashMap cache = new HashMap(); |
private boolean searching = false; |
private ResponseTextHandler responseTextHandler=null; |
protected PopupPanel choicesPopup = new PopupPanel(true); |
protected ListBox choices = new ListBox() { |
public void onBrowserEvent(Event event) { |
if (Event.ONCLICK == DOM.eventGetType(event)) { |
complete(); |
} |
} |
}; |
protected Vector items = new Vector(); |
protected boolean visible = false; |
/** |
* Value linked to current text |
*/ |
protected String currentValue = null; |
/** |
* Default Constructor |
* |
*/ |
public AutoCompleteAsyncTextBox(ResponseTextHandler rsp) |
{ |
super(); |
responseTextHandler=rsp; |
this.addKeyboardListener(this); |
choices.sinkEvents(Event.ONCLICK); |
this.setStyleName("AutoCompleteAsyncTextBox"); |
choicesPopup.add(choices); |
choicesPopup.addStyleName("AutoCompleteChoices"); |
choices.setStyleName("list"); |
} |
public void addAutoCompleteAsyncTextBoxListener(AutoCompleteAsyncTextBoxListener listener) { |
if (autoCompleteAsyncTextBoxListeners == null) { |
autoCompleteAsyncTextBoxListeners = new AutoCompleteAsyncTextBoxListenerCollection(); |
} |
autoCompleteAsyncTextBoxListeners.addElement(listener); |
} |
public void setSearchUrl(String url) { |
this.searchUrl=url; |
} |
private void doFetchURL(String match) { |
/* |
* Here we fetch the URL and call the handler |
*/ |
String rematch=match.replaceAll(" ","/"); |
rematch=rematch.replaceAll("%",""); |
if (this.searchUrl!=null && searching==false) { |
searching=true; |
// HTTPRequest.asyncGet(URL.encodeComponent(this.searchUrl) + rematch, responseTextHandler ); |
HTTPRequest.asyncGet(this.searchUrl + rematch, responseTextHandler ); |
} |
} |
public void onKeyDown(Widget arg0, char arg1, int arg2) { |
if(arg1 == KEY_ENTER) |
{ |
enterKey(arg0, arg1, arg2); |
} |
else if(arg1 == KEY_DOWN) |
{ |
downKey(arg0, arg1, arg2); |
} |
else if(arg1 == KEY_UP) |
{ |
upKey(arg0, arg1, arg2); |
} |
else if(arg1 == KEY_ESCAPE) |
{ |
escapeKey(arg0, arg1, arg2); |
} |
} |
/** |
* Not used at all (probleme avec ie, qui ne comprend pas les touches meta) |
*/ |
public void onKeyPress(Widget arg0, char arg1, int arg2) { |
} |
// The down key was pressed. |
protected void downKey(Widget arg0, char arg1, int arg2) { |
int selectedIndex = choices.getSelectedIndex(); |
selectedIndex++; |
if (selectedIndex >= choices.getItemCount()) |
{ |
selectedIndex = 0; |
} |
choices.setSelectedIndex(selectedIndex); |
} |
// The up key was pressed. |
protected void upKey(Widget arg0, char arg1, int arg2) { |
int selectedIndex = choices.getSelectedIndex(); |
selectedIndex--; |
if(selectedIndex < 0) |
{ |
selectedIndex = choices.getItemCount() - 1; |
} |
choices.setSelectedIndex(selectedIndex); |
} |
// The enter key was pressed. |
protected void enterKey(Widget arg0, char arg1, int arg2) { |
if(visible) |
{ |
complete(); |
} |
else { |
// Validation de l'entree : appel asynchrone |
if (autoCompleteAsyncTextBoxListeners!= null) { |
autoCompleteAsyncTextBoxListeners.fireTextBoxEnter(this,this.getText(),currentValue); |
} |
currentValue=null; |
this.setText(""); |
this.setValue(null); |
} |
} |
//The escape key was pressed. |
protected void escapeKey(Widget arg0, char arg1, int arg2) { |
choices.clear(); |
items.clear(); |
choicesPopup.hide(); |
visible = false; |
} |
// Any other non-special key was pressed. |
protected void otherKey(Widget arg0, char arg1, int arg2) { |
// Lancement appel |
String text = this.getText(); |
if(text.length() > 0) |
{ |
currentValue=null; |
items.clear(); |
if (getFromCache(text)!=null) { |
items=getFromCache(text); |
displayList(); |
} |
else { |
this.doFetchURL(text); |
} |
} |
} |
public void onKeyUp(Widget arg0, char arg1, int arg2) { |
switch(arg1) { |
case KEY_ALT: |
case KEY_CTRL: |
case KEY_DOWN: |
case KEY_END: |
case KEY_ENTER: |
case KEY_ESCAPE: |
case KEY_HOME: |
case KEY_LEFT: |
case KEY_PAGEDOWN: |
case KEY_PAGEUP: |
case KEY_RIGHT: |
case KEY_SHIFT: |
case KEY_TAB: |
case KEY_UP: |
break; |
default: |
otherKey(arg0, arg1, arg2); |
break; |
} |
} |
// Display assistant |
public void displayList() { |
searching=false; |
if(this.items.size() > 0) |
{ |
addToCache(this.getText(),(Vector) items.clone()); |
choices.clear(); |
for(int i = 0; i < items.size(); i++) |
{ |
choices.addItem(((String [])items.get(i))[0],((String [])items.get(i))[1]); |
} |
// if there is only one match and it is what is in the |
// text field anyways there is no need to show autocompletion |
// if(items.size() == 1 && (((String []) items.get(0))[0]).compareTo(this.getText()) == 0) |
// { |
// choicesPopup.hide(); |
// } else { |
choices.setSelectedIndex(0); |
choices.setVisibleItemCount(items.size()); |
visible = true; |
choicesPopup.setPopupPosition(this.getAbsoluteLeft(), this.getAbsoluteTop() + this.getOffsetHeight()); |
choicesPopup.setPopupPosition(this.getAbsoluteLeft(), this.getAbsoluteTop() + this.getOffsetHeight()); |
choicesPopup.setWidth(this.getOffsetWidth() + "px"); |
choices.setWidth(this.getOffsetWidth() + "px"); |
choicesPopup.show(); |
// } |
} else { |
visible = false; |
choicesPopup.hide(); |
} |
} |
/** |
* A mouseclick in the list of items |
*/ |
public void onChange(Widget arg0) { |
complete(); |
} |
public void onClick(Widget arg0) { |
complete(); |
} |
// add selected item to textbox |
protected void complete() |
{ |
if(choices.getItemCount() > 0) |
{ |
this.setText(choices.getItemText(choices.getSelectedIndex())); |
currentValue=choices.getValue(choices.getSelectedIndex()); |
if (autoCompleteAsyncTextBoxListeners!= null) { |
autoCompleteAsyncTextBoxListeners.fireTextBoxComplete(responseTextHandler,this.getText(),currentValue); |
} |
} |
visible=false; |
items.clear(); |
choices.clear(); |
choicesPopup.hide(); |
} |
public void addItem(String item, String value) { |
items.add(new String [] {item, value}); |
} |
private void addToCache (String query, Vector result) |
{ |
cache.put(query.toLowerCase(),result); |
} |
private Vector getFromCache (String query) |
{ |
return (Vector) cache.get(query.toLowerCase()); |
} |
public String getValue() { |
return currentValue; |
} |
public void setValue(String value) { |
this.currentValue=value; |
} |
} |
/trunk/src/org/tela_botanica/client/CalendarWidget.java |
---|
New file |
0,0 → 1,263 |
package org.tela_botanica.client; |
import java.util.Date; |
import com.google.gwt.user.client.DOM; |
import com.google.gwt.user.client.Element; |
import com.google.gwt.user.client.ui.Button; |
import com.google.gwt.user.client.ui.ChangeListener; |
import com.google.gwt.user.client.ui.ChangeListenerCollection; |
import com.google.gwt.user.client.ui.ClickListener; |
import com.google.gwt.user.client.ui.Composite; |
import com.google.gwt.user.client.ui.DockPanel; |
import com.google.gwt.user.client.ui.Grid; |
import com.google.gwt.user.client.ui.HTML; |
import com.google.gwt.user.client.ui.HasAlignment; |
import com.google.gwt.user.client.ui.HorizontalPanel; |
import com.google.gwt.user.client.ui.SourcesChangeEvents; |
import com.google.gwt.user.client.ui.Widget; |
public class CalendarWidget extends Composite |
implements ClickListener, SourcesChangeEvents { |
private class NavBar extends Composite implements ClickListener { |
public final DockPanel bar = new DockPanel(); |
public final Button prevMonth = new Button("<", this); |
public final Button prevYear = new Button("<<", this); |
public final Button nextYear = new Button(">>", this); |
public final Button nextMonth = new Button(">", this); |
public final HTML title = new HTML(); |
private final CalendarWidget calendar; |
public NavBar(CalendarWidget calendar) { |
this.calendar = calendar; |
setWidget(bar); |
bar.setStyleName("navbar"); |
title.setStyleName("header"); |
HorizontalPanel prevButtons = new HorizontalPanel(); |
prevButtons.add(prevYear); |
prevButtons.add(prevMonth); |
HorizontalPanel nextButtons = new HorizontalPanel(); |
nextButtons.add(nextMonth); |
nextButtons.add(nextYear); |
bar.add(prevButtons, DockPanel.WEST); |
bar.setCellHorizontalAlignment(prevButtons, DockPanel.ALIGN_LEFT); |
bar.add(nextButtons, DockPanel.EAST); |
bar.setCellHorizontalAlignment(nextButtons, DockPanel.ALIGN_RIGHT); |
bar.add(title, DockPanel.CENTER); |
bar.setVerticalAlignment(DockPanel.ALIGN_MIDDLE); |
bar.setCellHorizontalAlignment(title, HasAlignment.ALIGN_CENTER); |
bar.setCellVerticalAlignment(title, HasAlignment.ALIGN_MIDDLE); |
bar.setCellWidth(title, "100%"); |
} |
public void onClick(Widget sender) { |
if (sender == prevMonth) { |
calendar.prevMonth(); |
} else if (sender == prevYear) { |
calendar.prevYear(); |
} else if (sender == nextYear) { |
calendar.nextYear(); |
} else if (sender == nextMonth) { |
calendar.nextMonth(); |
} |
} |
} |
private static class CellHTML extends HTML { |
private int day; |
public CellHTML(String text, int day) { |
super(text); |
this.day = day; |
} |
public int getDay() { |
return day; |
} |
} |
private final NavBar navbar = new NavBar(this); |
private final DockPanel outer = new DockPanel(); |
private final Grid grid = new Grid(6, 7) { |
public boolean clearCell(int row, int column) { |
boolean retValue = super.clearCell(row, column); |
Element td = getCellFormatter().getElement(row, column); |
DOM.setInnerHTML(td, ""); |
return retValue; |
} |
}; |
private Date date = new Date(); |
private ChangeListenerCollection changeListeners; |
private String[] days = new String[] { "Dimanche", "Lundi", "Mardi", |
"Mercredi", "Jeudi", "Vendredi", "Samedi" }; |
private String[] months = new String[] { "Janvier", "Fevrier", "Mars", |
"Avril", "Mai", "Juin", "Juillet", "Aout", "Septembre", "Octobre", |
"Novembre", "Decembre" }; |
public CalendarWidget() { |
setWidget(outer); |
grid.setStyleName("table"); |
grid.setCellSpacing(0); |
outer.add(navbar, DockPanel.NORTH); |
outer.add(grid, DockPanel.CENTER); |
drawCalendar(); |
setStyleName("CalendarWidget"); |
} |
private void drawCalendar() { |
int year = getYear(); |
int month = getMonth(); |
int day = getDay(); |
setHeaderText(year, month); |
grid.getRowFormatter().setStyleName(0, "weekheader"); |
for (int i = 0; i < days.length; i++) { |
grid.getCellFormatter().setStyleName(0, i, "days"); |
grid.setText(0, i, days[i].substring(0, 3)); |
} |
Date now = new Date(); |
int sameDay = now.getDate(); |
int today = (now.getMonth() == month && now.getYear()+1900 == year) ? sameDay : 0; |
int firstDay = new Date(year - 1900, month, 1).getDay(); |
int numOfDays = getDaysInMonth(year, month); |
int j = 0; |
for (int i = 1; i < 6; i++) { |
for (int k = 0; k < 7; k++, j++) { |
int displayNum = (j - firstDay + 1); |
if (j < firstDay || displayNum > numOfDays) { |
grid.getCellFormatter().setStyleName(i, k, "empty"); |
grid.setHTML(i, k, " "); |
} else { |
HTML html = new CellHTML( |
"<span>" + String.valueOf(displayNum) + "</span>", |
displayNum); |
html.addClickListener(this); |
grid.getCellFormatter().setStyleName(i, k, "cell"); |
if (displayNum == today) { |
grid.getCellFormatter().addStyleName(i, k, "today"); |
} else if (displayNum == sameDay) { |
grid.getCellFormatter().addStyleName(i, k, "day"); |
} |
grid.setWidget(i, k, html); |
} |
} |
} |
} |
protected void setHeaderText(int year, int month) { |
navbar.title.setText(months[month] + ", " + year); |
} |
private int getDaysInMonth(int year, int month) { |
switch (month) { |
case 1: |
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) |
return 29; // leap year |
else |
return 28; |
case 3: |
return 30; |
case 5: |
return 30; |
case 8: |
return 30; |
case 10: |
return 30; |
default: |
return 31; |
} |
} |
public void prevMonth() { |
int month = getMonth() - 1; |
if (month < 0) { |
setDate(getYear() - 1, 11, getDay()); |
} else { |
setMonth(month); |
} |
drawCalendar(); |
} |
public void nextMonth() { |
int month = getMonth() + 1; |
if (month > 11) { |
setDate(getYear() + 1, 0, getDay()); |
} else { |
setMonth(month); |
} |
drawCalendar(); |
} |
public void prevYear() { |
setYear(getYear() - 1); |
drawCalendar(); |
} |
public void nextYear() { |
setYear(getYear() + 1); |
drawCalendar(); |
} |
private void setDate(int year, int month, int day) { |
date = new Date(year - 1900, month, day); |
} |
private void setYear(int year) { |
date.setYear(year - 1900); |
} |
private void setMonth(int month) { |
date.setMonth(month); |
} |
public int getYear() { |
return 1900 + date.getYear(); |
} |
public int getMonth() { |
return date.getMonth(); |
} |
public int getDay() { |
return date.getDate(); |
} |
public Date getDate() { |
return date; |
} |
public void onClick(Widget sender) { |
CellHTML cell = (CellHTML)sender; |
setDate(getYear(), getMonth(), cell.getDay()); |
drawCalendar(); |
if (changeListeners != null) { |
changeListeners.fireChange(this); |
} |
} |
public void addChangeListener(ChangeListener listener) { |
if (changeListeners == null) |
changeListeners = new ChangeListenerCollection(); |
changeListeners.add(listener); |
} |
public void removeChangeListener(ChangeListener listener) { |
if (changeListeners != null) |
changeListeners.remove(listener); |
} |
} |
/trunk/src/org/tela_botanica/client/CarnetEnLigneMediateur.java |
---|
New file |
0,0 → 1,154 |
package org.tela_botanica.client; |
import net.mygwt.ui.client.event.BaseEvent; |
import net.mygwt.ui.client.event.Listener; |
import net.mygwt.ui.client.util.Observable; |
import org.tela_botanica.client.image.ImageMediateur; |
import org.tela_botanica.client.interfaces.iMediateur; |
import org.tela_botanica.client.interfaces.iRetourUtilisateur; |
import org.tela_botanica.client.modeles.Utilisateur; |
import org.tela_botanica.client.observation.ObservationMediateur; |
public class CarnetEnLigneMediateur extends Observable implements iMediateur, Listener { |
// Evenenements |
final static public int ETAT_CONNEXION=1; |
final static public int DECONNEXION=2; |
final static public int CONNEXION = 3; |
private final CarnetEnLigneModele carnetEnLigneModele; |
private Utilisateur utilisateur=null; |
// Fonctionnement servicecs |
private boolean async=true; |
public CarnetEnLigneMediateur() { |
carnetEnLigneModele=new CarnetEnLigneModele(); |
addListener(ETAT_CONNEXION,this); |
getEtatUtilisateur(); // Alimente Objet Utilisateur |
} |
/** |
* Fin construction (est appelle sur reception evenement Applicatif ETAT_CONNEXION) |
* |
*/ |
private void _CarnetEnLigneMediateur() { |
new ImageMediateur(this); |
new ObservationMediateur(this); |
} |
private void getEtatUtilisateur() { // Pourrait devenir publique ... |
// TODO : utiliser une factory ici : Avec Modele synchrone ou non, ou au niveau methode comme dans cette exemple |
// Pas possible de traiter dans Modele car retour asynchrone devant etre traité ici. |
// if asynchrone |
if (async) { |
carnetEnLigneModele.getUtilisateurAsynchroneDAO( |
new iRetourUtilisateur() { |
public void onRetour(Utilisateur uti) { |
utilisateur=uti; |
fireEvent(ETAT_CONNEXION); |
} |
} |
); |
} |
// else if synchrone |
else { |
utilisateur= carnetEnLigneModele.getUtilisateurSynchroneDAO(); |
_CarnetEnLigneMediateur(); |
} |
} |
// Evenenements Applicatifs |
public void handleEvent(BaseEvent be) { |
if (be.type==CarnetEnLigneMediateur.ETAT_CONNEXION) { |
_CarnetEnLigneMediateur(); // Fin initialisation |
} |
} |
// Methode publiques |
/** |
* Recherche Identifiant utilisateur en cours et etat de connection |
* @return Utilisateur |
*/ |
public Utilisateur getUtilisateur() { |
return utilisateur; |
} |
/** |
* Deconnecte l'utilisateur passe en parametre |
* @param String uti (utilisateur connecte) |
*/ |
public void deconnecterUtilisateur() { |
carnetEnLigneModele.deconnecterUtilisateur( |
new iRetourUtilisateur() { |
public void onRetour(Utilisateur uti) { |
utilisateur=uti; |
fireEvent(DECONNEXION); |
} |
}, utilisateur.getIdentifiant() |
); |
} |
public void connecterUtilisateur(String login, String password) { |
carnetEnLigneModele.connecterUtilisateur( |
new iRetourUtilisateur() { |
public void onRetour(Utilisateur uti) { |
utilisateur=uti; |
fireEvent(CONNEXION); |
} |
}, login, password |
); |
} |
} |
/trunk/src/org/tela_botanica/client/DateFilterView.java |
---|
New file |
0,0 → 1,459 |
/* |
* Copyright 2006 Google Inc. |
* |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
* use this file except in compliance with the License. You may obtain a copy of |
* the License at |
* |
* http://www.apache.org/licenses/LICENSE-2.0 |
* |
* Unless required by applicable law or agreed to in writing, software |
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
* License for the specific language governing permissions and limitations under |
* the License. |
*/ |
package org.tela_botanica.client; |
import net.mygwt.ui.client.data.Model; |
import net.mygwt.ui.client.viewer.IAsyncContentCallback; |
import net.mygwt.ui.client.viewer.IAsyncTreeContentProvider; |
import net.mygwt.ui.client.viewer.IElementComparer; |
import net.mygwt.ui.client.viewer.ISelectionChangedListener; |
import net.mygwt.ui.client.viewer.ModelLabelProvider; |
import net.mygwt.ui.client.viewer.SelectionChangedEvent; |
import net.mygwt.ui.client.viewer.TreeViewer; |
import net.mygwt.ui.client.viewer.Viewer; |
import net.mygwt.ui.client.widget.ExpandBar; |
import net.mygwt.ui.client.widget.ExpandItem; |
import net.mygwt.ui.client.widget.tree.Tree; |
import com.google.gwt.json.client.JSONArray; |
import com.google.gwt.json.client.JSONParser; |
import com.google.gwt.json.client.JSONString; |
import com.google.gwt.json.client.JSONValue; |
import com.google.gwt.user.client.HTTPRequest; |
import com.google.gwt.user.client.ResponseTextHandler; |
import com.google.gwt.user.client.ui.Composite; |
public class DateFilterView extends Composite { |
private static final String VALUE_UNKNOWN = "Inconnus"; |
private String user; |
private String serviceBaseUrl = null; |
private String year = "all"; |
private String month = "all"; |
private String day = "all"; |
private Mediator mediator = null; |
private YEAR[] years=null; |
private MONTH[] months=null; |
private DAY[] days=null; |
private Model root = null; |
private MILLENIUM millenium = null; |
private Tree tree = null; |
private TreeViewer viewer=null; |
public DateFilterView(Mediator med, InventoryFilterView inventoryFilterView) { |
mediator=med; |
mediator.registerDateFilterView(this); |
user=mediator.getUser(); |
serviceBaseUrl = mediator.getServiceBaseUrl(); |
initTree(); |
ExpandItem dateFilter = new ExpandItem(); |
dateFilter.setText("Dates"); |
ExpandBar expandBar=inventoryFilterView.getExpandBar(); |
dateFilter.getContainer().add(tree); |
expandBar.add(dateFilter); |
} |
// Initialisation noeud de base |
void initTree() { |
// Enregistrement Mise à jour asynchrone |
IAsyncTreeContentProvider cp = new IAsyncTreeContentProvider() { |
public Object[] getElements(Object input) { |
Model m = (Model) input; |
return m.getChildren().toArray(); |
} |
public Object getParent(Object element) { |
return ((Model) element).getParent(); |
} |
public boolean hasChildren(Object parent) { |
if (parent instanceof DAY) { // Jour |
return false; |
} |
else { |
if (parent instanceof YEAR) { // Annee |
if (((YEAR)parent).toString().compareTo(VALUE_UNKNOWN)==0) |
return false; |
else |
return true; |
} |
else { |
return true; |
} |
} |
} |
public void getChildren(final Object parent, final IAsyncContentCallback callback) { |
if (parent instanceof YEAR) { |
// Annee + mois |
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryDateList/" + user + "/" |
+ ((YEAR) parent).getAsString("path"), |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
JSONValue jsonValue = JSONParser.parse(str); |
JSONArray jsonArray; |
JSONArray jsonArrayNested; |
int i=0; |
if ((jsonArray = jsonValue.isArray()) != null) { |
int arraySize = jsonArray.size(); |
months=new MONTH[arraySize]; |
for (i = 0; i < arraySize; ++i) { |
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) { |
String month=Util.toCelString(((JSONString)jsonArrayNested.get(0)).toString()); |
if (month.compareTo("0")==0) month=VALUE_UNKNOWN; |
months[i]=new MONTH((YEAR) parent,month); |
} |
} |
callback.setElements(months); |
} |
} |
}); |
} |
else if (parent instanceof MONTH) { |
// Mois + jours |
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryDateList/" + user + "/" |
+ ((MONTH) parent).getAsString("path") , |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
JSONValue jsonValue = JSONParser.parse(str); |
JSONArray jsonArray; |
JSONArray jsonArrayNested; |
int i=0; |
if ((jsonArray = jsonValue.isArray()) != null) { |
int arraySize = jsonArray.size(); |
days=new DAY[arraySize]; |
for (i = 0; i < arraySize; ++i) { |
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) { |
String day=Util.toCelString(((JSONString)jsonArrayNested.get(0)).toString()); |
if (day.compareTo("0")==0) day=VALUE_UNKNOWN; |
days[i]=new DAY((MONTH) parent, day); |
} |
} |
callback.setElements(days); |
} |
} |
}); |
} |
else if (parent instanceof MILLENIUM) { |
// Rafraichissement Racine |
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryDateList/" + user , |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
JSONValue jsonValue = JSONParser.parse(str); |
JSONArray jsonArray; |
JSONArray jsonArrayNested; |
int i=0; |
if ((jsonArray = jsonValue.isArray()) != null) { |
int arraySize = jsonArray.size(); |
years=new YEAR[arraySize]; |
for (i = 0; i < arraySize; ++i) { |
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) { |
String all=Util.toCelString(((JSONString)jsonArrayNested.get(0)).toString()); |
if (all.compareTo("0")==0) all=VALUE_UNKNOWN; |
years[i]=new YEAR(all); |
} |
} |
callback.setElements(years); |
} |
} |
}); |
} |
} |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
} |
}; |
tree = new Tree(); |
viewer = new TreeViewer(tree); |
viewer.setContentProvider(cp); |
viewer.setLabelProvider(new ModelLabelProvider()); |
viewer.setComparer(new IElementComparer() { |
public boolean equals(Object a, Object b) { |
if ((a==null) || b==null) |
return false; |
if (((Model) a).getAsString("name").compareTo(((Model) b).getAsString("name"))==0) { |
return true; |
} |
else return false; |
} |
} |
); |
viewer.addSelectionListener(new ISelectionChangedListener() { |
public void selectionChanged(SelectionChangedEvent se) { |
Model m = (Model) se.getSelection().getFirstElement(); |
// Info.show("Selection Changed", "{0} was selected", m.getAsString("path")); |
if (m instanceof MONTH) { // Mois |
month=m.getAsString("name"); |
if (month.compareTo(VALUE_UNKNOWN)==0) month="0"; |
year=m.getAsString("year"); |
if (year.compareTo(VALUE_UNKNOWN)==0) year="0"; |
day="all"; |
mediator.onDateSelected(year,month,day); |
} |
else |
if (m instanceof DAY) { // Jour |
month=m.getAsString("month"); |
if (month.compareTo(VALUE_UNKNOWN)==0) month="0"; |
year=m.getAsString("year"); |
if (year.compareTo(VALUE_UNKNOWN)==0) year="0"; |
day=m.getAsString("name"); |
if (day.compareTo(VALUE_UNKNOWN)==0) day="0"; |
mediator.onDateSelected(year,month,day); |
} |
else |
if (m instanceof YEAR) { // Annee |
month="all"; |
year=m.getAsString("name"); |
if (year.compareTo(VALUE_UNKNOWN)==0) year="0"; |
day="all"; |
mediator.onDateSelected(year,month,day); |
} |
if (m instanceof MILLENIUM) { // Tous |
month="all"; |
year="all"; |
day="all"; |
mediator.onDateSelected(year,month,day); |
} |
} |
}); |
// Initialisation premier niveau (doublon obligatoire avec rafraichissement asynchrone) |
root = new Model(); |
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryDateList/" + user, |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
JSONValue jsonValue = JSONParser.parse(str); |
JSONArray jsonArray; |
JSONArray jsonArrayNested; |
int i=0; |
if ((jsonArray = jsonValue.isArray()) != null) { |
int arraySize = jsonArray.size(); |
years=new YEAR[arraySize]; |
millenium = new MILLENIUM("Toutes"); |
for (i = 0; i < arraySize; ++i) { |
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) { |
String all=Util.toCelString(((JSONString)jsonArrayNested.get(0)).toString()); |
if (all.compareTo("0")==0) all=VALUE_UNKNOWN; |
years[i]=new YEAR(all); |
millenium.add(years[i]); |
} |
} |
root.add(millenium); |
viewer.setInput(root); |
} |
} |
}); |
} |
private class MILLENIUM extends Model { // Root |
public MILLENIUM(String name) { |
set("name", name); |
set("path", name); |
} |
public String toString() { |
return getAsString("name"); |
} |
} |
private class YEAR extends Model { // Annee |
public YEAR(String name) { |
set("name", name); |
set("path", name); |
} |
public String toString() { |
return getAsString("name"); |
} |
} |
private class MONTH extends Model { // Mois |
public MONTH(YEAR parent, String name) { |
set("name", name); |
set("year", parent.get("name")); |
set("path", parent.get("path")+"/"+name); |
} |
public String toString() { |
return getAsString("name"); |
} |
} |
private class DAY extends Model { // Jour |
public DAY(MONTH parent,String name) { |
set("name", name); |
set("year", parent.get("year")); |
set("month", parent.get("name")); |
set("path", parent.get("path")+"/"+name); |
} |
public String toString() { |
return getAsString("name"); |
} |
} |
public void setUser(String user) { |
this.user = user; |
} |
public void setYear(String year) { |
this.year = year; |
} |
public void setMonth(String month) { |
this.month = month; |
} |
public void setDay(String day) { |
this.day = day; |
} |
public void update() { |
Model r=new Model(); |
r.set("name","Toutes"); |
viewer.refresh(r); |
} |
} |
/trunk/src/org/tela_botanica/client/CarnetEnLigne.java |
---|
New file |
0,0 → 1,48 |
/** |
Auteurs : |
- David Delon david.delon@clapas.net 2007 |
Licence Cecill/GPL |
*/ |
/* |
* CarnetEnLigne.java (Point d'entree de l'application carnet en ligne) |
* |
* |
*/ |
package org.tela_botanica.client; |
import com.google.gwt.core.client.EntryPoint; |
/** |
* Entry point classes define <code>onModuleLoad()</code>. |
*/ |
public class CarnetEnLigne implements EntryPoint { |
public void onModuleLoad() { |
// new Mediator(); |
new CarnetEnLigneMediateur(); |
} |
} |
/* +--Fin du code ---------------------------------------------------------------------------------------+ |
* $Log$ |
* Revision 1.11 2008-01-02 21:26:04 ddelon |
* mise en place mygwt |
* |
* Revision 1.10 2007-09-17 19:25:34 ddelon |
* Documentation |
* |
* |
*/ |
/trunk/src/org/tela_botanica/client/InfoPopup.java |
---|
New file |
0,0 → 1,123 |
/* |
* Copyright 2006 Google Inc. |
* |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
* use this file except in compliance with the License. You may obtain a copy of |
* the License at |
* |
* http://www.apache.org/licenses/LICENSE-2.0 |
* |
* Unless required by applicable law or agreed to in writing, software |
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
* License for the specific language governing permissions and limitations under |
* the License. |
*/ |
package org.tela_botanica.client; |
import com.google.gwt.json.client.JSONArray; |
import com.google.gwt.json.client.JSONParser; |
import com.google.gwt.json.client.JSONString; |
import com.google.gwt.json.client.JSONValue; |
import com.google.gwt.user.client.HTTPRequest; |
import com.google.gwt.user.client.ResponseTextHandler; |
import com.google.gwt.user.client.ui.Image; |
import com.google.gwt.user.client.ui.PopupPanel; |
import com.google.gwt.user.client.ui.VerticalPanel; |
/** |
* Composite permet de wrapper des Widget pour creer un nouveau Widget cf methode initWidget() |
*/ |
public class InfoPopup extends PopupPanel { |
private Mediator mediator=null; |
private Image imageTop = new Image(); |
private Image imageBottom = new Image(); |
public InfoPopup(final Mediator med) { |
super(true); |
mediator=med; |
imageBottom.setPixelSize(150,150); |
imageTop.setPixelSize(150,150); |
// HorizontalPanel panel = new HorizontalPanel(); |
VerticalPanel panel = new VerticalPanel(); |
panel.add(imageTop); |
panel.add(imageBottom); |
add(panel); |
} |
public void setImageUrl(String value) { |
HTTPRequest.asyncGet(mediator.getServiceBaseUrl() + "/NameImage/" + value, |
new ResponseTextHandler() { |
public void onCompletion(String strcomplete) { |
JSONValue jsonValue = JSONParser.parse(strcomplete); |
JSONArray jsonArray; |
if ((jsonArray = jsonValue.isArray()) != null) { |
// Url Image |
setImageTop(((JSONString) jsonArray.get(0)).stringValue()); |
} |
} |
}); |
HTTPRequest.asyncGet(mediator.getServiceBaseUrl() + "/NameMap/" + value, |
new ResponseTextHandler() { |
public void onCompletion(String strcomplete) { |
JSONValue jsonValue = JSONParser.parse(strcomplete); |
JSONArray jsonArray; |
if ((jsonArray = jsonValue.isArray()) != null) { |
// Url Image |
setImageBottom(((JSONString) jsonArray.get(0)).stringValue()); |
} |
} |
}); |
} |
public void setImageTop(String url) { |
if (url.compareTo("null")!=0) { |
setPopupPosition(mediator.getWestContainer().getAbsoluteLeft()+10, mediator.getWestContainer().getAbsoluteTop() + (mediator.getWestContainer().getOffsetHeight()/3) +20); |
show(); |
imageTop.setUrl(url); |
} |
else { |
hide(); |
} |
} |
public void setImageBottom(String url) { |
if (url.compareTo("null")!=0) { |
setPopupPosition(mediator.getWestContainer().getAbsoluteLeft()+10, mediator.getWestContainer().getAbsoluteTop() + (mediator.getWestContainer().getOffsetHeight()/3) +20); |
show(); |
imageBottom.setUrl(url); |
} |
else { |
hide(); |
} |
} |
} |
/trunk/src/org/tela_botanica/client/AutoCompleteAsyncTextBoxListener.java |
---|
New file |
0,0 → 1,27 |
package org.tela_botanica.client; |
import com.google.gwt.user.client.ResponseTextHandler; |
/** |
* Event listener interface for table events. |
*/ |
public interface AutoCompleteAsyncTextBoxListener { |
/** |
* Fired when a AutoCompleteBox is validated (enter) |
* |
* @param sender the widget sending the event |
* @param text : text selected |
*/ |
void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender, String text, String value); |
/** |
* Fired when a AutoCompleteBox is completed (selection) |
* |
* @param sender the widget sending the event |
* @param text : text selected |
*/ |
void onComplete(ResponseTextHandler sender, String text, String value); |
} |
/trunk/src/org/tela_botanica/client/InventoryListView.java |
---|
New file |
0,0 → 1,912 |
/** |
David Delon david.delon@clapas.net 2007 |
*/ |
/* |
* ListeObservationsVue.java (Composite de Panel) |
* |
* Cas d'utilisation : |
* |
* Affichage de releve |
* |
* 1 : Recherche du nombre de releves associe au navigateur ou a l'utilisateur est connecte, en fonction des criteres de selection |
* 2 : Recherche des releves correspondant au critere precedent |
* 3 : Affichage des releves avec positionnement sur le dernier releve |
* |
* Selection de releve |
* |
* 1 : L'utilisateur selectionne un releve : lancement de l'affichage detaille pour le releve selectionne |
* |
* |
* Pagination : |
* |
* 1 : Avancement ou recul d'une page |
* |
* |
* |
* Suppression d'une liste d'element |
*/ |
/* Actions declenchees : |
* |
* onInventoryItemSelected(numero d'ordre de la ligne selectionne) : selection d'une ligne |
* onInventoryItemUnselected(numero d'ordre de la ligne selectionne) : deselection d'une ligne |
* onInventoryUpdated(location) : action suite a la modification, suppression, creation d'un element d'inventaire |
* |
*/ |
package org.tela_botanica.client; |
import net.mygwt.ui.client.Events; |
import net.mygwt.ui.client.Style; |
import net.mygwt.ui.client.event.BaseEvent; |
import net.mygwt.ui.client.event.Listener; |
import net.mygwt.ui.client.widget.ContentPanel; |
import net.mygwt.ui.client.widget.WidgetContainer; |
import net.mygwt.ui.client.widget.layout.BorderLayoutData; |
import net.mygwt.ui.client.widget.layout.FillLayout; |
import net.mygwt.ui.client.widget.table.Table; |
import net.mygwt.ui.client.widget.table.TableColumn; |
import net.mygwt.ui.client.widget.table.TableColumnModel; |
import net.mygwt.ui.client.widget.table.TableItem; |
import com.google.gwt.http.client.URL; |
import com.google.gwt.json.client.JSONArray; |
import com.google.gwt.json.client.JSONNumber; |
import com.google.gwt.json.client.JSONParser; |
import com.google.gwt.json.client.JSONString; |
import com.google.gwt.json.client.JSONValue; |
import com.google.gwt.user.client.HTTPRequest; |
import com.google.gwt.user.client.ResponseTextHandler; |
import com.google.gwt.user.client.ui.Composite; |
import com.google.gwt.user.client.ui.DockPanel; |
import com.google.gwt.user.client.ui.HTML; |
import com.google.gwt.user.client.ui.HorizontalPanel; |
import com.google.gwt.user.client.ui.Image; |
import com.google.gwt.user.client.ui.Button; |
import com.google.gwt.user.client.ui.Label; |
import com.google.gwt.user.client.ui.Widget; |
import com.google.gwt.user.client.ui.ClickListener; |
import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
import com.google.gwt.user.client.ui.HasVerticalAlignment; |
public class InventoryListView |
{ |
// Debut Barre de navigation |
private class NavBar extends Composite implements ClickListener { |
public final DockPanel bar = new DockPanel(); |
public final Button gotoFirst = new Button("<<", this); |
public final Button gotoNext = new Button(">", this); |
public final Button gotoPrev = new Button("<", this); |
public final Button gotoEnd = new Button(">>", this); |
public final Label status = new Label(); |
public NavBar() { |
initWidget(bar); |
status.setWordWrap(false); |
HorizontalPanel buttons = new HorizontalPanel(); |
buttons.add(status); |
buttons.setCellHorizontalAlignment(status, HasHorizontalAlignment.ALIGN_RIGHT); |
buttons.setCellVerticalAlignment(status, HasVerticalAlignment.ALIGN_MIDDLE); |
buttons.add(gotoFirst); |
buttons.add(gotoPrev); |
buttons.add(gotoNext); |
buttons.add(gotoEnd); |
bar.add(buttons, DockPanel.EAST); |
} |
public void onClick(Widget sender) { |
if (sender == gotoNext) { |
// Move forward a page. |
startIndex += VISIBLE_TAXON_COUNT; |
if (startIndex >= count) |
startIndex -= VISIBLE_TAXON_COUNT; |
} else { |
if (sender == gotoPrev) { |
// Move back a page. |
startIndex -= VISIBLE_TAXON_COUNT; |
if (startIndex < 0) |
startIndex = 0; |
} else { |
if (sender == gotoEnd) { |
gotoEnd(); |
} else { |
if (sender == gotoFirst) { |
startIndex = 0; |
} |
} |
} |
} |
update(); |
} |
} |
// Fin Barre de navigation |
// Conteneur (header et table sont dans panel) |
private ContentPanel panel =null; |
private Table table = null; |
// Services |
private String serviceBaseUrl = null; |
private String user; |
private Mediator mediator = null; |
// Navigation |
private int startIndex = 0; |
private int count = 0; |
private static final int VISIBLE_TAXON_COUNT = 15; |
private NavBar navBar=null; |
// Filtre par defaut : |
private String id_location = "all"; |
private String location = "all"; |
private String year = "all"; |
private String month = "all"; |
private String day = "all"; |
private String search = "all"; |
private String lieudit = "all"; |
private String ordre= null; |
public InventoryListView(Mediator med) { |
// Traitement contexte utilisateur et service |
mediator=med; |
user=mediator.getUser(); |
serviceBaseUrl = mediator.getServiceBaseUrl(); |
panel= new ContentPanel(Style.HEADER); |
panel.setLayout(new FillLayout()); |
// Barre navigation integree au header |
navBar = new NavBar(); |
panel.getHeader().addWidget(navBar); |
// Contenu : |
// Colonnes : |
TableColumn[] columns = new TableColumn[6]; |
// TODO : renderer date, alignement etc |
columns[0] = new TableColumn("etat","Aransmis", 50); |
columns[1] = new TableColumn("nom","Nom saisi", 250); |
columns[2] = new TableColumn("nomr","Nom retenu", 250); |
columns[3] = new TableColumn("lieu","Lieu", 350); |
columns[4] = new TableColumn("date","Date", 75); |
columns[5] = new TableColumn("ordre","Ordre", 50); |
TableColumnModel cm = new TableColumnModel(columns); |
// Table : |
table = new Table(Style.MULTI | Style.HORIZONTAL, cm); |
table.setBorders(false); |
panel.add(table); |
WidgetContainer center=mediator.getCenterContainer(); |
BorderLayoutData centerData = new BorderLayoutData(Style.CENTER, .75f, 100, 1000); |
center.add(panel,centerData); |
// Selection d'une ligne |
table.addListener(Events.RowClick, new Listener() { |
public void handleEvent(BaseEvent be) { |
TableItem item=(TableItem) be.item; |
if (item!=null) { |
if (ordre==null) { // Affichage de la ligne selectionne |
ordre= (String) item.getValue(5); |
mediator.onInventoryItemSelected(ordre); |
} |
else { |
// Si une ligne etait deja selectionne |
if (ordre.compareTo((String) item.getValue(5))==0) { // C'est la meme, on la deselectionne |
ordre=null; |
table.deselect(be.rowIndex); |
mediator.onInventoryItemUnselected(); |
} |
else { |
ordre= (String) item.getValue(5); // C'est une autre, on la selectionne |
mediator.onInventoryItemSelected(ordre); |
} |
} |
} |
} |
}); |
} |
/** |
* Suppression d'un ensemble d'element de la liste d'inventaire, on garde ici car s'applique a plusieurs elements |
* |
*/ |
public void deleteElement() { |
setStatusDisabled(); |
TableItem[] selection=table.getSelection(); |
StringBuffer ids=new StringBuffer(); |
for (int i = 0; i < selection.length; i++) { |
ids.append((String)(((TableItem) selection[i]).getValue(5))); |
if (i<(selection.length-1)) ids.append(","); |
} |
if (ids.length()>0) { |
HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/" + user |
+ "/" + ids.toString(), "action=DELETE", |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
mediator.onInventoryUpdated(id_location,"all","all"); |
mediator.getEntryView().clear(); |
} |
}); |
} |
setStatusEnabled(); |
} |
/** |
* Transmission de releve a Tela, on garde ici car s'applique a plusieurs elements |
*/ |
public void transmitElement() { |
setStatusDisabled(); |
TableItem[] selection=table.getSelection(); |
StringBuffer ids=new StringBuffer(); |
for (int i = 0; i < selection.length; i++) { |
ids.append((String)(((TableItem) selection[i]).getValue(5))); |
if (i<(selection.length-1)) ids.append(","); |
} |
if (ids.length()>0) { |
HTTPRequest.asyncPost(serviceBaseUrl + "/InventoryTransmit/" + user |
+ "/" + ids.toString(), "transmission=1", |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
update(); // Pour affichage logo |
} |
}); |
} |
setStatusEnabled(); |
} |
/** |
* Recherche nombre d'enregistrement pour l'utilisateur et la localite en cours |
* |
*/ |
public void updateCount () { |
setStatusDisabled(); |
// Transformation de la date selectionne vers date time stamp |
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryItemList/" + user + "/" + id_location + "/" + URL.encodeComponent(location) + "/" + year + "/" + month + "/" + day + "/" + URL.encodeComponent(search) + "/" + URL.encodeComponent(lieudit), |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
JSONValue jsonValue = JSONParser.parse(str); |
JSONNumber jsonNumber; |
if ((jsonNumber = jsonValue.isNumber()) != null) { |
count = (int) jsonNumber.getValue(); |
// if (location.compareTo("")==0) location="000null"; |
gotoEnd(); // Derniere page |
update(); |
} |
} |
}); |
} |
/** |
* Mise a jour de l'affichage, a partir des donnaes d'inventaire deja |
* saisies. La valeur de this.startIndex permet de determiner quelles |
* donnaes seront affichees |
* |
*/ |
public void update() { |
// TODO : optimisation (ne pas supprimer mais remplacer) |
// Ligne d'information |
// Toutes date par defaut |
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryItemList/" + user + "/" + id_location + "/" + URL.encodeComponent(location) +"/" + year + "/" + month + "/" + day + "/" + URL.encodeComponent(search) + "/" + URL.encodeComponent(lieudit) + "/" |
+ startIndex + "/" + VISIBLE_TAXON_COUNT, |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
JSONValue jsonValue = JSONParser.parse(str); |
JSONArray jsonArray; |
JSONArray jsonArrayNested; |
int i=0; |
if ((jsonArray = jsonValue.isArray()) != null) { |
StringBuffer lieu=null; |
int arraySize = jsonArray.size(); |
for (i = 0; i < arraySize; ++i) { |
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) { |
Object[] values = new Object[6]; |
// Statut Observation transmise ? |
String atransmit=((JSONString) jsonArrayNested .get(13)).stringValue(); |
if (atransmit.compareTo("1")==0) { |
values[0] = new Image("tela.gif"); |
} |
else { |
values[0] = new HTML(" "); |
} |
// Nom saisi |
values[1] = new HTML("<b>"+Util.toCelString(((JSONString) jsonArrayNested .get(0)).toString())+"</b>"); |
// Nom retenu |
String aname=Util.toCelString(((JSONString) jsonArrayNested .get(2)).toString()); |
if (aname.compareTo("null")==0) { |
values[2] = new HTML(" "); |
} |
else { |
values[2] = new HTML(aname); |
} |
// Num nomenclatural |
/* |
String ann=((JSONString) jsonArrayNested .get(3)).stringValue(); |
if (ann.compareTo("0")!=0) { |
observationText.append(""+ann+"-"); |
} |
else { |
observationText.append("0-"); |
} |
*/ |
// Num Taxonomique |
/* |
String ant=((JSONString) jsonArrayNested .get(4)).stringValue(); |
if (ant.compareTo("0")!=0) { |
observationText.append(ant+", "); |
} |
else { |
observationText.append("0, "); |
} |
*/ |
// Famille |
/* |
String afamily=Util.toCelString(((JSONString) jsonArrayNested .get(5)).toString()); |
if (afamily.compareTo("null")==0) { |
// |
} |
else { |
observationText.append(afamily+", "); |
} |
*/ |
// Localisation - Lieu |
lieu=new StringBuffer(); |
String aloc=Util.toCelString(((JSONString) jsonArrayNested .get(6)).toString()); |
if (aloc.compareTo("000null")==0) { |
if (lieu.length()==0) { |
lieu.append("Commune absente"); |
} |
else { |
lieu.append("commune absente"); |
} |
} |
else { |
if (lieu.length()==0) { |
lieu.append("Commune de "+aloc); |
} |
else { |
lieu.append("commune de "+aloc); |
} |
} |
String alieudit=Util.toCelString(((JSONString) jsonArrayNested .get(9)).toString()); |
// Localisation - Lieu dit |
if (alieudit.compareTo("000null")!=0) { |
lieu.append(", "+alieudit); |
} |
// Station - |
String astation=Util.toCelString(((JSONString) jsonArrayNested .get(10)).toString()); |
if (astation.compareTo("000null")!=0) { |
lieu.append(", "+astation); |
} |
// Milieu |
String amilieu=Util.toCelString(((JSONString) jsonArrayNested .get(11)).toString()); |
if (amilieu.compareTo("000null")!=0) { |
lieu.append(", "+amilieu); |
} |
String acomment=Util.toCelString(((JSONString) jsonArrayNested .get(12)).toString()); |
// Commentaire |
if (acomment.compareTo("null")!=0) { |
lieu.append(", "+acomment); |
} |
if (lieu.toString().compareTo("")==0) { |
values[3] = new HTML(" "); |
} |
else { |
values[3] = new HTML(lieu.toString()); |
} |
String adate=((JSONString) jsonArrayNested .get(8)).stringValue(); |
// Date |
if (adate.compareTo("0000-00-00 00:00:00")!=0) { |
values[4]=new HTML("<b>"+adate+"</b>"); |
} |
else { |
values[4] = new HTML(" "); |
} |
String aordre=((JSONString) jsonArrayNested.get(7)).stringValue(); |
// Numero d'ordre (cache) |
values[5] = aordre; |
if (i>=table.getItemCount()) { |
TableItem item = new TableItem(values); |
table.add(item); |
} |
else { |
TableItem item=table.getItem(i); |
item.setValue(0,values[0]); |
item.setValue(1,values[1]); |
item.setValue(2,values[2]); |
item.setValue(3,values[3]); |
item.setValue(4,values[4]); |
item.setValue(5,values[5]); |
} |
// Spagetti |
if (ordre!=null) { |
if (aordre.compareTo(ordre)==0) { |
table.select(i); |
} |
else { |
table.deselect(i); |
} |
} |
} |
} |
} |
// Suppression fin ancien affichage |
if (i<table.getItemCount()) { |
for (int j = table.getItemCount() -1 ; j >= i; j--) { |
TableItem item=table.getItem(j); |
table.remove(item); |
} |
} |
setStatusEnabled(); |
} |
}); |
} |
/** |
* Affichage message d'attente et desactivation navigation |
* |
* @param |
* @return void |
*/ |
private void setStatusDisabled() { |
navBar.gotoFirst.setEnabled(false); |
navBar.gotoPrev.setEnabled(false); |
navBar.gotoNext.setEnabled(false); |
navBar.gotoEnd.setEnabled(false); |
navBar.status.setText("Patientez ..."); |
} |
/** |
* Affichage numero de page et gestion de la navigation |
* |
*/ |
private void setStatusEnabled() { |
// Il y a forcemment un disabled avant d'arriver ici |
if (count > 0) { |
if (startIndex >= VISIBLE_TAXON_COUNT) { // Au dela de la |
// premiere page |
navBar.gotoPrev.setEnabled(true); |
navBar.gotoFirst.setEnabled(true); |
if (startIndex < (count - VISIBLE_TAXON_COUNT)) { // Pas la |
// derniere |
// page |
navBar.gotoNext.setEnabled(true); |
navBar.gotoEnd.setEnabled(true); |
navBar.status.setText((startIndex + 1) + " - " |
+ (startIndex + VISIBLE_TAXON_COUNT) + " sur " + count ); |
} else { // Derniere page |
navBar.status.setText((startIndex + 1) + " - " + count + " sur " + count ); |
} |
} else { // Premiere page |
if (count > VISIBLE_TAXON_COUNT) { // Des pages derrieres |
navBar.gotoNext.setEnabled(true); |
navBar.gotoEnd.setEnabled(true); |
navBar.status.setText((startIndex + 1) + " - " |
+ (startIndex + VISIBLE_TAXON_COUNT) + " sur " + count); |
} else { |
navBar.status.setText((startIndex + 1) + " - " + count + " sur " + count); |
} |
} |
} |
else { // Pas d'inventaire, pas de navigation |
navBar.status.setText("0 - 0 sur 0"); |
} |
} |
/* |
* Positionnement index de parcours (this.startIndex) pour affichage de la |
* derniere page |
* |
* @param |
* @return void |
*/ |
private void gotoEnd() { |
if ((count == 0) || (count % VISIBLE_TAXON_COUNT) > 0) { |
startIndex = count - (count % VISIBLE_TAXON_COUNT); |
} else { |
startIndex = count - VISIBLE_TAXON_COUNT; |
} |
} |
/* |
* Recherche en cours |
* |
*/ |
public void setSearch(String search) { |
this.search = search; |
} |
/* |
* Departement en cours |
* |
*/ |
public void setIdLocation(String id_location) { |
this.id_location = id_location; |
} |
/* |
* Localite en cours |
* |
*/ |
public void setLocation(String location) { |
this.location = location; |
} |
/* |
* Lieudit en cours |
* |
*/ |
public void setLieudit(String lieudit) { |
this.lieudit = lieudit; |
} |
/* |
* Date en cours |
* |
*/ |
public void setYear(String year) { |
this.year = year; |
} |
public void setMonth(String month) { |
this.month = month; |
} |
public void setDay(String day) { |
this.day = day; |
} |
/* |
* Utilisateur en cours |
* |
*/ |
public void setUser(String user) { |
this.user = user; |
} |
public void displayFilter() { |
// Mise a jour boutton export feuille de calcul |
mediator.getActionView().getExportButton().setHTML("<a href=\""+mediator.getServiceBaseUrl()+"/InventoryExport/" |
+ user + "/" |
+ URL.encodeComponent(id_location) + "/" |
+ URL.encodeComponent(location) + "/" |
+ URL.encodeComponent(lieudit)+ "/" |
+ year + "/" |
+ month + "/" |
+ day |
+ "\">"+"Export tableur</a>"); |
// Mise a jour ligne de selection |
String dep; |
if (id_location.compareTo("all")==0) { |
dep="Tous départements"; |
} |
else { |
if (id_location.compareTo("000null")==0) { |
dep="Départements non renseignées "; |
} |
else { |
dep="Département "+id_location; |
} |
} |
String com; |
if (location.compareTo("all")==0) { |
com=", toutes communes"; |
} |
else { |
if (location.compareTo("000null")==0) { |
com=", communes non renseignées"; |
} |
else { |
com=", commune de "+location; |
} |
} |
String lieu; |
if (lieudit.compareTo("all")==0) { |
lieu=", tous lieux dits"; |
} |
else { |
if (lieudit.compareTo("000null")==0) { |
lieu=", lieu-dit non renseignées"; |
} |
else { |
lieu=", lieu-dit "+ lieudit; |
} |
} |
String dat; |
if ((year.compareTo("all")==0) && (month.compareTo("all")==0) && (day.compareTo("all")==0)) { |
dat=", toutes periodes"; |
} |
else { |
String yea=""; |
String da=""; |
String mont=""; |
if (year.compareTo("all")==0) { |
yea=", toutes années"; |
} |
else { |
if (year.compareTo("0")==0) { |
yea=", periode non renseignée"; |
} |
else { |
yea=", "+ year; |
if (month.compareTo("all")==0) { |
mont=", tous mois"; |
} |
else { |
mont="/"+ month; |
} |
if (day.compareTo("all")==0) { |
da=", tous jours"; |
} |
else { |
da="/"+ day; |
} |
} |
} |
dat=yea + mont + da; |
} |
panel.getHeader().setText(dep + com + lieu + dat); |
} |
} |
/* +--Fin du code ---------------------------------------------------------------------------------------+ |
* $Log$ |
* Revision 1.3 2008-04-28 13:10:43 ddelon |
* Integration MyGwt |
* |
* Revision 1.2 2008-01-30 08:55:40 ddelon |
* fin mise en place mygwt |
* |
* Revision 1.1 2008-01-02 21:26:04 ddelon |
* mise en place mygwt |
* |
* Revision 1.8 2007-12-22 14:48:53 ddelon |
* Documentation et refactorisation |
* |
* Revision 1.7 2007-09-17 19:25:34 ddelon |
* Documentation |
* |
*/ |
/trunk/src/org/tela_botanica/client/SearchPanel.java |
---|
New file |
0,0 → 1,106 |
/** |
David Delon david.delon@clapas.net 2007 |
*/ |
/* |
* SearchPanel.java : recherche parmi les releves |
* |
* |
* 1: Le programme affiche une zone de saisie pour recherche |
* 2: Le programme arme l'action liee a l'envoi d'une recherche |
*/ |
package org.tela_botanica.client; |
import com.google.gwt.user.client.ui.ClickListener; |
import com.google.gwt.user.client.ui.Composite; |
import com.google.gwt.user.client.ui.HTML; |
import com.google.gwt.user.client.ui.HorizontalPanel; |
import com.google.gwt.user.client.ui.KeyboardListener; |
import com.google.gwt.user.client.ui.TextBox; |
import com.google.gwt.user.client.ui.Widget; |
/** |
* Composite permet de wrapper des Widget pour creer un nouveau Widget cf methode initWidget() |
*/ |
public class SearchPanel extends Composite { |
private Mediator mediator=null; |
private TextBox search = null; |
public SearchPanel(final Mediator med) { |
HorizontalPanel panel=new HorizontalPanel(); |
mediator=med; |
search = new TextBox(); |
// Recherche |
HTML searchButton=new HTML("Rechercher dans les relevés"); |
searchButton.setStyleName("html_button_long"); |
searchButton.addClickListener( |
new ClickListener() { |
public void onClick(Widget sender) { |
mediator.onSearch(search.getText()); |
} |
} |
); |
search.addKeyboardListener( new KeyboardListener() { |
public void onKeyDown(Widget arg0, char arg1, int arg2) { |
if(arg1 == KEY_ENTER) |
{ |
mediator.onSearch(search.getText()); |
} |
} |
public void onKeyUp(Widget arg0, char arg1, int arg2) { |
} |
public void onKeyPress(Widget arg0, char arg1, int arg2) { |
} |
} |
); |
panel.setSpacing(5); |
panel.add(search); |
panel.add(searchButton); |
initWidget(panel); |
} |
} |
/* +--Fin du code ---------------------------------------------------------------------------------------+ |
* $Log$ |
* Revision 1.4 2007-12-22 14:48:53 ddelon |
* Documentation et refactorisation |
* |
* Revision 1.5 2007-09-17 19:25:34 ddelon |
* Documentation |
* |
* |
*/ |
/trunk/src/org/tela_botanica/client/LoginDialog.java |
---|
New file |
0,0 → 1,231 |
/** |
David Delon david.delon@clapas.net 2007 |
*/ |
/* |
* LoginDialog.java (DialogBox) |
* |
* Cas d'utilisation : |
* Dialogue de validation de l'identification utilisateur |
* |
* 1 : L'utilisateur saisit son identifiant (e-mail) et son mot de passe |
* 2 : Le dialogue controle aupres du systeme distant la validite des informations saisies |
* 3 : Le dialogue transmet au systeme local les informations d'identification |
* 3a : Le dialogue informe l'utilisateur que les elements d'identification ne sont pas valide : retour au point 1, ou passe au point 4. |
* 4 : Cloture du dialogue |
* 5 : Appel du dialogue d'importation |
*/ |
package org.tela_botanica.client; |
import com.google.gwt.json.client.JSONArray; |
import com.google.gwt.json.client.JSONBoolean; |
import com.google.gwt.json.client.JSONParser; |
import com.google.gwt.json.client.JSONValue; |
import com.google.gwt.user.client.HTTPRequest; |
import com.google.gwt.user.client.ResponseTextHandler; |
import com.google.gwt.user.client.Window; |
import com.google.gwt.user.client.ui.ClickListener; |
import com.google.gwt.user.client.ui.DialogBox; |
import com.google.gwt.user.client.ui.Grid; |
import com.google.gwt.user.client.ui.HTML; |
import com.google.gwt.user.client.ui.KeyboardListener; |
import com.google.gwt.user.client.ui.PasswordTextBox; |
import com.google.gwt.user.client.ui.TextBox; |
import com.google.gwt.user.client.ui.VerticalPanel; |
import com.google.gwt.user.client.ui.Widget; |
public class LoginDialog extends DialogBox { |
private Mediator mediator=null; |
private TextBox login = new TextBox(); |
private PasswordTextBox password = new PasswordTextBox(); |
private Grid inner = new Grid(4,2); |
public LoginDialog(final Mediator med) { |
setText("Connexion"); |
mediator=med; |
VerticalPanel outer = new VerticalPanel(); |
/* |
* E-Mail : Zone_saisie_email |
* Mot-de-passe : Zone_saisie_mot_de_passe |
* Message d'information |
* Bouton_Ok Bouton_Annuler |
*/ |
// Validation bouton |
HTML okButton=new HTML("Ok"); |
okButton.setStyleName("html_button"); |
okButton.addClickListener( |
new ClickListener() { |
public void onClick(Widget sender) { |
loginFromService(); |
} |
} |
); |
// Annulation |
HTML cancelButton=new HTML("Annuler"); |
cancelButton.setStyleName("html_button"); |
cancelButton.addClickListener( |
new ClickListener() { |
public void onClick(Widget sender) { |
hide(); |
} |
} |
); |
//Validation utilisateur sans utilisation des boutons : |
login.addKeyboardListener( new KeyboardListener() { |
public void onKeyDown(Widget arg0, char arg1, int arg2) { |
if(arg1 == KEY_ENTER) |
{ |
loginFromService(); |
} |
} |
public void onKeyUp(Widget arg0, char arg1, int arg2) { } |
public void onKeyPress(Widget arg0, char arg1, int arg2) { } |
} |
); |
// Validation utilisateur sans utilisation des boutons : |
password.addKeyboardListener( new KeyboardListener() { |
public void onKeyDown(Widget arg0, char arg1, int arg2) { |
if(arg1 == KEY_ENTER) |
{ |
loginFromService(); |
} |
} |
public void onKeyUp(Widget arg0, char arg1, int arg2) { } |
public void onKeyPress(Widget arg0, char arg1, int arg2) { } |
} |
); |
inner.setHTML(0,0,"E-mail:"); |
inner.setWidget(0,1,login); |
inner.setHTML(1,0,"Mot de passe: "); |
inner.setWidget(1,1,password); |
inner.setWidget(3,0,okButton); |
inner.setWidget(3,1,cancelButton); |
inner.setCellPadding(10); |
outer.add(inner); |
setWidget(outer); |
} |
/** |
* Appel du service d'identification et positionnement de l'etat de connection en fonction du resultat. |
* |
* @param login : identifiant saisi |
* @param password : mot de passe saisi |
* |
*/ |
private void loginFromService() { |
final String login=this.login.getText(); |
String password=this.password.getText(); |
HTTPRequest.asyncGet(mediator.getServiceBaseUrl() + "/User/" + login + "/" + password , |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
JSONValue jsonValue = JSONParser.parse(str); |
JSONArray jsonArray; |
if ((jsonArray = jsonValue.isArray()) != null) { |
mediator.setConnected(((JSONBoolean) jsonArray.get(1)).booleanValue()); |
} |
if (mediator.getConnected()) { |
mediator.setUser(login); |
hide(); |
ImportDialog importDialog = new ImportDialog(mediator); |
// Position it roughly in the middle of the screen. |
int left = (Window.getClientWidth() - 512) / 2; |
int top = (Window.getClientHeight() - 256) / 2; |
importDialog.setPopupPosition(left, top); |
importDialog.show(); |
} |
else { |
inner.setHTML(2,0,"Identification incorrecte !"); |
} |
} |
}); |
} |
public boolean onKeyDownPreview(char key, int modifiers) { |
// Use the popup's key preview hooks to close the dialog when either |
// escape is pressed. |
switch (key) { |
case KeyboardListener.KEY_ESCAPE: |
hide(); |
break; |
} |
return true; |
} |
} |
/* +--Fin du code ---------------------------------------------------------------------------------------+ |
* $Log$ |
* Revision 1.9 2007-05-21 21:03:44 ddelon |
* nettoyage de code |
* |
* Revision 1.8 2007-05-21 18:14:06 ddelon |
* Gestion importation releve locaux |
* |
* Revision 1.7 2007-05-21 11:47:30 ddelon |
* meta cvs |
* |
* Revision 1.6 2007-05-21 11:39:48 ddelon |
* meta cvs |
* |
* Revision 1.5 2007-05-21 11:39:12 ddelon |
* meta cvs |
* |
* Revision 1.4 2007-05-21 11:37:35 ddelon |
* meta cvs |
* |
* Revision 1.3 2007-05-21 11:36:51 ddelon |
* meta cvs |
* |
*/ |
/trunk/src/org/tela_botanica/client/ImportDialog.java |
---|
New file |
0,0 → 1,158 |
/** |
David Delon david.delon@clapas.net 2007 |
*/ |
/* |
* ImportDialog.java (DialogBox) |
* |
* Cas d'utilisation : |
* Dialogue d'importation des donnees temporaires non liees a un utilisateur. |
* |
* 1 : Le dialogue propose a l'utilisateur d'importer des releves saisie avant identification |
* 2 : Le dialogue transmet au systeme distant la demande d'importation |
* 3 : Le dialogue transmet au systeme local les informations d'identification |
* 4 : Cloture du dialogue |
*/ |
package org.tela_botanica.client; |
import com.google.gwt.user.client.HTTPRequest; |
import com.google.gwt.user.client.ResponseTextHandler; |
import com.google.gwt.user.client.ui.ClickListener; |
import com.google.gwt.user.client.ui.DialogBox; |
import com.google.gwt.user.client.ui.Grid; |
import com.google.gwt.user.client.ui.HTML; |
import com.google.gwt.user.client.ui.KeyboardListener; |
import com.google.gwt.user.client.ui.VerticalPanel; |
import com.google.gwt.user.client.ui.Widget; |
public class ImportDialog extends DialogBox { |
private Mediator mediator=null; |
private String user = null; |
public ImportDialog(final Mediator med) { |
setHTML("Importer les relevés en cours ?"); |
mediator=med; |
user=mediator.getUser(); |
VerticalPanel outer = new VerticalPanel(); |
Grid inner = new Grid(2,2); |
/* |
* Voulez-vous importer vos relev�s en cours ? |
* Bouton_Ok Bouton_Annuler |
*/ |
// Validation bouton |
HTML okButton=new HTML("Oui"); |
okButton.setStyleName("html_button"); |
okButton.addClickListener( |
new ClickListener() { |
public void onClick(Widget sender) { |
importFromService(); |
} |
} |
); |
// Annulation |
HTML cancelButton=new HTML("Non"); |
cancelButton.setStyleName("html_button"); |
cancelButton.addClickListener( |
new ClickListener() { |
public void onClick(Widget sender) { |
mediator.onLogin(user); |
hide(); |
} |
} |
); |
inner.setWidget(0,0,okButton); |
inner.setWidget(0,1,cancelButton); |
inner.setCellPadding(10); |
outer.add(inner); |
setWidget(outer); |
} |
/** |
* Appel du service d'identification et positionnement de l'�tat de connection en fonction du r�sultat. |
* |
* @param login : identifiant saisi |
* @param password : mot de passe saisi |
* |
*/ |
private void importFromService() { |
HTTPRequest.asyncGet(mediator.getServiceBaseUrl() + "/InventoryImport/" + user , |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
mediator.onLogin(user); |
hide(); |
} |
}); |
} |
public boolean onKeyDownPreview(char key, int modifiers) { |
// Use the popup's key preview hooks to close the dialog when either |
// escape is pressed. |
switch (key) { |
case KeyboardListener.KEY_ESCAPE: |
mediator.onLogin(user); |
hide(); |
break; |
} |
return true; |
} |
} |
/* +--Fin du code ---------------------------------------------------------------------------------------+ |
* $Log$ |
* Revision 1.2 2007-06-06 13:29:30 ddelon |
* v0.09 |
* |
* Revision 1.1 2007-05-21 18:14:06 ddelon |
* Gestion importation releve locaux |
* |
* Revision 1.7 2007-05-21 11:47:30 ddelon |
* meta cvs |
* |
* Revision 1.6 2007-05-21 11:39:48 ddelon |
* meta cvs |
* |
* Revision 1.5 2007-05-21 11:39:12 ddelon |
* meta cvs |
* |
* Revision 1.4 2007-05-21 11:37:35 ddelon |
* meta cvs |
* |
* Revision 1.3 2007-05-21 11:36:51 ddelon |
* meta cvs |
* |
*/ |
/trunk/src/org/tela_botanica/client/ConnexionView.java |
---|
New file |
0,0 → 1,144 |
/** |
David Delon david.delon@clapas.net 2007 |
*/ |
/* |
* ConnexionView.java : affichage information portant sur le statut de la connexion utilisateur |
* |
* |
* 1: Le programme affiche le statut connecte si l'utilisateur s'est connecte precedemment, sinon s'affiche le statut deconnecte |
* 2: Le programme arme les actions liees a la connection ou a la deconnection |
* - Connection : affichage de la boite de connexion |
* - Deconnexion : appel du service de deconnexion, et appel de la re-initialisation de l'affichage pour le nouvel identifiant utilisateur obtenu (identifiant de session) |
*/ |
package org.tela_botanica.client; |
import net.mygwt.ui.client.widget.WidgetContainer; |
import com.google.gwt.json.client.JSONArray; |
import com.google.gwt.json.client.JSONBoolean; |
import com.google.gwt.json.client.JSONParser; |
import com.google.gwt.json.client.JSONString; |
import com.google.gwt.json.client.JSONValue; |
import com.google.gwt.user.client.HTTPRequest; |
import com.google.gwt.user.client.ResponseTextHandler; |
import com.google.gwt.user.client.Window; |
import com.google.gwt.user.client.ui.ClickListener; |
import com.google.gwt.user.client.ui.HTML; |
import com.google.gwt.user.client.ui.HorizontalPanel; |
import com.google.gwt.user.client.ui.Label; |
import com.google.gwt.user.client.ui.Widget; |
public class ConnexionView { |
private Mediator mediator=null; |
private String user =null; |
private HTML signLabel = new HTML() ; |
private String serviceBaseUrl = null; |
public ConnexionView(final Mediator med) { |
mediator=med; |
user=mediator.getUser(); |
serviceBaseUrl = mediator.getServiceBaseUrl(); |
if (!mediator.getConnected()) { |
signLabel.setHTML("Utilisez ce carnet en ligne pour saisir vos observations, <u>identifiez-vous</u> pour les transmettre à Tela Botanica "); |
} |
else { |
signLabel.setText(user+ " (deconnexion)"); |
} |
HorizontalPanel outer = new HorizontalPanel(); |
HorizontalPanel inner = new HorizontalPanel(); |
outer.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT); |
inner.add(signLabel); |
//inner.add(new HTML("<b>Carnet en ligne</b>")); |
inner.setSpacing(3); |
outer.add(inner); |
signLabel.addClickListener( |
new ClickListener() { |
public void onClick(Widget sender) { |
// Non connecte ? Lien vers boite de connection |
if (!mediator.getConnected()) { |
LoginDialog loginDialog = new LoginDialog(med); |
// Position it roughly in the middle of the screen. |
int left = (Window.getClientWidth() - 512) / 2; |
int top = (Window.getClientHeight() - 256) / 2; |
loginDialog.setPopupPosition(left, top); |
loginDialog.show(); |
} |
else { |
// Deja Connecte : lancement deconnexion sur selection de l'action |
HTTPRequest.asyncGet(serviceBaseUrl + "/User/" + user , |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
JSONValue jsonValue = JSONParser.parse(str); |
JSONArray jsonArray; |
if ((jsonArray = jsonValue.isArray()) != null) { |
user = Util.toCelString(((JSONString) jsonArray.get(0)).toString()); // Identifiant utilisateur : identifant de session |
mediator.setConnected(((JSONBoolean) jsonArray.get(1)).booleanValue()); |
} |
if (!mediator.getConnected()) { // La deconnexion a ete accepte : |
mediator.onLogoff(user); |
} |
} |
}); |
} |
} |
} |
); |
WidgetContainer north=mediator.getNorthContainer(); |
north.add(outer); |
} |
public Label getSignLabel() { |
return signLabel; |
} |
} |
/* +--Fin du code ---------------------------------------------------------------------------------------+ |
* $Log$ |
* Revision 1.1 2008-01-02 21:26:04 ddelon |
* mise en place mygwt |
* |
* Revision 1.6 2007-12-22 14:48:53 ddelon |
* Documentation et refactorisation |
* |
* Revision 1.5 2007-09-17 19:25:34 ddelon |
* Documentation |
* |
* |
*/ |
/trunk/src/org/tela_botanica/public/date.gif |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/trunk/src/org/tela_botanica/public/date.gif |
---|
New file |
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/trunk/src/org/tela_botanica/public/com.gif |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/trunk/src/org/tela_botanica/public/com.gif |
---|
New file |
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/trunk/src/org/tela_botanica/public/gray_gradient.gif |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/trunk/src/org/tela_botanica/public/gray_gradient.gif |
---|
New file |
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/trunk/src/org/tela_botanica/public/Cel.html |
---|
New file |
0,0 → 1,32 |
<head> |
<meta http-equiv="content-type" content="text/html;charset=utf-8" /> |
<meta http-equiv="Content-Style-Type" content="text/css" /> |
<title>Carnet en ligne</title> |
<style type="text/css" > |
body,td,a,div,.p{font-family:arial,sans-serif} |
div,td{color:#000000} |
a:link,.w,.w a:link{color:#0000cc} |
a:visited{color:#551a8b} |
a:active{color:#ff0000} |
</style> |
<link rel="stylesheet" href="Cel.css" type="text/css"> |
<script type="text/javascript"> |
var Parameters = { |
serviceBaseUrl: "http://localhost/david/jrest" |
}; |
</script> |
<script type="text/javascript" language='javascript' src='org.tela_botanica.Cel.nocache.js'> |
</script> |
</head> |
<body> |
<!-- OPTIONAL: include this if you want history support --> |
<iframe src="javascript:''" id="__gwt_historyFrame" style="width:0;height:0;border:0"></iframe> |
</body> |
</html> |
/trunk/src/org/tela_botanica/public/blue_gradient.gif |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/trunk/src/org/tela_botanica/public/blue_gradient.gif |
---|
New file |
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/trunk/src/org/tela_botanica/public/tela.gif |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/trunk/src/org/tela_botanica/public/tela.gif |
---|
New file |
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/trunk/src/org/tela_botanica/public/Cel.css |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/trunk/src/org/tela_botanica/public/Cel.css |
---|
New file |
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/trunk/src/org/tela_botanica/public/fond.gif |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/trunk/src/org/tela_botanica/public/fond.gif |
---|
New file |
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/trunk/src/org/tela_botanica/Cel.gwt.xml |
---|
New file |
0,0 → 1,14 |
<module> |
<!-- Inherit the core Web Toolkit stuff. --> |
<inherits name='com.google.gwt.user.User'/> |
<!-- Parsing JSON --> |
<inherits name='com.google.gwt.json.JSON' /> |
<!-- Passage de parametres --> |
<inherits name="com.google.gwt.i18n.I18N"/> |
<!-- URL encode et decode --> |
<inherits name="com.google.gwt.http.HTTP"/> |
<!-- MyGwt --> |
<inherits name='net.mygwt.ui.MyGWT'/> --> |
<!-- Specify the app entry point class. --> |
<entry-point class='org.tela_botanica.client.CarnetEnLigne'/> |
</module> |
/trunk/update_cel.sh |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/trunk/update_cel.sh |
---|
New file |
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/trunk/.classpath |
---|
New file |
0,0 → 1,9 |
<?xml version="1.0" encoding="UTF-8"?> |
<classpath> |
<classpathentry kind="src" path="src"/> |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> |
<classpathentry kind="lib" path="/opt/gwt/gwt-user.jar"/> |
<classpathentry kind="var" path="JUNIT_HOME/junit.jar"/> |
<classpathentry kind="lib" path="/opt/mygwt/mygwt.jar"/> |
<classpathentry kind="output" path="bin"/> |
</classpath> |
/trunk/update_all.sh |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/trunk/update_all.sh |
---|
New file |
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |