/trunk/src/org/tela_botanica/client/TaxonList.java |
---|
File deleted |
/trunk/src/org/tela_botanica/client/InventoryItemList.java |
---|
New file |
0,0 → 1,715 |
/* |
* 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.Iterator; |
import java.util.Vector; |
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.FlexTable; |
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.VerticalPanel; |
import com.google.gwt.user.client.ui.DockPanel; |
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.Label; |
/* |
* Le retour de getUser appelle updateCount qui appelle update pour veiller à une |
* initialisation correcte |
* |
*/ |
public class InventoryItemList extends Composite implements |
AutoCompleteAsyncTextBoxListener { |
// 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 HTML status = new HTML(); |
public NavBar() { |
initWidget(bar); |
bar.setStyleName("navbar"); |
status.setStyleName("status"); |
HorizontalPanel buttons = new HorizontalPanel(); |
buttons.add(status); |
buttons.setCellHorizontalAlignment(status, |
HasHorizontalAlignment.ALIGN_RIGHT); |
buttons.setCellVerticalAlignment(status, |
HasVerticalAlignment.ALIGN_MIDDLE); |
buttons.setCellWidth(status, "100%"); |
buttons.add(gotoFirst); |
buttons.add(gotoPrev); |
buttons.add(gotoNext); |
buttons.add(gotoEnd); |
bar.add(buttons, DockPanel.EAST); |
bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_RIGHT); |
bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_LEFT); |
bar.setVerticalAlignment(DockPanel.ALIGN_MIDDLE); |
VerticalPanel actions = new VerticalPanel(); |
HorizontalPanel actionButton = new HorizontalPanel(); |
HTML delButton=new HTML("Suppression"); |
delButton.setStyleName("html_button"); |
delButton.addClickListener( |
new ClickListener() { |
public void onClick(Widget sender) { |
mediator.getInventoryItemList().deleteElement(); |
} |
} |
); |
actionButton.add(delButton); |
HTML exportButton=new HTML("<a href=\""+mediator.getServiceBaseUrl()+"/InventoryExport/" +mediator.getUser()+"\">"+"Tout exporter</a>"); |
actionButton.add(exportButton); |
exportButton.setStyleName("html_button"); |
actionButton.setSpacing(5); |
actions.add(actionButton); |
bar.add(actions, DockPanel.WEST); |
} |
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(); |
} |
} |
private void setStatusText(String text) { |
navBar.status.setText(text); |
} |
private static final int VISIBLE_TAXON_COUNT = 15; |
private Grid header = new Grid(1, 7); |
private FlexTable table = new FlexTable(); |
private VerticalPanel panel = new VerticalPanel(); |
private int startIndex = 0; |
private String serviceBaseUrl = null; |
private int count = 65000; |
private String user; |
private NavBar navBar=null; |
private Mediator mediator = null; |
// Optimization |
int sizeChecked=0; |
int itemDeleted=0; |
// Données alimentant la saisie : texte et valeur localité, texte et valeur communes |
private String nameText=null; |
private String nameValue=null; |
private String locationText=null; |
private String locationValue=null; |
// |
private String location = "all"; |
public InventoryItemList(Mediator med) { |
mediator=med; |
mediator.registerInventoryItemList(this); |
user=mediator.getUser(); |
serviceBaseUrl = mediator.getServiceBaseUrl(); |
navBar = new NavBar(); |
// Information complementaire : un tableau associe au retour de |
// l'assistant de saisie |
// Mise en forme du header |
header.setCellSpacing(0); |
header.setCellPadding(2); |
header.setWidth("100%"); |
header.setStyleName("taxon-ListHeader"); |
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, "Famille"); |
header.setText(0, 6, "Localisation"); |
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, "9%"); |
header.getCellFormatter().setWidth(0, 6, "9%"); |
// Mise en forme de la table. |
table.setCellSpacing(0); |
table.setBorderWidth(0); |
table.setCellPadding(2); |
table.setWidth("100%"); |
// Mise en forme barre navigation |
navBar.setWidth("100%"); |
table.setStyleName("taxon-List"); |
panel.add(navBar); |
panel.add(header); |
panel.add(table); |
HorizontalPanel selections = new HorizontalPanel(); |
selections.setSpacing(3); |
selections.add(new HTML("Sélection : ")); |
Label allLabel = new Label("Tous"); |
Label separatorLabel = new Label(","); |
Label noneLabel = new Label("Aucun"); |
allLabel.setStyleName("selection_label"); |
noneLabel.setStyleName("selection_label"); |
selections.add(allLabel); |
allLabel.addClickListener( |
new ClickListener() { |
public void onClick(Widget sender) { |
selectAll(); |
} |
} |
); |
selections.add(separatorLabel); |
selections.add(noneLabel); |
noneLabel.addClickListener( |
new ClickListener() { |
public void onClick(Widget sender) { |
deselectAll(); |
} |
} |
); |
panel.add(selections); |
updateCount(); |
// update() |
initWidget(panel); |
} |
/** |
* Action lancee par la selection d'un nom dans l'assistant de saisie. Lance |
* la recherche d'informations complémentaires (famille, numero |
* nomenclaturaux etc) et met a jour l'inventaire (addelement()) |
* |
* @return void |
*/ |
public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender, |
String str, String value) { |
// Le nom de plante est requis |
if (mediator.getNameAssistant().getText().compareTo("")==0) { |
return; |
} |
nameText=(mediator.getNameAssistant()).getText(); |
nameValue=(mediator.getNameAssistant()).getValue(); |
locationText=(mediator.getLocationAssistant()).getText(); |
locationValue=(mediator.getLocationAssistant()).getValue(); |
// Suppresion indication departementale (on pourrait faire mieux !!) |
int pos=locationText.indexOf(" (" ); |
if (pos>=0) { |
locationText=locationText.substring(0,pos); |
} |
setStatusDisabled(); |
// On met a jour rapidement l'affichage puis on lance la requete .... |
/* int row = table.insertRow(table.getRowCount()); |
// Case a cocher |
table.setWidget(row, 0, new CheckBox()); |
// Nom saisi |
table.setText(row, 1, nameText); |
table.getFlexCellFormatter().setWidth(row, 0, "2%"); |
table.getFlexCellFormatter() |
.setWidth(row, 1, "31%");*/ |
// Recherche complement d'information |
if (nameValue !=null) { |
HTTPRequest.asyncGet(serviceBaseUrl + "/NameValid/" + nameValue, |
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(nameText, nameValue, |
((JSONString) jsonArray.get(0)) |
.stringValue(), |
((JSONString) jsonArray.get(1)) |
.stringValue(), |
((JSONString) jsonArray.get(2)) |
.stringValue(), |
((JSONString) jsonArray.get(3)) |
.stringValue(), |
locationText,locationValue); |
} |
} |
}); |
} |
// Saisie libre |
else { |
addElement(nameText, " ", " ", " ", " ", " ",locationText,locationValue); |
} |
} |
/** |
* Ajoute un element à l'inventaire |
* |
* @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 |
*/ |
public 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) { |
// Calcul du nouveau numéro d'ordre |
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 + "&location=" + loc + "&id_location=" + id_location, |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
location=loc; |
updateCount(); |
} |
}); |
} |
/** |
* Suppression d'un element lde l'inventaire, a partir de son numero d'ordre |
* |
*/ |
public void deleteElement() { |
setStatusDisabled(); |
boolean checked = false; |
Vector parseChecked = new Vector(); |
// Lifo ... |
for (int i = table.getRowCount() - 1; i >= 0; i--) { |
if (((CheckBox) table.getWidget(i, 0)).isChecked()) { |
checked = true; |
// Numero ordre |
parseChecked.add(table.getText(i, 7)); |
count--; |
} |
} |
sizeChecked=parseChecked.size(); |
itemDeleted=0; |
for (Iterator it = parseChecked.iterator(); it.hasNext();) { |
itemDeleted++; |
HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/" + user |
+ "/" + (String) it.next(), "action=DELETE", |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
// Optimisation : on ne lance la suppression qu'a la fin |
if (itemDeleted==sizeChecked) { |
updateCount(); |
} |
} |
}); |
} |
if (!checked) { |
setStatusEnabled(); |
} |
} |
/** |
* Selection de l'ensemble des elements affichés |
* |
*/ |
public void selectAll() { |
for (int i = table.getRowCount() - 1; i >= 0; i--) { |
((CheckBox) table.getWidget(i, 0)).setChecked(true); |
} |
} |
public void deselectAll() { |
for (int i = table.getRowCount() - 1; i >= 0; i--) { |
((CheckBox) table.getWidget(i, 0)).setChecked(false); |
} |
} |
/** |
* Recherche nombre d'enregistrement pour l'utilisateur et la localite en cours |
* |
*/ |
public void updateCount() { |
setStatusDisabled(); |
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryItemList/" + user + "/" + location, |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
JSONValue jsonValue = JSONParser.parse(str); |
JSONNumber jsonNumber; |
if ((jsonNumber = jsonValue.isNumber()) != null) { |
count = (int) jsonNumber.getValue(); |
/* |
if (count==0) { |
location="all"; |
} |
*/ |
if (location.compareTo("")==0) |
location="000null"; |
mediator.onInventoryItemUpdate(location); |
gotoEnd(); // Derniere page |
update(); |
} |
} |
}); |
} |
/** |
* Mise a jour de l'affichage, à partir des données d'inventaire deja |
* saisies. La valeur de this.startIndex permet de determiner quelles |
* données seront affichées |
* |
* @param deep : force une mise a jour totale |
*/ |
public void update() { |
setStatusDisabled(); |
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryItemList/" + user + "/" + location +"/" |
+ startIndex + "/" + VISIBLE_TAXON_COUNT, |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
JSONValue jsonValue = JSONParser.parse(str); |
JSONArray jsonArray; |
JSONArray jsonArrayNested; |
int row=0; |
int i=0; |
if ((jsonArray = jsonValue.isArray()) != null) { |
int arraySize = jsonArray.size(); |
for (i = 0; i < arraySize; ++i) { |
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) { |
if (i>=table.getRowCount()) { |
row = table.insertRow(table.getRowCount()); |
} |
else { |
row = i; |
} |
// Case a cocher |
table.setWidget(row, 0, new CheckBox()); |
// Nom saisi |
table.setText(row, 1, ((JSONString) jsonArrayNested |
.get(0)).stringValue()); |
// 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()); |
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, "9%"); |
// TODO : Bool ici non ? |
if (location.compareTo("all")==0) { |
// Localisation - Lieu |
String aloc=((JSONString) jsonArrayNested .get(6)).stringValue(); |
if (aloc.compareTo("000null")==00) { |
table.setText(row, 6, "Inconnu"); |
} |
else { |
table.setText(row, 6, ((JSONString) jsonArrayNested .get(6)).stringValue()); |
} |
header.getCellFormatter().setVisible(0, 6,true); |
} |
else { |
header.getCellFormatter().setVisible(0, 6,false); |
table.getCellFormatter().setVisible(row, 6,false); |
} |
table.getFlexCellFormatter().setWidth(row, 6, "9%"); |
// Numero d'ordre (caché) |
table.setText(row, 7, ((JSONString) jsonArrayNested |
.get(7)).stringValue()); |
table.getCellFormatter().setVisible(row, 7, false); |
} |
} |
} |
// Suppression fin ancien affichage |
if (i<table.getRowCount()-1) { |
for (int j = table.getRowCount() - 1; j > i-1; j--) { |
table.removeRow(j); |
} |
} |
setStatusEnabled(); |
} |
}); |
} |
/** |
* Affichage message d'attente et désactivation navigation |
* |
* @param |
* @return void |
*/ |
private void setStatusDisabled() { |
navBar.gotoFirst.setEnabled(false); |
navBar.gotoPrev.setEnabled(false); |
navBar.gotoNext.setEnabled(false); |
navBar.gotoEnd.setEnabled(false); |
setStatusText("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); |
setStatusText((startIndex + 1) + " - " |
+ (startIndex + VISIBLE_TAXON_COUNT) + " sur " + count ); |
} else { // Derniere page |
setStatusText((startIndex + 1) + " - " + count + " sur " + count ); |
} |
} else { // Premiere page |
if (count > VISIBLE_TAXON_COUNT) { // Des pages derrieres |
navBar.gotoNext.setEnabled(true); |
navBar.gotoEnd.setEnabled(true); |
setStatusText((startIndex + 1) + " - " |
+ (startIndex + VISIBLE_TAXON_COUNT) + " sur " + count); |
} else { |
setStatusText((startIndex + 1) + " - " + count + " sur " + count); |
} |
} |
} |
else { // Pas d'inventaire, pas de navigation |
setStatusText("0 - 0 sur 0"); |
} |
} |
/* |
* Positionnement index de parcours (this.startIndex) pour affichage de la |
* dernière 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; |
} |
} |
/* |
* Localite en cours |
* |
*/ |
public void setLocation(String location) { |
this.location = location; |
} |
} |
/trunk/src/org/tela_botanica/client/LeftPanel.java |
---|
16,6 → 16,7 |
package org.tela_botanica.client; |
import com.google.gwt.user.client.ui.Composite; |
import com.google.gwt.user.client.ui.HorizontalPanel; |
import com.google.gwt.user.client.ui.VerticalPanel; |
import org.tela_botanica.client.LocationList; |
26,14 → 27,17 |
public class LeftPanel extends Composite { |
private LocationList locationList = null; |
private TaxonList taxonList = null; |
public LeftPanel(Mediator mediator) { |
HorizontalPanel inner = new HorizontalPanel(); |
locationList = new LocationList(mediator); |
VerticalPanel outer = new VerticalPanel(); |
outer.add(inner); |
outer.add(locationList); |
outer.setCellHeight(inner,"100%"); |
initWidget(outer); |
} |
/trunk/src/org/tela_botanica/client/NameAssistant.java |
---|
5,7 → 5,6 |
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; |
18,7 → 17,7 |
import org.tela_botanica.client.AutoCompleteAsyncTextBox; |
/** |
* A composite that displays a list of names that can be selected. |
* Affiche une liste de nom pour selection. Son retournés le nom selectionné (gettext()) et un code associé (getvalue()). |
*/ |
public class NameAssistant extends Composite implements EventListener, ResponseTextHandler { |
26,16 → 25,23 |
private AutoCompleteAsyncTextBox autoCompletebox = new AutoCompleteAsyncTextBox(this); |
private HorizontalPanel panel = new HorizontalPanel(); |
public NameAssistant(AutoCompleteAsyncTextBoxListener listener) { |
private Mediator mediator = null; |
public NameAssistant(Mediator med) { |
mediator=med; |
mediator.registerNameAssistant(this); |
// autoCompletebox.setFocus(true); |
autoCompletebox.setSearchUrl(getServiceBaseUrl()+"/NameSearch/"); |
autoCompletebox.setSearchUrl(mediator.getServiceBaseUrl()+"/NameSearch/"); |
panel.add(autoCompletebox); |
autoCompletebox.setWidth("100%"); |
initWidget(panel); |
autoCompletebox.addAutoCompleteAsyncTextBoxListener(listener); |
autoCompletebox.addAutoCompleteAsyncTextBoxListener(mediator.getInventoryItemList()); |
} |
70,14 → 76,5 |
} |
public String getServiceBaseUrl() { |
Dictionary theme = Dictionary.getDictionary("Parameters"); |
return theme.get("serviceBaseUrl"); |
} |
} |
/trunk/src/org/tela_botanica/client/CenterPanel.java |
---|
1,13 → 1,10 |
package org.tela_botanica.client; |
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.VerticalPanel; |
import org.tela_botanica.client.TaxonList; |
import org.tela_botanica.client.NameAssistant; |
import org.tela_botanica.client.InventoryItemList; |
/** |
* Composite permet de wrapper des Widgett pour creer un nouveau Widget cf methode initWidget() |
16,56 → 13,18 |
public class CenterPanel extends Composite { |
private TaxonList taxonList = null; |
private NameAssistant nameAssistant = null; |
private LocationAssistant locationAssistant = null; |
private InventoryItemList inventoryItemList = null; |
public CenterPanel(Mediator mediator) { |
taxonList = new TaxonList(mediator); |
inventoryItemList = new InventoryItemList(mediator); |
nameAssistant = new NameAssistant(taxonList); |
locationAssistant = new LocationAssistant(taxonList); |
taxonList.setNameProvider(nameAssistant); |
taxonList.setLocationProvider(locationAssistant); |
VerticalPanel outer = new VerticalPanel(); |
DockPanel inner = new DockPanel(); |
DockPanel namePanel = new DockPanel(); |
DockPanel locationPanel = new DockPanel(); |
outer.add(inventoryItemList); |
inventoryItemList.setWidth("100%"); |
namePanel.add(new HTML("Nom: "),DockPanel.WEST); |
namePanel.add (nameAssistant,DockPanel.CENTER); |
nameAssistant.setWidth("100%"); |
namePanel.setCellWidth(nameAssistant,"100%"); |
namePanel.setWidth("100%"); |
locationPanel.add(new HTML("Lieu: "),DockPanel.WEST); |
locationPanel.add (locationAssistant,DockPanel.CENTER); |
locationAssistant.setWidth("100%"); |
locationPanel.setCellWidth(locationAssistant,"100%"); |
locationPanel.setWidth("100%"); |
inner.add(namePanel,DockPanel.WEST); |
inner.add(locationPanel,DockPanel.CENTER); |
inner.setCellWidth(namePanel,"50%"); |
inner.setCellWidth(locationPanel,"50%"); |
outer.add(inner); |
outer.add(taxonList); |
inner.setWidth("100%"); |
taxonList.setWidth("100%"); |
initWidget(outer); |
} |
/trunk/src/org/tela_botanica/client/LocationAssistant.java |
---|
5,7 → 5,6 |
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; |
18,7 → 17,9 |
import org.tela_botanica.client.AutoCompleteAsyncTextBox; |
/** |
* A composite that displays a list of locations that can be selected. |
* Affiche une liste de localite qui peuvent être selectionnées, retourne la valeur de la localité selectionne et une code associé |
* (gettext et getvalue pour le code associé) |
* Utilise un assistant de saisie asynchrone. |
*/ |
public class LocationAssistant extends Composite implements EventListener, ResponseTextHandler { |
26,16 → 27,21 |
private AutoCompleteAsyncTextBox autoCompletebox = new AutoCompleteAsyncTextBox(this); |
private HorizontalPanel panel = new HorizontalPanel(); |
public LocationAssistant(AutoCompleteAsyncTextBoxListener listener) { |
private Mediator mediator = null; |
public LocationAssistant(Mediator med) { |
mediator=med; |
mediator.registerLocationAssistant(this); |
// autoCompletebox.setFocus(true); |
autoCompletebox.setSearchUrl(getServiceBaseUrl()+"/LocationSearch/"); |
autoCompletebox.setSearchUrl(mediator.getServiceBaseUrl()+"/LocationSearch/"); |
panel.add(autoCompletebox); |
autoCompletebox.setWidth("100%"); |
initWidget(panel); |
autoCompletebox.addAutoCompleteAsyncTextBoxListener(listener); |
autoCompletebox.addAutoCompleteAsyncTextBoxListener(mediator.getInventoryItemList()); |
} |
63,17 → 69,13 |
} |
public String getValue() { |
return autoCompletebox.getValue(); |
public void setText(String str) { |
autoCompletebox.setText(str); |
} |
public String getServiceBaseUrl() { |
Dictionary theme = Dictionary.getDictionary("Parameters"); |
return theme.get("serviceBaseUrl"); |
public String getValue() { |
return autoCompletebox.getValue(); |
} |
/trunk/src/org/tela_botanica/client/TopPanel.java |
---|
16,8 → 16,10 |
package org.tela_botanica.client; |
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.VerticalPanel; |
/** |
* Composite permet de wrapper des Widget pour creer un nouveau Widget cf methode initWidget() |
25,14 → 27,61 |
public class TopPanel extends Composite { |
public TopPanel() { |
private NameAssistant nameAssistant = null; |
private LocationAssistant locationAssistant = null; |
HorizontalPanel outer = new HorizontalPanel(); |
public TopPanel(final Mediator mediator) { |
VerticalPanel outer = new VerticalPanel(); |
VerticalPanel inner = new VerticalPanel(); |
nameAssistant = new NameAssistant(mediator); |
locationAssistant = new LocationAssistant(mediator); |
DockPanel namePanel = new DockPanel(); |
DockPanel locationPanel = new DockPanel(); |
HTML labelNameAssistant = new HTML("Nom: "); |
namePanel.add(labelNameAssistant,DockPanel.WEST); |
namePanel.add (nameAssistant,DockPanel.CENTER); |
nameAssistant.setWidth("100%"); |
namePanel.setCellWidth(labelNameAssistant,"7%"); |
namePanel.setCellWidth(nameAssistant,"93%"); |
namePanel.setWidth("50%"); |
HTML labelLocationAssistant= new HTML("Lieu: "); |
locationPanel.add(labelLocationAssistant,DockPanel.WEST); |
locationPanel.add (locationAssistant,DockPanel.CENTER); |
locationAssistant.setWidth("100%"); |
locationPanel.setCellWidth(locationAssistant,"7%"); |
locationPanel.setCellWidth(locationAssistant,"93%"); |
locationPanel.setWidth("50%"); |
inner.add(namePanel); |
inner.add(locationPanel); |
inner.setCellWidth(namePanel,"50%"); |
inner.setCellWidth(locationPanel,"50%"); |
outer.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT); |
outer.add(new HTML("<b>Carnet en ligne</b>")); |
outer.setHorizontalAlignment(HorizontalPanel.ALIGN_LEFT); |
outer.add(inner); |
inner.setWidth("100%"); |
initWidget(outer); |
} |
/trunk/src/org/tela_botanica/client/Cel.java |
---|
5,12 → 5,8 |
import com.google.gwt.user.client.ui.DockPanel; |
import com.google.gwt.user.client.ui.RootPanel; |
import org.tela_botanica.client.TopPanel; |
import org.tela_botanica.client.CenterPanel; |
import org.tela_botanica.client.LeftPanel; |
/** |
* Entry point classes define <code>onModuleLoad()</code>. |
*/ |
17,7 → 13,6 |
public class Cel implements EntryPoint { |
private TopPanel topPanel = null; |
private CenterPanel centerPanel = null; |
private LeftPanel leftPanel = null; |
33,7 → 28,7 |
mediator= new Mediator(); |
mediator.registerCel(this); |
mediator.initUser(); |
mediator.initUser(); // Appelle initAsync suivant |
} |
41,8 → 36,8 |
public void initAsync() { |
topPanel = new TopPanel(); |
centerPanel = new CenterPanel(mediator); |
topPanel = new TopPanel(mediator); |
leftPanel = new LeftPanel(mediator); |
68,13 → 63,11 |
outer.setWidth("100%"); |
outer.setSpacing(4); |
outer.setCellWidth(centerPanel, "100%"); |
outer.setCellWidth(centerPanel, "85%"); |
// Window.enableScrolling(false); |
Window.setMargin("0px"); |
// Finally, add the outer panel to the RootPanel, so that it will be |
// displayed. |
RootPanel.get().add(outer); |
81,16 → 74,6 |
} |
public void onWindowResized(int width, int height) { |
// Adjust the shortcut panel and detail area to take up the available room |
// in the window. |
int shortcutHeight = height - leftPanel.getAbsoluteTop() - 8; |
if (shortcutHeight < 1) |
shortcutHeight = 1; |
leftPanel.setHeight("" + shortcutHeight); |
} |
} |
/trunk/src/org/tela_botanica/client/LocationList.java |
---|
17,17 → 17,26 |
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.Button; |
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.FlexTable; |
import com.google.gwt.user.client.ui.Grid; |
import com.google.gwt.user.client.ui.HTML; |
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.SourcesTableEvents; |
import com.google.gwt.user.client.ui.TableListener; |
import com.google.gwt.user.client.ui.VerticalPanel; |
import com.google.gwt.user.client.ui.Widget; |
/** |
* A tree displaying a set of email folders. |
35,6 → 44,87 |
public class LocationList extends Composite { |
// 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 HTML status = new HTML(); |
public NavBar() { |
initWidget(bar); |
bar.setStyleName("navbar"); |
status.setStyleName("status"); |
status.setWordWrap(false); |
HorizontalPanel buttons = new HorizontalPanel(); |
buttons.add(status); |
buttons.setCellHorizontalAlignment(status, |
HasHorizontalAlignment.ALIGN_RIGHT); |
buttons.setCellVerticalAlignment(status, |
HasVerticalAlignment.ALIGN_MIDDLE); |
buttons.setCellWidth(status, "100%"); |
buttons.add(gotoFirst); |
buttons.add(gotoPrev); |
buttons.add(gotoNext); |
buttons.add(gotoEnd); |
bar.add(buttons, DockPanel.EAST); |
bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_RIGHT); |
bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_LEFT); |
bar.setVerticalAlignment(DockPanel.ALIGN_MIDDLE); |
} |
public void onClick(Widget sender) { |
if (sender == gotoNext) { |
// Move forward a page. |
startIndex += VISIBLE_LOCATION_COUNT; |
if (startIndex >= count) |
startIndex -= VISIBLE_LOCATION_COUNT; |
} else { |
if (sender == gotoPrev) { |
// Move back a page. |
startIndex -= VISIBLE_LOCATION_COUNT; |
if (startIndex < 0) |
startIndex = 0; |
} else { |
if (sender == gotoEnd) { |
gotoEnd(); |
} else { |
if (sender == gotoFirst) { |
startIndex = 0; |
} |
} |
} |
} |
update(); |
} |
} |
private static final int VISIBLE_LOCATION_COUNT = 15; |
private static final String VALUE_UNKNOWN = "Inconnues"; |
55,6 → 145,12 |
private String location = "all"; |
private NavBar navBar=null; |
private int count = 65000; |
// Tous selectionné |
private int selectedRow = -1; |
70,6 → 166,7 |
user=mediator.getUser(); |
serviceBaseUrl = mediator.getServiceBaseUrl(); |
navBar = new NavBar(); |
// Mise en forme du header |
85,7 → 182,7 |
header.getCellFormatter().setWidth(0, 0, "100%"); |
// Mise en forme du selecteur |
// Mise en forme de l'entree "Toutes localités" |
selector.setCellSpacing(0); |
selector.setCellPadding(0); |
110,7 → 207,7 |
selector.setStyleName("location-ListElement"); |
// Mise en forme de la table. |
// Mise en forme du contenu |
table.setCellSpacing(0); |
table.setBorderWidth(0); |
121,8 → 218,12 |
// Mise en forme barre navigation |
outer.add(navBar); |
navBar.setWidth("100%"); |
outer.add(header); |
inner.add(selector); |
inner.add(selector); // Toutes localités |
inner.add(table); |
inner.setStyleName("location-List"); |
inner.setWidth("100%"); |
151,15 → 252,41 |
selector.getRowFormatter().addStyleName(0, "location-SelectedRow"); |
mediator.onLocationSelected("all"); |
update(); |
updateCount(); |
// update() |
initWidget(outer); |
} |
/** |
* Recherche nombre d'enregistrement pour l'utilisateur en cours |
* |
* |
*/ |
public void updateCount() { |
setStatusDisabled(); |
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryLocationList/" + user , |
new ResponseTextHandler() { |
public void onCompletion(String str) { |
JSONValue jsonValue = JSONParser.parse(str); |
JSONNumber jsonNumber; |
if ((jsonNumber = jsonValue.isNumber()) != null) { |
count = (int) jsonNumber.getValue(); |
update(); |
} |
} |
}); |
} |
private void selectRow(int row) { |
styleRow(selectedRow, false); |
194,14 → 321,8 |
public void update() { |
// TODO : ne pas recreer la table a chaque fois ... : parcouris le retour, le comparer au present |
// et inserer ou supprimer s'il le faut. |
setStatusDisabled(); |
// TODO : ou alors prevoir un update pour les ajouts (forcemment à la fin) et un update pour les suppressions ... |
// Sauf qu'il y a les chgts de pages ... : oui, la un fait un update normal ... |
// TODO : despaghettiser |
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryLocationList/" + user + "/" |
+ startIndex + "/" + VISIBLE_LOCATION_COUNT, |
213,21 → 334,19 |
JSONArray jsonArray; |
JSONArray jsonArrayNested; |
for (int i = table.getRowCount() - 1; i >= 0; i--) { |
table.removeRow(i); |
} |
int row=0; |
int i=0; |
if (location.compareTo("all")==0) { |
styleRow(selectedRow, false); |
selector.getRowFormatter().addStyleName(0, "location-SelectedRow"); |
} |
if ((jsonArray = jsonValue.isArray()) != null) { |
int arraySize = jsonArray.size(); |
for (int i = 0; i < arraySize; ++i) { |
for (i = 0; i < arraySize; ++i) { |
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) { |
int row = table.insertRow(table.getRowCount()); |
if (i>=table.getRowCount()) { |
row = table.insertRow(table.getRowCount()); |
} |
else { |
row = i; |
} |
// Lieu |
String loc=((JSONString)jsonArrayNested.get(0)).stringValue(); |
242,6 → 361,9 |
if (loc.compareTo(location)==0) { |
styleRow(row, true); |
} |
else { |
styleRow(row, false); |
} |
table.getFlexCellFormatter().setWidth(row, 0, "100%"); |
} |
249,7 → 371,21 |
} |
} |
if (location.compareTo("all")==0) { |
selector.getRowFormatter().addStyleName(0, "location-SelectedRow"); |
} |
// Suppression fin ancien affichage |
if (i<table.getRowCount()-1) { |
for (int j = table.getRowCount() - 1; j > i-1; j--) { |
table.removeRow(j); |
} |
} |
setStatusEnabled(); |
} |
}); |
} |
260,5 → 396,88 |
/* |
* Positionnement index de parcours (this.startIndex) pour affichage de la |
* dernière page |
* |
* @param |
* @return void |
*/ |
private void gotoEnd() { |
if ((count == 0) || (count % VISIBLE_LOCATION_COUNT) > 0) { |
startIndex = count - (count % VISIBLE_LOCATION_COUNT); |
} else { |
startIndex = count - VISIBLE_LOCATION_COUNT; |
} |
} |
/** |
* Affichage message d'attente et désactivation navigation |
* |
* @param |
* @return void |
*/ |
private void setStatusDisabled() { |
navBar.gotoFirst.setEnabled(false); |
navBar.gotoPrev.setEnabled(false); |
navBar.gotoNext.setEnabled(false); |
navBar.gotoEnd.setEnabled(false); |
setStatusText("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_LOCATION_COUNT) { // Au dela de la |
// premiere page |
navBar.gotoPrev.setEnabled(true); |
navBar.gotoFirst.setEnabled(true); |
if (startIndex < (count - VISIBLE_LOCATION_COUNT)) { // Pas la |
// derniere |
// page |
navBar.gotoNext.setEnabled(true); |
navBar.gotoEnd.setEnabled(true); |
setStatusText((startIndex + 1) + " - " |
+ (startIndex + VISIBLE_LOCATION_COUNT) + " sur " + count ); |
} else { // Derniere page |
setStatusText((startIndex + 1) + " - " + count + " sur " + count ); |
} |
} else { // Premiere page |
if (count > VISIBLE_LOCATION_COUNT) { // Des pages derrieres |
navBar.gotoNext.setEnabled(true); |
navBar.gotoEnd.setEnabled(true); |
setStatusText((startIndex + 1) + " - " |
+ (startIndex + VISIBLE_LOCATION_COUNT) + " sur " + count); |
} else { |
setStatusText((startIndex + 1) + " - " + count + " sur " + count); |
} |
} |
} |
else { // Pas d'inventaire, pas de navigation |
setStatusText("0 - 0 sur 0"); |
} |
} |
private void setStatusText(String text) { |
navBar.status.setText(text); |
} |
} |
/trunk/src/org/tela_botanica/client/Mediator.java |
---|
16,8 → 16,11 |
private String serviceBaseUrl = getServiceBaseUrlFromDictionnary(); |
private String user = null; |
private TaxonList taxonlist = null; |
private InventoryItemList inventoryItemList = null; |
private LocationList locationList = null; |
private NameAssistant nameAssistant=null; |
private LocationAssistant locationAssistant=null; |
private Cel cel = null; |
37,43 → 40,49 |
} |
/** |
* Action sur selection d'un lieu |
* Action sur selection d'un lieu : affichage de la liste des taxons correspondants |
* |
*/ |
public void onLocationSelected(String loc) { |
taxonlist.setLocation(loc); |
taxonlist.updateCount(); |
inventoryItemList.setLocation(loc); |
inventoryItemList.updateCount(); |
if ((loc.compareTo("000null")==0) || (loc.compareTo("all")==0)) { |
locationAssistant.setText(""); |
} |
else { |
locationAssistant.setText(loc); |
} |
} |
/** |
* Action sur ajout d'un taxon |
* Action sur ajout d'un taxon : affichage du lieu corresondant |
*/ |
public void onTaxonListUpdate(String loc) { |
public void onInventoryItemUpdate(String loc) { |
locationList.setLocation(loc); |
locationList.update(); |
locationList.updateCount(); |
} |
/** |
* Enregistrement TaxonList |
* @param taxonlist |
* Declaration InventoryItemList |
* @param inventoryItemList |
*/ |
public void registerTaxonList(TaxonList taxonlist) { |
public void registerInventoryItemList(InventoryItemList inventoryItemList) { |
this.taxonlist=taxonlist; |
this.inventoryItemList=inventoryItemList; |
} |
/** |
* Enregistremnt LocationList |
* Declaration LocationList |
* @param locationList |
*/ |
83,7 → 92,7 |
} |
/** |
* Enregistrement Cel |
* Declaration Cel |
* @param cel |
*/ |
93,10 → 102,30 |
} |
/** |
* Declaration NameAssistant |
* @param nameassistant |
*/ |
public void registerNameAssistant(NameAssistant nameAssistant) { |
this.nameAssistant=nameAssistant; |
} |
/** |
* Declaration LocationAssistant |
* @param locationassistant |
*/ |
public void registerLocationAssistant(LocationAssistant locationAssistant) { |
this.locationAssistant=locationAssistant; |
} |
/** |
* Recherche distante et asynchrone de l'utilisateur connecté, en retour lancement methode initialisation |
* de l'appellant Cel. (initAsunc) |
* de l'appellant Cel. (initAsync) |
* |
*/ |
154,4 → 183,22 |
public InventoryItemList getInventoryItemList() { |
return inventoryItemList; |
} |
public LocationList getLocationList() { |
return locationList; |
} |
public NameAssistant getNameAssistant() { |
return nameAssistant; |
} |
public LocationAssistant getLocationAssistant() { |
return locationAssistant; |
} |
} |