ingo@41: package de.intevation.flys.client.client.ui; ingo@41: ingo@43: import java.util.LinkedHashMap; ingo@53: import java.util.List; ingo@41: ingo@41: import com.google.gwt.core.client.GWT; raimund@235: import com.google.gwt.user.client.rpc.AsyncCallback; ingo@41: ingo@41: import com.smartgwt.client.widgets.Canvas; ingo@41: import com.smartgwt.client.widgets.Label; ingo@41: import com.smartgwt.client.widgets.form.DynamicForm; ingo@41: import com.smartgwt.client.widgets.form.fields.events.BlurHandler; ingo@41: import com.smartgwt.client.widgets.form.fields.events.BlurEvent; ingo@41: import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; ingo@41: import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; ingo@41: import com.smartgwt.client.widgets.form.fields.FormItem; ingo@41: import com.smartgwt.client.widgets.form.fields.RadioGroupItem; ingo@41: import com.smartgwt.client.widgets.layout.HLayout; ingo@41: import com.smartgwt.client.widgets.layout.VLayout; raimund@235: import com.smartgwt.client.widgets.grid.ListGrid; raimund@235: import com.smartgwt.client.widgets.grid.ListGridField; raimund@235: import com.smartgwt.client.widgets.grid.ListGridRecord; raimund@235: import com.smartgwt.client.widgets.grid.events.RecordClickHandler; raimund@235: import com.smartgwt.client.widgets.grid.events.RecordClickEvent; raimund@235: import com.smartgwt.client.widgets.grid.events.CellClickHandler; raimund@235: import com.smartgwt.client.widgets.grid.events.CellClickEvent; raimund@235: raimund@235: import com.smartgwt.client.widgets.tab.TabSet; raimund@235: import com.smartgwt.client.widgets.tab.Tab; raimund@235: import com.smartgwt.client.data.Record; raimund@235: raimund@235: import com.smartgwt.client.types.ListGridFieldType; ingo@41: ingo@41: import de.intevation.flys.client.shared.model.Data; ingo@46: import de.intevation.flys.client.shared.model.DataItem; ingo@51: import de.intevation.flys.client.shared.model.DataList; ingo@46: import de.intevation.flys.client.shared.model.DefaultData; ingo@46: import de.intevation.flys.client.shared.model.DefaultDataItem; raimund@235: import de.intevation.flys.client.shared.model.DistanceInfoObject; raimund@235: import de.intevation.flys.client.shared.model.DistanceInfoRecord; raimund@235: import de.intevation.flys.client.shared.model.ArtifactDescription; raimund@235: raimund@235: import de.intevation.flys.client.client.services.DistanceInfoService; raimund@235: import de.intevation.flys.client.client.services.DistanceInfoServiceAsync; ingo@211: import de.intevation.flys.client.client.FLYSConstants; raimund@235: import de.intevation.flys.client.client.FLYSImages; raimund@235: import de.intevation.flys.client.client.Config; ingo@41: ingo@41: ingo@41: /** ingo@41: * This UIProvider creates a widget to enter locations or a distance. ingo@41: * ingo@41: * @author Ingo Weinzierl ingo@41: */ ingo@41: public class LocationDistancePanel ingo@41: extends AbstractUIProvider ingo@41: implements ChangeHandler, BlurHandler ingo@41: { ingo@41: /** The message class that provides i18n strings.*/ ingo@211: protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); ingo@41: raimund@235: /** The interface that provides the image resources. */ raimund@235: private FLYSImages IMAGES = GWT.create(FLYSImages.class); raimund@235: raimund@235: /** The DistanceInfoService used to retrieve locations about rivers.*/ raimund@235: protected DistanceInfoServiceAsync distanceInfoService = raimund@235: GWT.create(DistanceInfoService.class); ingo@41: ingo@41: /** The constant name of the input field to enter locations.*/ ingo@41: public static final String FIELD_LOCATION = "location"; ingo@41: ingo@43: /** The constant name of the input field to enter distance.*/ ingo@43: public static final String FIELD_DISTANCE = "distance"; ingo@43: ingo@41: /** The constant name of the input field to enter the start of a distance.*/ ingo@41: public static final String FIELD_FROM = "from"; ingo@41: ingo@41: /** The constant name of the input field to enter the end of a distance.*/ ingo@41: public static final String FIELD_TO = "to"; ingo@41: ingo@41: /** The constant name of the input field to enter the step width of a ingo@41: * distance.*/ ingo@41: public static final String FIELD_WIDTH = "width"; ingo@41: ingo@53: public static final int WIDTH = 250; ingo@53: ingo@41: ingo@41: /** The radio group for input mode selection.*/ ingo@43: protected DynamicForm mode; ingo@41: ingo@41: /** A container that will contain the location or the distance panel.*/ ingo@41: protected HLayout container; ingo@41: ingo@55: /** The min value for a distance.*/ ingo@55: protected double min; ingo@55: ingo@55: /** The max value for a distance.*/ ingo@55: protected double max; ingo@55: ingo@43: /** The 'from' value entered in the distance mode.*/ ingo@43: protected double from; ingo@43: ingo@43: /** The 'to' value entered in the distance mode.*/ ingo@43: protected double to; ingo@43: ingo@43: /** The 'step' value entered in the distance mode.*/ ingo@43: protected double step; ingo@43: ingo@43: /** The values entered in the location mode.*/ ingo@43: protected double[] values; ingo@43: raimund@235: /** The input panel for locations */ raimund@235: protected DoubleArrayPanel locationPanel; raimund@235: raimund@235: /** The input panel for distances */ raimund@235: protected DoubleRangePanel distancePanel; raimund@235: raimund@235: /** The tab set containing the location and distance table*/ raimund@235: protected TabSet inputTables; raimund@235: raimund@235: /** The distance table. */ raimund@235: protected ListGrid distanceTable; raimund@235: raimund@235: /** The locations table */ raimund@235: protected ListGrid locationsTable; raimund@235: raimund@235: /** The locations table for distance input. */ raimund@235: protected ListGrid locationDistanceTable; ingo@41: raimund@237: /** The table data. */ raimund@237: protected DistanceInfoObject[] tableData; raimund@237: ingo@41: /** ingo@41: * Creates a new LocationDistancePanel instance. ingo@41: */ ingo@41: public LocationDistancePanel() { raimund@235: distanceTable = new ListGrid(); raimund@235: locationsTable = new ListGrid(); raimund@235: locationDistanceTable = new ListGrid(); ingo@41: } ingo@41: ingo@41: ingo@41: /** ingo@41: * This method creates a widget that contains a label, a panel with ingo@41: * checkboxes to switch the input mode between location and distance input, ingo@41: * and a the mode specific panel. ingo@41: * ingo@41: * @param data The data that might be inserted. ingo@41: * ingo@41: * @return a panel. ingo@41: */ ingo@51: public Canvas create(DataList data) { ingo@41: VLayout layout = new VLayout(); ingo@83: layout.setMembersMargin(10); ingo@41: ingo@55: initDefaults(data); ingo@55: ingo@57: Label label = new Label(MESSAGES.location_distance_state()); ingo@57: Canvas widget = createWidget(data); ingo@57: Canvas submit = getNextButton(); raimund@235: createDistanceInputPanel(); raimund@235: raimund@235: createDistanceTable(); raimund@235: createLocationTable(); raimund@237: createLocationTableDistance (); ingo@41: ingo@83: widget.setHeight(50); ingo@41: label.setHeight(25); ingo@41: ingo@41: layout.addMember(label); ingo@45: layout.addMember(widget); ingo@45: layout.addMember(submit); ingo@45: ingo@45: return layout; ingo@45: } ingo@45: ingo@45: raimund@235: /** raimund@235: * This method creates a table that contains the distance values. raimund@235: */ raimund@235: protected void createDistanceTable() { raimund@235: distanceTable.setWidth100(); raimund@235: distanceTable.setShowRecordComponents(true); raimund@235: distanceTable.setShowRecordComponentsByCell(true); raimund@235: distanceTable.setHeight100(); raimund@263: distanceTable.setEmptyMessage(MESSAGES.empty_table()); raimund@235: raimund@235: ListGridField addDistance = new ListGridField ("", ""); raimund@235: addDistance.setType (ListGridFieldType.ICON); raimund@235: addDistance.setWidth ("30"); raimund@235: addDistance.addRecordClickHandler (new RecordClickHandler () { raimund@235: public void onRecordClick (RecordClickEvent e) { raimund@235: if (!isLocationMode ()) { raimund@235: Record r = e.getRecord(); raimund@235: double min = r.getAttributeAsDouble("from"); raimund@235: double max = r.getAttributeAsDouble("to"); raimund@235: setDistanceValues(min, max); raimund@235: } raimund@235: else { raimund@235: double[] selected; raimund@261: Record r = e.getRecord(); raimund@261: double min = r.getAttributeAsDouble("from"); raimund@261: double max = r.getAttributeAsDouble("to"); raimund@235: if (getLocationValues() != null) { raimund@235: double[] val = getLocationValues(); raimund@235: selected = new double[val.length + 2]; raimund@235: for(int i = 0; i < val.length; i++){ raimund@235: selected[i] = val[i]; raimund@235: } raimund@235: selected[val.length] = min; raimund@235: selected[val.length + 1] = max; raimund@235: } raimund@235: else { raimund@235: selected = new double[2]; raimund@235: selected[0] = min; raimund@235: selected[1] = max; raimund@235: } raimund@235: setLocationValues(selected); raimund@235: } raimund@235: } raimund@235: }); raimund@235: addDistance.setCellIcon (IMAGES.markerGreen ().getURL ()); raimund@235: raimund@235: ListGridField ddescr = new ListGridField("description", raimund@235: MESSAGES.description()); raimund@235: ddescr.setType(ListGridFieldType.TEXT); raimund@235: ddescr.setWidth("*"); raimund@235: ListGridField from = new ListGridField("from", MESSAGES.from()); raimund@235: from.setType(ListGridFieldType.TEXT); raimund@235: from.setWidth(75); raimund@235: ListGridField to = new ListGridField("to", MESSAGES.to()); raimund@235: to.setType(ListGridFieldType.TEXT); raimund@235: to.setWidth(75); raimund@235: ListGridField dside = new ListGridField("riverside", raimund@235: MESSAGES.riverside()); raimund@235: dside.setType(ListGridFieldType.TEXT); raimund@235: dside.setWidth(60); raimund@235: raimund@235: distanceTable.setFields(addDistance, ddescr, from, to, dside); raimund@235: } raimund@235: raimund@235: raimund@235: /** raimund@235: * This method creates a table that contains the location values. raimund@235: */ raimund@235: protected void createLocationTable() { raimund@235: locationsTable.setWidth100(); raimund@235: locationsTable.setShowRecordComponents(true); raimund@235: locationsTable.setShowRecordComponentsByCell(true); raimund@235: locationsTable.setHeight100(); raimund@263: locationsTable.setEmptyMessage(MESSAGES.empty_table()); raimund@235: raimund@235: ListGridField addLocation = new ListGridField ("", ""); raimund@235: addLocation.setType (ListGridFieldType.ICON); raimund@235: addLocation.setWidth ("30"); raimund@235: addLocation.addRecordClickHandler (new RecordClickHandler () { raimund@235: public void onRecordClick (RecordClickEvent e) { raimund@235: ListGridRecord[] records = locationsTable.getSelection(); raimund@235: double[] selected; raimund@235: if (getLocationValues() != null) { raimund@235: double[] val = getLocationValues(); raimund@235: selected = new double[val.length + 1]; raimund@235: for(int i = 0; i < val.length; i++){ raimund@235: selected[i] = val[i]; raimund@235: } raimund@235: selected[val.length] = raimund@235: records[0].getAttributeAsDouble("from"); raimund@235: } raimund@235: else { raimund@235: selected = new double[1]; raimund@235: selected[0] = records[0].getAttributeAsDouble("from"); raimund@235: } raimund@235: setLocationValues(selected); raimund@235: } raimund@235: }); raimund@235: addLocation.setCellIcon (IMAGES.markerGreen ().getURL ()); raimund@235: raimund@235: ListGridField ldescr = new ListGridField("description", raimund@235: MESSAGES.description()); raimund@235: ldescr.setType(ListGridFieldType.TEXT); raimund@235: ldescr.setWidth("*"); raimund@235: ListGridField lside = new ListGridField("riverside", raimund@235: MESSAGES.riverside()); raimund@235: lside.setType(ListGridFieldType.TEXT); raimund@235: lside.setWidth(60); raimund@235: ListGridField loc = new ListGridField("from", MESSAGES.location()); raimund@235: loc.setType(ListGridFieldType.TEXT); raimund@235: loc.setWidth(80); raimund@235: locationsTable.setFields(addLocation, ldescr, loc, lside); raimund@235: } raimund@235: raimund@235: raimund@235: /** raimund@235: * This method creates a table that contains the location values. raimund@235: */ raimund@235: protected void createLocationTableDistance (){ raimund@237: locationDistanceTable = null; raimund@237: locationDistanceTable = new ListGrid (); raimund@235: locationDistanceTable.setWidth100(); raimund@235: locationDistanceTable.setShowRecordComponents(true); raimund@235: locationDistanceTable.setShowRecordComponentsByCell(true); raimund@235: locationDistanceTable.setHeight100(); raimund@263: locationDistanceTable.setEmptyMessage(MESSAGES.empty_table()); raimund@235: raimund@235: ListGridField addfrom = new ListGridField ("", ""); raimund@235: addfrom.setType (ListGridFieldType.ICON); raimund@235: addfrom.setWidth ("30"); raimund@235: addfrom.setCellIcon (IMAGES.markerGreen ().getURL ()); raimund@235: raimund@235: ListGridField addto2 = new ListGridField ("", ""); raimund@235: addto2.setType (ListGridFieldType.ICON); raimund@235: addto2.setWidth ("30"); raimund@235: addto2.setCellIcon (IMAGES.markerRed ().getURL ()); raimund@235: raimund@235: raimund@235: ListGridField ldescr = new ListGridField("description", raimund@235: MESSAGES.description()); raimund@235: ldescr.setType(ListGridFieldType.TEXT); raimund@235: ldescr.setWidth("*"); raimund@235: ListGridField lside = new ListGridField("riverside", raimund@235: MESSAGES.riverside()); raimund@235: lside.setType(ListGridFieldType.TEXT); raimund@235: lside.setWidth(60); raimund@235: ListGridField loc = new ListGridField("from", MESSAGES.location()); raimund@235: loc.setType(ListGridFieldType.TEXT); raimund@235: loc.setWidth(80); raimund@235: locationDistanceTable.addCellClickHandler (new CellClickHandler () { raimund@235: public void onCellClick (CellClickEvent e) { raimund@235: if (e.getColNum() == 0) { raimund@235: Record r = e.getRecord (); raimund@235: double fromvalue = r.getAttributeAsDouble ("from"); raimund@235: double tovalue = getTo (); raimund@235: setDistanceValues (fromvalue, tovalue); raimund@235: } raimund@235: else if (e.getColNum() == 1) { raimund@235: Record r = e.getRecord (); raimund@235: double fromvalue = getFrom (); raimund@235: double tovalue = r.getAttributeAsDouble ("to"); raimund@235: setDistanceValues (fromvalue, tovalue); raimund@235: } raimund@235: } raimund@235: }); raimund@235: locationDistanceTable.setFields(addfrom, addto2, ldescr, loc, lside); raimund@235: } raimund@235: raimund@235: ingo@53: public Canvas createOld(DataList dataList) { ingo@53: List items = dataList.getAll(); ingo@53: ingo@53: Data dFrom = getData(items, "ld_from"); ingo@53: Data dTo = getData(items, "ld_to"); ingo@53: Data dStep = getData(items, "ld_step"); ingo@53: ingo@53: DataItem[] from = dFrom.getItems(); ingo@53: DataItem[] to = dTo.getItems(); ingo@53: DataItem[] step = dStep.getItems(); ingo@53: ingo@53: HLayout layout = new HLayout(); raimund@91: layout.setWidth("400px"); raimund@91: ingo@53: Label label = new Label(dataList.getLabel()); raimund@91: label.setWidth("200px"); ingo@53: ingo@53: StringBuilder sb = new StringBuilder(); ingo@53: sb.append(from[0].getLabel()); ingo@53: sb.append(" " + MESSAGES.unitFrom() + " "); ingo@53: sb.append(to[0].getLabel()); ingo@53: sb.append(" " + MESSAGES.unitTo() + " "); ingo@53: sb.append(step[0].getLabel()); ingo@53: sb.append(" " + MESSAGES.unitWidth()); ingo@53: ingo@58: Canvas back = getBackButton(dataList.getState()); ingo@58: raimund@91: Label selected = new Label(sb.toString()); raimund@91: selected.setWidth("130px"); raimund@91: ingo@53: layout.addMember(label); raimund@91: layout.addMember(selected); ingo@58: layout.addMember(back); ingo@53: ingo@53: return layout; ingo@53: } ingo@53: ingo@53: ingo@53: /** ingo@55: * This method reads the default values defined in the DataItems of the Data ingo@55: * objects in list. ingo@55: * ingo@55: * @param list The DataList container that stores the Data objects. ingo@55: */ ingo@55: protected void initDefaults(DataList list) { ingo@55: Data f = getData(list.getAll(), "ld_from"); ingo@55: Data t = getData(list.getAll(), "ld_to"); ingo@55: Data s = getData(list.getAll(), "ld_step"); ingo@55: ingo@55: DataItem[] fItems = f.getItems(); ingo@55: DataItem[] tItems = t.getItems(); ingo@55: DataItem[] sItems = s.getItems(); ingo@55: ingo@55: min = Double.valueOf(fItems[0].getStringValue()); ingo@55: max = Double.valueOf(tItems[0].getStringValue()); ingo@55: step = Double.valueOf(sItems[0].getStringValue()); ingo@55: ingo@55: this.from = min; ingo@55: this.to = max; ingo@55: this.step = step; ingo@55: } ingo@55: ingo@55: ingo@55: /** ingo@53: * This method greps the Data with name name from the list and ingo@53: * returns it. ingo@53: * ingo@53: * @param items A list of Data. ingo@53: * @param name The name of the Data that we are searching for. ingo@53: * ingo@53: * @return the Data with the name name. ingo@53: */ ingo@53: protected Data getData(List data, String name) { ingo@53: for (Data d: data) { ingo@53: if (name.equals(d.getLabel())) { ingo@53: return d; ingo@53: } ingo@53: } ingo@53: ingo@53: return null; ingo@53: } ingo@53: ingo@53: ingo@51: protected Canvas createWidget(DataList data) { ingo@45: VLayout layout = new VLayout(); ingo@45: container = new HLayout(); ingo@45: Canvas checkboxPanel = createRadioButtonPanel(); ingo@45: ingo@45: // the initial view will display the location input mode raimund@235: locationPanel = new DoubleArrayPanel( ingo@45: MESSAGES.unitLocation(), ingo@45: getLocationValues(), ingo@45: this); ingo@45: container.addMember(locationPanel); ingo@45: ingo@41: layout.addMember(checkboxPanel); ingo@41: layout.addMember(container); ingo@41: raimund@235: container.setMembersMargin(30); raimund@235: raimund@235: inputTables = new TabSet(); raimund@235: Tab locations = new Tab(MESSAGES.location()); raimund@235: Tab distances = new Tab(MESSAGES.distance()); raimund@235: raimund@272: inputTables.setWidth100(); raimund@272: inputTables.setHeight100(); raimund@235: raimund@235: locations.setPane(locationsTable); raimund@235: distances.setPane(distanceTable); raimund@235: raimund@235: inputTables.addTab(locations); raimund@235: inputTables.addTab(distances); raimund@235: raimund@272: helperContainer.addChild(inputTables); ingo@41: ingo@41: return layout; ingo@41: } ingo@41: ingo@41: ingo@41: /** ingo@41: * This method returns the selected data. ingo@41: * ingo@41: * @return the selected/inserted data. ingo@41: */ ingo@41: public Data[] getData() { ingo@59: // XXX If we have entered a value and click right afterwards on the ingo@59: // 'next' button, the BlurEvent is not fired, and the values are not ingo@59: // saved. So, we gonna save those values explicitly. ingo@59: if (isLocationMode()) { ingo@59: Canvas member = container.getMember(0); ingo@59: if (member instanceof DoubleArrayPanel) { ingo@59: DoubleArrayPanel form = (DoubleArrayPanel) member; ingo@59: saveLocationValues(form); ingo@59: } ingo@59: } ingo@59: else { ingo@59: Canvas member = container.getMember(0); ingo@59: if (member instanceof DoubleRangePanel) { ingo@59: DoubleRangePanel form = (DoubleRangePanel) member; ingo@59: saveDistanceValues(form); ingo@59: } ingo@59: } ingo@59: ingo@46: return new Data[] { getDataFrom(), getDataTo(), getDataStep() }; ingo@46: } ingo@41: ingo@46: ingo@46: /** ingo@46: * Returns the Data object for the 'from' attribute. ingo@46: * ingo@46: * @return the Data object for the 'from' attribute. ingo@46: */ ingo@46: protected Data getDataFrom() { ingo@46: String value = Double.valueOf(getFinalFrom()).toString(); ingo@46: DataItem item = new DefaultDataItem("ld_from", "ld_from", value); ingo@46: return new DefaultData( ingo@51: "ld_from", null, null, new DataItem[] { item }); ingo@46: } ingo@46: ingo@46: ingo@46: /** ingo@46: * Returns the Data object for the 'to' attribute. ingo@46: * ingo@46: * @return the Data object for the 'to' attribute. ingo@46: */ ingo@46: protected Data getDataTo() { ingo@46: String value = Double.valueOf(getFinalTo()).toString(); ingo@46: DataItem item = new DefaultDataItem("ld_to", "ld_to", value); ingo@46: return new DefaultData( ingo@51: "ld_to", null, null, new DataItem[] { item }); ingo@46: } ingo@46: ingo@46: ingo@46: /** ingo@46: * Returns the Data object for the 'step' attribute. ingo@46: * ingo@46: * @return the Data object for the 'step' attribute. ingo@46: */ ingo@46: protected Data getDataStep() { ingo@46: String value = Double.valueOf(getFinalStep()).toString(); ingo@46: DataItem item = new DefaultDataItem("ld_step","ld_step", value); ingo@46: return new DefaultData( ingo@51: "ld_step", null, null, new DataItem[] { item }); ingo@46: } ingo@46: ingo@46: ingo@46: /** ingo@46: * Returns the value of 'from' depending on the selected input mode. ingo@46: * ingo@46: * @return the value of 'from' depending on the selected input mode. ingo@46: */ ingo@46: protected double getFinalFrom() { ingo@46: if (isLocationMode()) { ingo@46: double[] values = getLocationValues(); ingo@46: double value = Double.MAX_VALUE; ingo@46: ingo@46: for (double v: values) { ingo@46: value = value < v ? value : v; ingo@46: } ingo@46: ingo@46: return value; ingo@46: } ingo@46: else { ingo@46: return getFrom(); ingo@46: } ingo@46: } ingo@46: ingo@46: ingo@46: /** ingo@46: * Returns the value of 'to' depending on the selected input mode. ingo@46: * ingo@46: * @return the value of 'to' depending on the selected input mode. ingo@46: */ ingo@46: protected double getFinalTo() { ingo@46: if (isLocationMode()) { ingo@46: double[] values = getLocationValues(); ingo@46: double value = Double.MIN_VALUE; ingo@46: ingo@46: for (double v: values) { ingo@46: value = value > v ? value : v; ingo@46: } ingo@46: ingo@46: return value; ingo@46: } ingo@46: else { ingo@46: return getTo(); ingo@46: } ingo@46: } ingo@46: ingo@46: ingo@46: /** ingo@46: * Returns the value of 'step' depending on the selected input mode. ingo@46: * ingo@46: * @return the value of 'step' depending on the selected input mode. ingo@46: */ ingo@46: protected double getFinalStep() { ingo@46: if (isLocationMode()) { ingo@46: // we have no field to enter the 'step' attribute in the location ingo@46: // mode ingo@46: return 0.0; ingo@46: } ingo@46: else { ingo@46: return getStep(); ingo@46: } ingo@46: } ingo@46: ingo@46: ingo@46: /** ingo@46: * Determines the current input mode. ingo@46: * ingo@46: * @return true, if 'location' is the current input mode, otherwise false. ingo@46: */ ingo@46: public boolean isLocationMode() { ingo@46: String inputMode = mode.getValueAsString("mode"); ingo@46: ingo@46: return inputMode.equals(FIELD_LOCATION) ? true : false; ingo@41: } ingo@41: ingo@41: ingo@41: /** ingo@41: * This method switches the input mode between location and distance input. ingo@41: * ingo@41: * @param event The click event fired by a RadioButtonGroupItem. ingo@41: */ ingo@41: public void onChange(ChangeEvent event) { ingo@41: String value = (String) event.getValue(); ingo@41: ingo@41: if (value == null) { ingo@41: return; ingo@41: } ingo@43: if (value.equals(FIELD_LOCATION)) { raimund@235: locationPanel = new DoubleArrayPanel( ingo@43: MESSAGES.unitLocation(), ingo@43: getLocationValues(), ingo@43: this); ingo@43: ingo@41: container.removeMembers(container.getMembers()); ingo@41: container.addMember(locationPanel); raimund@237: while (inputTables.getNumTabs() > 0) { raimund@237: inputTables.removeTab(0); raimund@237: } raimund@235: Tab t1 = new Tab (MESSAGES.location()); raimund@235: createLocationTable(); raimund@235: t1.setPane(locationsTable); raimund@235: inputTables.addTab(t1); raimund@235: createDistanceTable(); raimund@235: Tab t2 = new Tab (MESSAGES.distance()); raimund@235: t2.setPane(distanceTable); raimund@235: inputTables.addTab(t2); raimund@237: updateDistanceInfo(tableData); raimund@237: raimund@272: helperContainer.addChild(inputTables); raimund@235: inputTables.selectTab(0); ingo@41: } ingo@43: else { raimund@235: distancePanel = new DoubleRangePanel( ingo@43: MESSAGES.unitFrom(), MESSAGES.unitTo(), MESSAGES.unitWidth(), ingo@43: getFrom(), getTo(), getStep(), ingo@43: 250, ingo@43: this); ingo@43: ingo@41: container.removeMembers(container.getMembers()); ingo@41: container.addMember(distancePanel); raimund@237: while (inputTables.getNumTabs () > 0) { raimund@237: inputTables.removeTab(0); raimund@237: } raimund@235: Tab t1 = new Tab(MESSAGES.location ()); raimund@235: createLocationTableDistance (); raimund@235: t1.setPane(locationDistanceTable); raimund@235: inputTables.addTab(t1); raimund@235: createDistanceTable (); raimund@235: Tab t2 = new Tab(MESSAGES.distance ()); raimund@235: t2.setPane(distanceTable); raimund@235: inputTables.addTab(t2); raimund@244: if (tableData != null) { raimund@244: updateDistanceInfo(tableData); raimund@244: } raimund@237: raimund@272: helperContainer.addChild(inputTables); raimund@235: inputTables.selectTab(1); ingo@41: } ingo@41: } ingo@41: ingo@41: ingo@41: /** ingo@41: * This method is used to validate the inserted data in the form fields. ingo@41: * ingo@41: * @param event The BlurEvent that gives information about the FormItem that ingo@41: * has been modified and its value. ingo@41: */ ingo@41: public void onBlur(BlurEvent event) { ingo@41: FormItem item = event.getItem(); ingo@41: String field = item.getFieldName(); ingo@41: ingo@41: if (field == null) { ingo@41: return; ingo@41: } ingo@41: ingo@43: if (field.equals(DoubleArrayPanel.FIELD_NAME)) { ingo@43: DoubleArrayPanel p = (DoubleArrayPanel) event.getForm(); ingo@41: ingo@59: saveLocationValue(p, item); ingo@41: } ingo@43: else { ingo@43: DoubleRangePanel p = (DoubleRangePanel) event.getForm(); ingo@41: ingo@59: saveDistanceValue(p, item); ingo@59: } ingo@59: } ingo@59: ingo@59: raimund@235: ingo@59: /** ingo@59: * Validates and stores all values entered in the location mode. ingo@59: * ingo@59: * @param p The DoubleArrayPanel. ingo@59: */ ingo@59: protected void saveLocationValues(DoubleArrayPanel p) { ingo@59: FormItem[] formItems = p.getFields(); ingo@59: ingo@59: for (FormItem item: formItems) { ingo@59: if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) { ingo@59: saveLocationValue(p, item); ingo@43: } ingo@41: } ingo@41: } ingo@41: ingo@41: ingo@41: /** ingo@59: * Validates and stores all values entered in the distance mode. ingo@59: * ingo@59: * @param p The DoubleRangePanel. ingo@59: */ ingo@59: protected void saveDistanceValues(DoubleRangePanel p) { ingo@59: FormItem[] formItems = p.getFields(); ingo@59: ingo@59: for (FormItem item: formItems) { ingo@59: saveDistanceValue(p, item); ingo@59: } ingo@59: } ingo@59: ingo@59: ingo@59: /** ingo@59: * Validates and stores a value entered in the location mode. ingo@59: * ingo@59: * @param p The DoubleArrayPanel. ingo@59: * @param item The item that needs to be validated. ingo@59: */ ingo@59: protected void saveLocationValue(DoubleArrayPanel p, FormItem item) { ingo@59: if (p.validateForm(item)) { ingo@59: setLocationValues(p.getInputValues(item)); ingo@59: } ingo@59: } ingo@59: ingo@59: ingo@59: /** ingo@59: * Validates and stores value entered in the distance mode. ingo@59: * ingo@59: * @param p The DoubleRangePanel. ingo@59: * @param item The item that needs to be validated. ingo@59: */ ingo@59: protected void saveDistanceValue(DoubleRangePanel p, FormItem item) { ingo@59: if (p.validateForm(item)) { ingo@59: setFrom(p.getFrom()); ingo@59: setTo(p.getTo()); ingo@59: setStep(p.getStep()); ingo@59: } ingo@59: } ingo@59: ingo@59: ingo@59: /** ingo@41: * This method creates the panel that contains the checkboxes to switch ingo@41: * between the input mode 'location' and 'distance'. ingo@41: * ingo@41: * @return the checkbox panel. ingo@41: */ ingo@41: protected Canvas createRadioButtonPanel() { ingo@43: mode = new DynamicForm(); ingo@41: ingo@43: RadioGroupItem radio = new RadioGroupItem("mode"); ingo@41: radio.setShowTitle(false); ingo@41: radio.setVertical(false); ingo@41: ingo@43: LinkedHashMap values = new LinkedHashMap(); ingo@43: values.put(FIELD_LOCATION, MESSAGES.location()); ingo@43: values.put(FIELD_DISTANCE, MESSAGES.distance()); ingo@43: ingo@45: LinkedHashMap initial = new LinkedHashMap(); ingo@45: initial.put("mode", FIELD_LOCATION); ingo@45: ingo@43: radio.setValueMap(values); ingo@41: radio.addChangeHandler(this); ingo@41: ingo@43: mode.setFields(radio); ingo@45: mode.setValues(initial); ingo@41: ingo@43: return mode; ingo@41: } ingo@41: ingo@41: raimund@235: protected void createDistanceInputPanel() { raimund@235: Config config = Config.getInstance(); raimund@235: String url = config.getServerUrl(); raimund@235: String locale = config.getLocale (); raimund@235: String river = ""; raimund@235: raimund@235: ArtifactDescription adescr = artifact.getArtifactDescription(); raimund@235: DataList[] data = adescr.getOldData(); raimund@235: raimund@235: if (data != null && data.length > 0) { raimund@235: for (int i = 0; i < data.length; i++) { raimund@235: DataList dl = data[i]; raimund@235: if (dl.getState().equals("state.winfo.river")) { raimund@235: for (int j = 0; j < dl.size(); j++) { raimund@235: Data d = dl.get(j); raimund@235: DataItem[] di = d.getItems(); raimund@235: if (di != null && di.length == 1) { raimund@235: river = d.getItems()[0].getStringValue(); raimund@235: } raimund@235: } raimund@235: } raimund@235: } raimund@235: } raimund@235: raimund@235: distanceInfoService.getDistanceInfo(url, locale, river, raimund@235: new AsyncCallback() { raimund@235: public void onFailure(Throwable caught) { raimund@235: GWT.log("Could not recieve distance informations."); raimund@235: GWT.log(caught.getMessage()); raimund@235: } raimund@235: raimund@235: public void onSuccess(DistanceInfoObject[] di) { raimund@235: int num = di != null ? di.length :0; raimund@237: GWT.log("Recieved " + num + " distance informations."); raimund@235: raimund@235: if (num == 0) { raimund@235: return; raimund@235: } raimund@237: tableData = di; raimund@235: updateDistanceInfo(di); raimund@235: } raimund@235: } raimund@235: ); raimund@235: } raimund@235: raimund@235: raimund@235: protected void updateDistanceInfo(DistanceInfoObject[] di) { raimund@235: int i = 0; raimund@235: for (DistanceInfoObject dio: di) { raimund@235: if (dio.getTo() != null) { raimund@235: distanceTable.addData(new DistanceInfoRecord(dio)); raimund@235: } raimund@235: else { raimund@235: locationsTable.addData(new DistanceInfoRecord(dio)); raimund@235: locationDistanceTable.addData(new DistanceInfoRecord(dio)); raimund@235: } raimund@235: } raimund@235: return; raimund@235: } raimund@235: raimund@235: ingo@43: protected double getFrom() { ingo@43: return from; ingo@41: } ingo@41: ingo@41: ingo@43: protected void setFrom(double from) { ingo@43: this.from = from; ingo@43: } ingo@41: ingo@41: ingo@43: protected double getTo() { ingo@43: return to; ingo@43: } ingo@41: ingo@41: ingo@43: protected void setTo(double to) { ingo@43: this.to = to; ingo@43: } ingo@41: ingo@43: ingo@43: protected double getStep() { ingo@43: return step; ingo@43: } ingo@43: ingo@43: ingo@43: protected void setStep(double step) { ingo@43: this.step = step; ingo@43: } ingo@43: ingo@43: ingo@43: protected double[] getLocationValues() { ingo@43: return values; ingo@43: } ingo@43: ingo@43: ingo@43: protected void setLocationValues(double[] values) { ingo@43: this.values = values; raimund@235: locationPanel.setValues(values); raimund@235: } raimund@235: raimund@235: raimund@235: protected void setDistanceValues (double from, double to) { raimund@235: setFrom(from); raimund@235: setTo(to); raimund@235: distancePanel.setValues(from, to, getStep()); ingo@41: } ingo@41: } ingo@41: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :