KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > cheatsheets > composite > explorer > TreeContentProvider


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.internal.cheatsheets.composite.explorer;
13
14 import org.eclipse.jface.viewers.ITreeContentProvider;
15 import org.eclipse.jface.viewers.Viewer;
16 import org.eclipse.ui.internal.cheatsheets.composite.model.AbstractTask;
17 import org.eclipse.ui.internal.provisional.cheatsheets.ICompositeCheatSheet;
18 import org.eclipse.ui.internal.provisional.cheatsheets.ITaskGroup;
19
20 class TreeContentProvider implements ITreeContentProvider {
21     public Object JavaDoc[] getChildren(Object JavaDoc parentElement) {
22         if (parentElement instanceof ICompositeCheatSheet) {
23             final Object JavaDoc[] rootTask = {((ICompositeCheatSheet) parentElement).getRootTask()};
24             return rootTask;
25         }
26         if (parentElement instanceof ITaskGroup)
27             return ((ITaskGroup) parentElement).getSubtasks();
28         return new Object JavaDoc[0];
29     }
30
31     public Object JavaDoc getParent(Object JavaDoc element) {
32         if (element instanceof AbstractTask) {
33             return ((AbstractTask)element).getParent();
34         }
35         return null;
36     }
37
38     public boolean hasChildren(Object JavaDoc element) {
39         if (element instanceof ICompositeCheatSheet)
40             return true;
41         if (element instanceof ITaskGroup)
42             return ((ITaskGroup) element).getSubtasks().length > 0;
43         return false;
44     }
45
46     public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
47         return getChildren(inputElement);
48     }
49
50     public void dispose() {
51     }
52
53     public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {
54     }
55 }
56
Popular Tags