use of org.eclipse.ui.internal.ide.ChooseWorkspaceData in project knime-core by knime.
the class KNIMEApplication method checkInstanceLocation.
/**
* Return true if a valid workspace path has been set and false otherwise.
* Prompt for and set the path if possible and required.
*
* @return true if a valid instance location has been set and false
* otherwise
*/
private boolean checkInstanceLocation() {
// -data @none was specified but an ide requires workspace
Location instanceLoc = Platform.getInstanceLocation();
if (instanceLoc == null) {
MessageDialog.openError(null, IDEWorkbenchMessages.IDEApplication_workspaceMandatoryTitle, IDEWorkbenchMessages.IDEApplication_workspaceMandatoryMessage);
return false;
}
// -data "/valid/path", workspace already set
if (instanceLoc.isSet()) {
// chosen to overwrite it).
if (!checkValidWorkspace(instanceLoc.getURL())) {
return false;
}
// metadata version information if successful
try {
if (instanceLoc.lock()) {
writeWorkspaceVersion();
return true;
}
// we failed to create the directory.
// Two possibilities:
// 1. directory is already in use
// 2. directory could not be created
File workspaceDirectory = new File(instanceLoc.getURL().getFile());
if (workspaceDirectory.exists()) {
MessageDialog.openError(null, IDEWorkbenchMessages.IDEApplication_workspaceCannotLockTitle, NLS.bind(IDEWorkbenchMessages.IDEApplication_workspaceCannotLockMessage, workspaceDirectory.getAbsolutePath()));
} else {
MessageDialog.openError(null, IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetTitle, IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetMessage);
}
} catch (IOException e) {
MessageDialog.openError(null, IDEWorkbenchMessages.InternalError, e.getMessage());
}
return false;
}
URL defaultLocation = instanceLoc.getDefault();
if (Platform.OS_MACOSX.equals(Platform.getOS())) {
if (defaultLocation.getPath().contains("/Knime.app/")) {
URL url = Platform.getInstallLocation().getURL();
try {
defaultLocation = new URL(url.getProtocol(), url.getHost(), url.getPath() + "/workspace");
} catch (MalformedURLException ex) {
// should not happen
}
}
}
// -data @noDefault or -data not specified, prompt and set
ChooseWorkspaceData launchData = new ChooseWorkspaceData(defaultLocation);
boolean force = false;
while (true) {
URL workspaceUrl = promptForWorkspace(launchData, force);
if (workspaceUrl == null) {
return false;
}
// if there is an error with the first selection, then force the
// dialog to open to give the user a chance to correct
force = true;
try {
// instance data area, so other checking is unneeded
if (instanceLoc.set(workspaceUrl, true)) {
launchData.writePersistedData();
writeWorkspaceVersion();
return true;
}
// by this point it has been determined that the workspace is
// already in use -- force the user to choose again
MessageDialog.openError(null, IDEWorkbenchMessages.IDEApplication_workspaceInUseTitle, NLS.bind(IDEWorkbenchMessages.IDEApplication_workspaceInUseMessage, workspaceUrl.getPath()));
} catch (Exception e) {
MessageDialog.openError(null, IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetTitle, IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetMessage);
}
}
}
Aggregations