Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 126079 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.xml (+28 lines)
Lines 754-759 Link Here
754
            description="%command.findAndInstallUpdates.description"
754
            description="%command.findAndInstallUpdates.description"
755
            id="org.eclipse.ui.update.findAndInstallUpdates"
755
            id="org.eclipse.ui.update.findAndInstallUpdates"
756
            name="%command.findAndInstallUpdates.name"/>
756
            name="%command.findAndInstallUpdates.name"/>
757
      <commandParameterType
758
            converter="org.eclipse.ui.internal.ide.commands.ResourcePathConverter"
759
            id="org.eclipse.ui.ide.resourcePath"
760
            type="org.eclipse.core.resources.IResource"/>
761
      <command
762
            categoryId="org.eclipse.ui.category.navigate"
763
            defaultHandler="org.eclipse.ui.internal.ide.commands.OpenFileByPathHandler"
764
            description="%command.openFileByPath.description"
765
            id="org.eclipse.ui.navigate.openFileByPath"
766
            name="%command.openFileByPath.name">
767
         <commandParameter
768
               id="filePath"
769
               name="%commandParameter.openFileByPath.filePath.name"
770
               optional="false"
771
               typeId="org.eclipse.ui.ide.resourcePath"/>
772
      </command>
773
      <command
774
            categoryId="org.eclipse.ui.category.navigate"
775
            defaultHandler="org.eclipse.ui.internal.ide.commands.ShowResourceByPathHandler"
776
            description="%command.showResourceByPath.description"
777
            id="org.eclipse.ui.navigate.showResourceByPath"
778
            name="%command.showResourceByPath.name">
779
         <commandParameter
780
               id="resourcePath"
781
               name="%commandParameter.showResourceByPath.resourcePath.name"
782
               optional="false"
783
               typeId="org.eclipse.ui.ide.resourcePath"/>
784
      </command>
757
   </extension>
785
   </extension>
758
   
786
   
759
   <extension
787
   <extension
(-)plugin.properties (+7 lines)
Lines 147-152 Link Here
147
command.findAndInstallUpdates.name= Find and Install Updates
147
command.findAndInstallUpdates.name= Find and Install Updates
148
command.findAndInstallUpdates.description= Open the feature install and update dialog
148
command.findAndInstallUpdates.description= Open the feature install and update dialog
149
149
150
command.openFileByPath.name= Open File
151
command.openFileByPath.description= Open an editor on a file given its path
152
commandParameter.openFileByPath.filePath.name= File Path
153
command.showResourceByPath.name= Show Resource in Navigator
154
command.showResourceByPath.description= Show a resource in the Navigator given its path
155
commandParameter.showResourceByPath.resourcePath.name= Resource Path
156
150
UpdateActionSet.label = Software Updates
157
UpdateActionSet.label = Software Updates
151
UpdateActionSet.menu.label = &Software Updates
158
UpdateActionSet.menu.label = &Software Updates
152
UpdateActionSet.updates.label = &Find and Install...
159
UpdateActionSet.updates.label = &Find and Install...
(-)src/org/eclipse/ui/internal/ide/commands/ShowResourceByPathHandler.java (+67 lines)
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
}
(-)src/org/eclipse/ui/internal/ide/commands/OpenFileByPathHandler.java (+65 lines)
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.IFile;
18
import org.eclipse.core.resources.IResource;
19
import org.eclipse.ui.IWorkbenchPage;
20
import org.eclipse.ui.IWorkbenchWindow;
21
import org.eclipse.ui.PartInitException;
22
import org.eclipse.ui.PlatformUI;
23
import org.eclipse.ui.ide.IDE;
24
25
/**
26
 * A command handler to open a file in its editor given the resource path.
27
 * 
28
 * @since 3.2
29
 */
30
public class OpenFileByPathHandler extends AbstractHandler {
31
32
	private static final String PARAM_ID_FILE_PATH = "filePath"; //$NON-NLS-1$
33
34
	public Object execute(ExecutionEvent event) throws ExecutionException {
35
36
		IResource resource = (IResource) event
37
				.getObjectParameterForExecution(PARAM_ID_FILE_PATH);
38
		
39
		if (!(resource instanceof IFile)) {
40
			throw new ExecutionException(
41
					"filePath parameter must identify a file"); //$NON-NLS-1$
42
		}
43
		IFile file = (IFile) resource;
44
45
		IWorkbenchWindow activeWindow = PlatformUI.getWorkbench()
46
				.getActiveWorkbenchWindow();
47
		if (activeWindow == null) {
48
			throw new ExecutionException("no active workbench window"); //$NON-NLS-1$
49
		}
50
51
		IWorkbenchPage activePage = activeWindow.getActivePage();
52
		if (activePage == null) {
53
			throw new ExecutionException("no active workbench page"); //$NON-NLS-1$
54
		}
55
56
		try {
57
			IDE.openEditor(activePage, file, true);
58
		} catch (PartInitException ex) {
59
			throw new ExecutionException("error opening file in editor", ex); //$NON-NLS-1$
60
		}
61
62
		return null;
63
	}
64
65
}
(-)src/org/eclipse/ui/internal/ide/commands/ResourcePathConverter.java (+57 lines)
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.AbstractParameterValueConverter;
15
import org.eclipse.core.commands.ParameterValueConversionException;
16
import org.eclipse.core.resources.IResource;
17
import org.eclipse.core.resources.IWorkspaceRoot;
18
import org.eclipse.core.resources.ResourcesPlugin;
19
import org.eclipse.core.runtime.Path;
20
21
/**
22
 * A command parameter value converter to convert between IResources and strings
23
 * encoding the path of a resource.
24
 * 
25
 * @since 3.2
26
 */
27
public class ResourcePathConverter extends AbstractParameterValueConverter {
28
29
	public Object convertToObject(String parameterValue)
30
			throws ParameterValueConversionException {
31
32
		Path path = new Path(parameterValue);
33
34
		IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
35
		IResource resource = workspaceRoot.findMember(path);
36
37
		if ((resource == null) || (!resource.exists())) {
38
			throw new ParameterValueConversionException(
39
					"parameterValue must be the path of an existing resource"); //$NON-NLS-1$
40
		}
41
42
		return resource;
43
	}
44
45
	public String convertToString(Object parameterValue)
46
			throws ParameterValueConversionException {
47
48
		if (!(parameterValue instanceof IResource)) {
49
			throw new ParameterValueConversionException(
50
					"parameterValue must be an IResource"); //$NON-NLS-1$
51
		}
52
		IResource resource = (IResource) parameterValue;
53
54
		return resource.getFullPath().toString();
55
	}
56
57
}

Return to bug 126079