Mercurial > dive4elements > river
diff flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixGaugeSelectPanel.java @ 2505:87ac5c532523
First part of the UI for fixing analysis parameter.
flys-client/trunk@4350 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Mon, 07 May 2012 13:22:43 +0000 |
parents | |
children | 8f528f5ae137 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixGaugeSelectPanel.java Mon May 07 13:22:43 2012 +0000 @@ -0,0 +1,175 @@ +package de.intevation.flys.client.client.ui.fixation; + +import java.util.List; +import java.util.ArrayList; +import java.util.LinkedHashMap; + +import java.lang.NumberFormatException; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; + +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.SelectItem; +import com.smartgwt.client.widgets.form.fields.StaticTextItem; + +import de.intevation.flys.client.client.FLYSConstants; + +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DataItem; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.DefaultDataItem; + +/** + * This UIProvider creates a panel for location or distance input. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class FixGaugeSelectPanel +extends FixationPanel +{ + /** The message class that provides i18n strings. */ + protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); + + protected String first; + protected String second; + + protected SelectItem from; + protected SelectItem to; + + public FixGaugeSelectPanel() { + htmlOverview = ""; + } + + public Canvas createWidget(DataList data) { + instances.put(this.artifact.getUuid(), this); + + VLayout layout = new VLayout(); + + Label title = new Label(MESSAGES.gauge_class()); + title.setHeight(25); + + LinkedHashMap map = new LinkedHashMap(); + map.put("0", "0"); + map.put("1", "1"); + map.put("2", "2"); + map.put("3", "3"); + + from = new SelectItem(MESSAGES.from()); + to = new SelectItem(MESSAGES.to()); + + from.setShowTitle(false); + to.setShowTitle(false); + from.setValueMap(map); + from.setWidth(60); + to.setValueMap(map); + to.setWidth(60); + + DynamicForm form = new DynamicForm(); + StaticTextItem separator = new StaticTextItem("separator"); + separator.setShowTitle(false); + separator.setValue(MESSAGES.to()); + form.setNumCols(5); + form.setFields(from, separator, to); + + layout.addMember(title); + layout.addMember(form); + + return layout; + } + + @Override + public Canvas createOld(DataList dataList) { + List<Data> items = dataList.getAll(); + + Data f = getData(items, "q1"); + Data t = getData(items, "q2"); + DataItem[] fItems = f.getItems(); + DataItem[] tItems = t.getItems(); + + StringBuilder sb = new StringBuilder(); + sb.append(fItems[0].getLabel()); + sb.append(" " + MESSAGES.to() + " "); + sb.append(tItems[0].getLabel()); + + Label old = new Label(sb.toString()); + old.setWidth(130); + + HLayout layout = new HLayout(); + layout.setWidth("400px"); + Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + + Canvas back = getBackButton(dataList.getState()); + + layout.addMember(label); + layout.addMember(old); + layout.addMember(back); + return layout; + } + + + /** + * This method returns the selected data. + * + * @return the selected/inserted data. + */ + public Data[] getData() { + List<Data> data = new ArrayList<Data>(); + + boolean valid = saveClassValues(); + if (valid) { + DataItem firstItem = new DefaultDataItem("q1", "q1", this.first); + DataItem secItem = new DefaultDataItem("q2", "q2", this.second); + data.add(new DefaultData( + "q1", + null, + null, + new DataItem[] { firstItem })); + data.add(new DefaultData( + "q2", + null, + null, + new DataItem[] { secItem })); + } + return (Data[]) data.toArray(new Data[data.size()]); + } + + + @Override + public void setValues(String cid, boolean checked) { + // No user interaction, do nothing. + } + + + @Override + public boolean renderCheckboxes() { + // No selection, return false. + return false; + } + + + protected boolean saveClassValues() { + String v1 = from.getValueAsString(); + String v2 = to.getValueAsString(); + try { + int v1i = Integer.valueOf(v1).intValue(); + int v2i = Integer.valueOf(v2).intValue(); + if (v1i <= v2i) { + this.first = v1; + this.second = v2; + return true; + } + } + catch(NumberFormatException nfe) { + return false; + } + return false; + } +}