comparison flys-client/src/main/java/org/dive4elements/river/client/shared/model/ThemeList.java @ 5834:f507086aa94b

Repaired internal references.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 12:31:32 +0200
parents flys-client/src/main/java/de/intevation/flys/client/shared/model/ThemeList.java@e0f4ea518d59
children 821a02bbfb4e
comparison
equal deleted inserted replaced
5833:a2bdc0f524e8 5834:f507086aa94b
1 package de.intevation.flys.client.shared.model;
2
3 import java.io.Serializable;
4
5 import java.util.ArrayList;
6 import java.util.LinkedHashMap;
7 import java.util.List;
8
9
10 /**
11 * Data Model for list of themes (shown facets).
12 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
13 */
14 public class ThemeList implements Serializable {
15
16 public List<Theme> themes;
17
18
19 public ThemeList() {
20 }
21
22
23 public ThemeList(List<Theme> themes) {
24 this.themes = themes;
25 }
26
27
28 public List<Theme> getThemes() {
29 return themes;
30 }
31
32
33 public List<Theme> getActiveThemes() {
34 List<Theme> active = new ArrayList<Theme>();
35 List<Theme> all = getThemes();
36
37 if (all == null || all.isEmpty()) {
38 return active;
39 }
40
41 for (Theme theme: all) {
42 if (theme.getActive() == 1) {
43 active.add(theme);
44 }
45 }
46
47 return active;
48 }
49
50
51 public int getThemeCount() {
52 return themes.size();
53 }
54
55
56 /**
57 * Returns (first) theme of which the artifact has given uuid, null if none
58 * found.
59 * @param uuid Artifacts identifier for which to search theme.
60 * @return theme of which getArtifact() equals given uuid.
61 */
62 public Theme getTheme(String uuid) {
63 for (Theme theme: themes) {
64 if (theme.getArtifact().equals(uuid)) {
65 return theme;
66 }
67 }
68 return null;
69 }
70
71
72 /**
73 * Returns a theme at a specific position. <b>NOTE: Themes start at position
74 * 1. So, take care in loops, that might start at index 0!</b>
75 *
76 * @param pos The position of the desired theme.
77 *
78 * @return a theme.
79 */
80 public Theme getThemeAt(int pos) {
81 for (Theme theme: themes) {
82 if (theme.getPosition() == pos) {
83 return theme;
84 }
85 }
86
87 return null;
88 }
89
90
91 public void removeTheme(Theme theme) {
92 if (theme != null) {
93 themes.remove(theme);
94 }
95 }
96
97
98 public void addTheme(Theme theme) {
99 if (theme != null) {
100 themes.add(theme);
101 }
102 }
103
104
105 /**
106 * Modifies the order of themes in this list and the position of the
107 * <i>theme</i> itself.
108 *
109 * @param theme The theme which position has to be modified.
110 * @param newPos The new position.
111 */
112 public void setThemePosition(Theme theme, int newPos) {
113 int count = getThemeCount();
114 int oldPos = theme.getPosition();
115
116 if (newPos == oldPos || newPos > count || newPos < 1) {
117 return;
118 }
119
120 boolean moveUp = newPos < oldPos;
121
122 for (Theme aTheme: themes) {
123 int tmpPos = aTheme.getPosition();
124
125 if (theme.equals(aTheme)) {
126 theme.setPosition(newPos);
127 }
128 else if (tmpPos >= newPos && tmpPos < oldPos && moveUp) {
129 aTheme.setPosition(tmpPos+1);
130 }
131 else if (tmpPos <= newPos && tmpPos > oldPos && !moveUp) {
132 aTheme.setPosition(tmpPos-1);
133 }
134 }
135 }
136
137
138 /**
139 * Create a map from index to description of facets that have a given name.
140 * Only visible facets are taken into account.
141 * @param facetName name to match against facets whose info to put in map.
142 * @return mapping of index to description
143 */
144 public LinkedHashMap<String, String> toMapIndexDescription(String facetName) {
145 int count = getThemeCount();
146 LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>();
147 for (int i = 0; i <= count; i++) {
148 Theme theme = getThemeAt(i + 1);
149
150 if (theme == null || theme.getVisible() == 0) {
151 continue;
152 }
153
154 if (theme.getFacet().equals(facetName)) {
155 valueMap.put(String.valueOf(theme.getIndex()),
156 theme.getDescription());
157 }
158 }
159 return valueMap;
160 }
161
162
163 public LinkedHashMap<String, String>
164 toMapArtifactUUIDDescription(String facetName
165 ) {
166 int count = getThemeCount();
167 LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>();
168 for (int i = 0; i <= count; i++) {
169 Theme theme = getThemeAt(i + 1);
170
171 if (theme == null || theme.getVisible() == 0) {
172 continue;
173 }
174
175 if (theme.getFacet().equals(facetName)) {
176 valueMap.put(theme.getArtifact(),
177 theme.getDescription());
178 }
179 }
180 return valueMap;
181 }
182 }
183 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org