4 package eu
.etaxonomy
.taxeditor
.model
;
6 import java
.util
.HashMap
;
7 import java
.util
.HashSet
;
11 import org
.eclipse
.ui
.IPartListener2
;
12 import org
.eclipse
.ui
.IPartService
;
13 import org
.eclipse
.ui
.IWorkbenchPartReference
;
14 import org
.eclipse
.ui
.PlatformUI
;
17 * <p>TaxeditorPartService class.</p>
22 public class TaxeditorPartService
implements IPartListener2
{
24 /** Constant <code>PART_ACTIVATED=10</code> */
25 public static final int PART_ACTIVATED
= 10;
26 /** Constant <code>PART_BROUGHT_TO_TOP=20</code> */
27 public static final int PART_BROUGHT_TO_TOP
= 20;
28 /** Constant <code>PART_CLOSED=30</code> */
29 public static final int PART_CLOSED
= 30;
30 /** Constant <code>PART_DEAVTICATED=40</code> */
31 public static final int PART_DEAVTICATED
= 40;
32 /** Constant <code>PART_HIDDEN=50</code> */
33 public static final int PART_HIDDEN
= 50;
34 /** Constant <code>PART_INPUT_CHANGED=60</code> */
35 public static final int PART_INPUT_CHANGED
= 60;
36 /** Constant <code>PART_OPENED=70</code> */
37 public static final int PART_OPENED
= 70;
38 /** Constant <code>PART_VISIBLE=80</code> */
39 public static final int PART_VISIBLE
= 80;
41 /** Constant <code>instance</code> */
42 public static TaxeditorPartService instance
= new TaxeditorPartService();
44 private IPartService partService
;
46 private Map
<Integer
, Set
<IPartChangeListener
>> listenerMap
= new HashMap
<Integer
, Set
<IPartChangeListener
>>();
48 private TaxeditorPartService() {
49 partService
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getPartService();
50 partService
.addPartListener(this);
54 * <p>Getter for the field <code>instance</code>.</p>
56 * @return a {@link eu.etaxonomy.taxeditor.model.TaxeditorPartService} object.
58 public static TaxeditorPartService
getInstance(){
65 * @param eventType a {@link java.lang.Integer} object.
66 * @param listener a {@link eu.etaxonomy.taxeditor.model.IPartChangeListener} object.
68 public void addListener(Integer eventType
, IPartChangeListener listener
){
69 Set
<IPartChangeListener
> partChangeListeners
= listenerMap
.get(eventType
);
71 if(partChangeListeners
== null){
72 partChangeListeners
= new HashSet
<IPartChangeListener
>();
73 listenerMap
.put(eventType
, partChangeListeners
);
76 partChangeListeners
.add(listener
);
80 * <p>removeListener</p>
82 * @param eventType a {@link java.lang.Integer} object.
83 * @param listener a {@link eu.etaxonomy.taxeditor.model.IPartChangeListener} object.
85 public void removeListener(Integer eventType
, IPartChangeListener listener
){
86 Set
<IPartChangeListener
> partChangeListeners
= listenerMap
.get(eventType
);
88 if(partChangeListeners
== null){
92 partChangeListeners
.remove(listener
);
95 private void notifyListeners(Integer eventType
, IWorkbenchPartReference partRef
){
96 Set
<IPartChangeListener
> partChangeListeners
= listenerMap
.get(eventType
);
98 if(partChangeListeners
== null){
102 for(IPartChangeListener listener
: partChangeListeners
){
103 listener
.partChanged(eventType
, partRef
);
109 public void partActivated(IWorkbenchPartReference partRef
) {
110 notifyListeners(PART_ACTIVATED
, partRef
);
114 public void partBroughtToTop(IWorkbenchPartReference partRef
) {
115 notifyListeners(PART_BROUGHT_TO_TOP
, partRef
);
119 public void partClosed(IWorkbenchPartReference partRef
) {
120 notifyListeners(PART_CLOSED
, partRef
);
124 public void partDeactivated(IWorkbenchPartReference partRef
) {
125 notifyListeners(PART_DEAVTICATED
, partRef
);
129 public void partOpened(IWorkbenchPartReference partRef
) {
130 notifyListeners(PART_OPENED
, partRef
);
134 public void partHidden(IWorkbenchPartReference partRef
) {
135 notifyListeners(PART_HIDDEN
, partRef
);
139 public void partVisible(IWorkbenchPartReference partRef
) {
140 notifyListeners(PART_VISIBLE
, partRef
);
144 public void partInputChanged(IWorkbenchPartReference partRef
) {
145 notifyListeners(PART_INPUT_CHANGED
, partRef
);