01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 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.views.navigator;
11:
12: import org.eclipse.core.resources.IContainer;
13: import org.eclipse.core.resources.IResource;
14: import org.eclipse.jface.viewers.StructuredSelection;
15: import org.eclipse.ui.PlatformUI;
16:
17: /**
18: * Implements the go to resource action. Opens a dialog and set
19: * the navigator selection with the resource selected by
20: * the user.
21: */
22: public class GotoResourceAction extends ResourceNavigatorAction {
23: /**
24: * Creates a new instance of the class.
25: *
26: * @param navigator the navigator
27: * @param label the label
28: * @since 2.0
29: */
30: public GotoResourceAction(IResourceNavigator navigator, String label) {
31: super (navigator, label);
32: PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
33: INavigatorHelpContextIds.GOTO_RESOURCE_ACTION);
34: }
35:
36: /**
37: * Collect all resources in the workbench open a dialog asking
38: * the user to select a resource and change the selection in
39: * the navigator.
40: */
41: public void run() {
42: IContainer container = (IContainer) getViewer().getInput();
43: GotoResourceDialog dialog = new GotoResourceDialog(getShell(),
44: container, IResource.FILE | IResource.FOLDER
45: | IResource.PROJECT);
46: dialog.open();
47: Object[] result = dialog.getResult();
48: if (result == null || result.length == 0
49: || result[0] instanceof IResource == false) {
50: return;
51: }
52:
53: IResource selection = (IResource) result[0];
54: getViewer().setSelection(new StructuredSelection(selection),
55: true);
56: }
57: }
|