KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > view > DependenciesViewTreePage


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.pde.internal.ui.view;
12
13 import org.eclipse.jface.action.Action;
14 import org.eclipse.jface.action.IMenuManager;
15 import org.eclipse.jface.action.IStatusLineManager;
16 import org.eclipse.jface.action.IToolBarManager;
17 import org.eclipse.jface.viewers.ITreeContentProvider;
18 import org.eclipse.jface.viewers.StructuredViewer;
19 import org.eclipse.jface.viewers.TreeViewer;
20 import org.eclipse.pde.internal.ui.PDEPluginImages;
21 import org.eclipse.pde.internal.ui.PDEUIMessages;
22 import org.eclipse.pde.internal.ui.wizards.ListUtil;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.events.DisposeEvent;
25 import org.eclipse.swt.events.DisposeListener;
26 import org.eclipse.swt.widgets.Composite;
27
28 public class DependenciesViewTreePage extends DependenciesViewPage {
29     class CollapseAllAction extends Action {
30         public CollapseAllAction() {
31             super();
32             setText(PDEUIMessages.DependenciesViewTreePage_CollapseAllAction_label);
33             setDescription(PDEUIMessages.DependenciesViewTreePage_CollapseAllAction_description);
34             setToolTipText(PDEUIMessages.DependenciesViewTreePage_CollapseAllAction_tooltip);
35             setImageDescriptor(PDEPluginImages.DESC_COLLAPSE_ALL);
36             setDisabledImageDescriptor(PDEPluginImages.DESC_COLLAPSE_ALL);
37         }
38
39         /*
40          * (non-Javadoc)
41          *
42          * @see org.eclipse.jface.action.Action#run()
43          */

44         public void run() {
45             super.run();
46             fTreeViewer.collapseAll();
47         }
48     }
49
50     ITreeContentProvider fContentProvider;
51
52     TreeViewer fTreeViewer;
53
54     public DependenciesViewTreePage(DependenciesView view,
55             ITreeContentProvider contentProvider) {
56         super(view);
57         fContentProvider = contentProvider;
58     }
59
60     /*
61      * (non-Javadoc)
62      *
63      * @see org.eclipse.pde.internal.ui.view.DependenciesViewPage#createViewer(org.eclipse.swt.widgets.Composite)
64      */

65     protected StructuredViewer createViewer(Composite parent) {
66         fTreeViewer = new TreeViewer(parent, SWT.MULTI | SWT.V_SCROLL
67                 | SWT.H_SCROLL);
68         fTreeViewer.setContentProvider(fContentProvider);
69         final DependenciesLabelProvider labelProvider = new DependenciesLabelProvider(
70                 true);
71         fTreeViewer.setLabelProvider(labelProvider);
72         fTreeViewer.getControl().addDisposeListener(new DisposeListener() {
73             public void widgetDisposed(DisposeEvent e) {
74                 labelProvider.dispose();
75             }
76         });
77         fTreeViewer.setSorter(ListUtil.PLUGIN_SORTER);
78         fTreeViewer.setAutoExpandLevel(2);
79
80         return fTreeViewer;
81     }
82
83     /*
84      * (non-Javadoc)
85      *
86      * @see org.eclipse.ui.part.Page#makeContributions(org.eclipse.jface.action.IMenuManager,
87      * org.eclipse.jface.action.IToolBarManager,
88      * org.eclipse.jface.action.IStatusLineManager)
89      */

90     public void makeContributions(IMenuManager menuManager,
91             IToolBarManager toolBarManager, IStatusLineManager statusLineManager) {
92         super.makeContributions(menuManager, toolBarManager, statusLineManager);
93         if (toolBarManager.find(DependenciesView.TREE_ACTION_GROUP) != null)
94             toolBarManager.prependToGroup(DependenciesView.TREE_ACTION_GROUP,
95                     new CollapseAllAction());
96         else
97             toolBarManager.add(new CollapseAllAction());
98     }
99 }
100
Popular Tags