9063
|
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 |
9076
|
11 import java.util.HashMap; |
|
12 import java.util.List; |
|
13 import java.util.Map; |
|
14 |
9063
|
15 import org.apache.log4j.Logger; |
9076
|
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; |
|
20 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; |
|
21 import org.dive4elements.river.artifacts.states.AddTableDataHelper; |
9063
|
22 import org.dive4elements.river.artifacts.states.DefaultState; |
9076
|
23 import org.dive4elements.river.model.sinfo.Collision; |
|
24 import org.w3c.dom.Element; |
9063
|
25 |
9073
|
26 public class LoadMultipleEpochSelectState extends DefaultState { |
9063
|
27 /** The log used in this class. */ |
9073
|
28 private static Logger log = Logger.getLogger(LoadMultipleEpochSelectState.class); |
9063
|
29 |
|
30 /** |
|
31 * The default constructor that initializes an empty State object. |
|
32 */ |
9073
|
33 public LoadMultipleEpochSelectState() { |
9063
|
34 } |
|
35 |
|
36 @Override |
|
37 protected String getUIProvider() { |
|
38 return "sinfo.collision.load_epoch_select"; |
|
39 } |
9076
|
40 |
|
41 @Override |
|
42 protected void appendItems(final Artifact artifact, final ElementCreator creator, final String name, final CallContext context, final Element select) { |
|
43 |
|
44 try { |
|
45 if ("epochs".equals(name)) { |
|
46 |
|
47 final AddTableDataHelper helper = new AddTableDataHelper(creator, select, "year", context.getMeta()); |
|
48 |
|
49 helper.addColumn(0, "pinfrom", "40", "common.client.ui.from", "ICON", "CENTER", "from"); |
|
50 helper.addColumn(1, "pinto", "40", "common.client.ui.to", "ICON", "CENTER", "to"); |
|
51 helper.addColumn(2, "year", "60", "year", "INTEGER", "LEFT", null); |
|
52 |
|
53 final CollisionAccess access = new CollisionAccess((SINFOArtifact) artifact); // Der River wurde im vorigen State bereits gesetzt |
|
54 |
|
55 final List<Collision> collisions = CollisionHibernateFactory.getCollisionsByRiver(access.getRiver()); |
|
56 for (final Collision coll : collisions) { // TODO: Filter on Range (?) |
|
57 final Integer year = coll.getYear(); |
|
58 final Map<String, String> row = new HashMap<>(); |
|
59 row.put("year", year.toString()); // Nullpointer? |
|
60 try { |
|
61 helper.addRow(row); |
|
62 } |
|
63 catch (final Exception e) { |
|
64 e.printStackTrace(); |
|
65 } |
|
66 } |
|
67 helper.submitMapToXml(); |
|
68 } |
|
69 } |
|
70 catch (final IllegalArgumentException iae) { |
|
71 iae.printStackTrace(); |
|
72 } |
|
73 } |
9063
|
74 } |