//OPEN PROJECTS
public Project openProject(final LoadOptions opt) {
Session session=SessionFactory.getInstance().getSession(opt.isLocal());
Job job=null;
final boolean recover;
if (opt.getId()>0){
Project p = findFromId(opt.getId());
if (p != null && !opt.isOpenAs()){
job=session.getEmptyJob("Recover project",p);
recover=true;
}else{
addLoadingProject(opt.getId());
recover=false;
}
}else recover=false;
if (job==null) job=session.getLoadProjectJob(opt);
job.addSwingRunnable(new JobRunnable("Local: addProject"){
public Object run() throws Exception{
Project project=(Project)getPreviousResult();
if (!recover){
if (project!=null) addProject(project,false,true);
if (opt.getId()>0) removeLoadingProject(opt.getId());
}
if (opt.getEndSwingClosure()!=null) opt.getEndSwingClosure().execute(project);
if (project != null && opt.isOpenAs() && project.isMaster())
project.setReadOnly(true); // don't allow copy of master
if (project != null && opt.isOpenAs()) {
project.setReadOnly(true);
project.setLocal(true);
}
return project;
}
},false);
if (opt.isSync()) job.addSync();
session.schedule(job);
try {
return (opt.isSync())?(Project)job.waitResult():null;
} catch (Exception e) {//Forward exception + Alert
return null;
}
}