Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Save As Dialog in RCP application
Save As Dialog in RCP application [message #463486] Mon, 12 February 2007 13:23 Go to next message
Eclipse UserFriend
Originally posted by: unidad.gmx.net

Hi!

I'm new to RCP and building a little RCP Editor app.

I'd like do build a "Save as dialog" with that a user can
save a copy of the current edited file in my editor
somewhere in the filesystem. (inside or outside the workplace.)

I've learned, that the class
org.eclipse.ui.dialogs.SaveAsDialog
doesn't work for standalone RCP applications.

Now I'm trying to build my own dialog.
My problem is:

How can I create a new IFile-object, that has no correspondence in the
workplace?

I have the absolute path where the new file should be created,
but I don't manage to create a IFile out of the path.

I need something like this:
IFile file = createMagicIFileInstanceOutOfChosenPath(chosenPathName);
....
file.create(stream, false, null);
....

Any ideas?

Greetings, Herman
Re: Save As Dialog in RCP application [message #463489 is a reply to message #463486] Mon, 12 February 2007 13:41 Go to previous messageGo to next message
Eclipse UserFriend
This has information on creating a resource.

http://wiki.eclipse.org/index.php/The_Official_Eclipse_FAQs# Workspace_and_Resources_API

You might be able to use the save as dialog if you pull in
org.eclipse.ui.ide

Later,
PW
Re: Save As Dialog in RCP application [message #463493 is a reply to message #463489] Mon, 12 February 2007 13:49 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: unidad.gmx.net

Hi!

Paul Webster schrieb:
> This has information on creating a resource.
> http://wiki.eclipse.org/index.php/The_Official_Eclipse_FAQs# Workspace_and_Resources_API

Thanks for the quick and helpful answer. :)

Greetings, Hermann
Re: Save As Dialog in RCP application [message #463497 is a reply to message #463489] Mon, 12 February 2007 14:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: unidad.gmx.net

Hi!

Paul Webster schrieb:
> This has information on creating a resource.
>
> http://wiki.eclipse.org/index.php/The_Official_Eclipse_FAQs# Workspace_and_Resources_API

| IWorkspace workspace = ResourcesPlugin.getWorkspace();
| IWorkspaceRoot root = workspace.getRoot();
| IProject project = root.getProject("MyProject");
| IFolder folder = project.getFolder("Folder1");
| IFile file = folder.getFile("hello.txt");

Hmm...that's not exactly that what I wanted to do.

The user gives me an absolute Path, that can be within the workspace but
need not to be. More likely it will be outside the workspace.

If I understand the example-code correctly, I can only create new files
inside the workspace?

Greeting, Hermann
Re: Save As Dialog in RCP application [message #463506 is a reply to message #463486] Mon, 12 February 2007 17:58 Go to previous messageGo to next message
Eclipse UserFriend
If you want to save a file in (out of) the workspace, you have to
implement separate editor inputs.
For example:
- if the file is in the workspace, you would use FileEditorInput
- if the file is external, you can use JavaEditorInput

When you save the file, you can use the following:

File file = new File("abc");
try {
IFileStore store = EFS.getStore(file.toURI());
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile[] files = root.findFilesForLocation(new Path(store.toURI()
.getPath()));
IEditorInput input = null;
if (files != null && files.length == 1) {
// the file is in the workspace
input = new FileEditorInput(files[0]);
} else {
// the file is external
input = new JavaFileEditorInput(store);
}
setInput(input);
} catch (CoreException e) {
// catch exception
}

Snjeza

Hermann Maier wrote:
> Hi!
>
> I'm new to RCP and building a little RCP Editor app.
>
> I'd like do build a "Save as dialog" with that a user can
> save a copy of the current edited file in my editor
> somewhere in the filesystem. (inside or outside the workplace.)
>
> I've learned, that the class
> org.eclipse.ui.dialogs.SaveAsDialog
> doesn't work for standalone RCP applications.
>
> Now I'm trying to build my own dialog.
> My problem is:
>
> How can I create a new IFile-object, that has no correspondence in the
> workplace?
>
> I have the absolute path where the new file should be created,
> but I don't manage to create a IFile out of the path.
>
> I need something like this:
> IFile file = createMagicIFileInstanceOutOfChosenPath(chosenPathName);
> ...
> file.create(stream, false, null);
> ...
>
> Any ideas?
>
> Greetings, Herman
Re: Save As Dialog in RCP application [message #463711 is a reply to message #463506] Wed, 14 February 2007 13:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: unidad.gmx.net

Hi!

Thanks for your answer!
But I don't find the class JavaFileEditorInput. Where is it?

Greetings, Hermann


Snjezana Peco schrieb:
> If you want to save a file in (out of) the workspace, you have to
> implement separate editor inputs.
> For example:
> - if the file is in the workspace, you would use FileEditorInput
> - if the file is external, you can use JavaEditorInput
>
> When you save the file, you can use the following:
>
> File file = new File("abc");
> try {
> IFileStore store = EFS.getStore(file.toURI());
> IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
> IFile[] files = root.findFilesForLocation(new Path(store.toURI()
> .getPath()));
> IEditorInput input = null;
> if (files != null && files.length == 1) {
> // the file is in the workspace
> input = new FileEditorInput(files[0]);
> } else {
> // the file is external
> input = new JavaFileEditorInput(store);
> }
> setInput(input);
> } catch (CoreException e) {
> // catch exception
> }
>
> Snjeza
Re: Save As Dialog in RCP application [message #463713 is a reply to message #463711] Wed, 14 February 2007 13:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: unidad.gmx.net

Hermann Maier schrieb:
> Hi!
>
> Thanks for your answer!
> But I don't find the class JavaFileEditorInput. Where is it?

I'm using Eclipse 3.2
Re: Save As Dialog in RCP application [message #463717 is a reply to message #463713] Wed, 14 February 2007 14:56 Go to previous messageGo to next message
Eclipse UserFriend
The JavaFileEditorInput class is in the org.eclipse.ui.editors plugin.

Snjeza

Hermann Maier wrote:
> Hermann Maier schrieb:
>> Hi!
>>
>> Thanks for your answer!
>> But I don't find the class JavaFileEditorInput. Where is it?
>
> I'm using Eclipse 3.2
Re: Save As Dialog in RCP application [message #463719 is a reply to message #463711] Wed, 14 February 2007 15:12 Go to previous messageGo to next message
Eclipse UserFriend
JavaFileEditorInput (which is like an IEditorInput for java.io.File) is
in JDT

PW
Re: Save As Dialog in RCP application [message #463740 is a reply to message #463719] Thu, 15 February 2007 03:32 Go to previous message
Eclipse UserFriend
Paul Webster wrote:

> JavaFileEditorInput (which is like an IEditorInput for java.io.File)
> is in JDT

No, it is not. It is an internal class in 'org.eclipse.ui.editors' which
will be deleted soon. If you use 3.3 you should use the
'FileStoreEditorInput' which is in 'org.eclipse.ui.ide'.

Dani

>
> PW
Previous Topic:!MESSAGE Invalid Menu Extension (Path is invalid): selectWorkingSets
Next Topic:Cheatsheet in a View and Cheatsheet State
Goto Forum:
  


Current Time: Sun Mar 16 19:25:43 EDT 2025

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

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

Back to the top