Subversion Repositories eFlore/Archives.cel-v1

Compare Revisions

Ignore whitespace Rev 3 → Rev 4

/trunk/src/org/tela_botanica/client/NameAssistant.java
5,10 → 5,18
import java.util.EventListener;
 
 
import com.google.gwt.i18n.client.Dictionary;
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 java.util.Vector;
 
 
import org.tela_botanica.client.AutoCompleteAsyncTextBox;
 
/**
15,18 → 23,17
* A composite that displays a list of names that can be selected.
*/
 
public class NameAssistant extends Composite implements EventListener {
public class NameAssistant extends Composite implements EventListener, ResponseTextHandler {
 
private AutoCompleteAsyncTextBox autoCompletebox = new AutoCompleteAsyncTextBox();
private AutoCompleteAsyncTextBox autoCompletebox = new AutoCompleteAsyncTextBox(this);
private HorizontalPanel panel = new HorizontalPanel();
 
private Vector complements=null;
public NameAssistant(AutoCompleteAsyncTextBoxListener listener) {
// autoCompletebox.setSearchUrl("http://localhost/david/PHPJSON/server/server.php");
// autoCompletebox.setSearchUrl("http://localhost/david/papyrus/client/eflore_bp/index.php?module=recherche&action=completion_nom_latin&referentiel=25&format=json&nom=");
autoCompletebox.setSearchUrl("http://localhost/david/jrest/NameSearch/");
public NameAssistant(AutoCompleteAsyncTextBoxListener listener,Vector comps) {
complements=comps;
autoCompletebox.setSearchUrl(getServiceBaseUrl()+"/NameSearch/");
panel.add(autoCompletebox);
 
autoCompletebox.setWidth("100%");
35,6 → 42,42
 
}
 
public void onCompletion(String str) {
JSONValue jsonValue= JSONParser.parse(str);
JSONArray jsonArray;
JSONArray jsonArrayNested;
JSONString jsonString;
 
complements.clear();
if ((jsonArray = jsonValue.isArray()) != null) {
for (int i = 0; i < jsonArray.size(); ++i) {
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
if ((jsonString = (jsonArrayNested.get(0)).isString()) != null) {
autoCompletebox.addItem(jsonString.stringValue());
}
if ((jsonString = (jsonArrayNested.get(1)).isString()) != null) {
complements.add(i,jsonString.stringValue());
}
}
}
}
 
autoCompletebox.displayList();
}
 
 
public String getServiceBaseUrl() {
Dictionary theme = Dictionary.getDictionary("Parameters");
return theme.get("serviceBaseUrl");
 
}
}
/trunk/src/org/tela_botanica/client/AutoCompleteAsyncTextBox.java
23,11 → 23,8
// TODO : traiter latence (augmenter en fonction rapidité saisie + texte vide)
// TODO : traiter Tab (selection)
// TODO : revoir traitement keyup, keydown
// TODO : reactiver le cache (du design à revoir dans ce cas la)
 
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.ChangeListener;
51,6 → 48,7
private HashMap cache = new HashMap();
private boolean searching = false;
private ResponseTextHandler responseTextHandler=null;
protected PopupPanel choicesPopup = new PopupPanel(true);
protected ListBox choices = new ListBox();
57,14 → 55,17
protected Vector items = new Vector();
protected boolean popupAdded = false;
protected boolean visible = false;
protected int current = -1;
/**
* Default Constructor
*
*/
public AutoCompleteAsyncTextBox()
public AutoCompleteAsyncTextBox(ResponseTextHandler rsp)
{
super();
responseTextHandler=rsp;
this.addKeyboardListener(this);
choices.addChangeListener(this);
this.setStyleName("AutoCompleteAsyncTextBox");
96,35 → 97,13
/*
* Here we fetch the URL and call the handler
*/
String rematch=match.replaceFirst(" ","/");
if (this.searchUrl!=null && searching==false) {
searching=true;
HTTPRequest.asyncGet(this.searchUrl + match,
new ResponseTextHandler(){
public void onCompletion(String str) {
JSONValue jsonValue= JSONParser.parse(str);
JSONArray jsonArray;
JSONString jsonString;
HTTPRequest.asyncGet(this.searchUrl + rematch, responseTextHandler );
 
if ((jsonArray = jsonValue.isArray()) != null) {
for (int i = 0; i < jsonArray.size(); ++i) {
if ((jsonString = (jsonArray.get(i)).isString()) != null) {
addItem(jsonString.stringValue());
}
}
}
 
displayList();
 
}
 
});
 
}
}
 
197,9 → 176,9
else {
// Validation de l'entree :
if (autoCompleteAsyncTextBoxListeners!= null) {
autoCompleteAsyncTextBoxListeners.fireTextBoxEnter(this, this.getText());
autoCompleteAsyncTextBoxListeners.fireTextBoxEnter(this,current, this.getText());
}
current=-1;
this.setText("");
}
224,13 → 203,13
{
items.clear();
if (getFromCache(text)!=null) {
/* if (getFromCache(text)!=null) {
items=getFromCache(text);
displayList();
}
else {
else {*/
this.doFetchURL(text);
}
//}
}
}
243,7 → 222,7
if(this.items.size() > 0)
{
addToCache(this.getText(),(Vector) items.clone());
//addToCache(this.getText(),(Vector) items.clone());
choices.clear();
298,6 → 277,7
if(choices.getItemCount() > 0)
{
this.setText(choices.getItemText(choices.getSelectedIndex()));
current=choices.getSelectedIndex();
}
 
visible=false;
/trunk/src/org/tela_botanica/client/AutoCompleteAsyncTextBoxListenerCollection.java
12,10 → 12,10
* @param sender the widget sending the event
* @param text the text sent
*/
public void fireTextBoxEnter(SourcesAutoCompleteAsyncTextBoxEvents sender, String text) {
public void fireTextBoxEnter(SourcesAutoCompleteAsyncTextBoxEvents sender, int pos, String text) {
for (Iterator it = iterator(); it.hasNext();) {
AutoCompleteAsyncTextBoxListener listener = (AutoCompleteAsyncTextBoxListener) it.next();
listener.onValidate(sender, text);
listener.onValidate(sender, pos, text);
}
}
}
/trunk/src/org/tela_botanica/client/CenterPanel.java
9,18 → 9,19
 
import org.tela_botanica.client.TaxonList;
import org.tela_botanica.client.NameAssistant;
import java.util.Vector;
 
 
/**
* Composite permet de wrapper des Widgett pour creer un nouveau Widget cf methode initWidget()
*/
 
public class CenterPanel extends Composite {
private TaxonList taxonList = new TaxonList();
private NameAssistant nameAssistant = new NameAssistant(taxonList);
 
private Vector complements=new Vector();
private TaxonList taxonList = new TaxonList(complements);
private NameAssistant nameAssistant = new NameAssistant(taxonList,complements);
 
 
public CenterPanel() {
VerticalPanel outer = new VerticalPanel();
46,5 → 47,5
 
initWidget(outer);
}
 
}
/trunk/src/org/tela_botanica/client/AutoCompleteAsyncTextBoxListener.java
12,5 → 12,5
* @param sender the widget sending the event
* @param text : text selected
*/
void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender, String text);
void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender,int pos, String text);
}
/trunk/src/org/tela_botanica/client/Cel.java
1,6 → 1,7
package org.tela_botanica.client;
 
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.i18n.client.Dictionary;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.RootPanel;
71,4 → 72,14
shortcuts.setHeight("" + shortcutHeight);
 
}
public String getServiceBaseUrl() {
Dictionary theme = Dictionary.getDictionary("Parameters");
return theme.get("serviceBaseUrl");
 
}
 
}
/trunk/src/org/tela_botanica/client/TaxonList.java
16,6 → 16,7
package org.tela_botanica.client;
 
 
import com.google.gwt.i18n.client.Dictionary;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONNumber;
import com.google.gwt.json.client.JSONParser;
33,11 → 34,16
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
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;
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.HasAlignment;
 
