“组件”事件
txtPort = new Text(composite, SWT.BORDER);
txtPort.setText("10000");//"10000"
txtPort.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
txtPort.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
}
});
nameCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
}
});
树事件
删除某个节点时,只用移除Root的某个节点,然后checkedTreeViewer.refresh()
这样树原来选中的才不会变
|
1.定义监听者接口
public interface IUIEventListener {
public void notifyUI(int cmd, long bussinessID, Object data);
}
2.创建实现类 {被管理的界面包括实现了IUIEventListener接口}
public class ExecuteEditor extends EditorPart implements IUIEventListener{
同理,如下
}
class UpAction extends Action implements IWorkbenchAction, IUIEventListener{
UIEventManager.getInstance().register(ID, this);
构造对象时,需注册
public void notifyUI(int cmd, long bussinessID, Object data) {
switch (cmd) {
case UIEventConst.SUITE_STATE_CHANGE_EVENT:
setActionEnable(getCurrentSelectElement());
break;
default:
break;
}
}
dispose销毁对象,需反注册
UIEventManager.getInstance().unregister(ID);
}
3.定义“监听事件的管理类(单例模式)”
public class UIEventManager {
private static UIEventManager manager = new UIEventManager();
/**
* 存储界面类的map
* Key值:
* 1 唯一的view,Key值就是ViewID
* 2 唯一的editor,Key值就是EditorID
* 3 多个Editor界面,例如profile list界面,Key值为 EditorID + 业务ID值
*/
private Map<String, IUIEventListener> mapPart = null;
private UIEventManager(){ mapPart = new HashMap<String, IUIEventListener>(); }
public static UIEventManager getInstance(){
if (manager == null){
manager = new UIEventManager();
}
return manager;
}
/*** 注册一个界面 @param id: 界面ID @param listener : 界面引用*/
public synchronized void register(String id, IUIEventListener listener){
mapPart.put(id, listener);
}
/** * 反注册一个界面 @param id :界面ID*/
public synchronized void unregister(String id){
mapPart.remove(id);
}
/**
* 通知所有的监听者
* @param cmd 命令字
* @param bussinessID 业务ID 根据需要传递
* @param data 参数 根据需要传递
*/
public synchronized void notifyAllListener(int cmd, long bussinessID, Object data){
IUIEventListener curListener = null;
for (Map.Entry<String,IUIEventListener> entry : mapPart.entrySet()) {
curListener = entry.getValue();
if (curListener != null){
curListener.notifyUI(cmd, bussinessID, data);
}
}
}
}
4.某个事件中,唤醒监听
UIEventManager.getInstance().notifyAllListener( UIEventConst.UI_ADD_GROUP_EVENT, addGroup.getGroupid(),
addGroup);
|