01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 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.part;
11:
12: import org.eclipse.jface.action.ToolBarManager;
13: import org.eclipse.jface.viewers.TreeViewer;
14: import org.eclipse.swt.SWT;
15: import org.eclipse.swt.layout.GridData;
16: import org.eclipse.swt.layout.GridLayout;
17: import org.eclipse.swt.widgets.Composite;
18: import org.eclipse.swt.widgets.ToolBar;
19:
20: /**
21: * Class <code>DrillDownComposite</code> implements a simple web
22: * style navigation metaphor. Home, back, and "drill into" buttons are
23: * added to a tree viewer for easier navigation.
24: * <p>
25: * To use the DrillDownComposite..
26: * </p>
27: * <ul>
28: * <li>Create an instance of <code>DrillDownComposite</code>.</li>
29: * <li>Create a tree viewer. </li>
30: * <li>Pass the second tree viewer into the composite by
31: * calling <code>setChildTree</code>.</li>
32: * </ol>
33: */
34: public class DrillDownComposite extends Composite {
35: private ToolBarManager toolBarMgr;
36:
37: private TreeViewer fChildTree;
38:
39: private DrillDownAdapter adapter;
40:
41: /**
42: * Constructs a new DrillDownTreeViewer.
43: *
44: * @param parent the parent composite for this control
45: * @param style the SWT style for this control
46: */
47: public DrillDownComposite(Composite parent, int style) {
48: super (parent, style);
49: createNavigationButtons();
50: }
51:
52: /**
53: * Creates the navigation buttons for this viewer.
54: */
55: protected void createNavigationButtons() {
56: GridData gid;
57: GridLayout layout;
58:
59: // Define layout.
60: layout = new GridLayout();
61: layout.marginHeight = layout.marginWidth = layout.horizontalSpacing = layout.verticalSpacing = 0;
62: setLayout(layout);
63:
64: // Create a toolbar.
65: toolBarMgr = new ToolBarManager(SWT.FLAT);
66: ToolBar toolBar = toolBarMgr.createControl(this );
67: gid = new GridData();
68: gid.horizontalAlignment = GridData.FILL;
69: gid.verticalAlignment = GridData.BEGINNING;
70: toolBar.setLayoutData(gid);
71: }
72:
73: /**
74: * Sets the child viewer. This method should only be called once, after the
75: * viewer has been created.
76: *
77: * @param aViewer the new child viewer
78: */
79: public void setChildTree(TreeViewer aViewer) {
80: // Save viewer.
81: fChildTree = aViewer;
82:
83: // Create adapter.
84: adapter = new DrillDownAdapter(fChildTree);
85: adapter.addNavigationActions(toolBarMgr);
86: toolBarMgr.update(true);
87:
88: // Set tree layout.
89: fChildTree.getTree().setLayoutData(
90: new GridData(SWT.FILL, SWT.FILL, true, true));
91: layout();
92: }
93: }
|