Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/collision/LoadMultipleYearSelectState.java @ 9074:766890addcb2
state To client communication;
author | gernotbelger |
---|---|
date | Fri, 18 May 2018 17:26:26 +0200 |
parents | cd650cacc926 |
children | 22d8928895a1 |
comparison
equal
deleted
inserted
replaced
9073:cd650cacc926 | 9074:766890addcb2 |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.artifacts.sinfo.collision; | 9 package org.dive4elements.river.artifacts.sinfo.collision; |
10 | 10 |
11 import java.util.HashMap; | |
12 import java.util.List; | |
13 import java.util.Map; | |
14 | |
11 import org.apache.log4j.Logger; | 15 import org.apache.log4j.Logger; |
12 import org.dive4elements.artifacts.Artifact; | 16 import org.dive4elements.artifacts.Artifact; |
17 import org.dive4elements.artifacts.CallContext; | |
18 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; | |
19 import org.dive4elements.river.artifacts.model.CollisionHibernateFactory; | |
13 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; | 20 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; |
21 import org.dive4elements.river.artifacts.states.AddTableDataHelper; | |
14 import org.dive4elements.river.artifacts.states.DefaultState; | 22 import org.dive4elements.river.artifacts.states.DefaultState; |
23 import org.dive4elements.river.model.sinfo.Collision; | |
24 import org.w3c.dom.Element; | |
15 | 25 |
16 /** State in which to fetch years for sedminent load calculation. */ | 26 /** State in which to fetch years for sedminent load calculation. */ |
17 public class LoadMultipleYearSelectState extends DefaultState { | 27 public class LoadMultipleYearSelectState extends DefaultState { |
18 private static final long serialVersionUID = 1L; | 28 private static final long serialVersionUID = 1L; |
19 /** The log used in this class. */ | 29 /** The log used in this class. */ |
26 } | 36 } |
27 | 37 |
28 /** Year Select Widget. */ | 38 /** Year Select Widget. */ |
29 @Override | 39 @Override |
30 protected String getUIProvider() { | 40 protected String getUIProvider() { |
31 return "minfo.sedimentload_year_select"; // TODO: eigenes Panel oder allgemeineren Code | 41 return "sinfo.collision.load_year_select"; |
32 } | 42 } |
33 | 43 |
34 @Override | 44 @Override |
35 public boolean validate(final Artifact artifact) throws IllegalArgumentException { | 45 protected void appendItems(final Artifact artifact, final ElementCreator creator, final String name, final CallContext context, final Element select) { |
46 | |
47 try { | |
48 if ("years".equals(name)) { | |
49 | |
50 final AddTableDataHelper helper = new AddTableDataHelper(creator, select, "year", context.getMeta()); | |
51 | |
52 helper.addColumn(0, "pinfrom", "60", "common.client.ui.selection", "ICON", "CENTER", "from"); | |
53 helper.addColumn(1, "year", "80", "year", "INTEGER", "RIGHT", null); | |
54 | |
55 final CollisionAccess access = new CollisionAccess((SINFOArtifact) artifact); // Der River wurde im vorigen State bereits gesetzt | |
56 | |
57 final List<Collision> collisions = CollisionHibernateFactory.getCollisionsByRiver(access.getRiver()); | |
58 for (final Collision coll : collisions) { | |
59 final Integer year = coll.getYear(); | |
60 final Map<String, String> row = new HashMap<>(); | |
61 row.put("year", year.toString()); // Nullpointer? | |
62 try { | |
63 helper.addRow(row); | |
64 } | |
65 catch (final Exception e) { | |
66 e.printStackTrace(); | |
67 } | |
68 } | |
69 helper.submitMapToXml(); | |
70 } | |
71 } | |
72 catch (final IllegalArgumentException iae) { | |
73 iae.printStackTrace(); | |
74 } | |
75 } | |
76 | |
77 @Override | |
78 public void validate(final Artifact artifact, final CallContext cc) throws IllegalArgumentException { | |
36 // TODO: check verstehen | 79 // TODO: check verstehen |
37 | 80 |
38 final CollisionAccess access = new CollisionAccess((SINFOArtifact) artifact); | 81 final CollisionAccess access = new CollisionAccess((SINFOArtifact) artifact); |
39 | 82 |
40 // Second year should be later than first. | 83 // Second year should be later than first. |
41 | 84 |
42 if (access.getYears() == null || access.getYears().length == 0) | 85 // if (access.getYears() == null || access.getYears().length == 0) |
43 return true; | 86 // return true; |
44 // throw new IllegalArgumentException("error_years_wrong"); | 87 // throw new IllegalArgumentException("error_years_wrong"); |
45 | 88 |
46 return true; | 89 // return true; |
47 } | 90 } |
48 } | 91 } |
49 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 92 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |