01: /*******************************************************************************
02: * Copyright (c) 2006, 2007 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.pde.internal.ui.editor.actions;
11:
12: import org.eclipse.jface.action.Action;
13: import org.eclipse.jface.action.IAction;
14: import org.eclipse.jface.viewers.AbstractTreeViewer;
15: import org.eclipse.pde.internal.ui.PDEPluginImages;
16:
17: public class CollapseAction extends Action {
18:
19: private AbstractTreeViewer fTreeViewer;
20:
21: private Object fTreeObject;
22:
23: private int fExpandToLevel;
24:
25: /**
26: * @param viewer
27: * @param tooltipText
28: * @param expandToLevel
29: * @param treeObject
30: */
31: public CollapseAction(AbstractTreeViewer viewer,
32: String tooltipText, int expandToLevel, Object treeObject) {
33: super (tooltipText, IAction.AS_PUSH_BUTTON);
34: fExpandToLevel = expandToLevel;
35: fTreeObject = treeObject;
36: initialize(viewer, tooltipText);
37: }
38:
39: /**
40: * @param viewer
41: * @param tooltipText
42: */
43: public CollapseAction(AbstractTreeViewer viewer, String tooltipText) {
44: super (tooltipText, IAction.AS_PUSH_BUTTON);
45: fExpandToLevel = 0;
46: fTreeObject = null;
47: initialize(viewer, tooltipText);
48: }
49:
50: /**
51: * @param viewer
52: * @param tooltipText
53: */
54: private void initialize(AbstractTreeViewer viewer,
55: String tooltipText) {
56: setToolTipText(tooltipText);
57: setImageDescriptor(PDEPluginImages.DESC_COLLAPSE_ALL);
58: fTreeViewer = viewer;
59: }
60:
61: /* (non-Javadoc)
62: * @see org.eclipse.jface.action.Action#run()
63: */
64: public void run() {
65:
66: if (fTreeViewer == null) {
67: return;
68: } else if ((fTreeObject != null) && (fExpandToLevel > 0)) {
69: // Redraw modification needed to avoid flicker
70: // Collapsing to a specific level does not work
71: fTreeViewer.getControl().setRedraw(false);
72: fTreeViewer.collapseAll();
73: fTreeViewer.expandToLevel(fTreeObject, 1);
74: fTreeViewer.getControl().setRedraw(true);
75: } else {
76: fTreeViewer.collapseAll();
77: }
78:
79: }
80:
81: }
|