Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5d586ee18c2f4b03b5682ae8a1296d54d18e4dd5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ui.synchronize.actions;

import java.util.Iterator;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.*;


public class ExpandAllAction extends Action implements ISelectionChangedListener {

	private final AbstractTreeViewer viewer;

	public ExpandAllAction(AbstractTreeViewer viewer) {
		this.viewer = viewer;
		viewer.addSelectionChangedListener(this);
	}
	@Override
	public void run() {
		expandAllFromSelection();
	}

	protected void expandAllFromSelection() {
		AbstractTreeViewer tree = viewer;
		if (tree == null) return;
		ISelection selection = tree.getSelection();
		if(! selection.isEmpty()) {
			Iterator elements = ((IStructuredSelection)selection).iterator();
			try {
				tree.getControl().setRedraw(false);
				while (elements.hasNext()) {
					Object next = elements.next();
					tree.expandToLevel(next, AbstractTreeViewer.ALL_LEVELS);
				}
			} finally {
				tree.getControl().setRedraw(true);
			}
		}
	}
	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
	 */
	@Override
	public void selectionChanged(SelectionChangedEvent event) {
		ISelection selection = event.getSelection();
		if (selection instanceof IStructuredSelection) {
			IStructuredSelection ss = (IStructuredSelection)selection;
			setEnabled(!ss.isEmpty());
			return;
		}
		setEnabled(false);
	}
}

Back to the top