01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.tests.views.properties.tabbed.dynamic.views;
11:
12: import org.eclipse.jface.viewers.IStructuredContentProvider;
13: import org.eclipse.jface.viewers.ITreeContentProvider;
14: import org.eclipse.jface.viewers.Viewer;
15: import org.eclipse.ui.tests.views.properties.tabbed.dynamic.model.DynamicTestsElement;
16:
17: /**
18: * A content provider for nodes in the tree of the dynamic tests view.
19: *
20: * @author Anthony Hunter
21: */
22: public class DynamicTestsViewContentProvider implements
23: IStructuredContentProvider, ITreeContentProvider {
24:
25: private DynamicTestsTreeNode invisibleRoot;
26:
27: private final DynamicTestsView view;
28:
29: public DynamicTestsViewContentProvider(
30: DynamicTestsView dynamicTestsView) {
31: super ();
32: this .view = dynamicTestsView;
33: }
34:
35: public void dispose() {
36: //
37: }
38:
39: public Object[] getChildren(Object parent) {
40: if (parent instanceof DynamicTestsTreeNode) {
41: return ((DynamicTestsTreeNode) parent).getChildren();
42: }
43: return new Object[0];
44: }
45:
46: public Object[] getElements(Object parent) {
47: if (parent.equals(this .view.getViewSite())) {
48: if (invisibleRoot == null)
49: initialize();
50: return getChildren(invisibleRoot);
51: }
52: return getChildren(parent);
53: }
54:
55: public DynamicTestsTreeNode getInvisibleRoot() {
56: return invisibleRoot;
57: }
58:
59: public Object getParent(Object child) {
60: if (child instanceof DynamicTestsTreeNode) {
61: return ((DynamicTestsTreeNode) child).getParent();
62: }
63: return null;
64: }
65:
66: public boolean hasChildren(Object parent) {
67: if (parent instanceof DynamicTestsTreeNode)
68: return ((DynamicTestsTreeNode) parent).hasChildren();
69: return false;
70: }
71:
72: public void initialize() {
73: String elements[] = new String[] { "icons/black_triangle.gif",//$NON-NLS-1$
74: "icons/blue_circle.gif",//$NON-NLS-1$
75: "icons/blue_square.gif",//$NON-NLS-1$
76: "icons/blue_triangle.gif",//$NON-NLS-1$
77: "icons/green_circle.gif",//$NON-NLS-1$
78: "icons/green_square.gif",//$NON-NLS-1$
79: "icons/green_triangle.gif",//$NON-NLS-1$
80: "icons/red_circle.gif",//$NON-NLS-1$
81: "icons/red_square.gif",//$NON-NLS-1$
82: "icons/red_star.gif",//$NON-NLS-1$
83: "icons/red_triangle.gif" };//$NON-NLS-1$
84: DynamicTestsTreeNode[] nodes = new DynamicTestsTreeNode[elements.length];
85: for (int i = 0; i < elements.length; i++) {
86: DynamicTestsElement dynamicTestsElement = new DynamicTestsElement(
87: view, elements[i]);
88: nodes[i] = new DynamicTestsTreeNode(dynamicTestsElement);
89: }
90: invisibleRoot = new DynamicTestsTreeNode(null);
91: invisibleRoot.setChildren(nodes);
92: }
93:
94: public void inputChanged(Viewer v, Object oldInput, Object newInput) {
95: //
96: }
97: }
|