Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » how and when to reconnect a view to an editor?
how and when to reconnect a view to an editor? [message #272311] Tue, 21 September 2004 21:15 Go to next message
Eclipse UserFriend
Originally posted by: user.example.net

if a view is an editor observer - the IPath for the IEditorInput or the
editor ID can be saved off and restored - and there is a findEditor
method in the WorkbenchPage for theEditorInput - but how do you know
when the editor is available? and what is the best way to find it? are
views recreated before editors? is there a particular WorkbenchPage that
holds the editors?

david
Re: how and when to reconnect a view to an editor? [message #272387 is a reply to message #272311] Wed, 22 September 2004 06:18 Go to previous messageGo to next message
Eclipse UserFriend
See IPartListener and IPartListener2;
IWorkbenchWindow#getPartService().addPartListener()

You might also use IPerspectiveListener, and IPerspectiveListener2.

Sebastian
Re: how and when to reconnect a view to an editor? [message #272521 is a reply to message #272387] Wed, 22 September 2004 21:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: user.example.net

that is ok when the workbench is running - but how do you (re)connect
when the workbench is restarted - especially if focus was on the view
when the workbench was closed - there will be no part event unless the
editor is created after the view and only then if the editor will get focus.

so i ended up searching all pages in the workbenchwindow for the editor
- but when the view is created - there are no pages - so i searched the
page from the viewsite - and i found the editor - but i still don't know
if editors are created before views - so i will always find it - or i
need both methods: search and if it is not there, wait until it is opened.

thanks for helping me-

Sebastian Davids wrote:
> See IPartListener and IPartListener2;
> IWorkbenchWindow#getPartService().addPartListener()
>
> You might also use IPerspectiveListener, and IPerspectiveListener2.
>
> Sebastian
Re: how and when to reconnect a view to an editor? [message #272531 is a reply to message #272521] Wed, 22 September 2004 22:39 Go to previous messageGo to next message
Eclipse UserFriend
Re-reading your initial post ...

Why do you listen on changes in the editor itself?

Don't they both share the same model?

Isn't the view registered as an observer of the model?

Here's some pseudo-code for coupling a view and editor/model:

View {

createPartControl(Composite parent) {
Composite comp = new Composite(parent, ...);
comp.setLayout(new GridLayout(1, true);
fContents = new Composite(comp, ...);
//setup real contents as children of fContents
fContents.setVisible(modelHasBeenSet);
fLabel = new Label(comp, ...);
fLabel.setText("Nothing to show");
fLabel.setVisible(!modelHasBeenSet);
}

setModel(Model model) {
//detatch listener from old model
if (validModel) {
//attach listener to new model
//update Widgets with new model
fContents.setVisible(true);
fLabel.setVisible(false);
} else {
fContents.setVisible(false);
fLabel.setVisible(true);
}
}

setModel could be called from your editor after it has restored its
contents.

Beware of the tight coupling between the editor and the view.

@@

A better alternative would be to have a ModelProvider which gets
instantiated upon plug-in startup (possibly as an instance variable in
your Plug-in class).

The provider would have a method getModel returning null or a
Null-object (depending on your programming style) when the model has not
been restored/initialized yet.

Your editor and view keep a reference to this provider and register
themselves as listeners.

After the provider has restored/initialzed the model it will broadcast
an event.

The listeners will then replace their placeholder by setting their model
to the one returned by ModelProvider#getModel ... this would be similar
to the other version above.

@@@@

Hope it isn't too cryptic :D

Sebastian
Re: how and when to reconnect a view to an editor? [message #272572 is a reply to message #272531] Thu, 23 September 2004 12:51 Go to previous message
Eclipse UserFriend
Originally posted by: user.example.net

thanks sebastain for the thoughful response - what you are suggesting
would be an architectural change - i will need some time to ponder that
improvement.

best-

p.s. i should change my last name to sebastian - then we would have
symmetry.

Sebastian Davids wrote:
> Re-reading your initial post ...
>
> Why do you listen on changes in the editor itself?
>
> Don't they both share the same model?
>
> Isn't the view registered as an observer of the model?
>
> Here's some pseudo-code for coupling a view and editor/model:
>
> View {
>
> createPartControl(Composite parent) {
> Composite comp = new Composite(parent, ...);
> comp.setLayout(new GridLayout(1, true);
> fContents = new Composite(comp, ...);
> //setup real contents as children of fContents
> fContents.setVisible(modelHasBeenSet);
> fLabel = new Label(comp, ...);
> fLabel.setText("Nothing to show");
> fLabel.setVisible(!modelHasBeenSet);
> }
>
> setModel(Model model) {
> //detatch listener from old model
> if (validModel) {
> //attach listener to new model
> //update Widgets with new model
> fContents.setVisible(true);
> fLabel.setVisible(false);
> } else {
> fContents.setVisible(false);
> fLabel.setVisible(true);
> }
> }
>
> setModel could be called from your editor after it has restored its
> contents.
>
> Beware of the tight coupling between the editor and the view.
>
> @@
>
> A better alternative would be to have a ModelProvider which gets
> instantiated upon plug-in startup (possibly as an instance variable in
> your Plug-in class).
>
> The provider would have a method getModel returning null or a
> Null-object (depending on your programming style) when the model has not
> been restored/initialized yet.
>
> Your editor and view keep a reference to this provider and register
> themselves as listeners.
>
> After the provider has restored/initialzed the model it will broadcast
> an event.
>
> The listeners will then replace their placeholder by setting their model
> to the one returned by ModelProvider#getModel ... this would be similar
> to the other version above.
>
> @@@@
>
> Hope it isn't too cryptic :D
>
> Sebastian
Previous Topic:[ECLIPSE.ORG] - users, please take care of the developers
Next Topic:Does anyone know of a Java editor plugin with hungry delete functionality?
Goto Forum:
  


Current Time: Sat May 10 18:44:35 EDT 2025

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

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

Back to the top