### Eclipse Workspace Patch 1.0 #P org.eclipse.ui.ide.application Index: src/org/eclipse/ui/internal/ide/application/IDEWorkbenchWindowAdvisor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/IDEWorkbenchWindowAdvisor.java,v retrieving revision 1.1 diff -u -r1.1 IDEWorkbenchWindowAdvisor.java --- src/org/eclipse/ui/internal/ide/application/IDEWorkbenchWindowAdvisor.java 9 Jan 2007 21:19:24 -0000 1.1 +++ src/org/eclipse/ui/internal/ide/application/IDEWorkbenchWindowAdvisor.java 15 Feb 2007 12:31:55 -0000 @@ -28,6 +28,7 @@ import org.eclipse.jface.resource.JFaceResources; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.FileTransfer; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; @@ -192,6 +193,7 @@ configurer.addEditorAreaTransfer(EditorInputTransfer .getInstance()); configurer.addEditorAreaTransfer(ResourceTransfer.getInstance()); + configurer.addEditorAreaTransfer(FileTransfer.getInstance()); configurer.addEditorAreaTransfer(MarkerTransfer.getInstance()); configurer .configureEditorAreaDropListener(new EditorAreaDropAdapter( #P org.eclipse.ui.ide Index: src/org/eclipse/ui/ide/IDE.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IDE.java,v retrieving revision 1.55 diff -u -r1.55 IDE.java --- src/org/eclipse/ui/ide/IDE.java 12 Jan 2007 18:59:43 -0000 1.55 +++ src/org/eclipse/ui/ide/IDE.java 15 Feb 2007 12:31:59 -0000 @@ -16,8 +16,25 @@ import java.util.Iterator; import java.util.List; +import org.eclipse.osgi.util.NLS; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Shell; + import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileStore; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.core.runtime.SafeRunner; +import org.eclipse.core.runtime.content.IContentDescription; +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.core.runtime.content.IContentTypeMatcher; + import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; @@ -32,23 +49,12 @@ import org.eclipse.core.resources.mapping.ResourceMapping; import org.eclipse.core.resources.mapping.ResourceMappingContext; import org.eclipse.core.resources.mapping.ResourceTraversal; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.core.runtime.SafeRunner; -import org.eclipse.core.runtime.content.IContentDescription; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.core.runtime.content.IContentTypeMatcher; + import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.util.SafeRunnable; import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Shell; + import org.eclipse.ui.IEditorDescriptor; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; @@ -1049,6 +1055,63 @@ return editor; } + /** + * Opens an editor on the given IFileStore object. + *

+ * Unlike the other openEditor methods, this one + * can be used to open files that reside outside the workspace + * resource set. + *

+ *

+ * If the page already has an editor open on the target object then that + * editor is brought to front; otherwise, a new editor is opened. + *

+ * + * @param page + * the page in which the editor will be opened + * @param fileStore + * the IFileStore representing the file to open + * @return an open editor or null if an external editor was opened + * @exception PartInitException + * if the editor could not be initialized + * @see org.eclipse.ui.IWorkbenchPage#openEditor(IEditorInput, String) + * @since 3.3 + */ + public static IEditorPart openEditorOnFileStore(IWorkbenchPage page, IFileStore fileStore) throws PartInitException { + //sanity checks + if (page == null) { + throw new IllegalArgumentException(); + } + + IEditorInput input = getEditorInput(fileStore); + String editorId = getEditorId(fileStore); + + // open the editor on the file + return page.openEditor(input, editorId); + } + + /** + * Get the id of the editor associated with the given IFileStore. + * + * @param workbench + * the Workbench to use to determine the appropriate editor's id + * @param fileStore + * the IFileStore representing the file for which the editor id is desired + * @return the id of the appropriate editor + * @since 3.3 + */ + private static String getEditorId(IFileStore fileStore) { + IEditorDescriptor descriptor; + try { + descriptor = IDE.getEditorDescriptor(fileStore.getName()); + } catch (PartInitException e) { + return null; + } + if (descriptor != null) + return descriptor.getId(); + return null; + } + /** * Save all dirty editors in the workbench whose editor input is a child * resource of one of the IResource's provided. Opens a Index: src/org/eclipse/ui/internal/ide/EditorAreaDropAdapter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/EditorAreaDropAdapter.java,v retrieving revision 1.11 diff -u -r1.11 EditorAreaDropAdapter.java --- src/org/eclipse/ui/internal/ide/EditorAreaDropAdapter.java 24 Oct 2006 17:04:32 -0000 1.11 +++ src/org/eclipse/ui/internal/ide/EditorAreaDropAdapter.java 15 Feb 2007 12:31:59 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2007 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 @@ -11,14 +11,18 @@ package org.eclipse.ui.internal.ide; +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Path; import org.eclipse.swt.dnd.DND; import org.eclipse.swt.dnd.DropTargetAdapter; import org.eclipse.swt.dnd.DropTargetEvent; +import org.eclipse.swt.dnd.FileTransfer; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IEditorDescriptor; import org.eclipse.ui.IEditorInput; @@ -119,6 +123,21 @@ } } + /* Open Editor for file from local file system */ + else if (FileTransfer.getInstance().isSupportedType( + event.currentDataType)) { + Assert.isTrue(event.data instanceof String[]); + String[] paths = (String[]) event.data; + for (int i = 0; i < paths.length; i++) { + IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(paths[i])); + try { + IDE.openEditorOnFileStore(page, fileStore); + } catch (PartInitException e) { + // silently ignore problems opening the editor + } + } + } + } /**