| Home >> All >> org >> eclipse >> ui >> [ internal Javadoc ] |
Source code: org/eclipse/ui/internal/PartListenerList2.java
1 /******************************************************************************* 2 * Copyright (c) 2000, 2004 IBM Corporation and others. 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Common Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://www.eclipse.org/legal/cpl-v10.html 7 * 8 * Contributors: 9 * IBM Corporation - initial API and implementation 10 *******************************************************************************/ 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.core.runtime.Platform; 14 import org.eclipse.jface.util.ListenerList; 15 import org.eclipse.jface.util.SafeRunnable; 16 import org.eclipse.ui.IPartListener2; 17 import org.eclipse.ui.IWorkbenchPartReference; 18 19 /** 20 * Part listener list. 21 */ 22 public class PartListenerList2 { 23 private ListenerList listeners = new ListenerList(); 24 /** 25 * PartNotifier constructor comment. 26 */ 27 public PartListenerList2() { 28 super(); 29 } 30 /** 31 * Adds an PartListener to the part service. 32 */ 33 public void addPartListener(IPartListener2 l) { 34 listeners.add(l); 35 } 36 /** 37 * Notifies the listener that a part has been activated. 38 */ 39 public void firePartActivated(final IWorkbenchPartReference ref) { 40 Object [] array = listeners.getListeners(); 41 for (int i = 0; i < array.length; i ++) { 42 final IPartListener2 l = (IPartListener2)array[i]; 43 Platform.run(new SafeRunnable() { 44 public void run() { 45 l.partActivated(ref); 46 } 47 }); 48 } 49 } 50 /** 51 * Notifies the listener that a part has been brought to top. 52 */ 53 public void firePartBroughtToTop(final IWorkbenchPartReference ref) { 54 Object [] array = listeners.getListeners(); 55 for (int i = 0; i < array.length; i ++) { 56 final IPartListener2 l = (IPartListener2)array[i]; 57 Platform.run(new SafeRunnable() { 58 public void run() { 59 l.partBroughtToTop(ref); 60 } 61 }); 62 } 63 } 64 /** 65 * Notifies the listener that a part has been closed 66 */ 67 public void firePartClosed(final IWorkbenchPartReference ref) { 68 Object [] array = listeners.getListeners(); 69 for (int i = 0; i < array.length; i ++) { 70 final IPartListener2 l = (IPartListener2)array[i]; 71 Platform.run(new SafeRunnable() { 72 public void run() { 73 l.partClosed(ref); 74 } 75 }); 76 } 77 } 78 /** 79 * Notifies the listener that a part has been deactivated. 80 */ 81 public void firePartDeactivated(final IWorkbenchPartReference ref) { 82 Object [] array = listeners.getListeners(); 83 for (int i = 0; i < array.length; i ++) { 84 final IPartListener2 l = (IPartListener2)array[i]; 85 Platform.run(new SafeRunnable() { 86 public void run() { 87 l.partDeactivated(ref); 88 } 89 }); 90 } 91 } 92 /** 93 * Notifies the listener that a part has been opened. 94 */ 95 public void firePartOpened(final IWorkbenchPartReference ref) { 96 Object [] array = listeners.getListeners(); 97 for (int i = 0; i < array.length; i ++) { 98 final IPartListener2 l = (IPartListener2)array[i]; 99 Platform.run(new SafeRunnable() { 100 public void run() { 101 l.partOpened(ref); 102 } 103 }); 104 } 105 } 106 /** 107 * Notifies the listener that a part has been opened. 108 */ 109 public void firePartHidden(final IWorkbenchPartReference ref) { 110 Object [] array = listeners.getListeners(); 111 for (int i = 0; i < array.length; i ++) { 112 final IPartListener2 l; 113 if(array[i] instanceof IPartListener2) 114 l = (IPartListener2)array[i]; 115 else 116 continue; 117 118 Platform.run(new SafeRunnable() { 119 public void run() { 120 l.partHidden(ref); 121 } 122 }); 123 } 124 } 125 /** 126 * Notifies the listener that a part has been opened. 127 */ 128 public void firePartVisible(final IWorkbenchPartReference ref) { 129 Object [] array = listeners.getListeners(); 130 for (int i = 0; i < array.length; i ++) { 131 final IPartListener2 l; 132 if(array[i] instanceof IPartListener2) 133 l = (IPartListener2)array[i]; 134 else 135 continue; 136 137 Platform.run(new SafeRunnable() { 138 public void run() { 139 l.partVisible(ref); 140 } 141 }); 142 } 143 } 144 /** 145 * Notifies the listener that a part has been opened. 146 */ 147 public void firePartInputChanged(final IWorkbenchPartReference ref) { 148 Object [] array = listeners.getListeners(); 149 for (int i = 0; i < array.length; i ++) { 150 final IPartListener2 l; 151 if(array[i] instanceof IPartListener2) 152 l = (IPartListener2)array[i]; 153 else 154 continue; 155 156 Platform.run(new SafeRunnable() { 157 public void run() { 158 l.partInputChanged(ref); 159 } 160 }); 161 } 162 } 163 /** 164 * Removes an IPartListener from the part service. 165 */ 166 public void removePartListener(IPartListener2 l) { 167 listeners.remove(l); 168 } 169 }