| 82 |
82 |
* If set, allows the command to notify its progress.
|
| 83 |
83 |
*/
|
| 84 |
84 |
protected IProgressMonitor monitor;
|
| 85 |
|
|
|
85 |
|
| 86 |
86 |
/**
|
| 87 |
87 |
* To manage the computing cancel with TreadDeath.
|
| 88 |
88 |
*/
|
| ... | ... | |
| 92 |
92 |
* To keep track of the parameters used for the last computing and to determine if the result is dirty.
|
| 93 |
93 |
*/
|
| 94 |
94 |
protected HashMap<String, Object> lastComputingParameters = new HashMap<String, Object>();
|
| 95 |
|
|
|
95 |
|
| 96 |
96 |
public HashMap<String, Object> getLastComputingParameters() {
|
| 97 |
97 |
return lastComputingParameters;
|
| 98 |
98 |
}
|
| 99 |
|
|
|
99 |
|
| 100 |
100 |
/**
|
| 101 |
101 |
* Creates a new TXMResult, child of the specified parent.
|
| 102 |
102 |
*
|
| ... | ... | |
| 129 |
129 |
this.dirty = true;
|
| 130 |
130 |
}
|
| 131 |
131 |
|
| 132 |
|
// /**
|
| 133 |
|
// * Creates a new TXMResult with no parent.
|
| 134 |
|
// */
|
| 135 |
|
// public TXMResult() {
|
| 136 |
|
// this(null);
|
| 137 |
|
// }
|
| 138 |
|
|
|
132 |
// /**
|
|
133 |
// * Creates a new TXMResult with no parent.
|
|
134 |
// */
|
|
135 |
// public TXMResult() {
|
|
136 |
// this(null);
|
|
137 |
// }
|
|
138 |
|
| 139 |
139 |
/**
|
| 140 |
140 |
* Creates and stores an UUID dedicated to persistence of this result.
|
| 141 |
141 |
*/
|
| ... | ... | |
| 167 |
167 |
lastComputingParameters.put(name, f.get(this));
|
| 168 |
168 |
}
|
| 169 |
169 |
}
|
| 170 |
|
|
|
170 |
|
| 171 |
171 |
protected Object getParameterForKey(String key) {
|
| 172 |
172 |
Field[] fields = this.getClass().getDeclaredFields();
|
| 173 |
173 |
for (Field f : fields) {
|
| ... | ... | |
| 186 |
186 |
}
|
| 187 |
187 |
return null;
|
| 188 |
188 |
}
|
| 189 |
|
|
|
189 |
|
| 190 |
190 |
protected boolean hasParameterChanged(String key) {
|
| 191 |
191 |
if ("".equals(key)) {
|
| 192 |
192 |
return false;
|
| ... | ... | |
| 199 |
199 |
return o.equals(newValue);
|
| 200 |
200 |
}
|
| 201 |
201 |
}
|
| 202 |
|
|
|
202 |
|
| 203 |
203 |
/**
|
| 204 |
204 |
* Updates the dirty states by comparing TXMResult @Parameter with previously used parameters in the compute() method.
|
| 205 |
205 |
*
|
| ... | ... | |
| 234 |
234 |
return dirty;
|
| 235 |
235 |
}
|
| 236 |
236 |
|
| 237 |
|
|
| 238 |
237 |
|
|
238 |
|
| 239 |
239 |
/**
|
| 240 |
240 |
* Updates the dirty state by comparing an old parameter with a new one.
|
| 241 |
241 |
*
|
| ... | ... | |
| 249 |
249 |
}
|
| 250 |
250 |
}
|
| 251 |
251 |
|
| 252 |
|
|
|
252 |
|
| 253 |
253 |
/**
|
| 254 |
254 |
* Gets the dirty states.
|
| 255 |
255 |
*
|
| ... | ... | |
| 280 |
280 |
return TXMPreferences.getKeys(this.preferencesNodeQualifier);
|
| 281 |
281 |
}
|
| 282 |
282 |
|
| 283 |
|
|
| 284 |
283 |
/**
|
| 285 |
284 |
* Gets the value of the specified key in parameters, local result node or
|
| 286 |
285 |
* default preferences nodes.
|
| ... | ... | |
| 347 |
346 |
return TXMPreferences.getString(key, this, this.preferencesNodeQualifier);
|
| 348 |
347 |
}
|
| 349 |
348 |
|
| 350 |
|
|
| 351 |
349 |
|
|
350 |
|
| 352 |
351 |
/**
|
| 353 |
352 |
* Stores the specified parameters pairs of key/value in a local node dedicated to the specified result. The node qualifier is generated by the <code>TXMResult.getUUID</code> method.
|
| 354 |
353 |
*
|
| ... | ... | |
| 359 |
358 |
TXMPreferences.putLocal(this, key, StringUtils.join(values, UNDERSCORE));
|
| 360 |
359 |
}
|
| 361 |
360 |
|
| 362 |
|
|
|
361 |
|
| 363 |
362 |
/**
|
| 364 |
363 |
* Stores the specified parameters pairs of key/value in a local node dedicated to the specified result. The node qualifier is generated by the <code>TXMResult.getUUID</code> method.
|
| 365 |
364 |
* @param result
|
| ... | ... | |
| 370 |
369 |
TXMPreferences.putLocal(this, key, value);;
|
| 371 |
370 |
}
|
| 372 |
371 |
|
| 373 |
|
|
|
372 |
|
| 374 |
373 |
/**
|
| 375 |
374 |
* Copies the parameters stored in the @Parameter Java class members : the pXXXXX named members to the local preferences node.
|
| 376 |
375 |
* Commands must define this method to persist their parameters.
|
| ... | ... | |
| 379 |
378 |
* @return
|
| 380 |
379 |
*/
|
| 381 |
380 |
// FIXME: need to implement here a generic way to save @Parameter
|
| 382 |
|
public boolean saveParameters() {
|
|
381 |
public boolean saveParameters() throws Exception {
|
|
382 |
Class clazz = this.getClass();
|
|
383 |
|
|
384 |
Field[] fields = clazz.getDeclaredFields();
|
|
385 |
for (Field f : fields) {
|
|
386 |
if (f.getClass().equals(Integer.class)) {
|
|
387 |
|
|
388 |
}
|
|
389 |
|
|
390 |
Parameter parameter = f.getAnnotation(Parameter.class);
|
|
391 |
if (parameter == null || parameter.type() != Parameter.COMPUTING) {
|
|
392 |
continue;
|
|
393 |
}
|
|
394 |
String key = parameter.key();
|
|
395 |
if ("".equals(key)) {
|
|
396 |
continue; // no preference key defined
|
|
397 |
}
|
|
398 |
|
|
399 |
// only manage simple types
|
|
400 |
if (f.getClass().equals(Integer.class) ||
|
|
401 |
f.getClass().equals(String.class) ||
|
|
402 |
f.getClass().equals(Double.class) ||
|
|
403 |
f.getClass().equals(Float.class) ||
|
|
404 |
f.getClass().equals(Boolean.class)) {
|
|
405 |
f.setAccessible(true); // set accessible to test the field values
|
|
406 |
try {
|
|
407 |
Object newValue = f.get(this);
|
|
408 |
if (newValue != null) {
|
|
409 |
this.saveParameter(key, newValue);
|
|
410 |
}
|
|
411 |
} catch (Exception e) {
|
|
412 |
e.printStackTrace();
|
|
413 |
}
|
|
414 |
}
|
|
415 |
}
|
| 383 |
416 |
return true;
|
| 384 |
417 |
}
|
| 385 |
|
|
|
418 |
|
| 386 |
419 |
/**
|
| 387 |
|
* Initialize the @Parameter class members objects
|
|
420 |
* Initialize the @Parameter class members objects using the default and persisted values in the Preference Store
|
| 388 |
421 |
*
|
| 389 |
|
* @param parameters
|
|
422 |
* extends and call this method if you need to load parameter with not simple type (e.g. Property, List, HashMap...)
|
|
423 |
*
|
| 390 |
424 |
* @return
|
|
425 |
* @throws Exception
|
|
426 |
* @throws Exception
|
| 391 |
427 |
*/
|
| 392 |
|
public abstract boolean setParameters(TXMParameters parameters) throws Exception;
|
|
428 |
public boolean loadParameters() throws Exception {
|
|
429 |
Class clazz = this.getClass();
|
| 393 |
430 |
|
|
431 |
Field[] fields = clazz.getDeclaredFields();
|
|
432 |
for (Field f : fields) {
|
|
433 |
|
|
434 |
Parameter parameter = f.getAnnotation(Parameter.class);
|
|
435 |
if (parameter == null || parameter.type() != Parameter.COMPUTING) {
|
|
436 |
continue;
|
|
437 |
}
|
|
438 |
String key = parameter.key();
|
|
439 |
if ("".equals(key)) {
|
|
440 |
continue; // no preference key defined
|
|
441 |
}
|
|
442 |
try {
|
|
443 |
f.setAccessible(true); // set accessible to test the field values
|
|
444 |
|
|
445 |
// only manage simple persisted types
|
|
446 |
if (f.getClass().equals(String.class)) {
|
|
447 |
String persistedValue = this.getStringParameterValue(key);
|
|
448 |
if (persistedValue != null) {
|
|
449 |
f.set(this, persistedValue);
|
|
450 |
}
|
|
451 |
} else if (f.getClass().equals(Integer.class)) {
|
|
452 |
Integer persistedValue = this.getIntParameterValue(key);
|
|
453 |
if (persistedValue != null) {
|
|
454 |
f.set(this, persistedValue);
|
|
455 |
}
|
|
456 |
} else if (f.getClass().equals( Double.class)) {
|
|
457 |
Double persistedValue = this.getDoubleParameterValue(key);
|
|
458 |
if (persistedValue != null) {
|
|
459 |
f.set(this, persistedValue);
|
|
460 |
}
|
|
461 |
} else if (f.getClass().equals(Float.class)) {
|
|
462 |
Float persistedValue = this.getFloatParameterValue(key);
|
|
463 |
if (persistedValue != null) {
|
|
464 |
f.set(this, persistedValue);
|
|
465 |
}
|
|
466 |
} else if (f.getClass().equals(Boolean.class)) {
|
|
467 |
Boolean persistedValue = this.getBooleanParameterValue(key);
|
|
468 |
if (persistedValue != null) {
|
|
469 |
f.set(this, persistedValue);
|
|
470 |
}
|
|
471 |
}
|
|
472 |
} catch (Exception e) {
|
|
473 |
e.printStackTrace();
|
|
474 |
}
|
|
475 |
}
|
|
476 |
return true;
|
|
477 |
}
|
|
478 |
|
| 394 |
479 |
/**
|
| 395 |
|
* Initialize the @Parameter class members objects using the default and persisted values in the Preference Store
|
|
480 |
* Initialize the @Parameter class members objects
|
| 396 |
481 |
*
|
|
482 |
* @param parameters
|
| 397 |
483 |
* @return
|
| 398 |
|
* @throws Exception
|
| 399 |
484 |
*/
|
| 400 |
|
public abstract boolean loadParameters() throws Exception;
|
|
485 |
public abstract boolean setParameters(TXMParameters parameters) throws Exception;
|
| 401 |
486 |
|
| 402 |
|
|
| 403 |
487 |
/**
|
| 404 |
488 |
* Deletes the object from its parent, also deletes the children. The <code>TXMResult.clean()</code> methods of this result and children results are applied before the deletion.
|
| 405 |
489 |
*
|
| ... | ... | |
| 966 |
1050 |
return false;
|
| 967 |
1051 |
}
|
| 968 |
1052 |
|
| 969 |
|
// // TODO THIS IS FUCKING LAZY LINE CODES OH YEAH YOU MAD BRO
|
|
1053 |
// // TODO THIS IS FUCKING LAZY LINE CODES OH YEAH YOU MAD BRO
|
| 970 |
1054 |
// TODO where do we put this parent compute ? :o
|
| 971 |
1055 |
// if (parent != null && !parent.getHasBeenComputedOnce()) { // parent must be computed at least one time
|
| 972 |
1056 |
// SJ: other way, test the object itself
|
| 973 |
1057 |
// if (parent != null && !this.getHasBeenComputedOnce()) {
|
| 974 |
1058 |
// this.parent.compute(update, monitor);
|
| 975 |
1059 |
// }
|
| 976 |
|
|
| 977 |
|
|
|
1060 |
|
|
1061 |
|
| 978 |
1062 |
if (!this._compute(update)) {
|
| 979 |
1063 |
|
| 980 |
1064 |
// FIXME: Debug
|
| ... | ... | |
| 1006 |
1090 |
*/
|
| 1007 |
1091 |
protected abstract boolean _compute(boolean update) throws Exception;
|
| 1008 |
1092 |
|
| 1009 |
|
// //removed for now, waiting to see if used
|
| 1010 |
|
// /**
|
| 1011 |
|
// * Computes the result according to specified command parameters.
|
| 1012 |
|
// * @param watcher
|
| 1013 |
|
// * @param parameters
|
| 1014 |
|
// * @return
|
| 1015 |
|
// */
|
| 1016 |
|
// public boolean compute(IProgressMonitor monitor, TXMParameters
|
| 1017 |
|
// parameters) throws Exception {
|
| 1018 |
|
// this.parameters = parameters;
|
| 1019 |
|
// return this.compute(monitor);
|
| 1020 |
|
// }
|
| 1021 |
|
|
| 1022 |
1093 |
/**
|
| 1023 |
|
* Copies the parameters from the local preference node if exists. Also fills the non existent parameters with the command default preferences.
|
| 1024 |
|
*/
|
| 1025 |
|
//public abstract void loadParameters();
|
| 1026 |
|
|
| 1027 |
|
/**
|
| 1028 |
1094 |
*
|
| 1029 |
1095 |
* @return the array of extensions to show in the FileDialog SWT widget
|
| 1030 |
1096 |
*/
|
| ... | ... | |
| 1080 |
1146 |
/**
|
| 1081 |
1147 |
* increment the process
|
| 1082 |
1148 |
*
|
| 1083 |
|
* @param amount
|
| 1084 |
|
* of work
|
|
1149 |
* @param amount of work
|
| 1085 |
1150 |
*/
|
| 1086 |
1151 |
public void worked(int amount) {
|
| 1087 |
1152 |
if (monitor != null) {
|