Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Where to construct model?
Where to construct model? [message #228099] Fri, 15 December 2006 18:07 Go to next message
Jeff Higgins is currently offline Jeff HigginsFriend
Messages: 51
Registered: July 2009
Member
Hi,
newbie question.
I have an RCP application that wishes to open
one editor. In my application's ActionBarAdvisor
I create an Open menu item and attach to my
OpenFileAction. OpenFileAction run() method looks
like this:

public void run() {
FileDialog fileDialog = new
FileDialog(window.getShell(), SWT.OPEN);
String fileName = fileDialog.open();
try {
window.getActivePage()
.openEditor(new MyPathEditorInput
(new Path(fileName)),"myEditorID");
} catch ()

Now, I have all of my EditParts and my model ready to go
except I don't know where to construct and keep my model?

Should I place a private instance of my model in my editor
and construct it in my editor's getContent() method?
Something like this?

private MyModel model;

protected Object getContent() {
MyPathEditorInput input =
getSite()
.getWorkbenchWindow()
.getActivePage()
.getInput()
.getAdapter(MyPathEditorInput);
File file = new File(input.getPath());
model = makeModel(file);
return model;
}

Thanks for any assistance.
Jeff Higgins
Re: Where to construct model? [message #228102 is a reply to message #228099] Fri, 15 December 2006 21:00 Go to previous messageGo to next message
Anthony Hunter is currently offline Anthony HunterFriend
Messages: 446
Registered: July 2009
Senior Member
Hi Jeff,

The editor is normally where the root of your model is cached.

Given you are calling openEditor, which calls
EditorPart.setInput(IEditorInput) , you are already passing the file
resource to your editor.

Look at the GEF Logic Editor example for an example.

Cheers...
Anthony

"Jeff Higgins" <oohiggins@yahoo.com> wrote in message
news:eluo9l$jel$1@utils.eclipse.org...
> Hi,
> newbie question.
> I have an RCP application that wishes to open
> one editor. In my application's ActionBarAdvisor
> I create an Open menu item and attach to my
> OpenFileAction. OpenFileAction run() method looks
> like this:
>
> public void run() {
> FileDialog fileDialog = new
> FileDialog(window.getShell(), SWT.OPEN);
> String fileName = fileDialog.open();
> try {
> window.getActivePage()
> .openEditor(new MyPathEditorInput
> (new Path(fileName)),"myEditorID");
> } catch ()
>
> Now, I have all of my EditParts and my model ready to go
> except I don't know where to construct and keep my model?
>
> Should I place a private instance of my model in my editor
> and construct it in my editor's getContent() method?
> Something like this?
>
> private MyModel model;
>
> protected Object getContent() {
> MyPathEditorInput input =
> getSite()
> .getWorkbenchWindow()
> .getActivePage()
> .getInput()
> .getAdapter(MyPathEditorInput);
> File file = new File(input.getPath());
> model = makeModel(file);
> return model;
> }
>
> Thanks for any assistance.
> Jeff Higgins
>
Re: Where to construct model? [message #228110 is a reply to message #228102] Fri, 15 December 2006 22:29 Go to previous messageGo to next message
Jeff Higgins is currently offline Jeff HigginsFriend
Messages: 51
Registered: July 2009
Member
Thank you Anthony.

Looking at GEF Logic Editor I see:

protected void setInput(IEditorInput input) {
superSetInput(input);

IFile file = ((IFileEditorInput)input).getFile();
try {
InputStream is = file.getContents(false);
ObjectInputStream ois = new ObjectInputStream(is);
setLogicDiagram((LogicDiagram)ois.readObject());
ois.close();
}

// other stuff
}

OK I'll do it here. But:

Given that I don't have access to org.eclipse.core.resources.IFile,
But I do have org.eclipse.core.runtime.IPath;
How do I cast IEditorInput to MyPathEditorInput so that I can have
access to it's public IPath getPath() method?

Thanks,
your help is greatly appreciated.
Jeff Higgins


"Anthony Hunter" <anthonyh@ca.ibm.com> wrote in message
news:elv2d0$vos$1@utils.eclipse.org...
> Hi Jeff,
>
> The editor is normally where the root of your model is cached.
>
> Given you are calling openEditor, which calls
> EditorPart.setInput(IEditorInput) , you are already passing the file
> resource to your editor.
>
> Look at the GEF Logic Editor example for an example.
>
> Cheers...
> Anthony
>
> "Jeff Higgins" <oohiggins@yahoo.com> wrote in message
> news:eluo9l$jel$1@utils.eclipse.org...
>> Hi,
>> newbie question.
>> I have an RCP application that wishes to open
>> one editor. In my application's ActionBarAdvisor
>> I create an Open menu item and attach to my
>> OpenFileAction. OpenFileAction run() method looks
>> like this:
>>
>> public void run() {
>> FileDialog fileDialog = new
>> FileDialog(window.getShell(), SWT.OPEN);
>> String fileName = fileDialog.open();
>> try {
>> window.getActivePage()
>> .openEditor(new MyPathEditorInput
>> (new Path(fileName)),"myEditorID");
>> } catch ()
>>
>> Now, I have all of my EditParts and my model ready to go
>> except I don't know where to construct and keep my model?
>>
>> Should I place a private instance of my model in my editor
>> and construct it in my editor's getContent() method?
>> Something like this?
>>
>> private MyModel model;
>>
>> protected Object getContent() {
>> MyPathEditorInput input =
>> getSite()
>> .getWorkbenchWindow()
>> .getActivePage()
>> .getInput()
>> .getAdapter(MyPathEditorInput);
>> File file = new File(input.getPath());
>> model = makeModel(file);
>> return model;
>> }
>>
>> Thanks for any assistance.
>> Jeff Higgins
>>
>
>
Re: Where to construct model? [message #228118 is a reply to message #228110] Fri, 15 December 2006 23:04 Go to previous message
Jeff Higgins is currently offline Jeff HigginsFriend
Messages: 51
Registered: July 2009
Member
oops!
IPath path = ((MyPathEditorInput)input).getPath();
Thanks again, greatly appreciated.
Jeff Higgins

"Jeff Higgins" <oohiggins@yahoo.com> wrote in message
news:elv7ma$8j7$1@utils.eclipse.org...
> Thank you Anthony.
>
> Looking at GEF Logic Editor I see:
>
> protected void setInput(IEditorInput input) {
> superSetInput(input);
>
> IFile file = ((IFileEditorInput)input).getFile();
> try {
> InputStream is = file.getContents(false);
> ObjectInputStream ois = new ObjectInputStream(is);
> setLogicDiagram((LogicDiagram)ois.readObject());
> ois.close();
> }
>
> // other stuff
> }
>
> OK I'll do it here. But:
>
> Given that I don't have access to org.eclipse.core.resources.IFile,
> But I do have org.eclipse.core.runtime.IPath;
> How do I cast IEditorInput to MyPathEditorInput so that I can have
> access to it's public IPath getPath() method?
>
> Thanks,
> your help is greatly appreciated.
> Jeff Higgins
>
[snip]
Previous Topic:[Announce] GEF 3.3 Project Plans
Next Topic:how to realize a "vertical label" in "Flow Container"
Goto Forum:
  


Current Time: Thu Apr 18 11:07:35 GMT 2024

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

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

Back to the top