# HG changeset patch # User Ingo Weinzierl # Date 1306234320 0 # Node ID ba606e575663418de647b6ed06994ecd7346ac40 # Parent 27ffaf628b544ce9dba9236c029270dac2c12670 ISSUE-85 (part II/III) Repaired broken location/range panel. flys-client/trunk@1987 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 27ffaf628b54 -r ba606e575663 flys-client/ChangeLog --- a/flys-client/ChangeLog Tue May 24 10:46:48 2011 +0000 +++ b/flys-client/ChangeLog Tue May 24 10:52:00 2011 +0000 @@ -1,3 +1,11 @@ +2011-05-24 Ingo Weinzierl + + ISSUE-85 (part II/III) + + * src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java: + Repaired this broken panel. Now, we distinguish between the two modes + 'range' and 'locations'. + 2011-05-24 Ingo Weinzierl * src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java: diff -r 27ffaf628b54 -r ba606e575663 flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java Tue May 24 10:46:48 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java Tue May 24 10:52:00 2011 +0000 @@ -66,11 +66,7 @@ protected DistanceInfoServiceAsync distanceInfoService = GWT.create(DistanceInfoService.class); - /** The constant name of the input field to enter locations.*/ - public static final String FIELD_LOCATION = "location"; - - /** The constant name of the input field to enter distance.*/ - public static final String FIELD_DISTANCE = "distance"; + public static final String FIELD_MODE = "mode"; /** The constant name of the input field to enter the start of a distance.*/ public static final String FIELD_FROM = "from"; @@ -78,6 +74,12 @@ /** The constant name of the input field to enter the end of a distance.*/ public static final String FIELD_TO = "to"; + /** The constant name of the input field to enter locations.*/ + public static final String FIELD_VALUE_LOCATION = "location"; + + /** The constant name of the input field to enter distance.*/ + public static final String FIELD_VALUE_DISTANCE = "distance"; + /** The constant name of the input field to enter the step width of a * distance.*/ public static final String FIELD_WIDTH = "width"; @@ -156,13 +158,13 @@ VLayout layout = new VLayout(); layout.setMembersMargin(10); - initDefaults(data); - Label label = new Label(MESSAGES.location_distance_state()); Canvas widget = createWidget(data); Canvas submit = getNextButton(); createDistanceInputPanel(); + initDefaults(data); + createDistanceTable(); createLocationTable(); createLocationTableDistance (); @@ -350,6 +352,47 @@ public Canvas createOld(DataList dataList) { List items = dataList.getAll(); + Data dMode = getData(items, "ld_mode"); + DataItem[] dItems = dMode.getItems(); + + boolean rangeMode = true; + if (dItems != null && dItems[0] != null) { + rangeMode = FIELD_VALUE_DISTANCE.equals(dItems[0].getStringValue()); + } + + HLayout layout = new HLayout(); + layout.setWidth("400px"); + + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + + Canvas back = getBackButton(dataList.getState()); + + layout.addMember(label); + + if (rangeMode) { + layout.addMember(getOldRangeSelection(dataList)); + } + else { + layout.addMember(getOldLocationSelection(dataList)); + } + + layout.addMember(back); + + return layout; + } + + + /** + * Creates a label for the selected range. + * + * @param dataList The DataList containing all values for this state. + * + * @return A label displaying the selected values. + */ + protected Label getOldRangeSelection(DataList dataList) { + List items = dataList.getAll(); + Data dFrom = getData(items, "ld_from"); Data dTo = getData(items, "ld_to"); Data dStep = getData(items, "ld_step"); @@ -358,12 +401,6 @@ DataItem[] to = dTo.getItems(); DataItem[] step = dStep.getItems(); - HLayout layout = new HLayout(); - layout.setWidth("400px"); - - Label label = new Label(dataList.getLabel()); - label.setWidth("200px"); - StringBuilder sb = new StringBuilder(); sb.append(from[0].getLabel()); sb.append(" " + MESSAGES.unitFrom() + " "); @@ -372,16 +409,32 @@ sb.append(step[0].getLabel()); sb.append(" " + MESSAGES.unitWidth()); - Canvas back = getBackButton(dataList.getState()); - Label selected = new Label(sb.toString()); selected.setWidth("130px"); - layout.addMember(label); - layout.addMember(selected); - layout.addMember(back); + return selected; + } - return layout; + + /** + * Creates a label for the selected locations. + * + * @param dataList The DataList containing all values for this state. + * + * @return A label displaying the selected values. + */ + protected Label getOldLocationSelection(DataList dataList) { + List items = dataList.getAll(); + + Data dLocations = getData(items, "ld_locations"); + DataItem[] lItems = dLocations.getItems(); + + String value = lItems[0].getStringValue(); + + Label selected = new Label(value); + selected.setWidth(130); + + return selected; } @@ -392,6 +445,8 @@ * @param list The DataList container that stores the Data objects. */ protected void initDefaults(DataList list) { + Data m = getData(list.getAll(), "ld_mode"); + Data l = getData(list.getAll(), "ld_locations"); Data f = getData(list.getAll(), "ld_from"); Data t = getData(list.getAll(), "ld_to"); Data s = getData(list.getAll(), "ld_step"); @@ -404,29 +459,37 @@ max = Double.valueOf(tItems[0].getStringValue()); step = Double.valueOf(sItems[0].getStringValue()); - this.from = min; - this.to = max; - this.step = step; - } - + DataItem mDef = m.getDefault(); + DataItem lDef = l.getDefault(); + DataItem fDef = f.getDefault(); + DataItem tDef = t.getDefault(); + DataItem sDef = s.getDefault(); - /** - * This method greps the Data with name name from the list and - * returns it. - * - * @param items A list of Data. - * @param name The name of the Data that we are searching for. - * - * @return the Data with the name name. - */ - protected Data getData(List data, String name) { - for (Data d: data) { - if (name.equals(d.getLabel())) { - return d; - } + String theMode = mDef != null + ? mDef.getStringValue() + : FIELD_VALUE_LOCATION; + + mode.setValue(FIELD_MODE, theMode); + + setFrom(fDef != null + ? Double.valueOf(fDef.getStringValue()) + : min); + + setTo(tDef != null + ? Double.valueOf(tDef.getStringValue()) + : max); + + setStep(sDef != null + ? Double.valueOf(sDef.getStringValue()) + : step); + + if (lDef != null) { + setLocationValues(lDef.getStringValue()); } - return null; + if (theMode.equals(FIELD_VALUE_DISTANCE)) { + enableDistancePanel(); + } } @@ -490,7 +553,53 @@ } } - return new Data[] { getDataFrom(), getDataTo(), getDataStep() }; + return new Data[] { + getDataMode(), + getDataLocations(), + getDataFrom(), + getDataTo(), + getDataStep() }; + } + + + /** + * Returns the Data object for the 'mode' attribute. + * + * @return the Data object for the 'mode' attribute. + */ + protected Data getDataMode() { + String value = mode.getValueAsString(FIELD_MODE); + DataItem item = new DefaultDataItem("ld_mode", "ld_mode", value); + return new DefaultData("ld_mode", null, null, new DataItem[] { item }); + } + + + protected Data getDataLocations() { + double[] locations = getLocationValues(); + boolean first = true; + + StringBuilder sb = new StringBuilder(); + + for (double l: locations) { + if (!first) { + sb.append(" "); + } + + sb.append(l); + + first = false; + } + + DataItem item = new DefaultDataItem( + "ld_locations", + "ld_locations", + sb.toString()); + + return new DefaultData( + "ld_locations", + null, + null, + new DataItem[] { item }); } @@ -500,7 +609,7 @@ * @return the Data object for the 'from' attribute. */ protected Data getDataFrom() { - String value = Double.valueOf(getFinalFrom()).toString(); + String value = Double.valueOf(getFrom()).toString(); DataItem item = new DefaultDataItem("ld_from", "ld_from", value); return new DefaultData( "ld_from", null, null, new DataItem[] { item }); @@ -513,7 +622,7 @@ * @return the Data object for the 'to' attribute. */ protected Data getDataTo() { - String value = Double.valueOf(getFinalTo()).toString(); + String value = Double.valueOf(getTo()).toString(); DataItem item = new DefaultDataItem("ld_to", "ld_to", value); return new DefaultData( "ld_to", null, null, new DataItem[] { item }); @@ -526,7 +635,7 @@ * @return the Data object for the 'step' attribute. */ protected Data getDataStep() { - String value = Double.valueOf(getFinalStep()).toString(); + String value = Double.valueOf(getStep()).toString(); DataItem item = new DefaultDataItem("ld_step","ld_step", value); return new DefaultData( "ld_step", null, null, new DataItem[] { item }); @@ -534,75 +643,43 @@ /** - * Returns the value of 'from' depending on the selected input mode. - * - * @return the value of 'from' depending on the selected input mode. - */ - protected double getFinalFrom() { - if (isLocationMode()) { - double[] values = getLocationValues(); - double value = Double.MAX_VALUE; - - for (double v: values) { - value = value < v ? value : v; - } - - return value; - } - else { - return getFrom(); - } - } - - - /** - * Returns the value of 'to' depending on the selected input mode. - * - * @return the value of 'to' depending on the selected input mode. - */ - protected double getFinalTo() { - if (isLocationMode()) { - double[] values = getLocationValues(); - double value = Double.MIN_VALUE; - - for (double v: values) { - value = value > v ? value : v; - } - - return value; - } - else { - return getTo(); - } - } - - - /** - * Returns the value of 'step' depending on the selected input mode. - * - * @return the value of 'step' depending on the selected input mode. - */ - protected double getFinalStep() { - if (isLocationMode()) { - // we have no field to enter the 'step' attribute in the location - // mode - return 0.0; - } - else { - return getStep(); - } - } - - - /** * Determines the current input mode. * * @return true, if 'location' is the current input mode, otherwise false. */ public boolean isLocationMode() { - String inputMode = mode.getValueAsString("mode"); + String inputMode = mode.getValueAsString(FIELD_MODE); - return inputMode.equals(FIELD_LOCATION) ? true : false; + return inputMode.equals(FIELD_VALUE_LOCATION) ? true : false; + } + + + /** + * Activates the location panel. + */ + protected void enableLocationPanel() { + locationPanel = new DoubleArrayPanel( + MESSAGES.unitLocation(), + getLocationValues(), + this); + + container.removeMembers(container.getMembers()); + container.addMember(locationPanel); + } + + + /** + * Activates the distance panel. + */ + protected void enableDistancePanel() { + distancePanel = new DoubleRangePanel( + MESSAGES.unitFrom(), MESSAGES.unitTo(), MESSAGES.unitWidth(), + getFrom(), getTo(), getStep(), + 250, + this); + + container.removeMembers(container.getMembers()); + container.addMember(distancePanel); } @@ -617,14 +694,9 @@ if (value == null) { return; } - if (value.equals(FIELD_LOCATION)) { - locationPanel = new DoubleArrayPanel( - MESSAGES.unitLocation(), - getLocationValues(), - this); + if (value.equals(FIELD_VALUE_LOCATION)) { + enableLocationPanel(); - container.removeMembers(container.getMembers()); - container.addMember(locationPanel); while (inputTables.getNumTabs() > 0) { inputTables.removeTab(0); } @@ -642,14 +714,8 @@ inputTables.selectTab(0); } else { - distancePanel = new DoubleRangePanel( - MESSAGES.unitFrom(), MESSAGES.unitTo(), MESSAGES.unitWidth(), - getFrom(), getTo(), getStep(), - 250, - this); + enableDistancePanel(); - container.removeMembers(container.getMembers()); - container.addMember(distancePanel); while (inputTables.getNumTabs () > 0) { inputTables.removeTab(0); } @@ -766,16 +832,16 @@ protected Canvas createRadioButtonPanel() { mode = new DynamicForm(); - RadioGroupItem radio = new RadioGroupItem("mode"); + RadioGroupItem radio = new RadioGroupItem(FIELD_MODE); radio.setShowTitle(false); radio.setVertical(false); LinkedHashMap values = new LinkedHashMap(); - values.put(FIELD_LOCATION, MESSAGES.location()); - values.put(FIELD_DISTANCE, MESSAGES.distance()); + values.put(FIELD_VALUE_LOCATION, MESSAGES.location()); + values.put(FIELD_VALUE_DISTANCE, MESSAGES.distance()); LinkedHashMap initial = new LinkedHashMap(); - initial.put("mode", FIELD_LOCATION); + initial.put(FIELD_MODE, FIELD_VALUE_LOCATION); radio.setValueMap(values); radio.addChangeHandler(this); @@ -889,6 +955,29 @@ } + protected void setLocationValues(String values) { + String[] vs = values.split(" "); + + if (vs == null) { + return; + } + + double[] ds = new double[vs.length]; + int idx = 0; + + for (String s: vs) { + try { + ds[idx++] = Double.valueOf(s); + } + catch (NumberFormatException nfe) { + // do nothing + } + } + + setLocationValues(ds); + } + + protected void setDistanceValues (double from, double to) { setFrom(from); setTo(to);