KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > part > DrillDownComposite


1 /*******************************************************************************
2  * Copyright (c) 2000, 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 package org.eclipse.ui.part;
12
13 import org.eclipse.jface.action.ToolBarManager;
14 import org.eclipse.jface.viewers.TreeViewer;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.layout.GridLayout;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.ToolBar;
20
21 /**
22  * Class <code>DrillDownComposite</code> implements a simple web
23  * style navigation metaphor. Home, back, and "drill into" buttons are
24  * added to a tree viewer for easier navigation.
25  * <p>
26  * To use the DrillDownComposite..
27  * </p>
28  * <ul>
29  * <li>Create an instance of <code>DrillDownComposite</code>.</li>
30  * <li>Create a tree viewer. </li>
31  * <li>Pass the second tree viewer into the composite by
32  * calling <code>setChildTree</code>.</li>
33  * </ol>
34  */

35 public class DrillDownComposite extends Composite {
36     private ToolBarManager toolBarMgr;
37
38     private TreeViewer fChildTree;
39
40     private DrillDownAdapter adapter;
41
42     /**
43      * Constructs a new DrillDownTreeViewer.
44      *
45      * @param parent the parent composite for this control
46      * @param style the SWT style for this control
47      */

48     public DrillDownComposite(Composite parent, int style) {
49         super(parent, style);
50         createNavigationButtons();
51     }
52
53     /**
54      * Creates the navigation buttons for this viewer.
55      */

56     protected void createNavigationButtons() {
57         GridData gid;
58         GridLayout layout;
59
60         // Define layout.
61
layout = new GridLayout();
62         layout.marginHeight = layout.marginWidth = layout.horizontalSpacing = layout.verticalSpacing = 0;
63         setLayout(layout);
64
65         // Create a toolbar.
66
toolBarMgr = new ToolBarManager(SWT.FLAT);
67         ToolBar toolBar = toolBarMgr.createControl(this);
68         gid = new GridData();
69         gid.horizontalAlignment = GridData.FILL;
70         gid.verticalAlignment = GridData.BEGINNING;
71         toolBar.setLayoutData(gid);
72     }
73
74     /**
75      * Sets the child viewer. This method should only be called once, after the
76      * viewer has been created.
77      *
78      * @param aViewer the new child viewer
79      */

80     public void setChildTree(TreeViewer aViewer) {
81         // Save viewer.
82
fChildTree = aViewer;
83
84         // Create adapter.
85
adapter = new DrillDownAdapter(fChildTree);
86         adapter.addNavigationActions(toolBarMgr);
87         toolBarMgr.update(true);
88
89         // Set tree layout.
90
fChildTree.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
91         layout();
92     }
93 }
94
Popular Tags