Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerArrayData.java @ 1527:252c22237fe7
Added new Data classes for integer array and integer options.
flys-client/trunk@3725 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 19 Jan 2012 16:59:43 +0000 |
parents | |
children | 0f2b94408bd1 |
comparison
equal
deleted
inserted
replaced
1526:4a5e65551923 | 1527:252c22237fe7 |
---|---|
1 package de.intevation.flys.client.shared.model; | |
2 | |
3 | |
4 public class IntegerArrayData implements Data { | |
5 | |
6 protected String label; | |
7 protected String description; | |
8 | |
9 protected int[] values; | |
10 | |
11 | |
12 public IntegerArrayData() { | |
13 } | |
14 | |
15 | |
16 public IntegerArrayData(String label, String description, int[] values) { | |
17 this.label = label; | |
18 this.description = description; | |
19 this.values = values; | |
20 } | |
21 | |
22 | |
23 /** | |
24 * Returns the label of the item. | |
25 * | |
26 * @return the label. | |
27 */ | |
28 public String getLabel() { | |
29 return label; | |
30 } | |
31 | |
32 | |
33 /** | |
34 * Returns the description of the item. | |
35 * | |
36 * @return the description. | |
37 */ | |
38 public String getDescription() { | |
39 return description; | |
40 } | |
41 | |
42 | |
43 /** | |
44 * Returns the type of the item. | |
45 * | |
46 * @return the type. | |
47 */ | |
48 public String getType() { | |
49 return "intarray"; | |
50 } | |
51 | |
52 | |
53 /** | |
54 * Returns a DataItem which value is a string that consists of the integer | |
55 * values separated by a ';'. | |
56 * | |
57 * @return the DataItem. | |
58 */ | |
59 public DataItem[] getItems() { | |
60 if (values == null || values.length == 0) { | |
61 return new DataItem[0]; | |
62 } | |
63 | |
64 StringBuilder sb = new StringBuilder(); | |
65 boolean first = true; | |
66 | |
67 for (int value: values) { | |
68 if (first) { | |
69 sb.append(String.valueOf(value)); | |
70 } | |
71 else { | |
72 sb.append(";" + String.valueOf(value)); | |
73 } | |
74 } | |
75 | |
76 String value = sb.toString(); | |
77 DataItem item = new DefaultDataItem(value, value, value); | |
78 | |
79 return new DataItem[] { item }; | |
80 } | |
81 | |
82 | |
83 /** | |
84 * @return always null. | |
85 */ | |
86 public DataItem getDefault() { | |
87 return null; | |
88 } | |
89 } | |
90 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |