Default new object/action - no wizard - file in root directory [message #480386] |
Sun, 16 August 2009 16:31 |
Jeff S. Messages: 29 Registered: July 2009 |
Junior Member |
|
|
So I have another newbie question (I'm only up to chapter 16 in the EMF
book).
I'm working on an RCP app, and I want to add a new action to the menubar
and toolbar. Rather than opening a wizard (like the default EMF
generated one), I want to load a file from the filesystem.
I've accomplished this by adding the following action in my
EsxEditorAdvisor class:
public static class NewAction extends WorkbenchWindowActionDelegate {
public void run(IAction action) {
openEditor(getWindow().getWorkbench(), EsxUtil.getDefaultEsxFileURI());
}
}
The applicable EsxUtil code looks like this:
public static String getDefaultEsxFilePath() {
String defaultEsxFilePath = "" +
Platform.getInstanceLocation().getURL().getPath() +
"defaults/DEFAULT.ESX";
return defaultEsxFilePath;
}
public static URI getDefaultEsxFileURI() {
return URI.createFileURI(getDefaultEsxFilePath());
}
This code will load up my default file at "defaults/DEFAULT.ESX". The
only "problem" is, I cannot load 2 new files at once (in separate
editors). I'm not *too* worried about this, but I would like to know
how to overcome it if needed. I see from 15.2.5 (EMF book), that
getResource() will normalize a URI, and return a resource that already
exists.
Is there a way to have getResource() open duplicate URI's? I could
always force the user to select a save point (like the generated wizard)
so that "new file" URIs are inherently different, but I would like to
have a strictly "in memory" version of the default new file (without
requiring a save).
My idea was always having IsDirty() return true if the URI is the
"default new" path, then figuring out how to allow getResource() to
allow opening a second version of the same URI. Should I try a hacky
way of modifying the URI with a timestamp on each "new action" (not even
sure this would work or be possible)?
Is there a standard/preferred way of loading duplicate URIs in separate
editor instances? Have other people ran into similar issues?
Thanks for any help you can provide.
-Jeff
|
|
|
Re: Default new object/action - no wizard - file in root directory [message #480451 is a reply to message #480386] |
Mon, 17 August 2009 08:27 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Jeff,
Comments below.
Jeff S. schrieb:
> So I have another newbie question (I'm only up to chapter 16 in the EMF
> book).
>
> I'm working on an RCP app, and I want to add a new action to the menubar
> and toolbar. Rather than opening a wizard (like the default EMF
> generated one), I want to load a file from the filesystem.
>
> I've accomplished this by adding the following action in my
> EsxEditorAdvisor class:
>
> public static class NewAction extends WorkbenchWindowActionDelegate {
> public void run(IAction action) {
> openEditor(getWindow().getWorkbench(),
> EsxUtil.getDefaultEsxFileURI());
> }
> }
>
> The applicable EsxUtil code looks like this:
>
> public static String getDefaultEsxFilePath() {
> String defaultEsxFilePath = "" +
> Platform.getInstanceLocation().getURL().getPath() +
> "defaults/DEFAULT.ESX";
> return defaultEsxFilePath;
> }
>
> public static URI getDefaultEsxFileURI() {
> return URI.createFileURI(getDefaultEsxFilePath());
> }
>
>
> This code will load up my default file at "defaults/DEFAULT.ESX". The
> only "problem" is, I cannot load 2 new files at once (in separate
> editors). I'm not *too* worried about this, but I would like to know
> how to overcome it if needed. I see from 15.2.5 (EMF book), that
> getResource() will normalize a URI, and return a resource that already
> exists.
The code you show above are basic workbench things, not EMF things.
>
> Is there a way to have getResource() open duplicate URI's?
Each resource set can load it's own copy of the resource.
I could
> always force the user to select a save point (like the generated wizard)
> so that "new file" URIs are inherently different, but I would like to
> have a strictly "in memory" version of the default new file (without
> requiring a save).
I think the workbench itself will want them to have unique URIs.
>
> My idea was always having IsDirty() return true if the URI is the
> "default new" path, then figuring out how to allow getResource() to
> allow opening a second version of the same URI. Should I try a hacky
> way of modifying the URI with a timestamp on each "new action" (not even
> sure this would work or be possible)?
It seems better to specify the location of the new file at the time of
the create..
>
> Is there a standard/preferred way of loading duplicate URIs in separate
> editor instances? Have other people ran into similar issues?
At what point are you expecting the user to specify a real location? I'd
try to do things more like how Eclipse does them...
>
> Thanks for any help you can provide.
>
> -Jeff
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.04142 seconds