1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package org.ximtec.igesture.tool.view;
28
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Properties;
32
33 import org.ximtec.igesture.algorithm.Algorithm;
34 import org.ximtec.igesture.algorithm.rubine.RubineAlgorithm;
35 import org.ximtec.igesture.algorithm.rubine3d.Rubine3DAlgorithm;
36 import org.ximtec.igesture.algorithm.rubinebd.RubineAlgorithmBigDecimal;
37 import org.ximtec.igesture.algorithm.siger.SigerAlgorithm;
38 import org.ximtec.igesture.algorithm.signature.SiGridAlgorithm;
39 import org.ximtec.igesture.configuration.Configuration;
40 import org.ximtec.igesture.core.GestureSet;
41 import org.ximtec.igesture.core.TestSet;
42 import org.ximtec.igesture.storage.IStorageManager;
43 import org.ximtec.igesture.storage.StorageEngine;
44 import org.ximtec.igesture.storage.StorageManager;
45 import org.ximtec.igesture.tool.locator.RunnableService;
46 import org.ximtec.igesture.tool.util.PropertyChangeVisitor;
47 import org.ximtec.igesture.tool.util.StorageManagerProxy;
48 import org.ximtec.igesture.tool.view.admin.wrapper.GestureSetList;
49 import org.ximtec.igesture.tool.view.testbench.wrapper.AlgorithmList;
50 import org.ximtec.igesture.tool.view.testbench.wrapper.AlgorithmWrapper;
51 import org.ximtec.igesture.tool.view.testset.wrapper.TestSetList;
52
53
54
55
56
57
58
59
60 public class MainModel implements RunnableService {
61
62 public static final String IDENTIFIER = "MainModel";
63
64 private IStorageManager storageManager;
65
66 private MainController mainController;
67
68 private Properties properties;
69
70 private AlgorithmList algorithmList;
71
72 private boolean isActive;
73
74 private String projectName;
75
76
77
78
79
80
81
82
83
84
85
86 public MainModel(StorageEngine engine, MainController mainController, Properties properties) {
87 this.mainController = mainController;
88 this.properties = properties;
89 setStorageEngine(engine);
90 }
91
92
93
94
95
96
97 public List<GestureSet> getGestureSets() {
98 return storageManager.load(GestureSet.class);
99 }
100
101
102
103
104
105
106 public List<TestSet> getTestSets() {
107 return storageManager.load(TestSet.class);
108 }
109
110
111
112
113
114
115
116
117 public List<Class<? extends Algorithm>> getAlgorithms() {
118 List<Class<? extends Algorithm>> algorithms = new ArrayList<Class<? extends Algorithm>>();
119 algorithms.add(RubineAlgorithm.class);
120 algorithms.add(SigerAlgorithm.class);
121 algorithms.add(SiGridAlgorithm.class);
122 algorithms.add(Rubine3DAlgorithm.class);
123 algorithms.add(RubineAlgorithmBigDecimal.class);
124 return algorithms;
125 }
126
127
128
129
130
131
132 public List<Configuration> getConfigurations() {
133 return storageManager.load(Configuration.class);
134 }
135
136
137
138
139
140
141
142 public GestureSetList getGestureSetList() {
143 GestureSetList rootSet = new GestureSetList(this);
144 rootSet.addPropertyChangeListener(mainController);
145 return rootSet;
146 }
147
148 public TestSetList getTestSetList() {
149 TestSetList testSetList = new TestSetList(this);
150 testSetList.addPropertyChangeListener(mainController);
151 return testSetList;
152 }
153
154
155
156
157
158
159
160
161
162
163
164 public synchronized AlgorithmList getAlgorithmList() {
165 if (algorithmList == null) {
166 algorithmList = new AlgorithmList(this);
167
168 for (Class<? extends Algorithm> algorithmClass : getAlgorithms()) {
169 AlgorithmWrapper algorithmWrapper = new AlgorithmWrapper(this, algorithmClass);
170 algorithmWrapper.addPropertyChangeListener(mainController);
171 algorithmList.addAlgorithm(algorithmWrapper);
172 }
173
174 algorithmList.addPropertyChangeListener(mainController);
175 }
176 return algorithmList;
177 }
178
179 @Override
180 public String getIdentifier() {
181 return IDENTIFIER;
182 }
183
184 @Override
185 public void reset() {
186
187 }
188
189 @Override
190 public void start() {
191
192 }
193
194 @Override
195 public void stop() {
196 storageManager.dispose();
197 }
198
199
200
201
202
203
204
205 public IStorageManager getStorageManager() {
206 return storageManager;
207 }
208
209
210
211
212
213
214
215
216 public void setStorageEngine(StorageEngine storageEngine) {
217 PropertyChangeVisitor visitor = new PropertyChangeVisitor(mainController);
218 this.storageManager = StorageManagerProxy.newInstance(new StorageManager(storageEngine), visitor);
219 isActive = storageEngine != null;
220 }
221
222
223
224
225
226
227
228
229 public void setProperty(String key, String value) {
230 properties.setProperty(key, value);
231 }
232
233
234
235
236
237
238
239
240 public String getProperty(String key) {
241 return properties.getProperty(key);
242 }
243
244
245
246
247
248
249 public void removeProperty(String key) {
250 properties.remove(key);
251 }
252
253 public Properties getProperties() {
254 return properties;
255 }
256
257 public boolean isActive() {
258 return isActive;
259 }
260
261 public void setProjectName(String projectName) {
262 this.projectName = projectName;
263 }
264
265 public String getProjectName() {
266 return projectName;
267 }
268
269 }