import java.util.Vector;
 
/* Le retour de getUser appelle getCount qui appelle update pour veiller à une initialisation correcte
 
/**
* A composite that displays a list of emails that can be selected.
*/
68,8 → 74,8
bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_RIGHT);
bar.add(status, DockPanel.CENTER);
bar.setVerticalAlignment(DockPanel.ALIGN_MIDDLE);
bar.setCellHorizontalAlignment(status, HasAlignment.ALIGN_RIGHT);
bar.setCellVerticalAlignment(status, HasAlignment.ALIGN_MIDDLE);
bar.setCellHorizontalAlignment(status, HasHorizontalAlignment.ALIGN_RIGHT);
bar.setCellVerticalAlignment(status, HasVerticalAlignment.ALIGN_MIDDLE);
bar.setCellWidth(status, "100%");
 
// Initialize prev & first button to disabled.
124,20 → 130,32
 
private static final int VISIBLE_TAXON_COUNT = 15;
private Grid header = new Grid(1,3);
private Grid header = new Grid(1,6);
private FlexTable table = new FlexTable();
private CellFormatter cellFormater = table.getCellFormatter();
private VerticalPanel panel = new VerticalPanel();
private int startIndex=0;
private String serviceBaseUrl=getServiceBaseUrl();
private int count=65000;
private Vector complements=null;
private String element=null;
private String complement=null;
private String user;
private NavBar navBar = new NavBar();
public TaxonList() {
public TaxonList(Vector comps) {
 
getUser();
 
// Information complementaire
complements=comps;
// Setup the header
header.setCellSpacing(0);
146,15 → 164,29
 
header.setStyleName("taxon-ListHeader");
header.setText(0, 0, "Action");
header.setText(0, 1, "Nom");
header.setText(0, 2, "Famille");
header.setText(0, 0, "");
header.setText(0, 1, "Nom saisi");
header.setText(0, 2, "Nom retenu");
header.setHTML(0, 3, "Code<br>Nomenclatural");
header.setHTML(0, 4, "Code<br>Taxonomique");
header.setText(0, 5, "");
header.getCellFormatter().setWidth(0,0,"2%");
header.getCellFormatter().setWidth(0,1,"31%");
header.getCellFormatter().setWidth(0,2,"31%");
header.getCellFormatter().setWidth(0,3,"9%");
header.getCellFormatter().setWidth(0,4,"9%");
header.getCellFormatter().setWidth(0,5,"18%");
 
 
header.setCellSpacing(0);
header.setCellPadding(2);
 
// Setup the table.
table.setCellSpacing(0);
table.setBorderWidth(0);
table.setCellPadding(2);
table.setWidth("100%");
 
171,46 → 203,60
initWidget(panel);
// Recherche derniere ligne ... (il y a une autre stratégie pour la calculer si le resultat n'arrive pas assez vite)
 
HTTPRequest.asyncGet("http://localhost/david/jrest/InventoryList/dd/",
new ResponseTextHandler(){
 
public void onCompletion(String str) {
 
// On se positionne sur la dernière page ...
JSONValue jsonValue= JSONParser.parse(str);
JSONNumber jsonNumber;
if ((jsonNumber = jsonValue.isNumber()) != null) {
count=(int) jsonNumber.getValue();
if ((count%VISIBLE_TAXON_COUNT)>0) {
startIndex=count-(count%VISIBLE_TAXON_COUNT);
}
else {
startIndex=count-VISIBLE_TAXON_COUNT;
}
update();
}
}
});
 
}
public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender, String str) {
public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender,int pos, String str) {
// Ajout ligne
// Recherche informations complementaires :
// et Ajout ligne
if (pos>=0) {
complement=(String) complements.get(pos);
element=str;
HTTPRequest.asyncGet(serviceBaseUrl+"/NameValid/"+complement,
new ResponseTextHandler(){
 
count++;
HTTPRequest.asyncPost("http://localhost/david/jrest/Inventory/", "identifiant=dd&nom="+str,
new ResponseTextHandler(){
public void onCompletion(String str) {
JSONValue jsonValue= JSONParser.parse(str);
JSONArray jsonArray;
complements.clear();
if ((jsonArray = jsonValue.isArray()) != null) {
// Nom retenu, Num Nomen nom retenu, Num Taxon, Famille
addElement(element,complement,((JSONString) jsonArray.get(0)).stringValue(),
((JSONString) jsonArray.get(1)).stringValue(),((JSONString) jsonArray.get(2)).stringValue(),
((JSONString) jsonArray.get(3)).stringValue());
}
}
 
public void onCompletion(String str) {
});
}
else {
complements.clear();
 
addElement(str," "," "," "," "," ");
}
}
 
public void addElement(String nom_sel, String num_nom_sel, String nom_ret, String num_nom_ret, String num_taxon, String famille) {
int lastOrdre=1;
if (table.getRowCount()>0) {
lastOrdre=new Integer(table.getText(table.getRowCount()-1,6)).intValue()+1;
}
count++;
HTTPRequest.asyncPost(serviceBaseUrl+"/Inventory/", "identifiant="+user+"&nom_sel="+nom_sel+"&num_nom_sel="+num_nom_sel
+"&nom_ret="+nom_ret+"&num_nom_ret="+num_nom_ret+"&num_taxon="+num_taxon+"&famille="+famille+"&ordre="+lastOrdre,
new ResponseTextHandler(){
public void onCompletion(String str) {
if ((count%VISIBLE_TAXON_COUNT)>0) {
startIndex=count-(count%VISIBLE_TAXON_COUNT);
}
217,31 → 263,32
else {
startIndex=count-VISIBLE_TAXON_COUNT;
}
if (startIndex < 0) {
startIndex = 0;
}
update();
}
});
}
});
}
 
}
 
