1 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 fTreeObject; 23 24 private int fExpandToLevel; 25 26 32 public CollapseAction(AbstractTreeViewer viewer, String tooltipText, 33 int expandToLevel, Object treeObject) { 34 super(tooltipText, IAction.AS_PUSH_BUTTON); 35 fExpandToLevel = expandToLevel; 36 fTreeObject = treeObject; 37 initialize(viewer, tooltipText); 38 } 39 40 44 public CollapseAction(AbstractTreeViewer viewer, String tooltipText) { 45 super(tooltipText, IAction.AS_PUSH_BUTTON); 46 fExpandToLevel = 0; 47 fTreeObject = null; 48 initialize(viewer, tooltipText); 49 } 50 51 55 private void initialize(AbstractTreeViewer viewer, String tooltipText) { 56 setToolTipText(tooltipText); 57 setImageDescriptor(PDEPluginImages.DESC_COLLAPSE_ALL); 58 fTreeViewer = viewer; 59 } 60 61 64 public void run() { 65 66 if (fTreeViewer == null) { 67 return; 68 } else if ((fTreeObject != null) && 69 (fExpandToLevel > 0)) { 70 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 |