|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 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 |
|
| 12 |
package org.eclipse.ui.internal.ide.commands; |
| 13 |
|
| 14 |
import org.eclipse.core.commands.AbstractHandler; |
| 15 |
import org.eclipse.core.commands.ExecutionEvent; |
| 16 |
import org.eclipse.core.commands.ExecutionException; |
| 17 |
import org.eclipse.core.resources.IResource; |
| 18 |
import org.eclipse.jface.viewers.ISelection; |
| 19 |
import org.eclipse.jface.viewers.StructuredSelection; |
| 20 |
import org.eclipse.ui.IPageLayout; |
| 21 |
import org.eclipse.ui.IViewPart; |
| 22 |
import org.eclipse.ui.IWorkbenchPage; |
| 23 |
import org.eclipse.ui.IWorkbenchWindow; |
| 24 |
import org.eclipse.ui.PartInitException; |
| 25 |
import org.eclipse.ui.PlatformUI; |
| 26 |
import org.eclipse.ui.part.ISetSelectionTarget; |
| 27 |
|
| 28 |
/** |
| 29 |
* A command handler to show a resource in the Navigator view given the resource |
| 30 |
* path. |
| 31 |
* |
| 32 |
* @since 3.2 |
| 33 |
*/ |
| 34 |
public class ShowResourceByPathHandler extends AbstractHandler { |
| 35 |
|
| 36 |
private static final String PARAM_ID_RESOURCE_PATH = "resourcePath"; //$NON-NLS-1$ |
| 37 |
|
| 38 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
| 39 |
|
| 40 |
IResource resource = (IResource) event |
| 41 |
.getObjectParameterForExecution(PARAM_ID_RESOURCE_PATH); |
| 42 |
|
| 43 |
IWorkbenchWindow activeWindow = PlatformUI.getWorkbench() |
| 44 |
.getActiveWorkbenchWindow(); |
| 45 |
if (activeWindow == null) { |
| 46 |
throw new ExecutionException("no active workbench window"); //$NON-NLS-1$ |
| 47 |
} |
| 48 |
|
| 49 |
IWorkbenchPage activePage = activeWindow.getActivePage(); |
| 50 |
if (activePage == null) { |
| 51 |
throw new ExecutionException("no active workbench page"); //$NON-NLS-1$ |
| 52 |
} |
| 53 |
|
| 54 |
try { |
| 55 |
IViewPart view = activePage.showView(IPageLayout.ID_RES_NAV); |
| 56 |
if (view instanceof ISetSelectionTarget) { |
| 57 |
ISelection selection = new StructuredSelection(resource); |
| 58 |
((ISetSelectionTarget) view).selectReveal(selection); |
| 59 |
} |
| 60 |
} catch (PartInitException e) { |
| 61 |
throw new ExecutionException("error showing resource in navigator"); //$NON-NLS-1$ |
| 62 |
} |
| 63 |
|
| 64 |
return null; |
| 65 |
} |
| 66 |
|
| 67 |
} |