运行 一个 eclipse 作业
Running an eclipse job
我正在开发一个 RCP 应用程序,我有一个用例,我检查根组件是否不为空,这意味着模型已经加载,如果为空,则模型未加载,如果模型未加载然后我尝试先在单独的作业中加载模型,然后在加载模型后获取模型。我写的是
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 子句中
谁能告诉我在获取模型之前如何运行这个模型加载作业?
谢谢
你将不得不推迟你想做的事情,直到工作有 运行。
一种方法是使用 IJobChangeListener
来监听工作变更事件。使用:
job.addJobChangeListener(new JobChangeAdapter()
{
@Override
public void done(IJobChangeEvent event) {
// TODO do your end of job processing here
}
});
添加侦听器。 在作业安排之前执行此操作。
我正在开发一个 RCP 应用程序,我有一个用例,我检查根组件是否不为空,这意味着模型已经加载,如果为空,则模型未加载,如果模型未加载然后我尝试先在单独的作业中加载模型,然后在加载模型后获取模型。我写的是
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 子句中谁能告诉我在获取模型之前如何运行这个模型加载作业?
谢谢
你将不得不推迟你想做的事情,直到工作有 运行。
一种方法是使用 IJobChangeListener
来监听工作变更事件。使用:
job.addJobChangeListener(new JobChangeAdapter()
{
@Override
public void done(IJobChangeEvent event) {
// TODO do your end of job processing here
}
});
添加侦听器。 在作业安排之前执行此操作。