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