# HG changeset patch # User Raimund Renkert # Date 1346412584 0 # Node ID 6ededa5aa803b496cfbd5a702cc8a5a0bcf24e6e # Parent 02d18d38fca7e8b49eae4d4bfd2647858e89e118 MINFO: Added new UI provider for bed quality calculation. flys-client/trunk@5329 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 02d18d38fca7 -r 6ededa5aa803 flys-client/ChangeLog --- a/flys-client/ChangeLog Fri Aug 31 11:19:29 2012 +0000 +++ b/flys-client/ChangeLog Fri Aug 31 11:29:44 2012 +0000 @@ -1,3 +1,13 @@ +2012-08-31 Raimund Renkert + + MINFO: Added new UI provider for bed quality calculation. + + * src/main/java/de/intevation/flys/client/client/ui/minfo/CheckboxPanel.java: + New. UI provider for a list of checkboxes. + + * src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java: + Added new UI provider. + 2012-08-31 Raimund Renkert * src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java: diff -r 02d18d38fca7 -r 6ededa5aa803 flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java Fri Aug 31 11:19:29 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java Fri Aug 31 11:29:44 2012 +0000 @@ -10,6 +10,7 @@ import de.intevation.flys.client.client.ui.sq.SQMultiPeriodPanel; import de.intevation.flys.client.client.ui.sq.SQPeriodPanel; import de.intevation.flys.client.client.ui.minfo.BedHeightsDatacagePanel; +import de.intevation.flys.client.client.ui.minfo.CheckboxPanel; import de.intevation.flys.client.shared.model.User; /** @@ -122,7 +123,7 @@ return new PeriodPanel(); } else if (uiProvider.equals("periods_select")) { - return new SQMultiPeriodPanel(); + return new MultiPeriodPanel(); } else if (uiProvider.equals("sq.period.select")) { return new SQPeriodPanel(); @@ -139,6 +140,9 @@ else if (uiProvider.equals("bedheights_twin_panel")) { return new BedHeightsDatacagePanel(user); } + else if (uiProvider.equals("minfo.bed.char_diameter")) { + return new CheckboxPanel(); + } else { //GWT.log("Picked default provider."); return new SelectProvider(); diff -r 02d18d38fca7 -r 6ededa5aa803 flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/CheckboxPanel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/CheckboxPanel.java Fri Aug 31 11:29:44 2012 +0000 @@ -0,0 +1,120 @@ +package de.intevation.flys.client.client.ui.minfo; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Set; + +import com.google.gwt.core.client.GWT; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.CheckboxItem; +import com.smartgwt.client.widgets.form.fields.FormItem; +import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; +import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; +import com.smartgwt.client.widgets.form.fields.events.ClickEvent; +import com.smartgwt.client.widgets.form.fields.events.ClickHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.ui.AbstractUIProvider; +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; + +public class CheckboxPanel extends AbstractUIProvider { + + private String dataName; + HashMap values; + + protected DynamicForm form; + + public CheckboxPanel() { + super(); + values = new HashMap(); + } + + @Override + public Canvas createOld(DataList dataList) { + Data data = dataList.get(0); + DataItem[] items = data.getItems(); + + HLayout layout = new HLayout(); + Label label = new Label(dataList.getLabel()); + Label value = new Label(items[0].getLabel()); + + layout.setHeight(35); + layout.setWidth(400); + label.setWidth(200); + + layout.addMember(label); + layout.addMember(value); + layout.addMember(getBackButton(dataList.getState())); + + return layout; + } + + @Override + public Canvas create(DataList dataList) { + Data data = dataList.get(0); + DataItem[] items = data.getItems(); + + this.dataName = data.getLabel(); + form = new DynamicForm(); + + VLayout layout = new VLayout(); + Label label = new Label(data.getDescription()); + LinkedList cbItems = new LinkedList(); + for (int i = 0; i < items.length; i++) { + CheckboxItem item = new CheckboxItem(items[i].getLabel()); + GWT.log(items[i].getStringValue() + "; " + items[i].getLabel()); + item.addChangedHandler(new ChangedHandler() { + @Override + public void onChanged(ChangedEvent event) { + values.put( + event.getItem().getName(), + (Boolean)event.getItem().getValue()); + } + }); + cbItems.add(item); + } + + form.setFields(cbItems.toArray(new CheckboxItem[cbItems.size()])); + layout.setMembersMargin(10); + layout.setHeight(35); + label.setHeight(35); + + layout.addMember(label); + layout.addMember(form); + layout.addMember(getNextButton()); + layout.setMembersMargin(10); + + return layout; + } + + @Override + protected Data[] getData() { + String value = ""; + Set entries = values.keySet(); + boolean first = true; + for (String s: values.keySet()) { + if (!first) { + value += ";"; + } + if ((Boolean)values.get(s) == true) { + value += s; + } + first = false; + } + DataItem item = new DefaultDataItem("diameter", "diameter", value); + + return new Data[] {new DefaultData( + "diameter", + null, + null, + new DataItem[]{item})}; + } + +}