Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to open external file as resource in editor
How to open external file as resource in editor [message #467489] Fri, 04 May 2007 09:57 Go to next message
Eclipse UserFriend
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 #467569 is a reply to message #467489] Mon, 07 May 2007 10:43 Go to previous messageGo to next message
Eclipse UserFriend
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.
>
>
With 3.2.2 you will have to write your own editor input and also your
own document provider. This is quite simple and there is an RCP example
that shows how to do this:
http://www.eclipse.org/eclipse/platform-text/development/rcp /examples/index.html

In 3.3 things have become much easier. Let me know if you need more
details regarding 3.3.

HTH
Dani

>
>Best Regards.
>
>Alex.
>
>
Re: How to open external file as resource in editor [message #467572 is a reply to message #467569] Mon, 07 May 2007 13:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: newsgroup.silveraxe.de

Hi Daniel,

>> 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.
>>
>
> In 3.3 things have become much easier. Let me know if you need more
> details regarding 3.3.


I'm very interested in this topic.

Thanks,
Hilmar
Re: How to open external file as resource in editor [message #467580 is a reply to message #467572] Tue, 08 May 2007 03:30 Go to previous messageGo to next message
Eclipse UserFriend
Hilmar Bunjes wrote:

> Hi Daniel,
>
>>> 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.
>>
>>
>> In 3.3 things have become much easier. Let me know if you need more
>> details regarding 3.3.
>
>
>
> I'm very interested in this topic.

In 3.3 the code that contributes the IDE application (window + menu
etc.) got pulled out into a separate plug-in (see bug 167893 for
details). This now allows you to use the org.eclipse.ui.editors plug-in
as its required plug-in org.eclipse.ui.ide no longer builds your
application. Of course your resulting RCP will be bigger and contain
code that you eventually won't need (e.g. marker views) but in turn you
get the text editor and the ability to open and save files from/to the
OS for free.

Dani

>
> Thanks,
> Hilmar
Re: How to open external file as resource in editor [message #467585 is a reply to message #467489] Tue, 08 May 2007 09:05 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
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
Previous Topic:File->New menu contributions
Next Topic:RCP JVM crash
Goto Forum:
  


Current Time: Wed May 21 11:30:01 EDT 2025

Powered by FUDForum. Page generated in 0.06984 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top