1 11 package org.eclipse.jdt.internal.ui.actions; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.runtime.Assert; 17 18 import org.eclipse.swt.widgets.Tree; 19 import org.eclipse.swt.widgets.TreeItem; 20 21 import org.eclipse.jface.action.Action; 22 import org.eclipse.jface.viewers.StructuredViewer; 23 import org.eclipse.jface.viewers.TableViewer; 24 import org.eclipse.jface.viewers.TreeViewer; 25 26 import org.eclipse.ui.PlatformUI; 27 28 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 29 30 33 public class SelectAllAction extends Action { 34 35 private StructuredViewer fViewer; 36 37 40 public SelectAllAction(TreeViewer viewer) { 41 this((StructuredViewer) viewer); 42 } 43 44 47 public SelectAllAction(TableViewer viewer) { 48 this((StructuredViewer) viewer); 49 } 50 51 private SelectAllAction(StructuredViewer viewer) { 52 super("selectAll"); setText(ActionMessages.SelectAllAction_label); 54 setToolTipText(ActionMessages.SelectAllAction_tooltip); 55 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.SELECT_ALL_ACTION); 56 Assert.isNotNull(viewer); 57 fViewer= viewer; 58 } 59 60 private void collectExpandedAndVisible(TreeItem[] items, List result) { 61 for (int i= 0; i < items.length; i++) { 62 TreeItem item= items[i]; 63 if (item.getData() != null) { 64 result.add(item); 65 if (item.getExpanded()) { 66 collectExpandedAndVisible(item.getItems(), result); 67 } 68 } 69 } 70 } 71 72 75 public void run() { 76 if (fViewer instanceof TreeViewer) { 77 ArrayList allVisible= new ArrayList (); 78 Tree tree= ((TreeViewer) fViewer).getTree(); 79 collectExpandedAndVisible(tree.getItems(), allVisible); 80 tree.setSelection((TreeItem[]) allVisible.toArray(new TreeItem[allVisible.size()])); 81 fViewer.setSelection(fViewer.getSelection()); 82 } else if (fViewer instanceof TableViewer) { 83 ((TableViewer) fViewer).getTable().selectAll(); 84 fViewer.setSelection(fViewer.getSelection()); 86 } 87 } 88 } 89 | Popular Tags |