Both methods almost work but unfortunately when you switch outer document windows, the inner docksite toolwindows list lastactivedatetime always gets updated so that the last toolwindow that was added is last in the list, and not the last tool window that was selected.
From my trace output...
Page 1 - I have added 4 new waveform windows...
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ordered toolwindows: Waveform 1 19/05/2016 12:35:43
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ordered toolwindows: Waveform 2 19/05/2016 12:35:44
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ordered toolwindows: Waveform 3 19/05/2016 12:35:48
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ordered toolwindows: Waveform 4 19/05/2016 12:36:02
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> LastActiveWindow is: Waveform 4
Add a new docksite to create Page 2 with 4 new scatterplot windows...
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ordered toolwindows: Scatterplot 1 19/05/2016 12:35:58
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ordered toolwindows: Scatterplot 2 19/05/2016 12:35:58
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ordered toolwindows: Scatterplot 3 19/05/2016 12:35:59
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ordered toolwindows: Scatterplot 4 19/05/2016 12:37:23
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> LastActiveWindow is: Scatterplot 4
Everything ok so far. Now I am going to click on ScatterPlot 2...
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ordered toolwindows: Scatterplot 1 19/05/2016 12:35:58
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ordered toolwindows: Scatterplot 3 19/05/2016 12:35:59
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ordered toolwindows: Scatterplot 4 19/05/2016 12:37:23
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ordered toolwindows: Scatterplot 2 19/05/2016 12:38:05
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> LastActiveWindow is: Scatterplot 2
Great, Scatterplot to is the last active window which is what I want.
Now I am going to click on Page 1.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ordered toolwindows: Waveform 1 19/05/2016 12:35:43
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ordered toolwindows: Waveform 2 19/05/2016 12:35:44
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ordered toolwindows: Waveform 3 19/05/2016 12:35:48
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ordered toolwindows: Waveform 4 19/05/2016 12:36:02
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> LastActiveWindow is: Waveform 4
Fine, nothing changed there...
Now I am going to click back to Page 2.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ordered toolwindows: Scatterplot 1 19/05/2016 12:35:58
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ordered toolwindows: Scatterplot 3 19/05/2016 12:35:59
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ordered toolwindows: Scatterplot 2 19/05/2016 12:38:05
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ordered toolwindows: Scatterplot 4 19/05/2016 12:39:16
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> LastActiveWindow is: Scatterplot 4
the last added scatterplot (scatterplot 4) has been actived by the framework when switching pages back to page 2.
I needed Scatterplot 2 to be last.
Using ActiveWindow also gives the same results.
I am going to cache off a local copy of the sorted toolwindows list in my PageDockSite to get around this but ideally it be nicer if I didn't have to.
Thanks.