* @throws Exception Throws an exception if something wrong happens while setting the workspace location.
*/
private boolean handleWorkspace(Display display) throws Exception{
Shell shell = new Shell(display, SWT.ON_TOP);
Location instanceLoc = Platform.getInstanceLocation();
if(instanceLoc.isSet())
return true;
boolean switch_failed = false;
if(SelectWorkspace.isSwitching()){
String switchTo = SelectWorkspace.getSwitchingWS();
if(switchTo == null || switchTo.isEmpty()){
MessageDialog.openError(shell, "Error", "Error while switching workspace.");
switch_failed = true;
}else{
String ret = SelectWorkspace.checkWorkspaceDirectory(Display.getDefault().getActiveShell(), switchTo, false, false);
if (ret != null) {
MessageDialog.openError(shell, "Error", "Error while switching workspace.\n" + ret);
switch_failed = true;
}
instanceLoc.set(new URL("file", null, switchTo), false);
}
SelectWorkspace.resetSwitch();
if(!switch_failed)
return true;
}
boolean remember = SelectWorkspace.isRememberWorkspace();
// get the last used workspace location
String lastUsedWs = SelectWorkspace.getLastSetWorkspaceDirectory();
// if we have a "remember" but no last used workspace, it's not much to remember
if (remember && (lastUsedWs == null || lastUsedWs.isEmpty())) {
remember = false;
}
// check to ensure the workspace location is still OK
if (remember) {
// if there's any problem whatsoever with the workspace, force a dialog which in its turn will tell them what's bad
String ret = SelectWorkspace.checkWorkspaceDirectory(Display.getDefault().getActiveShell(), lastUsedWs, false, false);
if (ret != null) {
remember = false;
}
}
// if we don't remember the workspace, show the dialog
if (!remember || switch_failed) {
SelectWorkspace dialog = new SelectWorkspace(shell);
// if the user cancelled, we can't do anything as we need a workspace, so in this case, we tell them and exit
if (dialog.open() == Window.CANCEL) {
MessageDialog.openError(shell, "Error",
"The application can not start without a workspace root and will now exit.");
try {
PlatformUI.getWorkbench().close();
} catch (Exception err) {
}
return false;
}
// tell Eclipse what the selected location was and continue
instanceLoc.set(new URL("file", null, dialog.getSelectedWorkspaceLocation()), false);
}
else {
// set the last used location and continue
instanceLoc.set(new URL("file", null, lastUsedWs), false);
}
return true;
}