9058
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
|
2 * Software engineering by Intevation GmbH |
|
3 * |
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
|
6 * documentation coming with Dive4Elements River for details. |
|
7 */ |
|
8 |
|
9 package org.dive4elements.river.artifacts.sinfo.collision; |
|
10 |
9074
|
11 import java.util.HashMap; |
|
12 import java.util.List; |
|
13 import java.util.Map; |
|
14 |
9058
|
15 import org.apache.log4j.Logger; |
|
16 import org.dive4elements.artifacts.Artifact; |
9074
|
17 import org.dive4elements.artifacts.CallContext; |
|
18 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; |
|
19 import org.dive4elements.river.artifacts.model.CollisionHibernateFactory; |
9067
|
20 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; |
9074
|
21 import org.dive4elements.river.artifacts.states.AddTableDataHelper; |
9058
|
22 import org.dive4elements.river.artifacts.states.DefaultState; |
9074
|
23 import org.dive4elements.river.model.sinfo.Collision; |
|
24 import org.w3c.dom.Element; |
9058
|
25 |
|
26 /** State in which to fetch years for sedminent load calculation. */ |
9073
|
27 public class LoadMultipleYearSelectState extends DefaultState { |
9058
|
28 private static final long serialVersionUID = 1L; |
|
29 /** The log used in this class. */ |
9073
|
30 private static Logger log = Logger.getLogger(LoadMultipleYearSelectState.class); |
9058
|
31 |
|
32 /** |
|
33 * The default constructor that initializes an empty State object. |
|
34 */ |
9073
|
35 public LoadMultipleYearSelectState() { |
9058
|
36 } |
|
37 |
|
38 /** Year Select Widget. */ |
|
39 @Override |
|
40 protected String getUIProvider() { |
9074
|
41 return "sinfo.collision.load_year_select"; |
9058
|
42 } |
|
43 |
|
44 @Override |
9074
|
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"); |
9076
|
53 helper.addColumn(1, "year", "60", "year", "INTEGER", "LEFT", null); |
9074
|
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 { |
9067
|
79 // TODO: check verstehen |
|
80 |
|
81 final CollisionAccess access = new CollisionAccess((SINFOArtifact) artifact); |
9058
|
82 |
|
83 // Second year should be later than first. |
9067
|
84 |
9074
|
85 // if (access.getYears() == null || access.getYears().length == 0) |
|
86 // return true; |
9058
|
87 // throw new IllegalArgumentException("error_years_wrong"); |
|
88 |
9074
|
89 // return true; |
9058
|
90 } |
|
91 } |
|
92 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |