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.pde.internal.ui.editor.toc;
11:
12: import java.util.List;
13:
14: import org.eclipse.jface.viewers.ITreeContentProvider;
15: import org.eclipse.pde.internal.core.text.toc.TocModel;
16: import org.eclipse.pde.internal.core.text.toc.TocObject;
17: import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
18:
19: /**
20: * TocContentProvider
21: *TODO: Comment
22: */
23: public class TocContentProvider extends DefaultContentProvider
24: implements ITreeContentProvider {
25:
26: /**
27: *
28: */
29: public TocContentProvider() {
30: // NO-OP
31: }
32:
33: /* (non-Javadoc)
34: * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
35: */
36: public Object[] getChildren(Object parentElement) {
37: if (parentElement instanceof TocModel) {
38: return new Object[] { ((TocModel) parentElement).getToc() };
39: } else if (parentElement instanceof TocObject) {
40: List list = ((TocObject) parentElement).getChildren();
41: // List is never null
42: if (list.size() > 0) {
43: return list.toArray();
44: }
45: }
46: return new Object[0];
47: }
48:
49: /* (non-Javadoc)
50: * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
51: */
52: public Object getParent(Object element) {
53: if (element instanceof TocObject) {
54: return ((TocObject) element).getParent();
55: }
56: return null;
57: }
58:
59: /* (non-Javadoc)
60: * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
61: */
62: public boolean hasChildren(Object element) {
63: return (getChildren(element).length > 0);
64: }
65:
66: /* (non-Javadoc)
67: * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
68: */
69: public Object[] getElements(Object inputElement) {
70: return getChildren(inputElement);
71: }
72:
73: }
|