KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > views > dependencies > DependenciesViewTreePage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.views.dependencies;
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.jface.viewers.Viewer;
21 import org.eclipse.jface.viewers.ViewerFilter;
22 import org.eclipse.osgi.service.resolver.BundleSpecification;
23 import org.eclipse.osgi.service.resolver.ImportPackageSpecification;
24 import org.eclipse.pde.internal.ui.PDEPluginImages;
25 import org.eclipse.pde.internal.ui.PDEUIMessages;
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.events.DisposeEvent;
28 import org.eclipse.swt.events.DisposeListener;
29 import org.eclipse.swt.widgets.Composite;
30 import org.osgi.framework.Constants;
31
32 public class DependenciesViewTreePage extends DependenciesViewPage {
33     class CollapseAllAction extends Action {
34         public CollapseAllAction() {
35             super();
36             setText(PDEUIMessages.DependenciesViewTreePage_CollapseAllAction_label);
37             setDescription(PDEUIMessages.DependenciesViewTreePage_CollapseAllAction_description);
38             setToolTipText(PDEUIMessages.DependenciesViewTreePage_CollapseAllAction_tooltip);
39             setImageDescriptor(PDEPluginImages.DESC_COLLAPSE_ALL);
40             setDisabledImageDescriptor(PDEPluginImages.DESC_COLLAPSE_ALL);
41         }
42
43         /*
44          * (non-Javadoc)
45          *
46          * @see org.eclipse.jface.action.Action#run()
47          */

48         public void run() {
49             super.run();
50             fTreeViewer.collapseAll();
51         }
52     }
53     
54     class OptionalFilter extends ViewerFilter {
55         
56         public boolean select(Viewer v, Object JavaDoc parent, Object JavaDoc element) {
57             if (element instanceof BundleSpecification) {
58                 return !((BundleSpecification)element).isOptional();
59             } else if (element instanceof ImportPackageSpecification)
60                 return !Constants.RESOLUTION_OPTIONAL.equals(
61                         ((ImportPackageSpecification)element).getDirective(Constants.RESOLUTION_DIRECTIVE));
62             return true;
63         }
64     }
65
66     TreeViewer fTreeViewer;
67     private OptionalFilter fHideOptionalFilter = new OptionalFilter();
68
69     public DependenciesViewTreePage(DependenciesView view,
70             ITreeContentProvider contentProvider) {
71         super(view, contentProvider);
72     }
73
74     /*
75      * (non-Javadoc)
76      *
77      * @see org.eclipse.pde.internal.ui.view.DependenciesViewPage#createViewer(org.eclipse.swt.widgets.Composite)
78      */

79     protected StructuredViewer createViewer(Composite parent) {
80         fTreeViewer = new TreeViewer(parent, SWT.MULTI | SWT.V_SCROLL
81                 | SWT.H_SCROLL);
82         fTreeViewer.setContentProvider(fContentProvider);
83         final DependenciesLabelProvider labelProvider = new DependenciesLabelProvider(
84                 true);
85         fTreeViewer.setLabelProvider(labelProvider);
86         fTreeViewer.getControl().addDisposeListener(new DisposeListener() {
87             public void widgetDisposed(DisposeEvent e) {
88                 labelProvider.dispose();
89             }
90         });
91         fTreeViewer.setAutoExpandLevel(2);
92
93         return fTreeViewer;
94     }
95
96     /*
97      * (non-Javadoc)
98      *
99      * @see org.eclipse.ui.part.Page#makeContributions(org.eclipse.jface.action.IMenuManager,
100      * org.eclipse.jface.action.IToolBarManager,
101      * org.eclipse.jface.action.IStatusLineManager)
102      */

103     public void makeContributions(IMenuManager menuManager,
104             IToolBarManager toolBarManager, IStatusLineManager statusLineManager) {
105         super.makeContributions(menuManager, toolBarManager, statusLineManager);
106         if (toolBarManager.find(DependenciesView.TREE_ACTION_GROUP) != null)
107             toolBarManager.prependToGroup(DependenciesView.TREE_ACTION_GROUP,
108                     new CollapseAllAction());
109         else
110             toolBarManager.add(new CollapseAllAction());
111     }
112     
113     protected void handleShowOptional(boolean isChecked, boolean refreshIfNecessary) {
114         if (isChecked)
115             fTreeViewer.removeFilter(fHideOptionalFilter);
116         else
117             fTreeViewer.addFilter(fHideOptionalFilter);
118         // filter automatically refreshes tree, therefore can ignore refreshIfNecessary
119
}
120     
121     protected boolean isShowingOptional() {
122         ViewerFilter[] filters = fTreeViewer.getFilters();
123         for (int i = 0; i < filters.length; i++)
124             if (filters[i].equals(fHideOptionalFilter))
125                 return false;
126         return true;
127     }
128
129 }
130
Popular Tags