我正在研究一个RCP应用程序,我有一个用例,我在其中检查根组件是否为空,这意味着模型已经加载,如果它是null,则模型未加载,如果模型是没有加载然后我尝试先在一个单独的作业中加载模型,然后在加载后获取模型。我写的是
if (cm != null) {
LoadModel m = null;
swaModel = architectureModelReader.getArchitectureModel();
Component rootComponent = swaModel.getRootComponent();
if(rootComponent != null){
MirrorConfigurationModel mcm = new MirrorConfigurationModel(rootComponent, connectionString, emptyEapName, platformDB.getAbsolutePath(),temp, getJetPath(), disabledComponents, disabledDiagrams, disabledInterfaces, disabledElements);
mcm.execute();
}
else{
final Job readArchitectureModelJob = new Job("Long Running Job") {
protected IStatus run(IProgressMonitor monitor) {
try {
architectureModelReader.createSamInstance(monitor, true);
return Status.OK_STATUS;
}catch(final Exception e) {
return Status.CANCEL_STATUS;
}
}
};
readArchitectureModelJob.addJobChangeListener(new JobChangeAdapter() {
public void done(IJobChangeEvent event) {
if (event.getResult().isOK()){
Component c = swaModel.getRootComponent();
System.out.println(c.getName());
}
else
System.out.println("Job did not complete successfully");
}
});
readArchitectureModelJob.setSystem(true);
readArchitectureModelJob.schedule();
}
}
}
所以这里如果根组件不是null镜像加载的模型(工作正常)但是如果根组件为null我尝试在else子句中加载模型然后获取模型但问题出在模型之前在else子句中加载处理程序跳转到
有人能告诉我如何在获得模型之前运行此模型加载作业吗?
由于
答案 0 :(得分:0)
在作业运行之前,你必须延迟你想做的事。
一种方法是使用IJobChangeListener
来监听工作变更事件。使用:
job.addJobChangeListener(new JobChangeAdapter()
{
@Override
public void done(IJobChangeEvent event) {
// TODO do your end of job processing here
}
});
添加侦听器。在安排作业>之前执行此操作。