Mercurial > dive4elements > river
annotate gwt-client/src/main/java/org/dive4elements/river/client/client/ui/AbstractSingleItemPanel.java @ 9256:6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
author | gernotbelger |
---|---|
date | Fri, 13 Jul 2018 12:04:21 +0200 |
parents | cbe393451ab0 |
children | b570b6fcc052 |
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 | |
9256
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
15 import org.dive4elements.river.client.client.FLYSConstants; |
9078 | 16 import org.dive4elements.river.client.client.ui.FromToTableHelperPanel.IColumnClickHandler; |
17 import org.dive4elements.river.client.shared.model.Data; | |
18 import org.dive4elements.river.client.shared.model.DataItem; | |
19 import org.dive4elements.river.client.shared.model.DataList; | |
20 import org.dive4elements.river.client.shared.model.DefaultData; | |
21 import org.dive4elements.river.client.shared.model.DefaultDataItem; | |
22 | |
23 import com.smartgwt.client.widgets.Canvas; | |
24 import com.smartgwt.client.widgets.Label; | |
25 import com.smartgwt.client.widgets.form.fields.TextItem; | |
26 import com.smartgwt.client.widgets.layout.HLayout; | |
27 import com.smartgwt.client.widgets.layout.VLayout; | |
28 | |
29 /** | |
30 * @author Domenico Nardi Tironi | |
31 * | |
32 */ | |
33 public abstract class AbstractSingleItemPanel extends AbstractUIProvider { | |
34 | |
9079 | 35 private static final long serialVersionUID = 1L; |
9078 | 36 |
9256
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
37 public interface IMultiSingleBehaviour { |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
38 void appendValue(final TextItem inputItem, final String value); |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
39 |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
40 List<String> validate(List<String> errors, String sValue); |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
41 |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
42 void setValidInputs(List<String> validInputs); |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
43 |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
44 void setErrorForItemMsg(String errorForItemMsg); |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
45 |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
46 void setMSG(FLYSConstants msg); |
9079 | 47 } |
9078 | 48 |
9079 | 49 private TextItem inputItem; |
50 | |
51 private List<String> validInputs = new ArrayList<String>(); | |
9078 | 52 |
9256
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
53 private final IMultiSingleBehaviour behaviour; |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
54 |
9078 | 55 protected abstract String getDatakey(); |
56 | |
9079 | 57 protected abstract Canvas createWidget(final DataList data); |
9078 | 58 |
9256
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
59 public AbstractSingleItemPanel(final IMultiSingleBehaviour behaviour) { |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
60 this.behaviour = behaviour; |
9079 | 61 } |
9078 | 62 |
63 @Override | |
9079 | 64 public final Canvas create(final DataList data) { |
9078 | 65 final VLayout layout = new VLayout(); |
66 final IColumnClickHandler fromHandler = new IColumnClickHandler() { // add to external class | |
67 | |
68 @Override | |
69 public void columnClicked(final String value) { | |
70 appendValue(value); | |
71 } | |
72 }; | |
73 | |
74 final FromToTableHelperPanel helper = new FromToTableHelperPanel(data, getDatakey(), this.MSG, fromHandler, null); | |
75 final Canvas table = helper.getTable(); | |
76 this.validInputs = helper.getKeycolEntries(); | |
9256
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
77 this.behaviour.setValidInputs(this.validInputs); |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
78 this.behaviour.setErrorForItemMsg(this.errorForItemMsg()); |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
79 this.behaviour.setMSG(this.MSG); |
9078 | 80 |
81 this.helperContainer.addMember(table); | |
82 | |
83 final Canvas submit = getNextButton(); | |
84 final Canvas widget = createWidget(data); | |
85 | |
86 layout.addMember(widget); | |
87 layout.addMember(submit); | |
88 | |
89 return layout; | |
90 } | |
91 | |
92 @Override | |
9079 | 93 public final Canvas createOld(final DataList dataList) { |
9078 | 94 final List<Data> items = dataList.getAll(); |
95 final Data years = getData(items, getDatakey()); | |
96 final DataItem[] yearsItems = years.getItems(); | |
97 | |
98 final String v1 = yearsItems[0].getStringValue().replace(" ", ", "); | |
99 | |
100 final Label old = new Label(v1); | |
101 final HLayout layout = new HLayout(); | |
102 layout.setWidth("400px"); | |
103 | |
104 final Label label = new Label(dataList.getLabel()); | |
105 label.setWidth("200px"); | |
106 | |
107 final Canvas back = getBackButton(dataList.getState()); | |
108 | |
109 layout.addMember(label); | |
110 layout.addMember(old); | |
111 layout.addMember(back); | |
112 | |
113 return layout; | |
114 } | |
115 | |
116 @Override | |
9079 | 117 protected final Data[] getData() { |
118 final List<String> errors = this.validate(); | |
119 if (errors.size() > 0) { | |
120 showErrors(errors); // TODO: do not allow advance state | |
121 // return null; | |
122 } | |
123 if (this.inputItem != null && !this.inputItem.getValueAsString().isEmpty()) { | |
124 final List<Data> data = new ArrayList<Data>(); | |
125 | |
126 final DataItem yearsdata = new DefaultDataItem(getDatakey(), getDatakey(), this.inputItem.getValueAsString().trim()); | |
127 data.add(new DefaultData(getDatakey(), null, null, new DataItem[] { yearsdata })); | |
128 | |
129 return data.toArray(new Data[data.size()]); | |
130 } | |
131 return new Data[0]; | |
132 } | |
133 | |
134 protected final TextItem createInputItem(final String title) { | |
135 this.inputItem = PanelHelper.createItem(title);// new TextItem(title); | |
136 return this.inputItem; | |
137 } | |
138 | |
139 private final List<String> checkForEmpty() { | |
9078 | 140 final List<String> errors = new ArrayList<String>(); |
141 | |
142 if (this.inputItem.getValueAsString() == null || this.inputItem.getValueAsString().trim().isEmpty()) { | |
143 errors.add(this.MSG.empty_filter()); | |
144 return errors; | |
145 } | |
9079 | 146 return errors; |
147 } | |
9078 | 148 |
9079 | 149 protected abstract String errorForItemMsg(); |
150 | |
151 protected final void appendValue(final String value) { | |
9256
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
152 this.behaviour.appendValue(this.inputItem, value); |
9079 | 153 } |
154 | |
155 @Override | |
156 public final List<String> validate() { | |
157 final List<String> errors = new ArrayList<String>(); | |
158 errors.addAll(this.checkForEmpty()); | |
159 final String sValue = this.inputItem.getValueAsString(); | |
9256
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
9241
diff
changeset
|
160 return this.behaviour.validate(errors, sValue); |
9078 | 161 } |
9079 | 162 } |