Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 33959 Details for
Bug 126079
[Commands] request: add commands to open/show resource with path parameter
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
patch with openFileByPath / showResourceByPath commands
resource-open-show-command-patch.txt (text/plain), 11.06 KB, created by
Christopher Daly
on 2006-02-01 14:38:52 EST
(
hide
)
Description:
patch with openFileByPath / showResourceByPath commands
Filename:
MIME Type:
Creator:
Christopher Daly
Created:
2006-02-01 14:38:52 EST
Size:
11.06 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ui.ide >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/plugin.xml,v >retrieving revision 1.144 >diff -u -r1.144 plugin.xml >--- plugin.xml 30 Jan 2006 21:11:15 -0000 1.144 >+++ plugin.xml 1 Feb 2006 19:38:15 -0000 >@@ -754,6 +754,34 @@ > description="%command.findAndInstallUpdates.description" > id="org.eclipse.ui.update.findAndInstallUpdates" > name="%command.findAndInstallUpdates.name"/> >+ <commandParameterType >+ converter="org.eclipse.ui.internal.ide.commands.ResourcePathConverter" >+ id="org.eclipse.ui.ide.resourcePath" >+ type="org.eclipse.core.resources.IResource"/> >+ <command >+ categoryId="org.eclipse.ui.category.navigate" >+ defaultHandler="org.eclipse.ui.internal.ide.commands.OpenFileByPathHandler" >+ description="%command.openFileByPath.description" >+ id="org.eclipse.ui.navigate.openFileByPath" >+ name="%command.openFileByPath.name"> >+ <commandParameter >+ id="filePath" >+ name="%commandParameter.openFileByPath.filePath.name" >+ optional="false" >+ typeId="org.eclipse.ui.ide.resourcePath"/> >+ </command> >+ <command >+ categoryId="org.eclipse.ui.category.navigate" >+ defaultHandler="org.eclipse.ui.internal.ide.commands.ShowResourceByPathHandler" >+ description="%command.showResourceByPath.description" >+ id="org.eclipse.ui.navigate.showResourceByPath" >+ name="%command.showResourceByPath.name"> >+ <commandParameter >+ id="resourcePath" >+ name="%commandParameter.showResourceByPath.resourcePath.name" >+ optional="false" >+ typeId="org.eclipse.ui.ide.resourcePath"/> >+ </command> > </extension> > > <extension >Index: plugin.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/plugin.properties,v >retrieving revision 1.73 >diff -u -r1.73 plugin.properties >--- plugin.properties 30 Jan 2006 21:11:15 -0000 1.73 >+++ plugin.properties 1 Feb 2006 19:38:15 -0000 >@@ -147,6 +147,13 @@ > command.findAndInstallUpdates.name= Find and Install Updates > command.findAndInstallUpdates.description= Open the feature install and update dialog > >+command.openFileByPath.name= Open File >+command.openFileByPath.description= Open an editor on a file given its path >+commandParameter.openFileByPath.filePath.name= File Path >+command.showResourceByPath.name= Show Resource in Navigator >+command.showResourceByPath.description= Show a resource in the Navigator given its path >+commandParameter.showResourceByPath.resourcePath.name= Resource Path >+ > UpdateActionSet.label = Software Updates > UpdateActionSet.menu.label = &Software Updates > UpdateActionSet.updates.label = &Find and Install... >Index: src/org/eclipse/ui/internal/ide/commands/ShowResourceByPathHandler.java >=================================================================== >RCS file: src/org/eclipse/ui/internal/ide/commands/ShowResourceByPathHandler.java >diff -N src/org/eclipse/ui/internal/ide/commands/ShowResourceByPathHandler.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/ui/internal/ide/commands/ShowResourceByPathHandler.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,67 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.ui.internal.ide.commands; >+ >+import org.eclipse.core.commands.AbstractHandler; >+import org.eclipse.core.commands.ExecutionEvent; >+import org.eclipse.core.commands.ExecutionException; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.jface.viewers.ISelection; >+import org.eclipse.jface.viewers.StructuredSelection; >+import org.eclipse.ui.IPageLayout; >+import org.eclipse.ui.IViewPart; >+import org.eclipse.ui.IWorkbenchPage; >+import org.eclipse.ui.IWorkbenchWindow; >+import org.eclipse.ui.PartInitException; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.part.ISetSelectionTarget; >+ >+/** >+ * A command handler to show a resource in the Navigator view given the resource >+ * path. >+ * >+ * @since 3.2 >+ */ >+public class ShowResourceByPathHandler extends AbstractHandler { >+ >+ private static final String PARAM_ID_RESOURCE_PATH = "resourcePath"; //$NON-NLS-1$ >+ >+ public Object execute(ExecutionEvent event) throws ExecutionException { >+ >+ IResource resource = (IResource) event >+ .getObjectParameterForExecution(PARAM_ID_RESOURCE_PATH); >+ >+ IWorkbenchWindow activeWindow = PlatformUI.getWorkbench() >+ .getActiveWorkbenchWindow(); >+ if (activeWindow == null) { >+ throw new ExecutionException("no active workbench window"); //$NON-NLS-1$ >+ } >+ >+ IWorkbenchPage activePage = activeWindow.getActivePage(); >+ if (activePage == null) { >+ throw new ExecutionException("no active workbench page"); //$NON-NLS-1$ >+ } >+ >+ try { >+ IViewPart view = activePage.showView(IPageLayout.ID_RES_NAV); >+ if (view instanceof ISetSelectionTarget) { >+ ISelection selection = new StructuredSelection(resource); >+ ((ISetSelectionTarget) view).selectReveal(selection); >+ } >+ } catch (PartInitException e) { >+ throw new ExecutionException("error showing resource in navigator"); //$NON-NLS-1$ >+ } >+ >+ return null; >+ } >+ >+} >Index: src/org/eclipse/ui/internal/ide/commands/OpenFileByPathHandler.java >=================================================================== >RCS file: src/org/eclipse/ui/internal/ide/commands/OpenFileByPathHandler.java >diff -N src/org/eclipse/ui/internal/ide/commands/OpenFileByPathHandler.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/ui/internal/ide/commands/OpenFileByPathHandler.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,65 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.ui.internal.ide.commands; >+ >+import org.eclipse.core.commands.AbstractHandler; >+import org.eclipse.core.commands.ExecutionEvent; >+import org.eclipse.core.commands.ExecutionException; >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.ui.IWorkbenchPage; >+import org.eclipse.ui.IWorkbenchWindow; >+import org.eclipse.ui.PartInitException; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.ide.IDE; >+ >+/** >+ * A command handler to open a file in its editor given the resource path. >+ * >+ * @since 3.2 >+ */ >+public class OpenFileByPathHandler extends AbstractHandler { >+ >+ private static final String PARAM_ID_FILE_PATH = "filePath"; //$NON-NLS-1$ >+ >+ public Object execute(ExecutionEvent event) throws ExecutionException { >+ >+ IResource resource = (IResource) event >+ .getObjectParameterForExecution(PARAM_ID_FILE_PATH); >+ >+ if (!(resource instanceof IFile)) { >+ throw new ExecutionException( >+ "filePath parameter must identify a file"); //$NON-NLS-1$ >+ } >+ IFile file = (IFile) resource; >+ >+ IWorkbenchWindow activeWindow = PlatformUI.getWorkbench() >+ .getActiveWorkbenchWindow(); >+ if (activeWindow == null) { >+ throw new ExecutionException("no active workbench window"); //$NON-NLS-1$ >+ } >+ >+ IWorkbenchPage activePage = activeWindow.getActivePage(); >+ if (activePage == null) { >+ throw new ExecutionException("no active workbench page"); //$NON-NLS-1$ >+ } >+ >+ try { >+ IDE.openEditor(activePage, file, true); >+ } catch (PartInitException ex) { >+ throw new ExecutionException("error opening file in editor", ex); //$NON-NLS-1$ >+ } >+ >+ return null; >+ } >+ >+} >Index: src/org/eclipse/ui/internal/ide/commands/ResourcePathConverter.java >=================================================================== >RCS file: src/org/eclipse/ui/internal/ide/commands/ResourcePathConverter.java >diff -N src/org/eclipse/ui/internal/ide/commands/ResourcePathConverter.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/ui/internal/ide/commands/ResourcePathConverter.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,57 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.ui.internal.ide.commands; >+ >+import org.eclipse.core.commands.AbstractParameterValueConverter; >+import org.eclipse.core.commands.ParameterValueConversionException; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.IWorkspaceRoot; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.Path; >+ >+/** >+ * A command parameter value converter to convert between IResources and strings >+ * encoding the path of a resource. >+ * >+ * @since 3.2 >+ */ >+public class ResourcePathConverter extends AbstractParameterValueConverter { >+ >+ public Object convertToObject(String parameterValue) >+ throws ParameterValueConversionException { >+ >+ Path path = new Path(parameterValue); >+ >+ IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); >+ IResource resource = workspaceRoot.findMember(path); >+ >+ if ((resource == null) || (!resource.exists())) { >+ throw new ParameterValueConversionException( >+ "parameterValue must be the path of an existing resource"); //$NON-NLS-1$ >+ } >+ >+ return resource; >+ } >+ >+ public String convertToString(Object parameterValue) >+ throws ParameterValueConversionException { >+ >+ if (!(parameterValue instanceof IResource)) { >+ throw new ParameterValueConversionException( >+ "parameterValue must be an IResource"); //$NON-NLS-1$ >+ } >+ IResource resource = (IResource) parameterValue; >+ >+ return resource.getFullPath().toString(); >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 126079
: 33959 |
34727