Mercurial > dive4elements > river
diff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/VegetationzonesTablePanel.java @ 9066:b5d7a9d79837
uinfo.inundation_duration ui
author | gernotbelger |
---|---|
date | Fri, 11 May 2018 17:04:35 +0200 |
parents | |
children | a5cf8d7bff3c |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/VegetationzonesTablePanel.java Fri May 11 17:04:35 2018 +0200 @@ -0,0 +1,257 @@ +/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ + +package org.dive4elements.river.client.client.ui.uinfo; + +import java.util.ArrayList; +import java.util.List; + +import org.dive4elements.river.client.client.ui.AbstractUIProvider; +import org.dive4elements.river.client.client.ui.PanelHelper; +import org.dive4elements.river.client.shared.model.Data; +import org.dive4elements.river.client.shared.model.DataItem; +import org.dive4elements.river.client.shared.model.DataList; +import org.dive4elements.river.client.shared.model.DefaultData; +import org.dive4elements.river.client.shared.model.DefaultDataItem; + +import com.smartgwt.client.data.Record; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.form.fields.TextItem; +import com.smartgwt.client.widgets.form.validator.IsIntegerValidator; +import com.smartgwt.client.widgets.form.validator.IsStringValidator; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +public class VegetationzonesTablePanel extends AbstractUIProvider { + private static final long serialVersionUID = 1L; + + protected ListGrid elements; + private TextItem vegzone; + private TextItem start; + private TextItem end; + private ListGrid table; + + private static final String datakey = "vegzones"; + + public Canvas createWidget(final DataList data) { + + final VLayout root = new VLayout(); + final HLayout input = new HLayout(); + final VLayout tableLayout = new VLayout(); + + this.elements = new ListGrid(); + + final Label title = new Label(data.get(0).getDescription()); + title.setHeight("35px"); // orig:25 + + this.vegzone = PanelHelper.createItem("uinfo_vegetation_zone_label", this.MSG.uinfo_vegetation_zone_label(), 200, new IsStringValidator()); + this.start = PanelHelper.createItem("uinfo_vegetation_zones_from", this.MSG.uinfo_vegetation_zones_from(), 40, new IsIntegerValidator()); + this.end = PanelHelper.createItem("uinfo_vegetation_zones_to", this.MSG.uinfo_vegetation_zones_to(), 40, new IsIntegerValidator()); + + final Label sel = new Label(this.MSG.select()); + sel.setHeight(25); + this.elements.setWidth(450); // 185 + this.elements.setHeight(500); // 120 + this.elements.setShowHeaderContextMenu(false); + this.elements.setCanReorderFields(false); + this.elements.setCanSort(false); + this.elements.setCanEdit(false); + final ListGridField vegzone = new ListGridField("vegzone", this.MSG.uinfo_vegetation_zones_label()); + final ListGridField from = new ListGridField("from", this.MSG.uinfo_vegetation_zones_from()); + final ListGridField to = new ListGridField("to", this.MSG.uinfo_vegetation_zones_to()); + vegzone.setWidth(285); + from.setWidth(70); + to.setWidth(70); + + for (final Data dataItem : data.getAll()) { + createEntry(dataItem); + } + + this.elements.setFields(vegzone, from, to); + + tableLayout.addMember(this.elements); + root.addMember(title); + root.addMember(input); + root.addMember(tableLayout); + root.addMember(PanelHelper.getSpacer(10)); + + return root; + } + + private void createEntry(final Data data) { + + if (data.getItems() != null) { + for (final DataItem dataItem : data.getItems()) { + if (dataItem.getStringValue() != null) { + if (dataItem.getStringValue().contains(",")) { + final String[] vals = dataItem.getStringValue().split(","); + if (vals.length == 3) { + final String vegzone = vals[0]; + final String from = vals[1]; + final String to = vals[2]; + + if (vegzone == null || from == null || to == null) { + return; + } + + final ListGridRecord r = new ListGridRecord(); + r.setAttribute("vegzone", vegzone); + r.setAttribute("from", from); + r.setAttribute("to", to); + this.elements.addData(r); + + } + } + } + } + } + } + + @Override + public Canvas createOld(final DataList dataList) { // TODO: Veg-Table übersichtlich oben anzeigen, irgendwie abkürzen (etwa "20 Einträge") + final HLayout layout = new HLayout(); + layout.setWidth("400px"); + final VLayout vLayout = new VLayout(); + vLayout.setWidth(130); + final Label label = new Label(dataList.getLabel()); + label.setWidth("200px"); + label.setHeight(25); + + final List<Data> items = dataList.getAll(); + final Data str = getData(items, datakey); + final DataItem[] strItems = str.getItems(); + + final String[] entries = strItems[0].getLabel().split(";"); + for (final String entry : entries) { + final String[] vals = entry.split(","); + final Label dateLabel = new Label(vals[0] + " TODO: MAKE SELECTED ENTRIES VEGZONE FOR ARTIFACT" + vals[1]); + dateLabel.setHeight(20); + vLayout.addMember(dateLabel); + } + final Canvas back = getBackButton(dataList.getState()); + layout.addMember(label); + layout.addMember(vLayout); + layout.addMember(back); + + return layout; + } + + @Override + public Canvas create(final DataList data) { + final VLayout layout = new VLayout(); + final Canvas helper = createHelper(); + this.helperContainer.addMember(helper); + + final Canvas submit = getNextButton(); + // if (data.size() == 0) { // TODO: GET DATA + + data.add(getDummyData()); + + // } + final Canvas widget = createWidget(data); + + layout.addMember(widget); + layout.addMember(submit); // TODO: SUBMIT + + // fetchSedimentLoadData(); //TODO: feed from database... + + return layout; + } + + private Canvas createHelper() { + this.table = new ListGrid(); + this.table.setShowHeaderContextMenu(false); + this.table.setWidth100(); + this.table.setShowRecordComponents(true); + this.table.setShowRecordComponentsByCell(true); + this.table.setHeight100(); + this.table.setEmptyMessage(this.MSG.empty_table()); + this.table.setCanReorderFields(false); + + /* Input support pins */ + // final String baseUrl = GWT.getHostPageBaseURL(); + // final ListGridField pinFrom = new ListGridField("fromIcon", this.MSG.uinfo_vegetation_zones_from()); + // pinFrom.setWidth(300); + // pinFrom.setType(ListGridFieldType.ICON); + // pinFrom.setCellIcon(baseUrl + this.MSG.markerGreen()); + // + // final ListGridField pinTo = new ListGridField("toIcon", this.MSG.uinfo_vegetation_zones_to()); + // pinTo.setType(ListGridFieldType.ICON); + // pinTo.setWidth(300); + // pinTo.setCellIcon(baseUrl + this.MSG.markerRed()); + // + // pinFrom.addRecordClickHandler(new RecordClickHandler() { + // @Override + // public void onRecordClick(final RecordClickEvent e) { + // final Record r = e.getRecord(); + // VegetationzonesTableEditPanel.this.vegzone.setValue(r.getAttribute("date")); // date?? + // } + // }); + // + // pinFrom.addRecordClickHandler(new RecordClickHandler() { + // @Override + // public void onRecordClick(final RecordClickEvent e) { + // final Record r = e.getRecord(); + // VegetationzonesTableEditPanel.this.start.setValue(r.getAttribute("date")); + // } + // }); + // + // pinTo.addRecordClickHandler(new RecordClickHandler() { + // @Override + // public void onRecordClick(final RecordClickEvent e) { + // final Record r = e.getRecord(); + // VegetationzonesTableEditPanel.this.end.setValue(r.getAttribute("date")); + // } + // }); + // + // final ListGridField date = new ListGridField("date", this.MSG.year()); + // date.setType(ListGridFieldType.TEXT); + // date.setWidth(100); + // + // final ListGridField descr = new ListGridField("description", this.MSG.description()); + // descr.setType(ListGridFieldType.TEXT); + // descr.setWidth("*"); + // + // this.table.setFields(pinFrom, pinTo, date, descr); + return this.table; + } + + @Override + protected Data[] getData() { + final List<Data> data = new ArrayList<Data>(); + + final ListGridRecord[] lgr = this.elements.getRecords(); + if (lgr.length == 0) { + return getDummyData();// return new Data[0]; + } + String d = ""; + for (final ListGridRecord element : lgr) { + final Record r = element; + d += r.getAttribute("vegzone") + "," + r.getAttribute("from") + "," + r.getAttribute("to"); + d += ";"; + } + + final DataItem item = new DefaultDataItem(datakey, null, d); // DATA-key + data.add(new DefaultData(datakey, null, null, new DataItem[] { item })); + return data.toArray(new Data[data.size()]); + } + + private Data[] getDummyData() { + final List<Data> data = new ArrayList<Data>(); + String d = ""; + d = d + "Zonaler Wald" + "," + "0" + "," + "5"; + final DataItem item = new DefaultDataItem(datakey, "entryDescription", d); // DATA-key + data.add(new DefaultData(datakey, null, null, new DataItem[] { item })); + return data.toArray(new Data[data.size()]); + } + +}