* @param allowCancel
* @param prompt
* @return null if cancelled
*/
public Job getRemoveProjectJob(final Project project, boolean allowCancel, boolean prompt,boolean calledFromSwing) {
Job job=null;
if (prompt && project.needsSaving()) {
// final boolean[] lock=new boolean[]{false};
// SwingUtilities.invokeLater(new Runnable(){
// public void run(){
// Alert.okCancel("test");
// synchronized (lock) {
// lock[0]=true;
// lock.notifyAll();
// }
// }
// });
// synchronized(lock){
// while (!lock[0]){
// try{
// lock.wait();
// }catch (InterruptedException e) {}
// }
// }
int promptResult = promptForSave(project,allowCancel);
if (promptResult == JOptionPane.YES_OPTION){
SaveOptions opt=new SaveOptions();
opt.setLocal(project.isLocal());
if (project.isLocal()){
String fileName=project.getFileName();
if (fileName==null){
fileName=SessionFactory.getInstance().getLocalSession().chooseFileName(true,project.getGuessedFileName());
}
if (fileName==null) return null;
project.setFileName(fileName);
opt.setFileName(fileName);
opt.setImporter(LocalSession.getImporter(project.getFileType()));
}
job=getSaveProjectJob(project, opt);
}
else if (promptResult == JOptionPane.CANCEL_OPTION)
return null;
}
final ArrayList toRemove = new ArrayList();
final ArrayList projects=new ArrayList();
DeepChildWalker.recursivelyTreatBranch(portfolio.getNodeModel(), project, new Closure() {
public void execute(Object arg0) {
Node node = (Node)arg0;
Object impl = node.getImpl();
if (!(impl instanceof Project))
return;
final Project p = (Project)impl;
toRemove.add(node);
if (Environment.getStandAlone()||project.isLockable()){
projects.add(p);
}
}
});
Job closeProjectJob=getCloseProjectsOnServerJob(projects);
if (closeProjectJob==null){
closeProjectJob=new Job(SessionFactory.getInstance().getJobQueue(),"closeProjects","Closing...",false);
}
if (job==null) job=closeProjectJob;
else job.addJob(closeProjectJob);