1 11 package org.eclipse.team.internal.ui.synchronize.actions; 12 13 import java.util.Iterator ; 14 15 import org.eclipse.jface.action.Action; 16 import org.eclipse.jface.viewers.*; 17 18 19 public class ExpandAllAction extends Action implements ISelectionChangedListener { 20 21 private final AbstractTreeViewer viewer; 22 23 public ExpandAllAction(AbstractTreeViewer viewer) { 24 this.viewer = viewer; 25 viewer.addSelectionChangedListener(this); 26 } 27 public void run() { 28 expandAllFromSelection(); 29 } 30 31 protected void expandAllFromSelection() { 32 AbstractTreeViewer tree = viewer; 33 if (tree == null) return; 34 ISelection selection = tree.getSelection(); 35 if(! selection.isEmpty()) { 36 Iterator elements = ((IStructuredSelection)selection).iterator(); 37 try { 38 tree.getControl().setRedraw(false); 39 while (elements.hasNext()) { 40 Object next = elements.next(); 41 tree.expandToLevel(next, AbstractTreeViewer.ALL_LEVELS); 42 } 43 } finally { 44 tree.getControl().setRedraw(true); 45 } 46 } 47 } 48 51 public void selectionChanged(SelectionChangedEvent event) { 52 ISelection selection = event.getSelection(); 53 if (selection instanceof IStructuredSelection) { 54 IStructuredSelection ss = (IStructuredSelection)selection; 55 setEnabled(!ss.isEmpty()); 56 return; 57 } 58 setEnabled(false); 59 } 60 } 61 | Popular Tags |