I am working on an RCP application, I have a use case in which I check if the root component is not null which means the model is already loaded and if it is null then the model is not loaded, if the model is not loaded then I try to load the model first in a separate job and then get the model once it is loaded. What I have written is
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();
}
}
}
So here if the root component is not null mirror the loaded model (which works fine) but if the root component is null I try to load the model in else clause and then getting the model but the problem is before the model is loaded in the else clause the handler jumps to
Can anyone tell me how to run this model loading job before I get the model?
Thanks
You will have to delay what you want to do until the Job has run.
One way to this is to use an IJobChangeListener
to listen for the job change events. Use:
job.addJobChangeListener(new JobChangeAdapter()
{
@Override
public void done(IJobChangeEvent event) {
// TODO do your end of job processing here
}
});
to add the listener. Do this before the job is scheduled.