KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > synchronize > actions > ExpandAllAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.team.internal.ui.synchronize.actions;
12
13 import java.util.Iterator JavaDoc;
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 JavaDoc elements = ((IStructuredSelection)selection).iterator();
37             try {
38                 tree.getControl().setRedraw(false);
39                 while (elements.hasNext()) {
40                     Object JavaDoc next = elements.next();
41                     tree.expandToLevel(next, AbstractTreeViewer.ALL_LEVELS);
42                 }
43             } finally {
44                 tree.getControl().setRedraw(true);
45             }
46         }
47     }
48     /* (non-Javadoc)
49      * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
50      */

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