Mercurial > dive4elements > river
view gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/VegetationzonesTable.java @ 9064:28c50f5efceb
work on uinfo-vegetation-zones table
author | gernotbelger |
---|---|
date | Wed, 09 May 2018 16:31:12 +0200 |
parents | |
children |
line wrap: on
line source
/* 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.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.google.gwt.core.client.GWT; import com.smartgwt.client.data.Record; import com.smartgwt.client.types.ListGridFieldType; import com.smartgwt.client.widgets.Button; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.form.DynamicForm; 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.form.validator.Validator; 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.grid.events.RecordClickEvent; import com.smartgwt.client.widgets.grid.events.RecordClickHandler; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VLayout; public class VegetationzonesTable extends AbstractUIProvider { private static final long serialVersionUID = 1L; protected ListGrid elements; private TextItem vegzone; private TextItem start; private TextItem end; private ListGrid table; private TextItem createItem(final String identifier, final String title, final int width, final Validator... validator) { final TextItem item = new TextItem(identifier, title); item.setWidth(width); item.setWrapTitle(false); item.setValidators(validator);// eigentlich überflüssig, oder? return item; } public Canvas createWidget(final DataList data) { final VLayout root = new VLayout(); final HLayout input = new HLayout(); final VLayout tableLayout = new VLayout(); final HLayout fields = new HLayout(); final HLayout fields2 = new HLayout(); final VLayout spacer = new VLayout(); spacer.setHeight(10); final Button add = new Button(this.MSG.add_date()); // TODO: make key more generic or change to more specific this.elements = new ListGrid(); final Label title = new Label(data.get(0).getDescription()); title.setHeight("35px"); // orig:25 this.vegzone = createItem("uinfo_vegetation_zone_label", this.MSG.uinfo_vegetation_zone_label(), 200, new IsStringValidator()); this.start = createItem("uinfo_vegetation_zones_from", this.MSG.uinfo_vegetation_zones_from(), 40, new IsIntegerValidator()); this.end = createItem("uinfo_vegetation_zones_to", this.MSG.uinfo_vegetation_zones_to(), 40, new IsIntegerValidator()); final DynamicForm form1 = new DynamicForm(); final DynamicForm form2 = new DynamicForm(); form2.setNumCols(5); form1.setNumCols(7); form1.setFields(this.vegzone); form2.setFields(this.start, this.end); add.addClickHandler(new ClickHandler() { @Override public void onClick(final ClickEvent ce) { final String v1 = VegetationzonesTable.this.start.getValueAsString(); final String v2 = VegetationzonesTable.this.end.getValueAsString(); final String v3 = VegetationzonesTable.this.vegzone.getValueAsString(); if (v1 == null || v2 == null || v3 == null) { return; } final ListGridRecord r = new ListGridRecord(); r.setAttribute("vegzone", v3); r.setAttribute("from", v1); r.setAttribute("to", v2); VegetationzonesTable.this.elements.addData(r); } }); 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); final ListGridField removeField = new ListGridField("_removeRecord", "Remove Record") { { setType(ListGridFieldType.ICON); setIcon(GWT.getHostPageBaseURL() + VegetationzonesTable.this.MSG.removeFeature()); setCanEdit(false); setCanFilter(false); setCanSort(false); setCanGroupBy(false); setCanFreeze(false); setWidth(25); } }; this.elements.addRecordClickHandler(new RecordClickHandler() { @Override public void onRecordClick(final RecordClickEvent event) { // Just handle remove-clicks if (!event.getField().getName().equals(removeField.getName())) { return; } event.getViewer().removeData(event.getRecord()); } }); this.elements.setFields(vegzone, from, to, removeField); fields.addMember(form1); fields2.addMember(form2); // fields2.addMember(add); tableLayout.addMember(this.elements); root.addMember(title); root.addMember(input); root.addMember(tableLayout); root.addMember(spacer); root.addMember(fields); root.addMember(fields2); root.addMember(spacer); root.addMember(add); root.addMember(spacer); root.addMember(spacer); return root; } @Override public Canvas createOld(final DataList dataList) { 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, "vegzones"); 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] + " - " + 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(); 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(); // VegetationzonesTable.this.vegzone.setValue(r.getAttribute("date")); // date?? // } // }); // // pinFrom.addRecordClickHandler(new RecordClickHandler() { // @Override // public void onRecordClick(final RecordClickEvent e) { // final Record r = e.getRecord(); // VegetationzonesTable.this.start.setValue(r.getAttribute("date")); // } // }); // // pinTo.addRecordClickHandler(new RecordClickHandler() { // @Override // public void onRecordClick(final RecordClickEvent e) { // final Record r = e.getRecord(); // VegetationzonesTable.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 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("vegzones", null, d); // DATA-key data.add(new DefaultData("vegzones", null, null, new DataItem[] { item })); return data.toArray(new Data[data.size()]); } }