1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package com.gridsystems.config.tools.console;
25
26 import java.util.ArrayList;
27 import java.util.Iterator;
28 import java.util.List;
29 import java.util.ResourceBundle;
30
31
32
33
34
35
36
37 public class GroupField extends Field {
38
39
40
41 protected String title;
42
43
44
45
46 protected List<Field> fields = new ArrayList<Field>();
47
48
49
50
51
52
53
54 public GroupField(ResourceBundle bundle, String title) {
55 this(bundle, title, null);
56 }
57
58
59
60
61
62
63
64
65 public GroupField(ResourceBundle bundle, String title, List<Field> fields) {
66 super(bundle);
67 if (fields == null) {
68 fields = new ArrayList<Field>();
69 }
70 this.title = title;
71 this.fields = new ArrayList<Field>(fields);
72 }
73
74
75
76
77
78
79 public void addField(Field field) {
80 this.fields.add(field);
81 }
82
83
84
85
86
87
88
89 public Field removeField(int pos) {
90 return (Field)this.fields.remove(pos);
91 }
92
93
94
95
96 public void clearFields() {
97 this.fields.clear();
98 }
99
100
101
102
103
104
105 public List getFields() {
106 return this.fields;
107 }
108
109
110
111
112
113
114 public ConsoleViewAction[] getActions() {
115 List<ConsoleViewAction> list = getActionList();
116
117 ConsoleViewAction[] actions = new ConsoleViewAction[list.size()];
118 list.toArray(actions);
119 return actions;
120 }
121
122
123
124
125
126
127 public List<ConsoleViewAction> getActionList() {
128 ArrayList<ConsoleViewAction> list = new ArrayList<ConsoleViewAction>();
129 for (Iterator it = fields.iterator(); it.hasNext();) {
130 Field field = (Field)it.next();
131 if (field instanceof ConsoleViewAction) {
132 list.add((ConsoleViewAction)field);
133 }
134 }
135 return list;
136 }
137
138
139
140
141 public String[] getContents() {
142 ArrayList<String> list = new ArrayList<String>();
143
144 list.add(getString(title));
145
146 for (Iterator it = fields.iterator(); it.hasNext();) {
147 Field f = (Field)it.next();
148 String[] lines = f.getContents();
149 for (int i = 0; i < lines.length; i++) {
150 list.add(lines[i]);
151 }
152 }
153 String[] contents = new String[list.size()];
154 list.toArray(contents);
155 return contents;
156 }
157 }