How to open external file as resource in editor [message #467489] |
Fri, 04 May 2007 09:57  |
Eclipse User |
|
|
|
My name is Alex and I am working on a simple Eclipse application (which is
supposed to run both as plugin and as RCP).
The application opens a template file, allows the user to modify it using
simple form editor, and saves it back to the disk as document.
I like Eclipse very much, but my product manager keeps saying that our
users don
|
|
|
|
|
|
Re: How to open external file as resource in editor [message #467585 is a reply to message #467489] |
Tue, 08 May 2007 09:05   |
Eclipse User |
|
|
|
Originally posted by: m.hybler.aegis.cz
Alex Romanov wrote:
> My name is Alex and I am working on a simple Eclipse application (which is
> supposed to run both as plugin and as RCP).
>
> The application opens a template file, allows the user to modify it using
> simple form editor, and saves it back to the disk as document.
>
> I like Eclipse very much, but my product manager keeps saying that our
> users don’t need Workspace and Projects and they would like to just open
> the template from anywhere on the disk and save it in any other path.
>
> I have seen multiple discussions on the subject, and my question is:
>
> Is it possible today (3.2.2) to open an editor on an external file and save
> the editing results to another external file without custom IStorage and
> IStorageEditorInput implementations.
>
> Best Regards.
>
> Alex.
I had the same problem. Solution is FileStoreEditorInput but it isnt
part of Eclipse (or not visible). I have created my own and copy the
code from some site.
There is:
-------------------------------------------------
/*********************************************************** ********************
* Copyright (c) 2000, 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 cz.aegis.cms.viewer.editor;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
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.IPathEditorInput;
import org.eclipse.ui.IPersistableElement;
import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.model.IWorkbenchAdapter;
/**
* Implements an IEditorInput instance appropriate for
+ * <code>IFileStore</code> elements that represent files
+ * that are not part of the current workspace.
+ *
+ * @since 3.3
+ *
*/
public class FileStoreEditorInput implements IPathEditorInput,
IStorageEditorInput {
/**
* The workbench adapter which simply provides the label.
*
* @since 3.3
*/
private class WorkbenchAdapter implements IWorkbenchAdapter {
/*
* @see
org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang .Object)
*/
public Object[] getChildren(Object o) {
return null;
}
/*
* @see
org.eclipse.ui.model.IWorkbenchAdapter#getImageDescriptor(ja va.lang.Object)
*/
public ImageDescriptor getImageDescriptor(Object object) {
return null;
}
/*
* @see
org.eclipse.ui.model.IWorkbenchAdapter#getLabel(java.lang.Ob ject)
*/
public String getLabel(Object o) {
return ((FileStoreEditorInput)o).getName();
}
/*
* @see
org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.O bject)
*/
public Object getParent(Object o) {
return null;
}
}
private IFileStore fFileStore;
private WorkbenchAdapter fWorkbenchAdapter= new WorkbenchAdapter();
private IStorage fStorage;
private IPath fPath;
/**
* @param fileStore
*/
public FileStoreEditorInput(IFileStore fileStore) {
Assert.isNotNull(fileStore);
Assert.isTrue(EFS.SCHEME_FILE.equals(fileStore.getFileSystem ().getScheme()));
fFileStore = fileStore;
fWorkbenchAdapter = new WorkbenchAdapter();
}
/*
* @see org.eclipse.ui.IEditorInput#exists()
*/
public boolean exists() {
return fFileStore.fetchInfo().exists();
}
/*
* @see org.eclipse.ui.IEditorInput#getImageDescriptor()
*/
public ImageDescriptor getImageDescriptor() {
return null;
}
/*
* @see org.eclipse.ui.IEditorInput#getName()
*/
public String getName() {
return fFileStore.getName();
}
/*
* @see org.eclipse.ui.IEditorInput#getPersistable()
*/
public IPersistableElement getPersistable() {
return null;
}
/*
* @see org.eclipse.ui.IEditorInput#getToolTipText()
*/
public String getToolTipText() {
return fFileStore.toString();
}
/*
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Cla ss)
*/
public Object getAdapter(Class adapter) {
if (IWorkbenchAdapter.class.equals(adapter))
return fWorkbenchAdapter;
return Platform.getAdapterManager().getAdapter(this, adapter);
}
/**
* HACK! need to figure out what 'ILocationProvider' is used for...
* @param element
* @return The path for the element
*/
public IPath getPath(Object element) {
if (element instanceof FileStoreEditorInput)
return ((FileStoreEditorInput)element).getPath();
return null;
}
/*
* @see org.eclipse.ui.IPathEditorInput#getPath()
* @since 3.1
*/
public IPath getPath() {
if (fPath == null)
fPath= new Path(fFileStore.toURI().getPath());
return fPath;
}
/*
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object o) {
if (o == this)
return true;
if (o instanceof FileStoreEditorInput) {
FileStoreEditorInput input= (FileStoreEditorInput) o;
return fFileStore.equals(input.fFileStore);
}
if (o instanceof IPathEditorInput) {
IPathEditorInput input= (IPathEditorInput)o;
return getPath().equals(input.getPath());
}
return false;
}
/*
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return fFileStore.hashCode();
}
/*
* @see org.eclipse.ui.IStorageEditorInput#getStorage()
* @since 3.2
*/
public IStorage getStorage() throws CoreException {
if (fStorage == null)
fStorage= new FileStoreStorage(fFileStore);
return fStorage;
}
}
-----------------------and one dependency------------------------------
package cz.aegis.cms.viewer.editor;
import java.io.InputStream;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
/**
* A storage for an <code>IFileStore</code> element.
*
* @since 3.3
*/
class FileStoreStorage implements IStorage {
private IFileStore fFileStore;
private IPath fFullPath;
public FileStoreStorage(IFileStore fileStore) {
Assert.isNotNull(fileStore);
Assert.isTrue(EFS.SCHEME_FILE.equals(fileStore.getFileSystem ().getScheme()));
fFileStore= fileStore;
}
/*
* @see org.eclipse.core.resources.IStorage#getContents()
*/
public InputStream getContents() throws CoreException {
return fFileStore.openInputStream(EFS.NONE, null);
}
/*
* @see org.eclipse.core.resources.IStorage#getFullPath()
*/
public IPath getFullPath() {
if (fFullPath == null)
fFullPath= new Path(fFileStore.toURI().getPath());
return fFullPath;
}
/*
* @see org.eclipse.core.resources.IStorage#getName()
*/
public String getName() {
return fFileStore.getName();
}
/*
* @see org.eclipse.core.resources.IStorage#isReadOnly()
*/
public boolean isReadOnly() {
return fFileStore.fetchInfo().getAttribute(EFS.ATTRIBUTE_READ_ONLY) ;
}
/*
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Cla ss)
*/
public Object getAdapter(Class adapter) {
return null;
}
}
------------------------------------------------
By now its working good.
Someone has any comments for this example?
Michal
|
|
|
Re: How to open external file as resource in editor [message #467594 is a reply to message #467585] |
Tue, 08 May 2007 11:25  |
Eclipse User |
|
|
|
Michal Hybler wrote:
> Alex Romanov wrote:
>
>> My name is Alex and I am working on a simple Eclipse application
>> (which is supposed to run both as plugin and as RCP). The application
>> opens a template file, allows the user to modify it using simple form
>> editor, and saves it back to the disk as document. I like Eclipse
>> very much, but my product manager keeps saying that our users don’t
>> need Workspace and Projects and they would like to just open the
>> template from anywhere on the disk and save it in any other path. I
>> have seen multiple discussions on the subject, and my question is: Is
>> it possible today (3.2.2) to open an editor on an external file and
>> save the editing results to another external file without custom
>> IStorage and IStorageEditorInput implementations. Best Regards. Alex.
>
>
> I had the same problem. Solution is FileStoreEditorInput but it isnt
> part of Eclipse (or not visible).
This is public API in 3.3
Dani
> I have created my own and copy the code from some site.
>
> There is:
> -------------------------------------------------
> /*********************************************************** ********************
>
> * Copyright (c) 2000, 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 cz.aegis.cms.viewer.editor;
>
> import org.eclipse.core.filesystem.EFS;
> import org.eclipse.core.filesystem.IFileStore;
> import org.eclipse.core.resources.IStorage;
> import org.eclipse.core.runtime.Assert;
> import org.eclipse.core.runtime.CoreException;
> 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.IPathEditorInput;
> import org.eclipse.ui.IPersistableElement;
> import org.eclipse.ui.IStorageEditorInput;
> import org.eclipse.ui.model.IWorkbenchAdapter;
>
> /**
> * Implements an IEditorInput instance appropriate for
> + * <code>IFileStore</code> elements that represent files
> + * that are not part of the current workspace.
> + *
> + * @since 3.3
> + *
> */
> public class FileStoreEditorInput implements IPathEditorInput,
> IStorageEditorInput {
>
> /**
> * The workbench adapter which simply provides the label.
> *
> * @since 3.3
> */
> private class WorkbenchAdapter implements IWorkbenchAdapter {
> /*
> * @see
> org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang .Object)
> */
> public Object[] getChildren(Object o) {
> return null;
> }
>
> /*
> * @see
> org.eclipse.ui.model.IWorkbenchAdapter#getImageDescriptor(ja va.lang.Object)
>
> */
> public ImageDescriptor getImageDescriptor(Object object) {
> return null;
> }
>
> /*
> * @see org.eclipse.ui.model.IWorkbenchAdapter#getLabel(java.lang.Ob ject)
> */
> public String getLabel(Object o) {
> return ((FileStoreEditorInput)o).getName();
> }
>
> /*
> * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.O bject)
> */
> public Object getParent(Object o) {
> return null;
> }
> }
>
> private IFileStore fFileStore;
> private WorkbenchAdapter fWorkbenchAdapter= new WorkbenchAdapter();
> private IStorage fStorage;
> private IPath fPath;
>
> /**
> * @param fileStore
> */
> public FileStoreEditorInput(IFileStore fileStore) {
> Assert.isNotNull(fileStore);
> Assert.isTrue(EFS.SCHEME_FILE.equals(fileStore.getFileSystem ().getScheme()));
>
> fFileStore = fileStore;
> fWorkbenchAdapter = new WorkbenchAdapter();
> }
> /*
> * @see org.eclipse.ui.IEditorInput#exists()
> */
> public boolean exists() {
> return fFileStore.fetchInfo().exists();
> }
>
> /*
> * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
> */
> public ImageDescriptor getImageDescriptor() {
> return null;
> }
>
> /*
> * @see org.eclipse.ui.IEditorInput#getName()
> */
> public String getName() {
> return fFileStore.getName();
> }
>
> /*
> * @see org.eclipse.ui.IEditorInput#getPersistable()
> */
> public IPersistableElement getPersistable() {
> return null;
> }
>
> /*
> * @see org.eclipse.ui.IEditorInput#getToolTipText()
> */
> public String getToolTipText() {
> return fFileStore.toString();
> }
>
> /*
> * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Cla ss)
> */
> public Object getAdapter(Class adapter) {
> if (IWorkbenchAdapter.class.equals(adapter))
> return fWorkbenchAdapter;
> return Platform.getAdapterManager().getAdapter(this, adapter);
> }
>
> /**
> * HACK! need to figure out what 'ILocationProvider' is used for...
> * @param element
> * @return The path for the element
> */
> public IPath getPath(Object element) {
> if (element instanceof FileStoreEditorInput)
> return ((FileStoreEditorInput)element).getPath();
>
> return null;
> }
>
> /*
> * @see org.eclipse.ui.IPathEditorInput#getPath()
> * @since 3.1
> */
> public IPath getPath() {
> if (fPath == null)
> fPath= new Path(fFileStore.toURI().getPath());
> return fPath;
> }
>
> /*
> * @see java.lang.Object#equals(java.lang.Object)
> */
> public boolean equals(Object o) {
> if (o == this)
> return true;
>
> if (o instanceof FileStoreEditorInput) {
> FileStoreEditorInput input= (FileStoreEditorInput) o;
> return fFileStore.equals(input.fFileStore);
> }
>
> if (o instanceof IPathEditorInput) {
> IPathEditorInput input= (IPathEditorInput)o;
> return getPath().equals(input.getPath());
> }
>
> return false;
> }
>
> /*
> * @see java.lang.Object#hashCode()
> */
> public int hashCode() {
> return fFileStore.hashCode();
> }
>
> /*
> * @see org.eclipse.ui.IStorageEditorInput#getStorage()
> * @since 3.2
> */
> public IStorage getStorage() throws CoreException {
> if (fStorage == null)
> fStorage= new FileStoreStorage(fFileStore);
> return fStorage;
> }
>
> }
> -----------------------and one dependency------------------------------
> package cz.aegis.cms.viewer.editor;
>
>
> import java.io.InputStream;
>
> import org.eclipse.core.filesystem.EFS;
> import org.eclipse.core.filesystem.IFileStore;
> import org.eclipse.core.resources.IStorage;
> import org.eclipse.core.runtime.Assert;
> import org.eclipse.core.runtime.CoreException;
> import org.eclipse.core.runtime.IPath;
> import org.eclipse.core.runtime.Path;
>
> /**
> * A storage for an <code>IFileStore</code> element.
> *
> * @since 3.3
> */
> class FileStoreStorage implements IStorage {
>
> private IFileStore fFileStore;
> private IPath fFullPath;
>
> public FileStoreStorage(IFileStore fileStore) {
> Assert.isNotNull(fileStore);
> Assert.isTrue(EFS.SCHEME_FILE.equals(fileStore.getFileSystem ().getScheme()));
>
> fFileStore= fileStore;
> }
>
> /*
> * @see org.eclipse.core.resources.IStorage#getContents()
> */
> public InputStream getContents() throws CoreException {
> return fFileStore.openInputStream(EFS.NONE, null);
> }
>
> /*
> * @see org.eclipse.core.resources.IStorage#getFullPath()
> */
> public IPath getFullPath() {
> if (fFullPath == null)
> fFullPath= new Path(fFileStore.toURI().getPath());
> return fFullPath;
> }
>
> /*
> * @see org.eclipse.core.resources.IStorage#getName()
> */
> public String getName() {
> return fFileStore.getName();
> }
>
> /*
> * @see org.eclipse.core.resources.IStorage#isReadOnly()
> */
> public boolean isReadOnly() {
> return fFileStore.fetchInfo().getAttribute(EFS.ATTRIBUTE_READ_ONLY) ;
> }
>
> /*
> * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Cla ss)
> */
> public Object getAdapter(Class adapter) {
> return null;
> }
> }
> ------------------------------------------------
> By now its working good.
>
> Someone has any comments for this example?
>
> Michal
|
|
|
Powered by
FUDForum. Page generated in 0.06984 seconds