New file |
0,0 → 1,448 |
/* |
* 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 java.util.Date; |
|
import com.google.gwt.json.client.JSONArray; |
import com.google.gwt.json.client.JSONNull; |
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.Window; |
import com.google.gwt.user.client.ui.Button; |
import com.google.gwt.user.client.ui.ChangeListener; |
import com.google.gwt.user.client.ui.CheckBox; |
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; |
|
/** |
* Composite permet de wrapper des Widget pour creer un nouveau Widget cf methode initWidget() |
*/ |
|
public class EntryPanel extends Composite { |
|
private NameAssistant nameAssistant = null; |
private LocationAssistant locationAssistant = null; |
TextBox date = new TextBox(); |
TextBox complementLocation = new TextBox(); |
TextBox comment = new TextBox(); |
Button dateSelector = new Button("..."); |
boolean visible=false; |
Mediator mediator=null; |
|
private String serviceBaseUrl = null; |
|
private String user= null; |
private String ordre =null; |
|
final CalendarWidget calendar = new CalendarWidget(); |
|
private PopupPanel choicesPopup = new PopupPanel(true); |
|
public EntryPanel(final Mediator med) { |
|
|
mediator=med; |
|
|
|
mediator.registerEntryPanel(this); |
|
mediator.registerDate(date); |
mediator.registerComment(comment); |
mediator.registerComplementLocation(complementLocation); |
|
|
user=mediator.getUser(); |
serviceBaseUrl = mediator.getServiceBaseUrl(); |
|
|
|
VerticalPanel outer = new VerticalPanel(); |
|
|
outer.add(new HTML("<b>Saisir un relevé :</b>")); |
|
|
|
Grid inner = new Grid(3,4); |
|
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 |
|
HTML labelNameAssistant = new HTML("Espèce: "); |
inner.setWidget(0,0,labelNameAssistant); |
inner.setWidget(0,1,nameAssistant); |
|
nameAssistant.setWidth("100%"); |
|
// Saisie lieu |
|
HTML labelLocationAssistant= new HTML("Commune: "); |
inner.setWidget(1,0,labelLocationAssistant); |
inner.setWidget(1,1,locationAssistant); |
|
locationAssistant.setWidth("100%"); |
|
// Saisie Date |
|
choicesPopup.add(calendar); |
|
dateSelector.addClickListener(new ClickListener () { |
|
public void onClick(Widget w) { |
|
if (visible) { |
visible=false; |
choicesPopup.hide(); |
} |
else { |
visible=true; |
choicesPopup.show(); |
choicesPopup.setPopupPosition(dateSelector.getAbsoluteLeft(), |
dateSelector.getAbsoluteTop() - dateSelector.getOffsetHeight() - choicesPopup.getOffsetHeight()); |
choicesPopup.setWidth(dateSelector.getOffsetWidth() + "px"); |
} |
} |
|
}); |
|
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(); |
} |
}); |
|
HTML labelDate= new HTML("Date: "); |
inner.setWidget(2,0,labelDate); |
|
HorizontalPanel datePanel = new HorizontalPanel(); |
datePanel.add(date); |
datePanel.add(dateSelector); |
inner.setWidget(2,1,datePanel); |
|
|
|
|
date.addKeyboardListener( new KeyboardListener() { |
|
public void onKeyDown(Widget arg0, char arg1, int arg2) { |
|
|
if(arg1 == KEY_ENTER) |
{ |
mediator.onAddInventoryItem(); |
date.setText(""); |
} |
|
} |
|
public void onKeyUp(Widget arg0, char arg1, int arg2) { |
} |
|
public void onKeyPress(Widget arg0, char arg1, int arg2) { |
} |
|
} |
); |
|
|
|
// Saisie Complement lieu |
|
HTML labelComplementLocation= new HTML("Station: "); |
inner.setWidget(1,2,labelComplementLocation); |
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) |
{ |
mediator.onAddInventoryItem(); |
complementLocation.setText(""); |
} |
|
} |
|
public void onKeyUp(Widget arg0, char arg1, int arg2) { |
} |
|
public void onKeyPress(Widget arg0, char arg1, int arg2) { |
} |
|
} |
); |
|
|
// Saisie Commentaire |
|
HTML labelComment= new HTML("Notes: "); |
inner.setWidget(2,2,labelComment); |
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) |
{ |
mediator.onAddInventoryItem(); |
comment.setText(""); |
} |
|
} |
|
public void onKeyUp(Widget arg0, char arg1, int arg2) { |
} |
|
public void onKeyPress(Widget arg0, char arg1, int arg2) { |
} |
|
} |
); |
|
|
Button addButton = new Button("Ajout"); |
Button updateButton = new Button("Modification"); |
|
addButton.addClickListener( |
|
new ClickListener() { |
|
public void onClick(Widget w) { |
mediator.onAddInventoryItem(); |
} |
} |
); |
|
HorizontalPanel buttonPanel = new HorizontalPanel(); |
|
|
updateButton.addClickListener( |
|
new ClickListener() { |
|
public void onClick(Widget w) { |
mediator.onModifyInventoryItem(ordre); |
} |
} |
); |
|
|
buttonPanel.add(addButton); |
buttonPanel.add(updateButton); |
|
|
inner.setWidth("100%"); |
|
outer.add(inner); |
outer.setCellWidth(inner, "100%"); |
outer.setSpacing(10); |
|
outer.setHorizontalAlignment(HorizontalPanel.ALIGN_CENTER); |
outer.add(buttonPanel); |
|
|
// Initialisation si provenance d'un lien |
|
if (History.getToken().length()>0) { |
|
final String anum=History.getToken(); |
|
HTTPRequest.asyncGet(serviceBaseUrl + "/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(serviceBaseUrl + "/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); |
} |
|
// 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; |
} |
|
} |