`
收藏列表
标题 标签 来源
rcp的job使用 eclipsercp
public static boolean isProgressWait = true; //用于判断进度条是否走下一格
private void setProgress(){
		Job runningJob = new Job("Task") {
			
			@Override
			protected IStatus run(IProgressMonitor monitor) {
				try {
					int count = allRunningCount;
					monitor.beginTask("任务("+count+"个)", count); 
					for (int i = 0; i < allRunningCount
							&& !monitor.isCanceled(); i++) {
						isProgressWait = true;
						while (isProgressWait) {
							Thread.sleep(500);
						}
						monitor.worked(1);
						monitor.subTask("第" + (i+2) + "个任务。");
					}
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				monitor.done(); 
				return Status.OK_STATUS;
			}
		};
		runningJob.setUser(true);//是否需要弹出进度条
		runningJob.schedule();
	}

其它地方设置isProgressWait = false;
前提,它的 configurer.setShowProgressIndicator(true);
RCP的一些事件 eclipsercp addModifyListener,addSelectionListener
“组件”事件
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()
这样树原来选中的才不会变
RCP中观察者模式的使用 eclipsercp
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);
Eclipse RCP插件开发群:101202692 eclipsercp

        
Global site tag (gtag.js) - Google Analytics