Mercurial > dive4elements > river
annotate gwt-client/src/main/java/org/dive4elements/river/client/client/ui/AbstractSingleItemPanel.java @ 9559:ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
author | gernotbelger |
---|---|
date | Wed, 24 Oct 2018 18:40:38 +0200 |
parents | 787fc085459b |
children |
rev | line source |
---|---|
9078 | 1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 package org.dive4elements.river.client.client.ui; | |
11 | |
12 import java.util.ArrayList; | |
13 import java.util.List; | |
14 | |
15 import org.dive4elements.river.client.client.ui.FromToTableHelperPanel.IColumnClickHandler; | |
16 import org.dive4elements.river.client.shared.model.Data; | |
17 import org.dive4elements.river.client.shared.model.DataItem; | |
18 import org.dive4elements.river.client.shared.model.DataList; | |
19 import org.dive4elements.river.client.shared.model.DefaultData; | |
20 import org.dive4elements.river.client.shared.model.DefaultDataItem; | |
21 | |
22 import com.smartgwt.client.widgets.Canvas; | |
23 import com.smartgwt.client.widgets.Label; | |
24 import com.smartgwt.client.widgets.form.fields.TextItem; | |
25 import com.smartgwt.client.widgets.layout.HLayout; | |
26 import com.smartgwt.client.widgets.layout.VLayout; | |
27 | |
28 /** | |
29 * @author Domenico Nardi Tironi | |
30 * | |
31 */ | |
32 public abstract class AbstractSingleItemPanel extends AbstractUIProvider { | |
33 | |
9079 | 34 private static final long serialVersionUID = 1L; |
9078 | 35 |
9256
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
36 public interface IMultiSingleBehaviour { |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
37 void appendValue(final TextItem inputItem, final String value); |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
38 |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
39 List<String> validate(List<String> errors, String sValue); |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
40 |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
41 void setValidInputs(List<String> validInputs); |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
42 |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
43 void setErrorForItemMsg(String errorForItemMsg); |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
44 |
9481 | 45 boolean isMultipleInputsAllowed(); |
46 | |
47 String titleForCreateOld(); | |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
48 |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
49 String appendStringForCreateOld(); |
9079 | 50 } |
9078 | 51 |
9079 | 52 private TextItem inputItem; |
53 | |
9481 | 54 private String title = null; |
55 | |
9270 | 56 protected List<String> validInputs = new ArrayList<String>(); |
9078 | 57 |
9256
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
58 private final IMultiSingleBehaviour behaviour; |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
59 |
9078 | 60 protected abstract String getDatakey(); |
61 | |
9079 | 62 protected abstract Canvas createWidget(final DataList data); |
9078 | 63 |
9256
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
64 public AbstractSingleItemPanel(final IMultiSingleBehaviour behaviour) { |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
65 this.behaviour = behaviour; |
9079 | 66 } |
9078 | 67 |
68 @Override | |
9079 | 69 public final Canvas create(final DataList data) { |
9078 | 70 final VLayout layout = new VLayout(); |
71 final IColumnClickHandler fromHandler = new IColumnClickHandler() { // add to external class | |
72 | |
73 @Override | |
74 public void columnClicked(final String value) { | |
75 appendValue(value); | |
76 } | |
77 }; | |
78 | |
9481 | 79 this.title = data.get(0).getDescription(); |
9078 | 80 final FromToTableHelperPanel helper = new FromToTableHelperPanel(data, getDatakey(), this.MSG, fromHandler, null); |
81 final Canvas table = helper.getTable(); | |
82 this.validInputs = helper.getKeycolEntries(); | |
9256
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
83 this.behaviour.setValidInputs(this.validInputs); |
9270 | 84 this.behaviour.setErrorForItemMsg(this.errorForItemMsg());// , this.MSG); |
9078 | 85 |
86 this.helperContainer.addMember(table); | |
87 | |
88 final Canvas submit = getNextButton(); | |
89 final Canvas widget = createWidget(data); | |
90 | |
91 layout.addMember(widget); | |
92 layout.addMember(submit); | |
93 | |
94 return layout; | |
95 } | |
96 | |
97 @Override | |
9079 | 98 public final Canvas createOld(final DataList dataList) { |
9078 | 99 final List<Data> items = dataList.getAll(); |
100 final Data years = getData(items, getDatakey()); | |
101 final DataItem[] yearsItems = years.getItems(); | |
102 | |
9481 | 103 final String v1 = this.behaviour.isMultipleInputsAllowed() ? yearsItems[0].getStringValue().replace(" ", ", ") : yearsItems[0].getStringValue(); |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
104 final String append = this.behaviour.appendStringForCreateOld() != null ? this.behaviour.appendStringForCreateOld() : ""; |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
105 final Label old = new Label(new StringBuilder().append(v1).append(" ").append(append).toString()); |
9078 | 106 final HLayout layout = new HLayout(); |
107 layout.setWidth("400px"); | |
108 | |
9481 | 109 final String labelStr = this.behaviour.titleForCreateOld() != null ? this.behaviour.titleForCreateOld() : dataList.getLabel(); |
110 final Label label = new Label(labelStr); | |
9078 | 111 label.setWidth("200px"); |
112 | |
113 final Canvas back = getBackButton(dataList.getState()); | |
114 | |
115 layout.addMember(label); | |
116 layout.addMember(old); | |
117 layout.addMember(back); | |
118 | |
119 return layout; | |
120 } | |
121 | |
122 @Override | |
9079 | 123 protected final Data[] getData() { |
9267 | 124 final List<String> errors = this.validate(); // do not allow advance state |
9079 | 125 if (errors.size() > 0) { |
9267 | 126 showErrors(errors); |
9079 | 127 } |
128 if (this.inputItem != null && !this.inputItem.getValueAsString().isEmpty()) { | |
129 final List<Data> data = new ArrayList<Data>(); | |
130 | |
9270 | 131 final DataItem yearsdata = new DefaultDataItem(getDatakey(), getDatakey(), StringArrayParseHelper.trimRawString(this.inputItem.getValueAsString())); |
9079 | 132 data.add(new DefaultData(getDatakey(), null, null, new DataItem[] { yearsdata })); |
133 | |
134 return data.toArray(new Data[data.size()]); | |
135 } | |
136 return new Data[0]; | |
137 } | |
138 | |
139 protected final TextItem createInputItem(final String title) { | |
140 this.inputItem = PanelHelper.createItem(title);// new TextItem(title); | |
141 return this.inputItem; | |
142 } | |
143 | |
144 protected abstract String errorForItemMsg(); | |
145 | |
146 protected final void appendValue(final String value) { | |
9256
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
147 this.behaviour.appendValue(this.inputItem, value); |
9079 | 148 } |
149 | |
150 @Override | |
151 public final List<String> validate() { | |
152 final List<String> errors = new ArrayList<String>(); | |
9260 | 153 errors.addAll(ValidationHelper.checkForEmpty(this.inputItem, this.MSG)); |
9079 | 154 final String sValue = this.inputItem.getValueAsString(); |
9256
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
155 return this.behaviour.validate(errors, sValue); |
9078 | 156 } |
9481 | 157 |
9079 | 158 } |