|
Added
Link Here
|
| 1 |
/* |
| 2 |
* (c) Copyright IBM Corp. 2000, 2001. |
| 3 |
* All Rights Reserved. |
| 4 |
*/ |
| 5 |
package org.eclipse.ui.views.navigator; |
| 6 |
|
| 7 |
import java.net.MalformedURLException; |
| 8 |
import java.net.URL; |
| 9 |
|
| 10 |
import org.eclipse.core.runtime.Platform; |
| 11 |
import org.eclipse.jface.resource.ImageDescriptor; |
| 12 |
import org.eclipse.ui.PlatformUI; |
| 13 |
import org.eclipse.ui.help.WorkbenchHelp; |
| 14 |
import org.eclipse.ui.plugin.AbstractUIPlugin; |
| 15 |
|
| 16 |
/** |
| 17 |
* Collapse all project nodes. |
| 18 |
*/ |
| 19 |
public class CollapseAllAction extends ResourceNavigatorAction { |
| 20 |
private static final String COLLAPSE_ALL_TOOL_TIP = ResourceNavigatorMessages.getString("CollapseAllAction.toolTip"); //$NON-NLS-1$ |
| 21 |
|
| 22 |
|
| 23 |
/** |
| 24 |
* Creates the action. |
| 25 |
* |
| 26 |
* @param navigator the resource navigator |
| 27 |
* @param label the label for the action |
| 28 |
*/ |
| 29 |
public CollapseAllAction(IResourceNavigator navigator, String label) { |
| 30 |
super(navigator, label); |
| 31 |
setToolTipText(COLLAPSE_ALL_TOOL_TIP); |
| 32 |
setImageDescriptor(getImageDescriptor("elcl16/collapseall.gif")); //$NON-NLS-1$ |
| 33 |
WorkbenchHelp.setHelp(this, INavigatorHelpContextIds.COLLAPSE_ALL_ACTION); |
| 34 |
setEnabled(true); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Returns the image descriptor with the given relative path. |
| 39 |
*/ |
| 40 |
private ImageDescriptor getImageDescriptor(String relativePath) { |
| 41 |
String iconPath = "icons/full/"; //$NON-NLS-1$ |
| 42 |
try { |
| 43 |
AbstractUIPlugin plugin = (AbstractUIPlugin) Platform.getPlugin(PlatformUI.PLUGIN_ID); |
| 44 |
URL installURL = plugin.getDescriptor().getInstallURL(); |
| 45 |
URL url = new URL(installURL, iconPath + relativePath); |
| 46 |
return ImageDescriptor.createFromURL(url); |
| 47 |
} catch (MalformedURLException e) { |
| 48 |
// should not happen |
| 49 |
return ImageDescriptor.getMissingImageDescriptor(); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
/* |
| 54 |
* Implementation of method defined on <code>IAction</code>. |
| 55 |
*/ |
| 56 |
public void run() { |
| 57 |
getNavigator().getViewer().collapseAll(); |
| 58 |
} |
| 59 |
} |