New file |
0,0 → 1,463 |
/** |
David Delon david.delon@clapas.net 2007 |
|
*/ |
|
/* |
* EntryPanel.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 |
* |
*/ |
|
|
package org.tela_botanica.client; |
|
import java.util.Date; |
|
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.Button; |
import com.google.gwt.user.client.ui.ChangeListener; |
import com.google.gwt.user.client.ui.ClickListener; |
import com.google.gwt.user.client.ui.Composite; |
import com.google.gwt.user.client.ui.Grid; |
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.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 EntryPanel extends Composite { |
|
private NameAssistant nameAssistant = null; |
private LocationAssistant locationAssistant = null; |
private TextBox date = new TextBox(); |
private TextBox complementLocation = 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 EntryPanel(final Mediator med) { |
|
|
Grid inner = new Grid(3,4); |
|
|
|
mediator=med; |
user=mediator.getUser(); |
|
mediator.registerEntryPanel(this); |
|
mediator.registerDate(date); |
mediator.registerComment(comment); |
mediator.registerComplementLocation(complementLocation); |
|
|
VerticalPanel outer = new VerticalPanel(); |
|
|
outer.add(new HTML("<b>Saisir un relevé :</b>")); |
|
|
|
for (int i=0; i<3;i++) { |
inner.getCellFormatter().setWidth(i, 0, "3%"); |
inner.getCellFormatter().setWidth(i, 1, "47%"); |
inner.getCellFormatter().setWidth(i, 2, "3%"); |
inner.getCellFormatter().setWidth(i, 3, "47%"); |
} |
|
|
|
|
nameAssistant = new NameAssistant(mediator); |
locationAssistant = new LocationAssistant(mediator); |
|
|
// Saisie Nom |
|
inner.setHTML(0,0,"Espèce: "); |
inner.setWidget(0,1,nameAssistant); |
|
nameAssistant.setWidth("100%"); |
|
// Saisie lieu |
|
inner.setHTML(1,0,"Commune: "); |
inner.setWidget(1,1,locationAssistant); |
|
locationAssistant.setWidth("100%"); |
|
// Saisie Date |
|
|
dateSelector.addClickListener(new ClickListener () { |
|
public void onClick(Widget w) { |
|
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"); |
} |
} |
|
}); |
|
|
inner.setHTML(2,0,"Date: "); |
|
HorizontalPanel datePanel = new HorizontalPanel(); |
datePanel.add(date); |
datePanel.add(dateSelector); |
inner.setWidget(2,1,datePanel); |
|
// Saisie date |
|
date.addKeyboardListener( new KeyboardListener() { |
|
public void onKeyDown(Widget arg0, char arg1, int arg2) { |
if(arg1 == KEY_ENTER) |
{ |
if (ordre==null) { |
mediator.onAddInventoryItem(); |
date.setText(""); |
} |
else { |
mediator.onModifyInventoryItem(ordre); |
ordre=null; |
} |
} |
} |
|
public void onKeyUp(Widget arg0, char arg1, int arg2) { } |
public void onKeyPress(Widget arg0, char arg1, int arg2) { } |
|
} |
); |
|
|
|
// Saisie Complement de lieu (station) |
|
inner.setHTML(1,2,"Station: "); |
inner.setWidget(1,3,complementLocation); |
|
complementLocation.setWidth("100%"); |
|
|
complementLocation.addKeyboardListener( new KeyboardListener() { |
|
public void onKeyDown(Widget arg0, char arg1, int arg2) { |
if(arg1 == KEY_ENTER) |
{ |
if (ordre==null) { |
mediator.onAddInventoryItem(); |
complementLocation.setText(""); |
} |
else { |
mediator.onModifyInventoryItem(ordre); |
ordre=null; |
} |
} |
|
} |
|
public void onKeyUp(Widget arg0, char arg1, int arg2) { } |
|
public void onKeyPress(Widget arg0, char arg1, int arg2) { } |
|
} |
); |
|
|
// Saisie Commentaire |
|
inner.setHTML(2,2,"Notes: "); |
inner.setWidget(2,3,comment); |
|
comment.setWidth("100%"); |
|
|
comment.addKeyboardListener( new KeyboardListener() { |
|
public void onKeyDown(Widget arg0, char arg1, int arg2) { |
if(arg1 == KEY_ENTER) |
{ |
if (ordre==null) { |
mediator.onAddInventoryItem(); |
comment.setText(""); |
} |
else { |
mediator.onModifyInventoryItem(ordre); |
ordre=null; |
} |
} |
|
} |
|
public void onKeyUp(Widget arg0, char arg1, int arg2) { } |
public void onKeyPress(Widget arg0, char arg1, int arg2) { } |
|
} |
); |
|
|
Button validButton = new Button("Valider"); |
|
|
validButton.addClickListener( |
|
new ClickListener() { |
|
public void onClick(Widget w) { |
if (ordre==null) { |
mediator.onAddInventoryItem(); |
} |
else { |
mediator.onModifyInventoryItem(ordre); |
ordre=null; |
} |
} |
} |
); |
|
|
|
HorizontalPanel actionPanel= new HorizontalPanel(); |
|
actionPanel.add(validButton); |
|
|
inner.setWidth("100%"); |
|
outer.add(inner); |
outer.setCellWidth(inner, "100%"); |
outer.setSpacing(10); |
|
outer.setHorizontalAlignment(HorizontalPanel.ALIGN_CENTER); |
outer.add(actionPanel); |
|
|
// 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 = ((JSONString) jsonArray.get(0)).stringValue(); |
|
// Nom |
|
if (aname.compareTo("null")!=0) { |
nameAssistant.setText(((JSONString) jsonArray.get(0)).stringValue()); |
|
// Numero nomenclatural |
|
nameAssistant.setValue(anum); |
|
} |
|
} |
} |
|
}); |
|
|
} |
|
|
initWidget(outer); |
|
|
} |
|
/* |
* Numero d'ordre du relev� affich� |
* |
*/ |
|
public void setOrdre(String ordre) { |
this.ordre = ordre; |
} |
|
|
/* |
* Numero d'ordre du relev� affich� |
* |
*/ |
|
public String getOrdre() { |
return this.ordre; |
} |
|
|
|
/** |
* Mise a jour de l'affichage a partir de donn�es 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(((JSONString) jsonArray.get(0)).stringValue()); |
|
// 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=((JSONString) jsonArray .get(6)).stringValue(); |
|
if (aloc.compareTo("000null")!=0) { |
locationAssistant.setText(aloc); |
} |
else { |
locationAssistant.setText(""); |
} |
|
String adate=((JSONString) jsonArray .get(8)).stringValue(); |
|
// Date |
if (adate.compareTo("0000-00-00 00:00:00")!=0) { |
date.setText(adate); |
} |
else { |
date.setText(""); |
} |
|
|
String astation=((JSONString) jsonArray .get(9)).stringValue(); |
|
// Station |
if (astation.compareTo("000null")!=0) { |
complementLocation.setText(astation); |
} |
else { |
complementLocation.setText(""); |
} |
|
|
String acomment=((JSONString) jsonArray .get(10)).stringValue(); |
// 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.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 |
* |
* |
*/ |