Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKai Maetzel2003-09-30 17:16:11 +0000
committerKai Maetzel2003-09-30 17:16:11 +0000
commitf5f6e8e91e57453c2801657e328e2267de8dcb31 (patch)
tree0bb7fbec0ea7250b76f8361c41989780c09b0ad1 /org.eclipse.ui.editors/src
parentfd870d2da2429bfa98d14a055bf468465f77ecf5 (diff)
downloadeclipse.platform.text-f5f6e8e91e57453c2801657e328e2267de8dcb31.tar.gz
eclipse.platform.text-f5f6e8e91e57453c2801657e328e2267de8dcb31.tar.xz
eclipse.platform.text-f5f6e8e91e57453c2801657e328e2267de8dcb31.zip
external file support
Diffstat (limited to 'org.eclipse.ui.editors/src')
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/ILocationProvider.java26
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/TextFileDocumentProvider.java68
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/EditorsPlugin.java48
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/FileEditorInputAdapterFactory.java63
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/JavaFileEditorInput.java90
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/OpenExternalFileAction.java109
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties2
7 files changed, 374 insertions, 32 deletions
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/ILocationProvider.java b/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/ILocationProvider.java
new file mode 100644
index 00000000000..cb8c9fb5270
--- /dev/null
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/ILocationProvider.java
@@ -0,0 +1,26 @@
+/**********************************************************************
+Copyright (c) 2000, 2003 IBM Corp. and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Common Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/cpl-v10.html
+
+Contributors:
+ IBM Corporation - Initial implementation
+**********************************************************************/
+package org.eclipse.ui.editors.text;
+
+import org.eclipse.core.runtime.IPath;
+
+/**
+ * @since 3.0
+ */
+public interface ILocationProvider {
+
+ /**
+ * Returns the location of the given object or <code>null</code>.
+ *
+ * @return the location of the given object or <code>null</code>
+ */
+ IPath getPath(Object element);
+}
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/TextFileDocumentProvider.java b/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/TextFileDocumentProvider.java
index adf86f48005..8c1a0dcb094 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/TextFileDocumentProvider.java
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/TextFileDocumentProvider.java
@@ -29,7 +29,10 @@ import org.eclipse.core.filebuffers.ITextFileBuffer;
import org.eclipse.core.filebuffers.ITextFileBufferManager;
import org.eclipse.core.internal.filebuffers.ContainerGenerator;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -170,10 +173,12 @@ public class TextFileDocumentProvider implements IDocumentProvider, IDocumentPr
}
/*
- * @see org.eclipse.core.buffer.text.IBufferedFileListener#underlyingFileMoved(org.eclipse.core.buffer.text.IBufferedFile, org.eclipse.core.resources.IFile)
+ * @see org.eclipse.core.buffer.text.IBufferedFileListener#underlyingFileMoved(org.eclipse.core.buffer.text.IBufferedFile, org.eclipse.core.runtime.IPath)
*/
- public void underlyingFileMoved(IFileBuffer file, IFile target) {
- IEditorInput input= target == null ? null : new FileEditorInput(target);
+ public void underlyingFileMoved(IFileBuffer file, IPath newLocation) {
+ IWorkspace workspace=ResourcesPlugin.getWorkspace();
+ IFile newFile= workspace.getRoot().getFile(newLocation);
+ IEditorInput input= newFile == null ? null : new FileEditorInput(newFile);
List list= new ArrayList(fElementStateListeners);
Iterator e= list.iterator();
while (e.hasNext()) {
@@ -289,19 +294,41 @@ public class TextFileDocumentProvider implements IDocumentProvider, IDocumentPr
return new FileInfo();
}
+ /**
+ * Returns the workspace file at the given location or <code>null</code> if
+ * the location is not a valid location in the workspace.
+ *
+ * @param location the location
+ * @return the workspace file at the location or <code>null</code>
+ */
+ protected IFile getWorkspaceFileAtLocation(IPath location) {
+// IWorkspace workspace= ResourcesPlugin.getWorkspace();
+// return workspace.getRoot().getFileForLocation(location);
+ return null;
+ }
+
protected FileInfo createFileInfo(Object element) throws CoreException {
- if (element instanceof IFileEditorInput) {
- IFileEditorInput input= (IFileEditorInput) element;
-
- IFile file= input.getFile();
+
+ IPath location= null;
+ if (element instanceof IAdaptable) {
+ IAdaptable adaptable= (IAdaptable) element;
+ ILocationProvider provider= (ILocationProvider) adaptable.getAdapter(ILocationProvider.class);
+ if (provider != null)
+ location= provider.getPath(element);
+ }
+
+ if (location != null) {
ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
- manager.connect(file, getProgressMonitor());
- manager.requestSynchronizationContext(file);
- ITextFileBuffer f= manager.getTextFileBuffer(file);
+ manager.connect(location, getProgressMonitor());
+ manager.requestSynchronizationContext(location);
+ ITextFileBuffer fileBuffer= manager.getTextFileBuffer(location);
FileInfo info= createEmptyFileInfo();
- info.fTextFileBuffer= f;
- info.fModel= createAnnotationModel(file);
+ info.fTextFileBuffer= fileBuffer;
+
+ IFile file= getWorkspaceFileAtLocation(location);
+ if (file != null && file.exists())
+ info.fModel= createAnnotationModel(file);
return info;
}
return null;
@@ -334,9 +361,9 @@ public class TextFileDocumentProvider implements IDocumentProvider, IDocumentPr
protected void disposeFileInfo(Object element, FileInfo info) {
IFileBufferManager manager= FileBuffers.getTextFileBufferManager();
try {
- IFile file= info.fTextFileBuffer.getUnderlyingFile();
- manager.releaseSynchronizationContext(file);
- manager.disconnect(file, getProgressMonitor());
+ IPath location= info.fTextFileBuffer.getLocation();
+ manager.releaseSynchronizationContext(location);
+ manager.disconnect(location, getProgressMonitor());
} catch (CoreException x) {
handleCoreException(x, "FileDocumentProvider.disposeElementInfo"); //$NON-NLS-1$
}
@@ -404,12 +431,8 @@ public class TextFileDocumentProvider implements IDocumentProvider, IDocumentPr
*/
public long getModificationStamp(Object element) {
FileInfo info= (FileInfo) fFileInfoMap.get(element);
- if (info != null) {
- File file= getSystemFile(info);
- if (file != null)
- return file.lastModified();
- return info.fTextFileBuffer.getUnderlyingFile().getModificationStamp();
- }
+ if (info != null)
+ return info.fTextFileBuffer.getModifcationStamp();
return getParentProvider().getModificationStamp(element);
}
@@ -649,8 +672,7 @@ public class TextFileDocumentProvider implements IDocumentProvider, IDocumentPr
}
protected File getSystemFile(FileInfo info) {
- IFile file= info.fTextFileBuffer.getUnderlyingFile();
- IPath path= file.getLocation();
+ IPath path= info.fTextFileBuffer.getLocation();
return path == null ? null : path.toFile();
}
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/EditorsPlugin.java b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/EditorsPlugin.java
index 756997528f8..510bd06487e 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/EditorsPlugin.java
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/EditorsPlugin.java
@@ -10,9 +10,13 @@
*******************************************************************************/
package org.eclipse.ui.internal.editors.text;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.IPluginDescriptor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.preference.IPreferenceStore;
@@ -28,14 +32,10 @@ import org.eclipse.ui.plugin.AbstractUIPlugin;
*/
public class EditorsPlugin extends AbstractUIPlugin {
- private static EditorsPlugin fgInst;
- public EditorsPlugin(IPluginDescriptor descriptor) {
- super(descriptor);
- fgInst= this;
- }
-
+ private static EditorsPlugin fgInstance;
+
public static EditorsPlugin getDefault() {
- return fgInst;
+ return fgInstance;
}
public static void log(IStatus status) {
@@ -49,7 +49,7 @@ public class EditorsPlugin extends AbstractUIPlugin {
public static void logErrorMessage(String message) {
log(new Status(IStatus.ERROR, getPluginId(), IEditorsStatusConstants.INTERNAL_ERROR, message, null));
}
-
+
public static void logErrorStatus(String message, IStatus status) {
if (status == null) {
logErrorMessage(message);
@@ -63,11 +63,41 @@ public class EditorsPlugin extends AbstractUIPlugin {
public static void log(Throwable e) {
log(new Status(IStatus.ERROR, getPluginId(), IEditorsStatusConstants.INTERNAL_ERROR, TextEditorMessages.getString("EditorsPlugin.internal_error"), e)); //$NON-NLS-1$
}
+
+
+
+ private FileEditorInputAdapterFactory fFileEditorInputAdapterFactory;
+
+
+ public EditorsPlugin(IPluginDescriptor descriptor) {
+ super(descriptor);
+ fgInstance= this;
+ }
+
- /* (non-Javadoc)
+ /*
* @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeDefaultPreferences(org.eclipse.jface.preference.IPreferenceStore)
*/
protected void initializeDefaultPreferences(IPreferenceStore store) {
TextEditorPreferenceConstants.initializeDefaultValues(store);
}
+
+ /*
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#startup()
+ */
+ public void startup() throws CoreException {
+ super.startup();
+ fFileEditorInputAdapterFactory= new FileEditorInputAdapterFactory();
+ IAdapterManager manager= Platform.getAdapterManager();
+ manager.registerAdapters(fFileEditorInputAdapterFactory, IFile.class);
+ }
+
+ /*
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#shutdown()
+ */
+ public void shutdown() throws CoreException {
+ IAdapterManager manager= Platform.getAdapterManager();
+ manager.unregisterAdapters(fFileEditorInputAdapterFactory);
+ super.shutdown();
+ }
}
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/FileEditorInputAdapterFactory.java b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/FileEditorInputAdapterFactory.java
new file mode 100644
index 00000000000..3ae26c1076b
--- /dev/null
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/FileEditorInputAdapterFactory.java
@@ -0,0 +1,63 @@
+/**********************************************************************
+Copyright (c) 2000, 2003 IBM Corp. and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Common Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/cpl-v10.html
+
+Contributors:
+ IBM Corporation - Initial implementation
+**********************************************************************/
+
+package org.eclipse.ui.internal.editors.text;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.core.runtime.IPath;
+
+//import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.editors.text.ILocationProvider;
+
+/**
+ * @since 3.0
+ */
+public class FileEditorInputAdapterFactory implements IAdapterFactory {
+
+ private static class LocationProvider implements ILocationProvider {
+ /*
+ * @see org.eclipse.ui.editors.text.ILocationProvider#getLocation(java.lang.Object)
+ */
+ public IPath getPath(Object element) {
+ if (element instanceof IFileEditorInput) {
+ IFileEditorInput input= (IFileEditorInput) element;
+ return input.getFile().getLocation();
+ }
+ return null;
+ }
+ }
+
+ /** The list of provided adapters. */
+ private static final Class[] ADAPTER_LIST= new Class[] { ILocationProvider.class };
+
+ /** The provided location provider */
+ private ILocationProvider fLocationProvider= new LocationProvider();
+
+ /*
+ * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
+ */
+ public Object getAdapter(Object adaptableObject, Class adapterType) {
+ if (ILocationProvider.class.equals(adapterType)) {
+ if (adaptableObject instanceof IFile)
+ return fLocationProvider;
+ }
+ return null;
+ }
+
+ /*
+ * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
+ */
+ public Class[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/JavaFileEditorInput.java b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/JavaFileEditorInput.java
new file mode 100644
index 00000000000..2b8cfaf940d
--- /dev/null
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/JavaFileEditorInput.java
@@ -0,0 +1,90 @@
+/**********************************************************************
+Copyright (c) 2000, 2003 IBM Corp. and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Common Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/cpl-v10.html
+
+Contributors:
+ IBM Corporation - Initial implementation
+**********************************************************************/
+package org.eclipse.ui.internal.editors.text;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+import org.eclipse.ui.editors.text.ILocationProvider;
+
+/**
+ * @since 3.0
+ */
+public class JavaFileEditorInput implements IEditorInput, ILocationProvider {
+
+ private File fFile;
+
+ public JavaFileEditorInput(File file) {
+ super();
+ fFile= file;
+ }
+ /*
+ * @see org.eclipse.ui.IEditorInput#exists()
+ */
+ public boolean exists() {
+ return fFile.exists();
+ }
+
+ /*
+ * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
+ */
+ public ImageDescriptor getImageDescriptor() {
+ return null;
+ }
+
+ /*
+ * @see org.eclipse.ui.IEditorInput#getName()
+ */
+ public String getName() {
+ return fFile.getName();
+ }
+
+ /*
+ * @see org.eclipse.ui.IEditorInput#getPersistable()
+ */
+ public IPersistableElement getPersistable() {
+ return null;
+ }
+
+ /*
+ * @see org.eclipse.ui.IEditorInput#getToolTipText()
+ */
+ public String getToolTipText() {
+ return fFile.getAbsolutePath();
+ }
+
+ /*
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ */
+ public Object getAdapter(Class adapter) {
+ if (ILocationProvider.class.equals(adapter))
+ return this;
+ return Platform.getAdapterManager().getAdapter(this, adapter);
+ }
+
+ /*
+ * @see org.eclipse.ui.editors.text.ILocationProvider#getPath(java.lang.Object)
+ */
+ public IPath getPath(Object element) {
+ if (element instanceof JavaFileEditorInput) {
+ JavaFileEditorInput input= (JavaFileEditorInput) element;
+ return new Path(input.fFile.getAbsolutePath());
+ }
+ return null;
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/OpenExternalFileAction.java b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/OpenExternalFileAction.java
new file mode 100644
index 00000000000..074092fabd5
--- /dev/null
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/OpenExternalFileAction.java
@@ -0,0 +1,109 @@
+/**********************************************************************
+Copyright (c) 2000, 2003 IBM Corp. and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Common Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/cpl-v10.html
+
+Contributors:
+ IBM Corporation - Initial implementation
+**********************************************************************/
+package org.eclipse.ui.internal.editors.text;
+
+import java.io.File;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.FileDialog;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorRegistry;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.ui.PartInitException;
+
+/**
+ * @since 3.0
+ */
+public class OpenExternalFileAction extends Action implements IWorkbenchWindowActionDelegate {
+
+ private IWorkbenchWindow fWindow;
+
+ public OpenExternalFileAction() {
+// setId("org.eclipse.ui.edit.text.openExternalFile");
+// setActionDefinitionId("org.eclipse.ui.edit.text.openExternalFile");
+ setEnabled(true);
+ }
+
+ /*
+ * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
+ */
+ public void dispose() {
+ fWindow= null;
+ }
+
+ /*
+ * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
+ */
+ public void init(IWorkbenchWindow window) {
+ fWindow= window;
+ }
+
+ /*
+ * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+ */
+ public void run(IAction action) {
+ run();
+ }
+
+ /*
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+ private File queryFile() {
+ FileDialog dialog= new FileDialog(fWindow.getShell(), SWT.OPEN);
+ dialog.setText(TextEditorMessages.getString("OpenExternalFileAction.dialog.text")); //$NON-NLS-1$
+ String path= dialog.open();
+ if (path != null)
+ return new File(path);
+ return null;
+ }
+
+ /*
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ public void run() {
+ File file= queryFile();
+ if (file != null && file.exists()) {
+ IEditorInput input= createEditorInput(file);
+ String editorId= getEditorId(file);
+ IWorkbenchPage page= fWindow.getActivePage();
+ try {
+ page.openEditor(input, editorId);
+ } catch (PartInitException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private String getEditorId(File file) {
+ IWorkbench workbench= fWindow.getWorkbench();
+ IEditorRegistry editorRegistry= workbench.getEditorRegistry();
+ IEditorDescriptor descriptor= editorRegistry.getDefaultEditor(file.getName());
+ if (descriptor != null)
+ return descriptor.getId();
+ return "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$
+ }
+
+ private IEditorInput createEditorInput(File file) {
+ return new JavaFileEditorInput(file);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties
index debe3d650a4..10b69200e4d 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties
@@ -50,3 +50,5 @@ TextEditorPreferencePage.quickdiff.referenceprovidertitle=Quickdiff &reference p
TextEditorPreferencePage.quickdiff.setDefault=Make &Default
TextEditorPreferencePage.quickdiff.defaultlabel= (default)
TextEditorPreferencePage.quickDiffCharacterMode= Show changes using &characters instead of colors (on line number bar only)
+
+OpenExternalFileAction.dialog.text=Open External File

Back to the top