001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.views.dependencies;
011:
012: import org.eclipse.jface.action.Action;
013: import org.eclipse.jface.action.IMenuManager;
014: import org.eclipse.jface.action.IStatusLineManager;
015: import org.eclipse.jface.action.IToolBarManager;
016: import org.eclipse.jface.viewers.ITreeContentProvider;
017: import org.eclipse.jface.viewers.StructuredViewer;
018: import org.eclipse.jface.viewers.TreeViewer;
019: import org.eclipse.jface.viewers.Viewer;
020: import org.eclipse.jface.viewers.ViewerFilter;
021: import org.eclipse.osgi.service.resolver.BundleSpecification;
022: import org.eclipse.osgi.service.resolver.ImportPackageSpecification;
023: import org.eclipse.pde.internal.ui.PDEPluginImages;
024: import org.eclipse.pde.internal.ui.PDEUIMessages;
025: import org.eclipse.swt.SWT;
026: import org.eclipse.swt.events.DisposeEvent;
027: import org.eclipse.swt.events.DisposeListener;
028: import org.eclipse.swt.widgets.Composite;
029: import org.osgi.framework.Constants;
030:
031: public class DependenciesViewTreePage extends DependenciesViewPage {
032: class CollapseAllAction extends Action {
033: public CollapseAllAction() {
034: super ();
035: setText(PDEUIMessages.DependenciesViewTreePage_CollapseAllAction_label);
036: setDescription(PDEUIMessages.DependenciesViewTreePage_CollapseAllAction_description);
037: setToolTipText(PDEUIMessages.DependenciesViewTreePage_CollapseAllAction_tooltip);
038: setImageDescriptor(PDEPluginImages.DESC_COLLAPSE_ALL);
039: setDisabledImageDescriptor(PDEPluginImages.DESC_COLLAPSE_ALL);
040: }
041:
042: /*
043: * (non-Javadoc)
044: *
045: * @see org.eclipse.jface.action.Action#run()
046: */
047: public void run() {
048: super .run();
049: fTreeViewer.collapseAll();
050: }
051: }
052:
053: class OptionalFilter extends ViewerFilter {
054:
055: public boolean select(Viewer v, Object parent, Object element) {
056: if (element instanceof BundleSpecification) {
057: return !((BundleSpecification) element).isOptional();
058: } else if (element instanceof ImportPackageSpecification)
059: return !Constants.RESOLUTION_OPTIONAL
060: .equals(((ImportPackageSpecification) element)
061: .getDirective(Constants.RESOLUTION_DIRECTIVE));
062: return true;
063: }
064: }
065:
066: TreeViewer fTreeViewer;
067: private OptionalFilter fHideOptionalFilter = new OptionalFilter();
068:
069: public DependenciesViewTreePage(DependenciesView view,
070: ITreeContentProvider contentProvider) {
071: super (view, contentProvider);
072: }
073:
074: /*
075: * (non-Javadoc)
076: *
077: * @see org.eclipse.pde.internal.ui.view.DependenciesViewPage#createViewer(org.eclipse.swt.widgets.Composite)
078: */
079: protected StructuredViewer createViewer(Composite parent) {
080: fTreeViewer = new TreeViewer(parent, SWT.MULTI | SWT.V_SCROLL
081: | SWT.H_SCROLL);
082: fTreeViewer.setContentProvider(fContentProvider);
083: final DependenciesLabelProvider labelProvider = new DependenciesLabelProvider(
084: true);
085: fTreeViewer.setLabelProvider(labelProvider);
086: fTreeViewer.getControl().addDisposeListener(
087: new DisposeListener() {
088: public void widgetDisposed(DisposeEvent e) {
089: labelProvider.dispose();
090: }
091: });
092: fTreeViewer.setAutoExpandLevel(2);
093:
094: return fTreeViewer;
095: }
096:
097: /*
098: * (non-Javadoc)
099: *
100: * @see org.eclipse.ui.part.Page#makeContributions(org.eclipse.jface.action.IMenuManager,
101: * org.eclipse.jface.action.IToolBarManager,
102: * org.eclipse.jface.action.IStatusLineManager)
103: */
104: public void makeContributions(IMenuManager menuManager,
105: IToolBarManager toolBarManager,
106: IStatusLineManager statusLineManager) {
107: super .makeContributions(menuManager, toolBarManager,
108: statusLineManager);
109: if (toolBarManager.find(DependenciesView.TREE_ACTION_GROUP) != null)
110: toolBarManager.prependToGroup(
111: DependenciesView.TREE_ACTION_GROUP,
112: new CollapseAllAction());
113: else
114: toolBarManager.add(new CollapseAllAction());
115: }
116:
117: protected void handleShowOptional(boolean isChecked,
118: boolean refreshIfNecessary) {
119: if (isChecked)
120: fTreeViewer.removeFilter(fHideOptionalFilter);
121: else
122: fTreeViewer.addFilter(fHideOptionalFilter);
123: // filter automatically refreshes tree, therefore can ignore refreshIfNecessary
124: }
125:
126: protected boolean isShowingOptional() {
127: ViewerFilter[] filters = fTreeViewer.getFilters();
128: for (int i = 0; i < filters.length; i++)
129: if (filters[i].equals(fHideOptionalFilter))
130: return false;
131: return true;
132: }
133:
134: }
|