Updated DocViewer plug-in
Category DocViewer plug-in IPartListener2
Bookmark :
If you are using the DocViewer plug-in version 1.0.5 is now available from the usual place. There's nothing new from a functional point of view but there are a few small changes to the user interface.
The main reason for the update is to fix a potential performance problem.
The DocViewer plug-in works by listening for changes in selection in the Notes Client. When it detects that a new document is selected it reads the values of all the Items on the Document and displays them in a table in the sidebar.
This is all fine, but what happens if the DocViewer or the Sidebar is minimised and not visible in the UI? The answer is that previous versions still listened for changes in selection and still read/displayed all the Items. This is very inefficient because the plug-in is still reading data even if no one is looking at it.
What's needed is some way for DocViewer to know if it is actually visible. If it's not then it can stop responding to changes in selection and save the extra network/server load of reading all the Items.
In Eclipse/Notes the way to do this is to implement the IPartListener2 interface. Our implementation is called DocViewPartListener. By implementing this interface and registering it with the Workbench, the plug-in will be told about changes in it's lifecycle, such as when it becomes visible, hidden or closed.
Creating the new class is a matter of clicking on File -> New -> Class, specifying the name and then specifying that we want to implement the com.eclipse.ui.IPartListener2 interface. Eclipse then creates the class and stubs of all the required methods.
The methods we are interested in are partVisible and partHidden which get called when the plug-in becomes visible or hidden.
15 public class DocViewerPartListener implements IPartListener2 {
16
17 /* A flag wich indicates whether the ViewPart is visible in the UI */
18 private boolean isVisible = false ;
19 /* The ViewPart we are listening to */
20 private IViewPart viewPart ;
21
22 public DocViewerPartListener( IViewPart viewPart ) {
23 this.viewPart = viewPart ;
24 }
46 public void partHidden(IWorkbenchPartReference part) {
47 if ( part.getPart( true ) == viewPart ) {
48 isVisible = false ;
49 }
50 }
60 public void partVisible(IWorkbenchPartReference part) {
61 if ( part.getPart( true ) == viewPart ) {
62 isVisible = true ;
63 }
64 }
65
69 public boolean isVisible() {
70 return isVisible;
71 }
72
76 public void setVisible(boolean isVisible) {
77 this.isVisible = isVisible;
78 }
79
80 }
Creating an instance of our part listener and registering it with the Workbench is done in the DocViewerView class.
131 // Create a part listener. This listener will be told whenever part of the
132 // workbench is visible, hidden, closed etc.
133 partListener = new DocViewerPartListener( this ) ;
134 workbenchPage = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage() ;
135 workbenchPage.addPartListener( partListener ) ;
As with all listeners it is best practice to stop listening when the plug-in is closed.
92 public void dispose() {
93
94 // When the view is disposed, ie closed, we need to make sure we stop
95 // listening to changes in selection.
97 workbenchPage.removePartListener( partListener ) ;
98
99 }
The final step is to change the showSelection method so that we don't bother responding to new Documents if the plug-in is hidden.
176 // if the DocViewer isn't visible, don't respond to any changes in selection.
177 if ( !partListener.isVisible() ) {
178 return ;
179 }
Bookmark :
If you are using the DocViewer plug-in version 1.0.5 is now available from the usual place. There's nothing new from a functional point of view but there are a few small changes to the user interface.
The main reason for the update is to fix a potential performance problem.
The DocViewer plug-in works by listening for changes in selection in the Notes Client. When it detects that a new document is selected it reads the values of all the Items on the Document and displays them in a table in the sidebar.
This is all fine, but what happens if the DocViewer or the Sidebar is minimised and not visible in the UI? The answer is that previous versions still listened for changes in selection and still read/displayed all the Items. This is very inefficient because the plug-in is still reading data even if no one is looking at it.
What's needed is some way for DocViewer to know if it is actually visible. If it's not then it can stop responding to changes in selection and save the extra network/server load of reading all the Items.
In Eclipse/Notes the way to do this is to implement the IPartListener2 interface. Our implementation is called DocViewPartListener. By implementing this interface and registering it with the Workbench, the plug-in will be told about changes in it's lifecycle, such as when it becomes visible, hidden or closed.
Creating the new class is a matter of clicking on File -> New -> Class, specifying the name and then specifying that we want to implement the com.eclipse.ui.IPartListener2 interface. Eclipse then creates the class and stubs of all the required methods.
The methods we are interested in are partVisible and partHidden which get called when the plug-in becomes visible or hidden.
15 public class DocViewerPartListener implements IPartListener2 {
16
17 /* A flag wich indicates whether the ViewPart is visible in the UI */
18 private boolean isVisible = false ;
19 /* The ViewPart we are listening to */
20 private IViewPart viewPart ;
21
22 public DocViewerPartListener( IViewPart viewPart ) {
23 this.viewPart = viewPart ;
24 }
46 public void partHidden(IWorkbenchPartReference part) {
47 if ( part.getPart( true ) == viewPart ) {
48 isVisible = false ;
49 }
50 }
60 public void partVisible(IWorkbenchPartReference part) {
61 if ( part.getPart( true ) == viewPart ) {
62 isVisible = true ;
63 }
64 }
65
69 public boolean isVisible() {
70 return isVisible;
71 }
72
76 public void setVisible(boolean isVisible) {
77 this.isVisible = isVisible;
78 }
79
80 }
Creating an instance of our part listener and registering it with the Workbench is done in the DocViewerView class.
131 // Create a part listener. This listener will be told whenever part of the
132 // workbench is visible, hidden, closed etc.
133 partListener = new DocViewerPartListener( this ) ;
134 workbenchPage = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage() ;
135 workbenchPage.addPartListener( partListener ) ;
As with all listeners it is best practice to stop listening when the plug-in is closed.
92 public void dispose() {
93
94 // When the view is disposed, ie closed, we need to make sure we stop
95 // listening to changes in selection.
97 workbenchPage.removePartListener( partListener ) ;
98
99 }
The final step is to change the showSelection method so that we don't bother responding to new Documents if the plug-in is hidden.
176 // if the DocViewer isn't visible, don't respond to any changes in selection.
177 if ( !partListener.isVisible() ) {
178 return ;
179 }
Comments
Hope you will take the challenge
Thank you
Torben Bang
Posted by Torben Bang At 07:41:44 On 24/11/2008 | - Website - |
[url={ Link }
Posted by kowe At 07:29:16 On 04/09/2010 | - Website - |