1 package eu
.etaxonomy
.taxeditor
;
3 import java
.util
.ArrayList
;
5 import org
.eclipse
.jface
.viewers
.IStructuredContentProvider
;
6 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
7 import org
.eclipse
.jface
.viewers
.LabelProvider
;
8 import org
.eclipse
.jface
.viewers
.TreeViewer
;
9 import org
.eclipse
.jface
.viewers
.Viewer
;
10 import org
.eclipse
.swt
.SWT
;
11 import org
.eclipse
.swt
.graphics
.Image
;
12 import org
.eclipse
.swt
.widgets
.Composite
;
13 import org
.eclipse
.ui
.ISharedImages
;
14 import org
.eclipse
.ui
.PlatformUI
;
15 import org
.eclipse
.ui
.part
.ViewPart
;
17 public class NavigationView
extends ViewPart
{
18 public static final String ID
= "eu.etaxonomy.taxeditor.navigationView";
19 private TreeViewer viewer
;
23 private TreeParent parent
;
25 public TreeObject(String name
) {
28 public String
getName() {
31 public void setParent(TreeParent parent
) {
34 public TreeParent
getParent() {
37 public String
toString() {
42 class TreeParent
extends TreeObject
{
43 private ArrayList children
;
44 public TreeParent(String name
) {
46 children
= new ArrayList();
48 public void addChild(TreeObject child
) {
50 child
.setParent(this);
52 public void removeChild(TreeObject child
) {
53 children
.remove(child
);
54 child
.setParent(null);
56 public TreeObject
[] getChildren() {
57 return (TreeObject
[]) children
.toArray(new TreeObject
[children
.size()]);
59 public boolean hasChildren() {
60 return children
.size()>0;
64 class ViewContentProvider
implements IStructuredContentProvider
,
65 ITreeContentProvider
{
67 public void inputChanged(Viewer v
, Object oldInput
, Object newInput
) {
70 public void dispose() {
73 public Object
[] getElements(Object parent
) {
74 return getChildren(parent
);
77 public Object
getParent(Object child
) {
78 if (child
instanceof TreeObject
) {
79 return ((TreeObject
)child
).getParent();
84 public Object
[] getChildren(Object parent
) {
85 if (parent
instanceof TreeParent
) {
86 return ((TreeParent
)parent
).getChildren();
91 public boolean hasChildren(Object parent
) {
92 if (parent
instanceof TreeParent
)
93 return ((TreeParent
)parent
).hasChildren();
98 class ViewLabelProvider
extends LabelProvider
{
100 public String
getText(Object obj
) {
101 return obj
.toString();
103 public Image
getImage(Object obj
) {
104 String imageKey
= ISharedImages
.IMG_OBJ_ELEMENT
;
105 if (obj
instanceof TreeParent
)
106 imageKey
= ISharedImages
.IMG_OBJ_FOLDER
;
107 return PlatformUI
.getWorkbench().getSharedImages().getImage(imageKey
);
112 * We will set up a dummy model to initialize tree heararchy. In real
113 * code, you will connect to a real model and expose its hierarchy.
115 private TreeObject
createDummyModel() {
116 TreeObject to1
= new TreeObject("Pilosella piloselloides (Vill.) Soják");
117 TreeObject to2
= new TreeObject("Pilosella pavichii (Heuff.) Arv.-Touv.");
118 TreeObject to3
= new TreeObject("Pilosella vahlii (Froel.) F. W. Schultz & Sch. Bip.");
119 TreeParent p1
= new TreeParent("Pilosella treatment");
124 TreeParent p2
= new TreeParent("Some other treatment");
126 TreeParent root
= new TreeParent("");
133 * This is a callback that will allow us to create the viewer and initialize
136 public void createPartControl(Composite parent
) {
137 viewer
= new TreeViewer(parent
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.BORDER
);
138 viewer
.setContentProvider(new ViewContentProvider());
139 viewer
.setLabelProvider(new ViewLabelProvider());
140 viewer
.setInput(createDummyModel());
144 * Passing the focus request to the viewer's control.
146 public void setFocus() {
147 viewer
.getControl().setFocus();