public void deleteElement() {
 
// Lifo ...
for (int i=table.getRowCount()-1; i>=0;i--){
if (((CheckBox) table.getWidget(i,0)).isChecked()) {
String str=table.getText(i,2);
String str=table.getText(i,6);
count--;
HTTPRequest.asyncPost("http://localhost/david/jrest/Inventory/dd/"+str, "action=DELETE",
HTTPRequest.asyncPost(serviceBaseUrl+"/Inventory/"+user+"/"+str, "action=DELETE",
new ResponseTextHandler(){
 
public void onCompletion(String str) {
if ((count%VISIBLE_TAXON_COUNT)>0) {
startIndex=count-(count%VISIBLE_TAXON_COUNT);
}
else {
if ((count%VISIBLE_TAXON_COUNT)==0) {
startIndex=count-VISIBLE_TAXON_COUNT;
}
if (startIndex < 0) {
startIndex = 0;
}
update();
}
});
249,9 → 296,63
}
}
}
 
private void getUser() {
HTTPRequest.asyncGet(serviceBaseUrl+"/User/",
new ResponseTextHandler(){
 
public void onCompletion(String str) {
JSONValue jsonValue= JSONParser.parse(str);
JSONString jsonString;
if ((jsonString = jsonValue.isString()) != null) {
user = jsonString.stringValue();
}
getCount();
}
});
 
}
 
private void getCount() {
// Recherche derniere ligne ... (il y a une autre stratégie pour la calculer si le resultat n'arrive pas assez vite)
 
HTTPRequest.asyncGet(serviceBaseUrl+"/InventoryList/"+user+"/",
new ResponseTextHandler(){
 
public void onCompletion(String str) {
 
//On se positionne sur la dernière page ...
JSONValue jsonValue= JSONParser.parse(str);
JSONNumber jsonNumber;
if ((jsonNumber = jsonValue.isNumber()) != null) {
count=(int) jsonNumber.getValue();
if ((count%VISIBLE_TAXON_COUNT)>0) {
startIndex=count-(count%VISIBLE_TAXON_COUNT);
}
else {
startIndex=count-VISIBLE_TAXON_COUNT;
}
if (startIndex < 0) {
startIndex = 0;
}
update();
}
}
});
 
}
 
private void update() {
// TODO : optimisation : ne supprimer que les lignes qui ne seront pas alimentes .
 
navBar.gotoFirst.setEnabled(false);
navBar.gotoPrev.setEnabled(false);
260,7 → 361,7
setStatusText("Patientez ...");
 
HTTPRequest.asyncGet("http://localhost/david/jrest/InventoryList/dd/"+startIndex+"/"+VISIBLE_TAXON_COUNT,
HTTPRequest.asyncGet(serviceBaseUrl+"/InventoryList/"+user+"/"+startIndex+"/"+VISIBLE_TAXON_COUNT,
new ResponseTextHandler(){
 
public void onCompletion(String str) {
275,18 → 376,40
}
 
 
int j=0;
if ((jsonArray = jsonValue.isArray()) != null) {
int i;
for (i = 0; i < jsonArray.size(); ++i) {
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
int row=table.insertRow(table.getRowCount());
// Case a cocher
table.setWidget(row,0,new CheckBox());
// Nom saisi
table.setText(row,1,((JSONString) jsonArrayNested.get(0)).stringValue());
table.setText(row,2,((JSONString) jsonArrayNested.get(1)).stringValue());
cellFormater.setVisible(row,2,false);
// Nom retenu
table.setText(row,2,((JSONString) jsonArrayNested.get(2)).stringValue());
// Num nomenclatural
table.setText(row,3,((JSONString) jsonArrayNested.get(1)).stringValue());
// Num Taxonomique
table.setText(row,4,((JSONString) jsonArrayNested.get(4)).stringValue());
// Famille
table.setText(row,5,((JSONString) jsonArrayNested.get(5)).stringValue());
// Numero d'ordre
table.setText(row,6,((JSONString) jsonArrayNested.get(6)).stringValue());
table.getCellFormatter().setVisible(row,6,true);
table.getFlexCellFormatter().setWidth(row,0,"2%");
table.getFlexCellFormatter().setWidth(row,1,"31%");
table.getFlexCellFormatter().setWidth(row,2,"31%");
table.getFlexCellFormatter().setWidth(row,3,"9%");
table.getFlexCellFormatter().setWidth(row,4,"9%");
table.getFlexCellFormatter().setWidth(row,5,"18%");
j++;
}
}
// Calcul nombre d'enregistrement total
// Calcul nombre d'enregistrement total (c'est un doublon, c'est normal ...)
if (i<VISIBLE_TAXON_COUNT) {
count = startIndex+i;
}
293,14 → 416,19
// Navigation
setStatusText((startIndex + 1) + " - " + (startIndex + VISIBLE_TAXON_COUNT));
 
// Premiere page
if (startIndex<VISIBLE_TAXON_COUNT) {
if (startIndex<VISIBLE_TAXON_COUNT ) {
navBar.gotoPrev.setEnabled(false);
navBar.gotoFirst.setEnabled(false);
navBar.gotoNext.setEnabled(true);
navBar.gotoEnd.setEnabled(true);
if (count < VISIBLE_TAXON_COUNT) {
setStatusText((startIndex + 1) + " - " + count );
}
else {
setStatusText((startIndex + 1) + " - " + (startIndex + VISIBLE_TAXON_COUNT));
}
}
// Derniere page
312,21 → 440,37
navBar.gotoEnd.setEnabled(false);
setStatusText((startIndex + 1) + " - " + count);
}
// Page normale
else {
navBar.gotoPrev.setEnabled(true);
navBar.gotoFirst.setEnabled(true);
navBar.gotoNext.setEnabled(true);
navBar.gotoEnd.setEnabled(true);
setStatusText((startIndex + 1) + " - " + (startIndex + VISIBLE_TAXON_COUNT));
}
}
}
// Tableau vide (TODO : despaguettiser)
if (j==0) {
navBar.gotoPrev.setEnabled(false);
navBar.gotoFirst.setEnabled(false);
navBar.gotoNext.setEnabled(false);
navBar.gotoEnd.setEnabled(false);
setStatusText(0 + " - " + 0);
}
}
});
 
}
private String getServiceBaseUrl() {
Dictionary theme = Dictionary.getDictionary("Parameters");
return theme.get("serviceBaseUrl");
 
}
 
 
 
}
/trunk/src/org/tela_botanica/public/Cel.html
4,7 → 4,7
<!-- -->
<!-- Any title is fine -->
<!-- -->
<title>Wrapper HTML for Cel</title>
<title>Carnet en ligne</title>
 
<!-- -->
<!-- Use normal html, such as style -->
16,7 → 16,17
a:visited{color:#551a8b}
a:active{color:#ff0000}
</style>
<script type="text/javascript">
var Parameters = {
serviceBaseUrl: "http://localhost/david/jrest"
};
</script>
 
 
 
<!-- -->
<!-- The module reference below is the link -->
<!-- between html and your Web Toolkit module -->
/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/Cel.gwt.xml
3,6 → 3,7
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<inherits name='com.google.gwt.json.JSON' />
<inherits name="com.google.gwt.i18n.I18N"/>
 
<!-- Specify the app entry point class. -->
<entry-point class='org.tela_botanica.client.Cel'/>