KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > actions > CollapseAction


1 /*******************************************************************************
2  * Copyright (c) 2006, 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.editor.actions;
12
13 import org.eclipse.jface.action.Action;
14 import org.eclipse.jface.action.IAction;
15 import org.eclipse.jface.viewers.AbstractTreeViewer;
16 import org.eclipse.pde.internal.ui.PDEPluginImages;
17
18 public class CollapseAction extends Action {
19
20     private AbstractTreeViewer fTreeViewer;
21     
22     private Object JavaDoc fTreeObject;
23     
24     private int fExpandToLevel;
25
26     /**
27      * @param viewer
28      * @param tooltipText
29      * @param expandToLevel
30      * @param treeObject
31      */

32     public CollapseAction(AbstractTreeViewer viewer, String JavaDoc tooltipText,
33             int expandToLevel, Object JavaDoc treeObject) {
34         super(tooltipText, IAction.AS_PUSH_BUTTON);
35         fExpandToLevel = expandToLevel;
36         fTreeObject = treeObject;
37         initialize(viewer, tooltipText);
38     }
39     
40     /**
41      * @param viewer
42      * @param tooltipText
43      */

44     public CollapseAction(AbstractTreeViewer viewer, String JavaDoc tooltipText) {
45         super(tooltipText, IAction.AS_PUSH_BUTTON);
46         fExpandToLevel = 0;
47         fTreeObject = null;
48         initialize(viewer, tooltipText);
49     }
50
51     /**
52      * @param viewer
53      * @param tooltipText
54      */

55     private void initialize(AbstractTreeViewer viewer, String JavaDoc 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) &&
69                 (fExpandToLevel > 0)) {
70             // Redraw modification needed to avoid flicker
71
// Collapsing to a specific level does not work
72
fTreeViewer.getControl().setRedraw(false);
73             fTreeViewer.collapseAll();
74             fTreeViewer.expandToLevel(fTreeObject, 1);
75             fTreeViewer.getControl().setRedraw(true);
76         } else {
77             fTreeViewer.collapseAll();
78         }
79         
80     }
81
82 }
83
Popular Tags