0

I'm writting an RCP application which has an application model that can be simplified as below:

==================================================
= lpart                ||  rpart1 | rpart2       =
= -------------------- || ---------------------- =
=     <a table>        ||  <some sfuff about     =
=                      ||   the selected item>   =
==================================================
  1. The window is divided into two part stacks: left and right
  2. The left PS contains one part, and the part contains only a table
  3. The right PS contains two parts, each will show some details about the selected item in the table

The problem:

  1. It seems that Eclipse is lazily initializing my part implementation class. If I call MPart.getObject() on rpart2 before I ever clicked the tab, it returns null. Can I make Eclipse to initialize all my part implementation class when it starts up.
  2. How can I tell which one of rpart1 and rpart2 is showing. I want to avoid loading data for both parts whenever the selection of the table changes, after all, only one of them is really showing.

What I want to achieve:

  1. Whenever an item gets selected, both rpart1 and rpart2 get notified and remember the selection (item id or sth. similar). It will be impossible if rpart2 is lazily initialized.
  2. Only the part that is currently showing will fetch the details it needs. It will be impossible if a part cannot tell whether it is showing.
  3. When the other part gets selected, it will fetch and display its data according to the remembered selection. Well, this is the only part I know how to do it.

Any help would be really appreciated! Thanks a lot!

fengye87
  • 2,433
  • 4
  • 24
  • 41

2 Answers2

3

You can use the EPartService addPartListener method to add a listener that is notified about all part activation (and other) events.

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • This can solve my second problem, but how about the first one? Thanks! And BTW, it seems MPart.isVisible() and MPart.isOnTop() is not returning the right value, instead MPart.isVisible() always returns true and MPart.isOnTop() always returns false. Am I missing sth. here? – fengye87 May 21 '14 at 11:34
  • I think the isVisible value just represents the Visible setting in the application model, not that the part is actually visible. I don't know what isOnTop does. I don't know of any way to initialize parts other than when they are first rendered. You could keep the selection state in an object stored in the eclipse context. – greg-449 May 21 '14 at 11:49
1

I think EPartService.isPartVisible(MPart) (rather than MPart.isVisible()) solves your first problem.

Zephyr
  • 226
  • 1
  • 5