Jump to: navigation, search

Difference between revisions of "FAQ How do I find out what view or editor is selected?"

 
m
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
''
+
To find out what view or editor is selected, use the <tt>IPartService</tt>.  As with <tt>ISelectionService</tt>, you can add a listener to this service
 +
to track the active part or simply query it whenever you need to know.  Note, saying that the part is <i>active</i> does not imply that it has <i>focus</i>.  If a dialog opens on top of the workbench window, the active part does not change, even though the active part loses focus.  The part service will also notify you when parts are closed, hidden, brought to the top of a stack, and during other lifecycle events.
  
 +
Two types of listeners can be added to the part service: <tt>IPartListener</tt> and the poorly named <tt>IPartListener2</tt>. You should always use this second one as it can handle part-change events on parts that have not yet been created because they are hidden in a stack behind another part.  This listener will also tell you when a part is made visible or hidden or when an editor's input is changed:
  
 
 
 
 
 
To find out what view or editor is selected, use the <tt>IPartService</tt>.
 
As with <tt>ISelectionService</tt>, you can add a listener to this service
 
to track the active part or simply query it whenever you need to know.  Note,
 
saying that the part is <i>active</i> does not imply that it has <i>focus</i>.
 
If a dialog opens on top of the workbench window, the active part does not
 
change, even though the active part loses focus.  The part service
 
will also notify you when parts are closed, hidden, brought to the top
 
of a stack, and during other lifecycle events.
 
 
 
 
 
Two types of listeners can be added to the
 
part service: <tt>IPartListener</tt> and the poorly named
 
<tt>IPartListener2</tt>.  You should always use this second
 
one as it can handle part-change events on parts that have not
 
yet been created because they are hidden in a stack behind another part.
 
This listener will also tell you when a part is made visible or hidden or when an editor&#146;s
 
input is changed:
 
 
<pre>
 
<pre>
 
   IWorkbenchPage page = ...;
 
   IWorkbenchPage page = ...;
Line 40: Line 18:
 
</pre>
 
</pre>
  
 
+
<tt>IWorkbenchPage</tt> implements <tt>IPartService</tt> directly. You can also access a activation service by using <tt>IWorkbenchWindow.getPartService</tt>.
 
+
 
+
<tt>IWorkbenchPage</tt> implements <tt>IPartService</tt>
+
directly. You can also access a activation service by using
+
<tt>IWorkbenchWindow.getPartService</tt>.
+
 
+
 
+
 
+
 
+
  
 
== See Also: ==
 
== See Also: ==
 +
*[[FAQ How do I find out what object is selected?]]
 +
*[[FAQ How do I find the active workbench page?]]
 +
*[[FAQ Why do the names of some interfaces end with the digit 2?]]
  
 
+
{{Template:FAQ_Tagline}}
[[FAQ_How_do_I_find_out_what_object_is_selected%3F]]
+
 
+
 
+
[[FAQ_How_do_I_find_the_active_workbench_page%3F]]
+
 
+
 
+
[[FAQ_Why_do_the_names_of_some_interfaces_end_with_the_digit_2%3F]]
+
 
+
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>
+

Latest revision as of 23:32, 8 June 2006

To find out what view or editor is selected, use the IPartService. As with ISelectionService, you can add a listener to this service to track the active part or simply query it whenever you need to know. Note, saying that the part is active does not imply that it has focus. If a dialog opens on top of the workbench window, the active part does not change, even though the active part loses focus. The part service will also notify you when parts are closed, hidden, brought to the top of a stack, and during other lifecycle events.

Two types of listeners can be added to the part service: IPartListener and the poorly named IPartListener2. You should always use this second one as it can handle part-change events on parts that have not yet been created because they are hidden in a stack behind another part. This listener will also tell you when a part is made visible or hidden or when an editor's input is changed:

   IWorkbenchPage page = ...;
   //the active part
   IWorkbenchPart active = page.getActivePart();
   //adding a listener
   IPartListener2 pl = new IPartListener2() {
      public void partActivated(IWorkbenchPartReference ref)
         System.out.println("Active: "+ref.getTitle());
      }
      ... other listener methods ...
   };
   page.addPartListener(pl);

IWorkbenchPage implements IPartService directly. You can also access a activation service by using IWorkbenchWindow.getPartService.

See Also:


This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.