1 11 package org.eclipse.search.internal.ui; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.swt.widgets.Tree; 17 import org.eclipse.swt.widgets.TreeItem; 18 19 import org.eclipse.jface.action.Action; 20 import org.eclipse.jface.viewers.StructuredViewer; 21 import org.eclipse.jface.viewers.TableViewer; 22 import org.eclipse.jface.viewers.TreeViewer; 23 24 import org.eclipse.ui.PlatformUI; 25 26 29 public class SelectAllAction extends Action { 30 31 private StructuredViewer fViewer; 32 33 36 public SelectAllAction() { 37 super("selectAll"); setText(SearchMessages.SelectAllAction_label); 39 setToolTipText(SearchMessages.SelectAllAction_tooltip); 40 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, ISearchHelpContextIds.SELECT_ALL_ACTION); 41 } 42 43 public void setViewer(StructuredViewer viewer) { 44 fViewer= viewer; 45 } 46 47 private void collectExpandedAndVisible(TreeItem[] items, List result) { 48 for (int i= 0; i < items.length; i++) { 49 TreeItem item= items[i]; 50 result.add(item); 51 if (item.getExpanded()) { 52 collectExpandedAndVisible(item.getItems(), result); 53 } 54 } 55 } 56 57 60 public void run() { 61 if (fViewer == null || fViewer.getControl().isDisposed()) { 62 return; 63 } 64 if (fViewer instanceof TreeViewer) { 65 ArrayList allVisible= new ArrayList (); 66 Tree tree= ((TreeViewer) fViewer).getTree(); 67 collectExpandedAndVisible(tree.getItems(), allVisible); 68 tree.setSelection((TreeItem[]) allVisible.toArray(new TreeItem[allVisible.size()])); 69 } else if (fViewer instanceof TableViewer) { 70 ((TableViewer) fViewer).getTable().selectAll(); 71 fViewer.setSelection(fViewer.getSelection()); 73 } 74 } 75 } 76 | Popular Tags |