01: /*******************************************************************************
02: * Copyright (c) 2006, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.ide.handlers;
11:
12: import org.eclipse.core.commands.AbstractHandler;
13: import org.eclipse.core.commands.ExecutionEvent;
14: import org.eclipse.core.commands.ExecutionException;
15: import org.eclipse.core.resources.IResource;
16: import org.eclipse.jface.viewers.ISelection;
17: import org.eclipse.jface.viewers.StructuredSelection;
18: import org.eclipse.ui.IPageLayout;
19: import org.eclipse.ui.IViewPart;
20: import org.eclipse.ui.IWorkbenchPage;
21: import org.eclipse.ui.IWorkbenchWindow;
22: import org.eclipse.ui.PartInitException;
23: import org.eclipse.ui.handlers.HandlerUtil;
24: import org.eclipse.ui.part.ISetSelectionTarget;
25:
26: /**
27: * A command handler to show a resource in the Navigator view given the resource
28: * path.
29: *
30: * @since 3.2
31: */
32: public class ShowResourceByPathHandler extends AbstractHandler {
33:
34: private static final String PARAM_ID_RESOURCE_PATH = "resourcePath"; //$NON-NLS-1$
35:
36: public Object execute(ExecutionEvent event)
37: throws ExecutionException {
38:
39: IResource resource = (IResource) event
40: .getObjectParameterForExecution(PARAM_ID_RESOURCE_PATH);
41:
42: IWorkbenchWindow activeWindow = HandlerUtil
43: .getActiveWorkbenchWindowChecked(event);
44:
45: IWorkbenchPage activePage = activeWindow.getActivePage();
46: if (activePage == null) {
47: throw new ExecutionException("no active workbench page"); //$NON-NLS-1$
48: }
49:
50: try {
51: IViewPart view = activePage
52: .showView(IPageLayout.ID_RES_NAV);
53: if (view instanceof ISetSelectionTarget) {
54: ISelection selection = new StructuredSelection(resource);
55: ((ISetSelectionTarget) view).selectReveal(selection);
56: }
57: } catch (PartInitException e) {
58: throw new ExecutionException(
59: "error showing resource in navigator"); //$NON-NLS-1$
60: }
61:
62: return null;
63: }
64:
65: }
|