摘抄部分例子源码
/**
* Notifies listeners of property changes, handling any exceptions
*/
class PropertyNotifier implements ISafeRunnable { //AbstractConsole.PropertyNotifier
private IPropertyChangeListener fListener;
private PropertyChangeEvent fEvent;
/**
* @see org.eclipse.core.runtime.ISafeRunnable#handleException(java.lang.Throwable)
*/
public void handleException(Throwable exception) {
IStatus status = new Status(IStatus.ERROR, ConsolePlugin.getUniqueIdentifier(), IConsoleConstants.INTERNAL_ERROR, ConsoleMessages.AbstractConsole_0, exception);
ConsolePlugin.log(status); //调用框架日志
}
/**
* @see org.eclipse.core.runtime.ISafeRunnable#run()
*/
public void run() throws Exception {
fListener.propertyChange(fEvent);
}
/**
* Notifies listeners of the property change
*
* @param event the event that describes the property that has changed
*/
public void notify(PropertyChangeEvent event) {
if (fListeners == null) {
return;
}
fEvent = event;
Object[] copiedListeners= fListeners.getListeners();
for (int i= 0; i < copiedListeners.length; i++) {
fListener = (IPropertyChangeListener)copiedListeners[i];
SafeRunner.run(this); //SafeRunner类捕获处理,handleException()定义处理异常方式
}
fListener = null;
}
}
源码解析:PropertyNotifier类实现细节
本文详细解析了PropertyNotifier类的实现原理,包括内部成员变量、方法及异常处理机制,帮助开发者理解如何通知监听者属性变化。
7378

被折叠的 条评论
为什么被折叠?



