|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2008, 2009 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 |
* @author Prakash G. R. |
| 12 |
******************************************************************************/ |
| 13 |
|
| 14 |
package org.eclipse.ui.handlers; |
| 15 |
import org.eclipse.core.commands.AbstractHandler; |
| 16 |
import org.eclipse.core.commands.ExecutionEvent; |
| 17 |
import org.eclipse.core.runtime.Assert; |
| 18 |
import org.eclipse.jface.viewers.AbstractTreeViewer; |
| 19 |
import org.eclipse.ui.IWorkbenchCommandConstants; |
| 20 |
|
| 21 |
/** |
| 22 |
* Expand a tree viewer. |
| 23 |
* <p> |
| 24 |
* It can be used in a part's createPartControl(Composite) method: |
| 25 |
* |
| 26 |
* <pre> |
| 27 |
* IHandlerService handlerService = (IHandlerService) getSite().getService( |
| 28 |
* IHandlerService.class); |
| 29 |
* expandHandler = new ExpandAllHandler(myViewer); |
| 30 |
* handlerService.activateHandler(ExpandAllHandler.COMMAND_ID, expandHandler); |
| 31 |
* </pre> |
| 32 |
* |
| 33 |
* The part should dispose the handler in its own dispose() method. The part can |
| 34 |
* provide its own expand all handler if desired, or if it needs to delegate to |
| 35 |
* multiple tree viewers. |
| 36 |
* </p> |
| 37 |
* <p> |
| 38 |
* <b>Note</b>: This class can be instantiated. It should not be subclasses. |
| 39 |
* </p> |
| 40 |
* |
| 41 |
* @since 3.6 |
| 42 |
*/ |
| 43 |
public class ExpandAllHandler extends AbstractHandler { |
| 44 |
/** |
| 45 |
* The command id for collapse all. |
| 46 |
*/ |
| 47 |
public static final String COMMAND_ID = IWorkbenchCommandConstants.NAVIGATE_EXPAND_ALL; |
| 48 |
|
| 49 |
private AbstractTreeViewer treeViewer; |
| 50 |
|
| 51 |
/** |
| 52 |
* Create the handler for this tree viewer. |
| 53 |
* |
| 54 |
* @param viewer |
| 55 |
* The viewer to expand. Must not be <code>null</code>. |
| 56 |
*/ |
| 57 |
public ExpandAllHandler(AbstractTreeViewer viewer) { |
| 58 |
Assert.isNotNull(viewer); |
| 59 |
treeViewer = viewer; |
| 60 |
} |
| 61 |
|
| 62 |
/* |
| 63 |
* (non-Javadoc) |
| 64 |
* |
| 65 |
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
| 66 |
*/ |
| 67 |
public Object execute(ExecutionEvent event) { |
| 68 |
treeViewer.expandAll(); |
| 69 |
return null; |
| 70 |
} |
| 71 |
|
| 72 |
/* |
| 73 |
* (non-Javadoc) |
| 74 |
* |
| 75 |
* @see org.eclipse.core.commands.AbstractHandler#dispose() |
| 76 |
*/ |
| 77 |
public void dispose() { |
| 78 |
treeViewer = null; |
| 79 |
} |
| 80 |
} |