KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > navigator > GotoResourceAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 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 package org.eclipse.ui.views.navigator;
12
13 import org.eclipse.core.resources.IContainer;
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.jface.viewers.StructuredSelection;
16 import org.eclipse.ui.PlatformUI;
17
18 /**
19  * Implements the go to resource action. Opens a dialog and set
20  * the navigator selection with the resource selected by
21  * the user.
22  */

23 public class GotoResourceAction extends ResourceNavigatorAction {
24     /**
25      * Creates a new instance of the class.
26      *
27      * @param navigator the navigator
28      * @param label the label
29      * @since 2.0
30      */

31     public GotoResourceAction(IResourceNavigator navigator, String JavaDoc label) {
32         super(navigator, label);
33         PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
34                 INavigatorHelpContextIds.GOTO_RESOURCE_ACTION);
35     }
36
37     /**
38      * Collect all resources in the workbench open a dialog asking
39      * the user to select a resource and change the selection in
40      * the navigator.
41      */

42     public void run() {
43         IContainer container = (IContainer) getViewer().getInput();
44         GotoResourceDialog dialog = new GotoResourceDialog(getShell(),
45                 container, IResource.FILE | IResource.FOLDER
46                         | IResource.PROJECT);
47         dialog.open();
48         Object JavaDoc[] result = dialog.getResult();
49         if (result == null || result.length == 0
50                 || result[0] instanceof IResource == false) {
51             return;
52         }
53
54         IResource selection = (IResource) result[0];
55         getViewer().setSelection(new StructuredSelection(selection), true);
56     }
57 }
58
Popular Tags