01: package net.refractions.udig.validation.ui;
02:
03: import net.refractions.udig.validation.ValidationProcessor;
04:
05: import org.eclipse.jface.viewers.ITreeContentProvider;
06: import org.eclipse.jface.viewers.Viewer;
07: import org.geotools.validation.dto.PlugInDTO;
08: import org.geotools.validation.dto.TestDTO;
09:
10: /**
11: * Content provider for representing launch configuration types & launch configurations in a tree.
12: *
13: */
14: public class ValidationTreeContentProvider implements
15: ITreeContentProvider { //, ICheckable {
16:
17: /**
18: * Empty Object array
19: */
20: private static final Object[] EMPTY_ARRAY = new Object[0];
21:
22: /**
23: * The Shell context
24: */
25: private ValidationProcessor validationProcessor;
26:
27: public ValidationTreeContentProvider() {
28: }
29:
30: /**
31: * Returns the children of the element:
32: * - for a ValidationProcessor, returns the list of available validations (plugins)
33: * - for a validation plugin, returns a list of configured validation tests
34: */
35: public Object[] getChildren(Object parentElement) {
36: if (parentElement instanceof ValidationProcessor) {
37: // this is the root of our tree; at this point we want to return
38: // the list of all available plugins as children
39: ValidationProcessor processor = (ValidationProcessor) parentElement;
40: return processor.getPlugins().toArray();
41: } else if (parentElement instanceof PlugInDTO) {
42: // this is a plugin (validation test), so we'll grab instances of
43: // each test for this type
44: return validationProcessor.getTests(parentElement);
45: }
46: return EMPTY_ARRAY;
47: }
48:
49: /**
50: * Return the available elements.
51: *
52: * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
53: */
54: public Object[] getElements(Object inputElement) {
55: return getChildren(inputElement);
56: }
57:
58: /* (non-Javadoc)
59: * @see org.eclipse.jface.viewers.IContentProvider#dispose()
60: */
61: public void dispose() {
62: }
63:
64: /* (non-Javadoc)
65: * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
66: */
67: public void inputChanged(Viewer viewer, Object oldInput,
68: Object newInput) {
69: if (newInput == oldInput)
70: return;
71: ValidationProcessor newProcessor = (ValidationProcessor) newInput;
72: validationProcessor = newProcessor;
73: }
74:
75: public Object getParent(Object element) {
76: if (element instanceof TestDTO) {
77: TestDTO test = (TestDTO) element;
78: return test.getPlugIn();
79: }
80: return null;
81: }
82:
83: public boolean hasChildren(Object element) {
84: if (element instanceof TestDTO) {
85: return false;
86: } else if (element instanceof PlugInDTO) {
87: //count tests for this plugin
88: int count = validationProcessor.getTests(element).length;
89: if (count > 0)
90: return true;
91: else
92: return false;
93: }
94: return false;
95: }
96: }
|