Mercurial > dive4elements > river
annotate gwt-client/src/main/java/org/dive4elements/river/client/client/ui/AbstractSingleItemPanel.java @ 9409:38201f5b0dd9
Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
author | mschaefer |
---|---|
date | Thu, 16 Aug 2018 08:47:41 +0200 |
parents | 7337034eb5d5 |
children | 787fc085459b |
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 |
9270 | 45 // void setMSG(FLYSConstants msg); |
9079 | 46 } |
9078 | 47 |
9079 | 48 private TextItem inputItem; |
49 | |
9270 | 50 protected List<String> validInputs = new ArrayList<String>(); |
9078 | 51 |
9256
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
52 private final IMultiSingleBehaviour behaviour; |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
53 |
9078 | 54 protected abstract String getDatakey(); |
55 | |
9079 | 56 protected abstract Canvas createWidget(final DataList data); |
9078 | 57 |
9256
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
58 public AbstractSingleItemPanel(final IMultiSingleBehaviour behaviour) { |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
59 this.behaviour = behaviour; |
9079 | 60 } |
9078 | 61 |
62 @Override | |
9079 | 63 public final Canvas create(final DataList data) { |
9078 | 64 final VLayout layout = new VLayout(); |
65 final IColumnClickHandler fromHandler = new IColumnClickHandler() { // add to external class | |
66 | |
67 @Override | |
68 public void columnClicked(final String value) { | |
69 appendValue(value); | |
70 } | |
71 }; | |
72 | |
73 final FromToTableHelperPanel helper = new FromToTableHelperPanel(data, getDatakey(), this.MSG, fromHandler, null); | |
74 final Canvas table = helper.getTable(); | |
75 this.validInputs = helper.getKeycolEntries(); | |
9256
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
76 this.behaviour.setValidInputs(this.validInputs); |
9270 | 77 this.behaviour.setErrorForItemMsg(this.errorForItemMsg());// , this.MSG); |
9078 | 78 |
79 this.helperContainer.addMember(table); | |
80 | |
81 final Canvas submit = getNextButton(); | |
82 final Canvas widget = createWidget(data); | |
83 | |
84 layout.addMember(widget); | |
85 layout.addMember(submit); | |
86 | |
87 return layout; | |
88 } | |
89 | |
90 @Override | |
9079 | 91 public final Canvas createOld(final DataList dataList) { |
9078 | 92 final List<Data> items = dataList.getAll(); |
93 final Data years = getData(items, getDatakey()); | |
94 final DataItem[] yearsItems = years.getItems(); | |
95 | |
96 final String v1 = yearsItems[0].getStringValue().replace(" ", ", "); | |
97 | |
98 final Label old = new Label(v1); | |
99 final HLayout layout = new HLayout(); | |
100 layout.setWidth("400px"); | |
101 | |
102 final Label label = new Label(dataList.getLabel()); | |
103 label.setWidth("200px"); | |
104 | |
105 final Canvas back = getBackButton(dataList.getState()); | |
106 | |
107 layout.addMember(label); | |
108 layout.addMember(old); | |
109 layout.addMember(back); | |
110 | |
111 return layout; | |
112 } | |
113 | |
114 @Override | |
9079 | 115 protected final Data[] getData() { |
9267 | 116 final List<String> errors = this.validate(); // do not allow advance state |
9079 | 117 if (errors.size() > 0) { |
9267 | 118 showErrors(errors); |
9079 | 119 } |
120 if (this.inputItem != null && !this.inputItem.getValueAsString().isEmpty()) { | |
121 final List<Data> data = new ArrayList<Data>(); | |
122 | |
9270 | 123 final DataItem yearsdata = new DefaultDataItem(getDatakey(), getDatakey(), StringArrayParseHelper.trimRawString(this.inputItem.getValueAsString())); |
9079 | 124 data.add(new DefaultData(getDatakey(), null, null, new DataItem[] { yearsdata })); |
125 | |
126 return data.toArray(new Data[data.size()]); | |
127 } | |
128 return new Data[0]; | |
129 } | |
130 | |
131 protected final TextItem createInputItem(final String title) { | |
132 this.inputItem = PanelHelper.createItem(title);// new TextItem(title); | |
133 return this.inputItem; | |
134 } | |
135 | |
136 protected abstract String errorForItemMsg(); | |
137 | |
138 protected final void appendValue(final String value) { | |
9256
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
139 this.behaviour.appendValue(this.inputItem, value); |
9079 | 140 } |
141 | |
142 @Override | |
143 public final List<String> validate() { | |
144 final List<String> errors = new ArrayList<String>(); | |
9260 | 145 errors.addAll(ValidationHelper.checkForEmpty(this.inputItem, this.MSG)); |
9079 | 146 final String sValue = this.inputItem.getValueAsString(); |
9256
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
147 return this.behaviour.validate(errors, sValue); |
9078 | 148 } |
9079 | 149 } |