Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Restoring editors
Restoring editors [message #151458] Wed, 10 May 2006 15:07 Go to next message
Eclipse UserFriend
Originally posted by: apill.dolby.co.uk

How do I get an editor not to open with it's restored state if the state
cannot be loaded.

For example,

1. if I close my RCP application with an editor open for a resource.

2. Then i delete the resource

3. Reopen the RCP app.

Currently the editor opens and contains a stack trace. I don't know what
my IElementFactory should do if it cannot create a valid input.
Returning null in the IElementFactory.createElement() method causes a
PartInit exception.

Can anyone tell me what i need to do? I must need to return or set some
status somewhere so eclipse does not re-create my editor.

Thanks

Adrian
Re: Restoring editors [message #151608 is a reply to message #151458] Thu, 11 May 2006 11:50 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Adrian wrote:
> How do I get an editor not to open with it's restored state if the state
> cannot be loaded.

I don't think there's a way to avoid that right now. Say you have 8
editors open, and you restart eclipse. It has all 8 editor references,
but only instantiates them as they become visible to the user.

The way to avoid it for now is to not delete files outside of your RCP
.... do it from within your RCP. Or maybe you can schedule the workspace
to do a refresh on startup ... it'll slow down your startup time
(depending on how big your workspace is), but maybe the refresh will
cause the resource delta to close editors it no longer needs.

Hacky, and while I haven't tried this, what about adding an
IPartListener2 and trying to close the ErrorPart as soon as it's active.
You'd have to use some chicanery and it would flicker, but then be gone.

Later,
PW


Re: Restoring editors [message #151636 is a reply to message #151608] Thu, 11 May 2006 14:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: apill.dolby.co.uk

Paul Webster wrote:
> Adrian wrote:
>
>> How do I get an editor not to open with it's restored state if the
>> state cannot be loaded.
>
>
> I don't think there's a way to avoid that right now. Say you have 8
> editors open, and you restart eclipse. It has all 8 editor references,
> but only instantiates them as they become visible to the user.
>
> The way to avoid it for now is to not delete files outside of your RCP
> ... do it from within your RCP. Or maybe you can schedule the workspace
> to do a refresh on startup ... it'll slow down your startup time
> (depending on how big your workspace is), but maybe the refresh will
> cause the resource delta to close editors it no longer needs.
>
> Hacky, and while I haven't tried this, what about adding an
> IPartListener2 and trying to close the ErrorPart as soon as it's active.
> You'd have to use some chicanery and it would flicker, but then be gone.
>
> Later,
> PW

Thanks for the help, but actually the resource i am editing is in a
database. We are using RCP as a front end to our J2EE EJB3 tier. So, the
resources are quite likely to be deteled by other users of the system.

I'll look into your other suggestions. Otherwise, I might get the editor
to handle a specific error and tell the user the resource no longer exits.

Ta.
A
Re: Restoring editors [message #151692 is a reply to message #151636] Thu, 11 May 2006 16:36 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Adrian wrote:
>
>
> Thanks for the help, but actually the resource i am editing is in a
> database. We are using RCP as a front end to our J2EE EJB3 tier. So, the
> resources are quite likely to be deteled by other users of the system.
>
> I'll look into your other suggestions. Otherwise, I might get the editor
> to handle a specific error and tell the user the resource no longer exits.

Something else to consider is the model that text editors use.

an IEditorInput is an abstract, like a filename. A text editor gets an
IDocumentProvider, and asks it for an IDocument.

The IDocument is your model.

The editor then registers an IElementStateListener with the
IDocumentProvider, and when the IDocumentProvider calls the editor with
elementDeleted(*), the editor can call the closeEditor(*) method to
close itself.

Check out how AbstractTextEditor#updateDocumentProvider(*) works with
the IDocumentProvider and ElementStateListener.

Your IEditorInput would be some kind of object reference, your
IDocumentProvider would hold the connection information, InitialContext,
etc, and your IDocument would provide access into your model.

On startup based on re-connection, your IDocumentProvider could fire the
elementDeleted(*) for the IEditorInputs that no longer exist.

Later,
PW


Re: Restoring editors [message #153577 is a reply to message #151692] Sat, 20 May 2006 09:06 Go to previous messageGo to next message
Alexander Karnstedt is currently offline Alexander KarnstedtFriend
Messages: 68
Registered: July 2009
Member
I'm trying to do something similar to the AbstractTextEditor for
database objects.

Another problem I've encountered: How can the IEditorInput provide the
name and tooltip information if it just holds some kind of database ID?

These information are only available after reading the model objects
from the database.

Alex

Paul Webster schrieb:
>
> Your IEditorInput would be some kind of object reference, your
> IDocumentProvider would hold the connection information, InitialContext,
> etc, and your IDocument would provide access into your model.
>
> On startup based on re-connection, your IDocumentProvider could fire the
> elementDeleted(*) for the IEditorInputs that no longer exist.
Re: Restoring editors [message #153581 is a reply to message #151458] Sat, 20 May 2006 12:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Lamont_Gilbert.rigidsoftware.com

Adrian wrote:
> How do I get an editor not to open with it's restored state if the state
> cannot be loaded.
>
> For example,
>
> 1. if I close my RCP application with an editor open for a resource.
>
> 2. Then i delete the resource
>
> 3. Reopen the RCP app.
>
> Currently the editor opens and contains a stack trace. I don't know what
> my IElementFactory should do if it cannot create a valid input.
> Returning null in the IElementFactory.createElement() method causes a
> PartInit exception.
>
> Can anyone tell me what i need to do? I must need to return or set some
> status somewhere so eclipse does not re-create my editor.
>
> Thanks
>
> Adrian


Why are you automatically opening editors if you can not be sure they
can open?

I have a part listener registered on my Editor. In part activated I
check to see if the model is null. If it is i create a job that closes
the editor and make it a system job and schedule it...

My program is also a database program using JDO &/|| jdbc. Its a nasty
technique but I started it years ago and I have not reviewed if a better
technique is available or not.


CL
Re: Restoring editors [message #153584 is a reply to message #151692] Sat, 20 May 2006 15:38 Go to previous messageGo to next message
Alexander Karnstedt is currently offline Alexander KarnstedtFriend
Messages: 68
Registered: July 2009
Member
But *when* should the editor register an IElementStateListener? The
#init method is called just when the editor is brought on top (too
late). The editor should be closed when it's not on top on startup.

Alex

Paul Webster schrieb:
>
> The editor then registers an IElementStateListener with the
> IDocumentProvider, and when the IDocumentProvider calls the editor with
> elementDeleted(*), the editor can call the closeEditor(*) method to
> close itself.
>
> On startup based on re-connection, your IDocumentProvider could fire the
> elementDeleted(*) for the IEditorInputs that no longer exist.
Re: Restoring editors [message #153588 is a reply to message #153584] Sat, 20 May 2006 15:56 Go to previous messageGo to next message
Alexander Karnstedt is currently offline Alexander KarnstedtFriend
Messages: 68
Registered: July 2009
Member
Ok, I see the IDE provides a similar behavior: only after one is
clicking on the editors tab of a deleted file, a "File Deleted" dialog
prompts either for save or close.

I think this works in my case just as well.

Alexander Karnstedt schrieb:
> But *when* should the editor register an IElementStateListener? The
> #init method is called just when the editor is brought on top (too
> late). The editor should be closed when it's not on top on startup.
>
> Alex
Re: Restoring editors [message #153789 is a reply to message #153581] Tue, 23 May 2006 11:22 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

CL [dnoyeb] Gilbert wrote:
>
> Why are you automatically opening editors if you can not be sure they
> can open?

I think he was just asking about system behaviour and was looking for a
solution like yours.

Later,
PW


Re: Restoring editors [message #153831 is a reply to message #153577] Tue, 23 May 2006 19:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Lamont_Gilbert.rigidsoftware.com

Alexander Karnstedt wrote:
> I'm trying to do something similar to the AbstractTextEditor for
> database objects.
>
> Another problem I've encountered: How can the IEditorInput provide the
> name and tooltip information if it just holds some kind of database ID?
>

The IEditorInput needs to be given a name. It needs to hold more than a
simple database ID. Surely the human editing the 'thing' calls it by
something other than an ID?

I do have editors that do not use names as well.

Of course getting Names to go with your ID can be quite tricky as people
that deal with/develop ORM sometimes go off the deep end and try to act
like a program should not know any info or even ID of an object. They
try to make the persistance so transparent it becomes problematic.



> These information are only available after reading the model objects
> from the database.
>

how did you get the ID? Thats how you get the name. This may involve
significant change to your app but thats the way it is.

CL
Re: Restoring editors [message #155319 is a reply to message #153831] Sat, 03 June 2006 10:23 Go to previous message
Alexander Karnstedt is currently offline Alexander KarnstedtFriend
Messages: 68
Registered: July 2009
Member
Basically right. Nothing to be said against this prerequisite to obtain
a naming information at the places where I want to trigger an editor
open event.

The reference object (pendant to IResource) self could hold a name
attribute additionally to the ID.

Just had some problems with external applications demanding to open
editors by transmitting lists of ID's to the RCP app. In this case, if
the RCP app receives a list of ID's, at first it could query the DB to
figure out all information needed to construct the reference objects.

It's the same pattern as constructing a File, Project or Folder out of
an IPath.

new File(IPath path, Workspace container)

new MyDatabaseResource(String dbId, String name)


Alex

CL [dnoyeb] Gilbert schrieb:
> The IEditorInput needs to be given a name. It needs to hold more than a
> simple database ID. Surely the human editing the 'thing' calls it by
> something other than an ID?
>
> how did you get the ID? Thats how you get the name. This may involve
> significant change to your app but thats the way it is.
>
> CL
Previous Topic:Unable to update Eclipse - Help!
Next Topic:EOF character through System.in
Goto Forum:
  


Current Time: Wed Apr 24 13:41:03 GMT 2024

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

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

Back to the top