Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Tiede2012-05-22 15:22:04 +0000
committerMarkus Tiede2012-05-22 15:22:04 +0000
commit9a6220598ac6b0bc7f2bb91a89c820c6ccb17827 (patch)
tree9f85bb48811658abcbacc15988b6b40faf224c9e
parentfa216af8ccba97d68858a8d3aa82b2f6d228501d (diff)
downloadorg.eclipse.jubula.core-9a6220598ac6b0bc7f2bb91a89c820c6ccb17827.tar.gz
org.eclipse.jubula.core-9a6220598ac6b0bc7f2bb91a89c820c6ccb17827.tar.xz
org.eclipse.jubula.core-9a6220598ac6b0bc7f2bb91a89c820c6ccb17827.zip
Sprint task - switch to 'standard' eclipse workspace chooser / behavior - see 380278 for further information.
-rw-r--r--org.eclipse.jubula.app/META-INF/MANIFEST.MF1
-rw-r--r--org.eclipse.jubula.app/src/org/eclipse/jubula/app/Launcher.java576
-rw-r--r--org.eclipse.jubula.app/src/org/eclipse/jubula/app/core/WorkSpaceData.java336
-rw-r--r--org.eclipse.jubula.app/src/org/eclipse/jubula/app/i18n/Messages.java27
-rw-r--r--org.eclipse.jubula.app/src/org/eclipse/jubula/app/i18n/messages.properties27
-rw-r--r--org.eclipse.jubula.app/src/org/eclipse/jubula/app/ui/ChooseWorkspaceDialog.java200
6 files changed, 362 insertions, 805 deletions
diff --git a/org.eclipse.jubula.app/META-INF/MANIFEST.MF b/org.eclipse.jubula.app/META-INF/MANIFEST.MF
index a2c78313b..8b61e6ae0 100644
--- a/org.eclipse.jubula.app/META-INF/MANIFEST.MF
+++ b/org.eclipse.jubula.app/META-INF/MANIFEST.MF
@@ -8,6 +8,7 @@ Bundle-Vendor: Eclipse Jubula
Bundle-Localization: plugin
Require-Bundle: org.eclipse.ui;bundle-version="[3.6.1,4.0.0)",
org.eclipse.ui.ide;bundle-version="[3.6.1,4.0.0)",
+ org.eclipse.ui.ide.application;bundle-version="[1.0.0,2.0.0)",
org.eclipse.ui.console;bundle-version="[3.5.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.6.0,4.0.0)",
org.eclipse.core.resources;bundle-version="[3.6.0,4.0.0)",
diff --git a/org.eclipse.jubula.app/src/org/eclipse/jubula/app/Launcher.java b/org.eclipse.jubula.app/src/org/eclipse/jubula/app/Launcher.java
index 972162466..f80ca336e 100644
--- a/org.eclipse.jubula.app/src/org/eclipse/jubula/app/Launcher.java
+++ b/org.eclipse.jubula.app/src/org/eclipse/jubula/app/Launcher.java
@@ -20,48 +20,60 @@ import java.net.URL;
import java.util.Properties;
import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.core.runtime.ILogListener;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.jubula.app.core.JubulaWorkbenchAdvisor;
-import org.eclipse.jubula.app.core.WorkSpaceData;
-import org.eclipse.jubula.app.i18n.Messages;
-import org.eclipse.jubula.app.ui.ChooseWorkspaceDialog;
import org.eclipse.jubula.client.ui.rcp.Plugin;
-import org.eclipse.jubula.tools.constants.StringConstants;
import org.eclipse.osgi.service.datalocation.Location;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.application.WorkbenchAdvisor;
+import org.eclipse.ui.internal.WorkbenchPlugin;
+import org.eclipse.ui.internal.ide.ChooseWorkspaceData;
+import org.eclipse.ui.internal.ide.ChooseWorkspaceDialog;
+import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
+import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
+import org.eclipse.ui.internal.ide.StatusUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * This is the (standalone) launcher class.
+ * This is the (standalone) launcher class - most of the content belongs to
+ * <code>org.eclipse.ui.internal.ide.application.IDEApplication</code>
*
* @author BREDEX GmbH
* @created 24.03.2005
*/
-public class Launcher implements IApplication,
- IExecutableExtension {
- /** the metadata folder*/
- private static final String METADATA_FOLDER = ".metadata"; //$NON-NLS-1$
+public class Launcher implements IApplication {
+ /** The name of the folder containing metadata information for the workspace. */
+ public static final String METADATA_FOLDER = ".metadata"; //$NON-NLS-1$
/** the version filename */
private static final String VERSION_FILENAME = "version.ini"; //$NON-NLS-1$
/** the workspace version key */
private static final String WORKSPACE_VERSION_KEY = "org.eclipse.core.runtime"; //$NON-NLS-1$
/** the workspace version value */
private static final String WORKSPACE_VERSION_VALUE = "1"; //$NON-NLS-1$
-
+ /** a proper exit code */
+ private static final String PROP_EXIT_CODE = "eclipse.exitcode"; //$NON-NLS-1$
+
+ /**
+ * A special return code that will be recognized by the launcher and used to
+ * restart the workbench.
+ */
+ private static final Integer EXIT_RELAUNCH = new Integer(24);
+
/** for log messages */
private static Logger log = LoggerFactory.getLogger(Launcher.class);
@@ -74,153 +86,197 @@ public class Launcher implements IApplication,
/**
- * Return true if a valid workspace path has been set and false otherwise.
- * Prompt for and set the path if possible and required.
- * @param shell The actual shell.
- * @return true if a valid instance location has been set and false
- * otherwise
- */
- protected boolean checkInstanceLocation(Shell shell) {
- // -data @none was specified but an ide requires workspace
- Location instanceLoc = Platform.getInstanceLocation();
- if (instanceLoc == null) {
- MessageDialog.openError(shell, Messages
- .LauncherValidWorkspaceTitle,
- Messages.LauncherValidWorkspace);
- return false;
- }
-
- // -data "/valid/path", workspace already set
- if (instanceLoc.isSet()) {
- return true;
- }
- // -data @noDefault or -data not specified, prompt and set
- URL defaultUrl = instanceLoc.getDefault();
- String initialDefault = defaultUrl == null ? null : defaultUrl
- .getFile();
- WorkSpaceData launchData = new WorkSpaceData(initialDefault);
-
- while (true) {
- URL workspaceUrl = promptForWorkspace(shell, launchData);
- if (workspaceUrl == null) {
- return false;
- }
- try {
- // the operation will fail if the url is not a valid
- // instance data area, so other checking is unneeded
- if (instanceLoc.set(workspaceUrl, true)) {
- launchData.writePersistedData(shell);
- writeWorkspaceVersion(shell);
- return true;
- }
- } catch (IllegalStateException e) {
- MessageDialog.openError(shell, Messages
- .LauncherCannotBeSetTitle,
- Messages.LauncherCannotBeSet);
- return false;
- } catch (IOException e) {
- MessageDialog.openError(shell, Messages
- .LauncherCannotBeSetTitle,
- Messages.LauncherCannotBeSet);
- return false;
- }
-
- // by this point it has been determined that the workspace is
- // already
- // in use -- force the user to choose again
- MessageDialog.openError(shell, Messages
- .LauncherAlreadyInUseTitle,
- Messages.LauncherAlreadyInUse);
- }
- }
-
- /**
* Open a workspace selection dialog on the argument shell, populating the
* argument data with the user's selection. Perform first level validation
* on the selection by comparing the version information. This method does
* not examine the runtime state (e.g., is the workspace already locked?).
*
- * @param shell The actual shell.
- * @param launchData The workspace data to launch.
+ * @param shell the shell
+ * @param launchData the launch data
+ * @param force
+ * setting to true makes the dialog open regardless of the
+ * showDialog value
* @return An URL storing the selected workspace or null if the user has
* canceled the launch operation.
*/
- private URL promptForWorkspace(Shell shell, WorkSpaceData launchData) {
+ private URL promptForWorkspace(Shell shell, ChooseWorkspaceData launchData,
+ boolean force) {
+ boolean doForce = force;
URL url = null;
do {
- ChooseWorkspaceDialog wd =
- new ChooseWorkspaceDialog(shell, launchData);
- wd.open();
-
+ // okay to use the shell now - this is the splash shell
+ new ChooseWorkspaceDialog(shell, launchData, false, true)
+ .prompt(doForce);
String instancePath = launchData.getSelection();
- if (instancePath == null
- || wd.getReturnCode() == Window.CANCEL) {
+ if (instancePath == null) {
return null;
}
+
+ // the dialog is not forced on the first iteration, but is on every
+ // subsequent one -- if there was an error then the user needs to be
+ // allowed to fix it
+ doForce = true;
+
+ // 70576: don't accept empty input
+ if (instancePath.length() <= 0) {
+ MessageDialog.openError(shell,
+ IDEWorkbenchMessages.IDEApplication_workspaceEmptyTitle,
+ IDEWorkbenchMessages.IDEApplication_workspaceEmptyMessage);
+ continue;
+ }
+
+ // create the workspace if it does not already exist
+ File workspace = new File(instancePath);
+ if (!workspace.exists()) {
+ workspace.mkdir();
+ }
+
try {
-
- File file = new File(instancePath);
- url = file.toURL();
+ // Don't use File.toURL() since it adds a leading slash that Platform does not
+ // handle properly. See bug 54081 for more details.
+ String path = workspace.getAbsolutePath().replace(
+ File.separatorChar, '/');
+ url = new URL("file", null, path); //$NON-NLS-1$
} catch (MalformedURLException e) {
- MessageDialog.openError(shell, Messages
- .LauncherNotValidTitle,
- Messages.LauncherNotValid);
+ MessageDialog.openError(shell,
+ IDEWorkbenchMessages.IDEApplication_workspaceInvalidTitle,
+ IDEWorkbenchMessages
+ .IDEApplication_workspaceInvalidMessage);
continue;
}
- } while (!isValidWorkspace(shell, url));
+ } while (!checkValidWorkspace(shell, url));
+
return url;
}
/**
- * @param shell The actual shell.
- * @param url The workspace url.
- * @return True if the argument directory is ok to use as a workspace and
- * false otherwise. A version check will be performed, and a confirmation
- * box may be displayed on the argument shell if an older version is
- * detected.
+ * The version file is stored in the metadata area of the workspace. This
+ * method returns an URL to the file or null if the directory or file does
+ * not exist (and the create parameter is false).
+ * @param create If the directory and file does not exist this parameter controls whether it will be created.
+ * @param workspaceUrl The URL of the workspace.
+ * @return An url to the file or null if the version file does not exist or could not be created.
*/
- private boolean isValidWorkspace(Shell shell, URL url) {
- String version = readWorkspaceVersion(url, shell);
- // if the version could not be read, then there is not any existing
- // workspace data to trample, e.g., perhaps its a new directory that
- // is just starting to be used as a workspace
- if (version == null) {
- return true;
+ private static File getVersionFile(URL workspaceUrl, boolean create) {
+ if (workspaceUrl == null) {
+ return null;
}
- final int ideversion = Integer.parseInt(WORKSPACE_VERSION_VALUE);
- int workspaceversion = Integer.parseInt(version);
- // equality test is required since any version difference (newer
- // or older) may result in data being trampled
- if (workspaceversion == ideversion) {
- return true;
+ try {
+ // make sure the directory exists
+ URL metaUrl = new URL(workspaceUrl, METADATA_FOLDER);
+ File metaDir = new File(metaUrl.getFile());
+ if (!metaDir.exists() && (!create || !metaDir.mkdir())) {
+ return null;
+ }
+ // make sure the file exists
+ URL versionUrl = new URL(metaDir.toURL(), VERSION_FILENAME);
+ File versionFile = new File(versionUrl.getFile());
+ if (!versionFile.exists()
+ && (!create || !versionFile.createNewFile())) {
+ return null;
+ }
+ return versionFile;
+ } catch (IOException e) {
+ // cannot log because instance area has not been set
+ return null;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setInitializationData(IConfigurationElement config,
+ String propertyName, Object data) {
+ // do nothing
+ }
+
+
+ /**
+ * Creates the display used by the application.
+ *
+ * @return the display used by the application
+ */
+ protected Display createDisplay() {
+ return PlatformUI.createDisplay();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object start(IApplicationContext context) throws Exception {
+ Display.setAppName(getAppName());
+ Display display = createDisplay();
+
+ try {
+
+ // look and see if there's a splash shell we can parent off of
+ Shell shell = WorkbenchPlugin.getSplashShell(display);
+ if (shell != null) {
+ // should should set the icon and message for this shell to be the
+ // same as the chooser dialog - this will be the guy that lives in
+ // the task bar and without these calls you'd have the default icon
+ // with no message.
+ shell.setText(ChooseWorkspaceDialog.getWindowTitle());
+ shell.setImages(Window.getDefaultImages());
+ }
+
+ Object instanceLocationCheck = checkInstanceLocation(shell);
+ if (instanceLocationCheck != null) {
+ WorkbenchPlugin.unsetSplashShell(display);
+ Platform.endSplash();
+ return instanceLocationCheck;
+ }
+
+ Platform.addLogListener(new ILogListener() {
+ public void logging(IStatus status, String pluginId) {
+ if (status.getException() instanceof RuntimeException) {
+ Plugin.getDefault().handleError(status.getException());
+ }
+ }
+ });
+
+ // create the workbench with this advisor and run it until it exits
+ // N.B. createWorkbench remembers the advisor, and also registers
+ // the workbench globally so that all UI plug-ins can find it using
+ // PlatformUI.getWorkbench() or AbstractUIPlugin.getWorkbench()
+ int returnCode = PlatformUI.createAndRunWorkbench(display,
+ getWorkbenchAdvisor());
+
+ // the workbench doesn't support relaunch yet (bug 61809) so
+ // for now restart is used, and exit data properties are checked
+ // here to substitute in the relaunch return code if needed
+ if (returnCode != PlatformUI.RETURN_RESTART) {
+ return EXIT_OK;
+ }
+
+ // if the exit code property has been set to the relaunch code, then
+ // return that code now, otherwise this is a normal restart
+ return EXIT_RELAUNCH.equals(
+ Integer.getInteger(PROP_EXIT_CODE)) ? EXIT_RELAUNCH
+ : EXIT_RESTART;
+ } finally {
+ if (display != null) {
+ display.dispose();
+ }
+ Location instanceLoc = Platform.getInstanceLocation();
+ if (instanceLoc != null) {
+ instanceLoc.release();
+ }
}
- // At this point workspace has been detected to be from a version
- // other than the current ide version -- find out if the user wants
- // to use it anyhow.
- String title = Messages.LauncherDifferentVersionTitle;
- // Use NLS.bind in Eclipse3.1
- String message = NLS.bind(
- Messages.LauncherDifferentVersionMessage,
- url.getFile());
- MessageBox mbox = new MessageBox(shell, SWT.OK | SWT.CANCEL
- | SWT.ICON_WARNING | SWT.APPLICATION_MODAL);
- mbox.setText(title);
- mbox.setMessage(message);
- return mbox.open() == SWT.OK;
}
/**
* Look at the argument URL for the workspace's version information. Return
* that version if found and null otherwise.
- * @param workspace The workspace url.
- * @param shell The actual shell.
- * @return The workspace version.
+ * @param workspace the workspace
+ * @return the workspace version
*/
- private static String readWorkspaceVersion(URL workspace, Shell shell) {
+ private static String readWorkspaceVersion(URL workspace) {
File versionFile = getVersionFile(workspace, false);
if (versionFile == null || !versionFile.exists()) {
return null;
}
+
try {
// Although the version file is not spec'ed to be a Java properties
// file, it happens to follow the same format currently, so using
@@ -232,42 +288,94 @@ public class Launcher implements IApplication,
} finally {
is.close();
}
+
return props.getProperty(WORKSPACE_VERSION_KEY);
} catch (IOException e) {
- log.error(Messages.CouldNotReadVersionFile, e);
- MessageDialog.openError(shell, Messages
- .LauncherCouldNotReadTitle,
- Messages.LauncherCouldNotRead);
+ IDEWorkbenchPlugin.log("Could not read version file", new Status(//$NON-NLS-1$
+ IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH,
+ IStatus.ERROR,
+ e.getMessage() == null ? "" : e.getMessage(), //$NON-NLS-1$,
+ e));
return null;
}
}
/**
+ * Return true if the argument directory is ok to use as a workspace and
+ * false otherwise. A version check will be performed, and a confirmation
+ * box may be displayed on the argument shell if an older version is
+ * detected.
+ *
+ * @param shell the shell to use
+ * @param url the url to check
+ * @return true if the argument URL is ok to use as a workspace and false
+ * otherwise.
+ */
+ private boolean checkValidWorkspace(Shell shell, URL url) {
+ // a null url is not a valid workspace
+ if (url == null) {
+ return false;
+ }
+
+ String version = readWorkspaceVersion(url);
+
+ // if the version could not be read, then there is not any existing
+ // workspace data to trample, e.g., perhaps its a new directory that
+ // is just starting to be used as a workspace
+ if (version == null) {
+ return true;
+ }
+
+ final int ideVersion = Integer.parseInt(WORKSPACE_VERSION_VALUE);
+ int workspaceVersion = Integer.parseInt(version);
+
+ // equality test is required since any version difference (newer
+ // or older) may result in data being trampled
+ if (workspaceVersion == ideVersion) {
+ return true;
+ }
+
+ // At this point workspace has been detected to be from a version
+ // other than the current ide version -- find out if the user wants
+ // to use it anyhow.
+ String title = IDEWorkbenchMessages.IDEApplication_versionTitle;
+ String message = NLS.bind(
+ IDEWorkbenchMessages.IDEApplication_versionMessage,
+ url.getFile());
+
+ MessageBox mbox = new MessageBox(shell, SWT.OK | SWT.CANCEL
+ | SWT.ICON_WARNING | SWT.APPLICATION_MODAL);
+ mbox.setText(title);
+ mbox.setMessage(message);
+ return mbox.open() == SWT.OK;
+ }
+
+ /**
* Write the version of the metadata into a known file overwriting any
- * existing file contents. Writing the version file isn't really crucial, so
- * the function is silent about failure.
- * @param shell The actual shell.
+ * existing file contents. Writing the version file isn't really crucial,
+ * so the function is silent about failure
*/
- private static void writeWorkspaceVersion(Shell shell) {
+ private static void writeWorkspaceVersion() {
Location instanceLoc = Platform.getInstanceLocation();
if (instanceLoc == null || instanceLoc.isReadOnly()) {
return;
}
+
File versionFile = getVersionFile(instanceLoc.getURL(), true);
if (versionFile == null) {
return;
}
+
OutputStream output = null;
try {
- String versionLine = WORKSPACE_VERSION_KEY
- + StringConstants.EQUALS_SIGN + WORKSPACE_VERSION_VALUE;
+ String versionLine = WORKSPACE_VERSION_KEY + '='
+ + WORKSPACE_VERSION_VALUE;
+
output = new FileOutputStream(versionFile);
output.write(versionLine.getBytes("UTF-8")); //$NON-NLS-1$
} catch (IOException e) {
- log.error(Messages.CouldNotWriteVersionFile, e);
- MessageDialog.openError(shell, Messages
- .LauncherCouldNotWriteTitle,
- Messages.LauncherCouldNotWrite);
+ IDEWorkbenchPlugin.log("Could not write version file", //$NON-NLS-1$
+ StatusUtil.newStatus(IStatus.ERROR, e.getMessage(), e));
} finally {
try {
if (output != null) {
@@ -278,102 +386,140 @@ public class Launcher implements IApplication,
}
}
}
-
+
/**
- * The version file is stored in the metadata area of the workspace. This
- * method returns an URL to the file or null if the directory or file does
- * not exist (and the create parameter is false).
- * @param create If the directory and file does not exist this parameter controls whether it will be created.
- * @param workspaceUrl The URL of the workspace.
- * @return An url to the file or null if the version file does not exist or could not be created.
+ * Return <code>null</code> if a valid workspace path has been set and an exit code otherwise.
+ * Prompt for and set the path if possible and required.
+ *
+ * @param shell the shell to use
+ * @return <code>null</code> if a valid instance location has been set and an exit code
+ * otherwise
*/
- private static File getVersionFile(URL workspaceUrl, boolean create) {
- if (workspaceUrl == null) {
- return null;
+ private Object checkInstanceLocation(Shell shell) {
+ // -data @none was specified but an ide requires workspace
+ Location instanceLoc = Platform.getInstanceLocation();
+ if (instanceLoc == null) {
+ MessageDialog.openError(shell,
+ IDEWorkbenchMessages.IDEApplication_workspaceMandatoryTitle,
+ IDEWorkbenchMessages.IDEApplication_workspaceMandatoryMessage);
+ return EXIT_OK;
}
- try {
- // make sure the directory exists
- URL metaUrl = new URL(workspaceUrl, METADATA_FOLDER);
- File metaDir = new File(metaUrl.getFile());
- if (!metaDir.exists() && (!create || !metaDir.mkdir())) {
- return null;
+ // -data "/valid/path", workspace already set
+ if (instanceLoc.isSet()) {
+ // make sure the meta data version is compatible (or the user has
+ // chosen to overwrite it).
+ if (!checkValidWorkspace(shell, instanceLoc.getURL())) {
+ return EXIT_OK;
}
- // make sure the file exists
- URL versionUrl = new URL(metaDir.toURL(), VERSION_FILENAME);
- File versionFile = new File(versionUrl.getFile());
- if (!versionFile.exists()
- && (!create || !versionFile.createNewFile())) {
- return null;
+ // at this point its valid, so try to lock it and update the
+ // metadata version information if successful
+ try {
+ if (instanceLoc.lock()) {
+ writeWorkspaceVersion();
+ return null;
+ }
+ // 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());
+ handleError(shell, workspaceDirectory);
+ } catch (IOException e) {
+ IDEWorkbenchPlugin.log("Could not obtain lock for workspace location", //$NON-NLS-1$
+ e);
+ MessageDialog.openError(shell,
+ IDEWorkbenchMessages.InternalError,
+ e.getMessage());
+ }
+ return EXIT_OK;
+ }
+ // -data @noDefault or -data not specified, prompt and set
+ ChooseWorkspaceData launchData = new ChooseWorkspaceData(instanceLoc
+ .getDefault());
+ boolean force = false;
+ while (true) {
+ URL workspaceUrl = promptForWorkspace(shell, launchData, force);
+ if (workspaceUrl == null) {
+ return EXIT_OK;
}
- return versionFile;
- } catch (IOException e) {
- // cannot log because instance area has not been set
- return null;
+ // 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 {
+ // the operation will fail if the url is not a valid
+ // instance data area, so other checking is unneeded
+ if (instanceLoc.setURL(workspaceUrl, true)) {
+ launchData.writePersistedData();
+ writeWorkspaceVersion();
+ return null;
+ }
+ } catch (IllegalStateException e) {
+ MessageDialog.openError(shell,
+ IDEWorkbenchMessages
+ .IDEApplication_workspaceCannotBeSetTitle,
+ IDEWorkbenchMessages
+ .IDEApplication_workspaceCannotBeSetMessage);
+ return EXIT_OK;
+ }
+ // by this point it has been determined that the workspace is
+ // already in use -- force the user to choose again
+ MessageDialog.openError(shell, IDEWorkbenchMessages
+ .IDEApplication_workspaceInUseTitle,
+ IDEWorkbenchMessages.IDEApplication_workspaceInUseMessage);
}
}
+
/**
- * {@inheritDoc}
+ * @param shell the shell to use
+ * @param workspaceDirectory the workspace dir
*/
- public void setInitializationData(IConfigurationElement config,
- String propertyName, Object data) {
- // do nothing
+ protected void handleError(Shell shell, File workspaceDirectory) {
+ if (workspaceDirectory.exists()) {
+ MessageDialog.openError(shell,
+ IDEWorkbenchMessages
+ .IDEApplication_workspaceCannotLockTitle,
+ IDEWorkbenchMessages
+ .IDEApplication_workspaceCannotLockMessage);
+ } else {
+ MessageDialog.openError(shell,
+ IDEWorkbenchMessages
+ .IDEApplication_workspaceCannotBeSetTitle,
+ IDEWorkbenchMessages
+ .IDEApplication_workspaceCannotBeSetMessage);
+ }
}
-
+
/**
* {@inheritDoc}
*/
- public Object start(IApplicationContext context) throws Exception {
- // create and startup the display for the workbench
- Display.setAppName("Jubula"); //$NON-NLS-1$
- Display display = new Display();
- try {
- Shell shell = new Shell(display, SWT.SYSTEM_MODAL | SWT.ON_TOP);
- try {
- if (!checkInstanceLocation(shell)) {
- context.applicationRunning();
- return EXIT_OK;
- }
- } finally {
- if (shell != null) {
- shell.dispose();
+ public void stop() {
+ final IWorkbench workbench = PlatformUI.getWorkbench();
+ if (workbench == null) {
+ return;
+ }
+ final Display display = workbench.getDisplay();
+ display.syncExec(new Runnable() {
+ public void run() {
+ if (!display.isDisposed()) {
+ workbench.close();
}
}
-
- Platform.addLogListener(new ILogListener() {
- public void logging(IStatus status, String pluginId) {
- if (status.getException() instanceof RuntimeException) {
- Plugin.getDefault().handleError(status.getException());
- }
- }
- });
-
- // create the workbench with this advisor and run it until it exits
- // N.B. createWorkbench remembers the advisor, and also registers
- // the
- // workbench globally so that all UI plug-ins can find it using
- // N.B. createWorkbench remembers the advisor, and also registers
- // the workbench globally so that all UI plug-ins can find it using
- // PlatformUI.getWorkbench() or AbstractUIPlugin.getWorkbench()
- // exit the application with an appropriate return code
- int returnCode = PlatformUI.createAndRunWorkbench(display,
- new JubulaWorkbenchAdvisor());
- // exit the application with an appropriate return code
- return returnCode == PlatformUI.RETURN_RESTART
- ? IApplication.EXIT_RESTART : IApplication.EXIT_OK;
-
- } finally {
- if (display != null) {
- display.dispose();
- }
- }
+ });
+ }
+
+ /**
+ * @return a new workbench advisor instance
+ */
+ protected WorkbenchAdvisor getWorkbenchAdvisor() {
+ return new JubulaWorkbenchAdvisor();
}
+
/**
- * {@inheritDoc}
+ * @return an human readable application name
*/
- public void stop() {
- // nothing yet
-
+ protected String getAppName() {
+ return "Jubula"; //$NON-NLS-1$
}
} \ No newline at end of file
diff --git a/org.eclipse.jubula.app/src/org/eclipse/jubula/app/core/WorkSpaceData.java b/org.eclipse.jubula.app/src/org/eclipse/jubula/app/core/WorkSpaceData.java
deleted file mode 100644
index 94df55c8d..000000000
--- a/org.eclipse.jubula.app/src/org/eclipse/jubula/app/core/WorkSpaceData.java
+++ /dev/null
@@ -1,336 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2010 BREDEX GmbH.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * BREDEX GmbH - initial API and implementation and/or initial documentation
- *******************************************************************************/
-package org.eclipse.jubula.app.core;
-
-import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.Writer;
-import java.net.URL;
-
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jubula.app.i18n.Messages;
-import org.eclipse.osgi.service.datalocation.Location;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IMemento;
-import org.eclipse.ui.WorkbenchException;
-import org.eclipse.ui.XMLMemento;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class stores the information behind the "Launch Workspace" dialog. The
- * class is able to read and write itself to a well known configuration file.
- * @author BREDEX GmbH
- * @created 18.12.2006
- */
-public class WorkSpaceData {
- /**
- * The default max length of the recent workspace mru list. The values
- * stored in xml (both the max-length parameter and actual size of the list)
- * will supersede this value.
- */
- private static final int RECENT_MAX_LENGTH = 5;
-
- /**
- * The directory within the config area that will be used for the receiver's
- * persisted data.
- */
- private static final String PERS_FOLDER = "org.eclipse.jubula.app"; //$NON-NLS-1$
-
- /**
- * The name of the file within the config area that will be used for the
- * recever's persisted data.
- *
- * {@inheritDoc}
- */
- private static final String PERS_FILENAME = "recentWorkspaces.xml"; //$NON-NLS-1$
- /***/
- private static final int PERS_ENCODING_VERSION = 1;
-
- /** for log messages */
- private static Logger log = LoggerFactory.getLogger(WorkSpaceData.class);
- /** the initial default */
- private String m_initialDefault;
- /** the selected workspace*/
- private String m_selection;
- /** all recent workspaces */
- private String[] m_recentWorkspaces;
-
- /** xml tags */
- private static interface XML {
- /** the protocol */
- public static final String PROTOCOL = "protocol"; //$NON-NLS-1$
- /** the version */
- public static final String VERSION = "version"; //$NON-NLS-1$
- /** the workspace */
- public static final String WORKSPACE = "workspace"; //$NON-NLS-1$
- /** last used workspace */
- public static final String LAST_USED_WORKSPACE = "lastUsedWorkspace"; //$NON-NLS-1$
- /** all recent workspaces */
- public static final String RECENT_WORKSPACES = "recentWorkspaces"; //$NON-NLS-1$
- /** the max quantity of workspaces to store */
- public static final String MAX_LENGTH = "maxLength"; //$NON-NLS-1$
- /** the path */
- public static final String PATH = "path"; //$NON-NLS-1$
- }
-
- /**
- * Creates a new instance, loading persistent data if its found.
- * @param initialDefault The inital default.
- */
- public WorkSpaceData(String initialDefault) {
- readPersistedData();
- m_initialDefault = initialDefault;
- }
-
- /**
- * @return the folder to be used as a default if no other information exists.
- * Does not return null.
- */
- public String getInitialDefault() {
- if (m_initialDefault == null) {
- m_initialDefault = System.getProperty("user.dir") + File.separator //$NON-NLS-1$
- + "jubulaWorkspace"; //$NON-NLS-1$
- }
- return m_initialDefault;
- }
-
- /**
- * @return The currently selected workspace or null if nothing is selected.
- */
- public String getSelection() {
- return m_selection;
- }
-
- /**
- * @return An array of recent workspaces sorted with the most recently used at the start.
- */
- public String[] getRecentWorkspaces() {
- return m_recentWorkspaces;
- }
-
- /**
- * The argument workspace has been selected, update the receiver. Does not persist the new values.
- * @param dir The selected workspace directory.
- */
- public void workspaceSelected(String dir) {
- // this just stores the m_selection, it is not inserted and persisted
- // until the workspace is actually selected
- m_selection = dir;
- }
-
- /**
- * Update the persistent store. Call this function after the currently
- * selected value has been found to be ok.
- * @param shell The actual shell.
- */
- public void writePersistedData(Shell shell) {
- Location configLoc = Platform.getUserLocation();
- if (configLoc == null || configLoc.isReadOnly()) {
- return;
- }
- URL persUrl = getPersistenceUrl(configLoc.getURL(), true);
- if (persUrl == null) {
- return;
- }
- // move the new m_selection to the front of the list
- if (m_selection != null) {
- String oldEntry = m_recentWorkspaces[0];
- m_recentWorkspaces[0] = m_selection;
- for (int i = 1; i < m_recentWorkspaces.length && oldEntry != null;
- ++i) {
- if (m_selection.equals(oldEntry)) {
- break;
- }
- String tmp = m_recentWorkspaces[i];
- m_recentWorkspaces[i] = oldEntry;
- oldEntry = tmp;
- }
- }
- Writer writer = null;
- try {
- writer = new FileWriter(persUrl.getFile());
-
- // E.g.,
- // <launchWorkspaceData>
- // <protocol version="1"/>
- // <recentWorkspaces maxLength="5">
- // <lastUsedWorkspace="C:\eclipse\workspace1"/>
- // <workspace path="C:\eclipse\workspace0"/>
- // <workspace path="C:\eclipse\workspace1"/>
- // </recentWorkspaces>
- // </launchWorkspaceData>
-
- XMLMemento memento = XMLMemento
- .createWriteRoot(Messages.LaunchWorkspaceData);
-
- memento.createChild(XML.PROTOCOL).putInteger(XML.VERSION,
- PERS_ENCODING_VERSION);
- memento.createChild(XML.LAST_USED_WORKSPACE).putString(XML.PATH,
- m_selection);
- IMemento recentMemento = memento.createChild(XML.RECENT_WORKSPACES);
- recentMemento.putInteger(XML.MAX_LENGTH, m_recentWorkspaces.length);
- for (int i = 0; i < m_recentWorkspaces.length; ++i) {
- if (m_recentWorkspaces[i] == null) {
- break;
- }
- recentMemento.createChild(XML.WORKSPACE).putString(XML.PATH,
- m_recentWorkspaces[i]);
- }
- memento.save(writer);
- } catch (IOException e) {
- log.error(Messages.UnableToWriteWorkspaceData, e);
- MessageDialog.openError(shell,
- Messages.WorkSpaceDataCantWriteDataTitle,
- Messages.WorkSpaceDataCanWriteData);
- } finally {
- if (writer != null) {
- try {
- writer.close();
- } catch (IOException e1) {
- // do nothing
- }
- }
- }
- }
-
- /**
- * Look for and read data that might have been persisted from some previous
- * run. Leave the receiver in a default state if no persistent data is
- * found.
- */
- public void readPersistedData() {
- URL persUrl = null;
-
- Location configLoc = Platform.getUserLocation();
- if (configLoc != null) {
- persUrl = getPersistenceUrl(configLoc.getURL(), true);
- }
- try {
- // inside try to get the safe default creation in the finally
- // clause
- if (persUrl == null) {
- return;
- }
- // E.g.,
- // <launchWorkspaceData>
- // <protocol version="1"/>
- // <lastUsedWorkspace="C:\eclipse\workspace1"/>
- // <recentWorkspaces maxLength="5">
- // <workspace path="C:\eclipse\workspace0"/>
- // <workspace path="C:\eclipse\workspace1"/>
- // </recentWorkspaces>
- // </launchWorkspaceData>
-
- Reader reader = new FileReader(persUrl.getFile());
- XMLMemento memento = XMLMemento.createReadRoot(reader);
- if (memento == null || !compatibleProtocol(memento)) {
- return;
- }
- IMemento recent = memento.getChild(XML.RECENT_WORKSPACES);
- if (recent == null) {
- return;
- }
- Integer maxLength = recent.getInteger(XML.MAX_LENGTH);
- int max = RECENT_MAX_LENGTH;
- if (maxLength != null) {
- max = maxLength.intValue();
- }
- IMemento indices[] = recent.getChildren(XML.WORKSPACE);
- if (indices == null || indices.length <= 0) {
- return;
- }
- // if a user has edited maxLength to be shorter than the listed
- // indices, accept the list (its tougher for them to retype a long
- // list of paths than to update a max number)
- max = Math.max(max, indices.length);
-
- m_recentWorkspaces = new String[max];
- for (int i = 0; i < indices.length; ++i) {
- String path = indices[i].getString(XML.PATH);
- if (path == null) {
- break;
- }
- m_recentWorkspaces[i] = path;
- }
- IMemento lastUsed = memento.getChild(XML.LAST_USED_WORKSPACE);
- if (lastUsed == null) {
- m_selection = m_initialDefault;
- return;
- }
- m_selection = lastUsed.getString(XML.PATH);
- return;
- } catch (IOException e) {
- // do nothing -- cannot log because instance area has not been set
- } catch (WorkbenchException e) {
- // do nothing -- cannot log because instance area has not been set
- } finally {
- // create safe default if needed
- if (m_recentWorkspaces == null) {
- m_recentWorkspaces = new String[RECENT_MAX_LENGTH];
- }
- }
- }
-
- /**
- * @return True if the protocol used to encode the argument memento is
- * compatible with the receiver's implementation and false otherwise.
- * @param memento The memento.
- */
- private static boolean compatibleProtocol(IMemento memento) {
- IMemento protocolMemento = memento.getChild(XML.PROTOCOL);
- if (protocolMemento == null) {
- return false;
- }
- Integer version = protocolMemento.getInteger(XML.VERSION);
- return version != null && version.intValue() == PERS_ENCODING_VERSION;
- }
-
- /**
- * The workspace data is stored in the well known file pointed to by the
- * result of this method.
- * @param create If the directory and file does not exist this parameter controls whether it will be created.
- * @param baseUrl The base url.
- * @return An url to the file and null if it does not exist or could not be created.
- */
- private static URL getPersistenceUrl(URL baseUrl, boolean create) {
- if (baseUrl == null) {
- return null;
- }
- try {
- // make sure the base directory exists
- URL url = new URL(baseUrl, PERS_FOLDER);
- File baseDir = new File(baseUrl.getFile());
- if (!baseDir.exists() && (!create || !baseDir.mkdir())) {
- return null;
- }
- // make sure the sub directory exists
- File dir = new File(url.getFile());
- if (!dir.exists() && (!create || !dir.mkdir())) {
- return null;
- }
- // make sure the file exists
- url = new URL(dir.toURL(), PERS_FILENAME);
- File persFile = new File(url.getFile());
- if (!persFile.exists() && (!create || !persFile.createNewFile())) {
- return null;
- }
- return persFile.toURL();
- } catch (IOException e) {
- // cannot log because instance area has not been set
- return null;
- }
- }
-}
diff --git a/org.eclipse.jubula.app/src/org/eclipse/jubula/app/i18n/Messages.java b/org.eclipse.jubula.app/src/org/eclipse/jubula/app/i18n/Messages.java
index f5bea1b4d..4651563b4 100644
--- a/org.eclipse.jubula.app/src/org/eclipse/jubula/app/i18n/Messages.java
+++ b/org.eclipse.jubula.app/src/org/eclipse/jubula/app/i18n/Messages.java
@@ -47,35 +47,8 @@ public class Messages extends NLS {
public static String ActionBuildershowView;
public static String ActionBuilderWindowEntry;
public static String CannotOpenThePerspective;
- public static String ChooseWorkspaceDialogBrowse;
- public static String ChooseWorkspaceDialogDialogMessage;
- public static String ChooseWorkspaceDialogDialogText;
- public static String ChooseWorkspaceDialogMessaageDir;
- public static String ChooseWorkspaceDialogMessageArea;
- public static String ChooseWorkspaceDialogSelectDir;
- public static String ChooseWorkspaceDialogWorkspace;
- public static String CouldNotReadVersionFile;
- public static String CouldNotWriteVersionFile;
- public static String LauncherAlreadyInUse;
- public static String LauncherAlreadyInUseTitle;
- public static String LauncherCannotBeSet;
- public static String LauncherCannotBeSetTitle;
- public static String LauncherCouldNotRead;
- public static String LauncherCouldNotReadTitle;
- public static String LauncherCouldNotWrite;
- public static String LauncherCouldNotWriteTitle;
- public static String LauncherDifferentVersionMessage;
- public static String LauncherDifferentVersionTitle;
- public static String LauncherNotValid;
- public static String LauncherNotValidTitle;
- public static String LauncherValidWorkspace;
- public static String LauncherValidWorkspaceTitle;
public static String JubulaWorkbenchWindowAdvisorWindowTitle;
- public static String LaunchWorkspaceData;
- public static String UnableToWriteWorkspaceData;
public static String UnhandledRuntimeException;
- public static String WorkSpaceDataCantWriteDataTitle;
- public static String WorkSpaceDataCanWriteData;
static {
// initialize resource bundle
diff --git a/org.eclipse.jubula.app/src/org/eclipse/jubula/app/i18n/messages.properties b/org.eclipse.jubula.app/src/org/eclipse/jubula/app/i18n/messages.properties
index 367bdd35e..a60d93a76 100644
--- a/org.eclipse.jubula.app/src/org/eclipse/jubula/app/i18n/messages.properties
+++ b/org.eclipse.jubula.app/src/org/eclipse/jubula/app/i18n/messages.properties
@@ -33,32 +33,5 @@ ActionBuilderSearch=Se&arch
ActionBuildershowView=Show &View
ActionBuilderWindowEntry=&Window
CannotOpenThePerspective=Cannot open the perspective\:
-ChooseWorkspaceDialogBrowse=&Browse...
-ChooseWorkspaceDialogDialogMessage=Select a workspace
-ChooseWorkspaceDialogDialogText=Workspace Launcher
-ChooseWorkspaceDialogMessaageDir=Select the workspace directory to use.
-ChooseWorkspaceDialogMessageArea=The application stores user preferences in a directory called a workspace.\nSelect the workspace directory to use for this session.
-ChooseWorkspaceDialogSelectDir=Select Workspace Directory
-ChooseWorkspaceDialogWorkspace=&Workspace\:
-CouldNotReadVersionFile=Could not read version file.
-CouldNotWriteVersionFile=Could not write version file.
JubulaWorkbenchWindowAdvisorWindowTitle=Jubula
-LauncherAlreadyInUse=Workspace already in use. Please choose another one
-LauncherAlreadyInUseTitle=Workspace in use
-LauncherCannotBeSet=Error in runtime. Workspace cannot be set.\n\nExiting.
-LauncherCannotBeSetTitle=Workspace cannot be set
-LauncherCouldNotRead=Could not read version file.
-LauncherCouldNotReadTitle=Could not read
-LauncherCouldNotWrite=Could not write version file.
-LauncherCouldNotWriteTitle=Could not write
-LauncherDifferentVersionMessage=This workspace has been written with a different version of the product and needs to be updated.\r\n\r\n\r\nUpdating the workspace may make it incompatible with other versions of the product.\r\nPress OK to update the workspace and open it. Press Cancel to select a different workspace.
-LauncherDifferentVersionTitle=Different Workspace Version
-LauncherNotValid=Selected workspace is not valid; choose a different one.
-LauncherNotValidTitle=Invalid Workspace
-LauncherValidWorkspace=The Application needs a valid workspace; restart without the @none option.
-LauncherValidWorkspaceTitle=Workspace not optional
-LaunchWorkspaceData=launchWorkspaceData
-UnableToWriteWorkspaceData=Unable to write recent workspace data
UnhandledRuntimeException=Unhandled runtime exception \:
-WorkSpaceDataCantWriteDataTitle=Write data error
-WorkSpaceDataCanWriteData=Unable to write recent workspace data. \ No newline at end of file
diff --git a/org.eclipse.jubula.app/src/org/eclipse/jubula/app/ui/ChooseWorkspaceDialog.java b/org.eclipse.jubula.app/src/org/eclipse/jubula/app/ui/ChooseWorkspaceDialog.java
deleted file mode 100644
index e7f6e94ed..000000000
--- a/org.eclipse.jubula.app/src/org/eclipse/jubula/app/ui/ChooseWorkspaceDialog.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2010 BREDEX GmbH.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * BREDEX GmbH - initial API and implementation and/or initial documentation
- *******************************************************************************/
-package org.eclipse.jubula.app.ui;
-
-/**
- * @author BREDEX GmbH
- * @created 23.03.2005
- */
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.jubula.app.core.WorkSpaceData;
-import org.eclipse.jubula.app.i18n.Messages;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.DirectoryDialog;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-
-
-/**
- * A dialog that prompts for a directory to use as a workspace.
- * @author BREDEX GmbH
- * @created 18.12.2006
- */
-public class ChooseWorkspaceDialog extends TitleAreaDialog {
- /** the workspace launch data */
- private WorkSpaceData m_launchData;
- /** the actual selected workspace */
- private String m_currentSelection;
-
- /**
- * Create a modal dialog on the arugment shell, using and updating the
- * argument data object.
- * @param launchData The workbench luanch data.
- * @param parentShell The parent shell.
- */
- public ChooseWorkspaceDialog(Shell parentShell, WorkSpaceData launchData) {
- super(parentShell);
- this.m_launchData = launchData;
- }
-
- /**
- * Creates and returns the contents of the upper part of this dialog (above
- * the button bar).
- * <p>
- * The <code>Dialog</code> implementation of this framework method creates
- * and returns a new <code>Composite</code> with no margins and spacing.
- * </p>
- *
- * @param parent The parent composite to contain the dialog area.
- * @return The dialog area control.
- */
- protected Control createDialogArea(Composite parent) {
- Composite composite = (Composite)super.createDialogArea(parent);
- setTitle(Messages.ChooseWorkspaceDialogDialogMessage);
- setMessage(Messages.ChooseWorkspaceDialogMessageArea);
- super.setShellStyle(SWT.ON_TOP | SWT.SYSTEM_MODAL);
- setShellStyle(SWT.ON_TOP | SWT.SYSTEM_MODAL);
- createWorkspaceBrowseRow(composite);
- return composite;
- }
-
- /**
- * Configures the given shell in preparation for opening this window in it.
- * <p>
- * The default implementation of this framework method sets the shell's
- * image and gives it a grid layout. Subclasses may extend or reimplement.
- * </p>
- *
- * @param shell The shell.
- */
- protected void configureShell(Shell shell) {
- super.configureShell(shell);
- shell.setText(Messages.ChooseWorkspaceDialogDialogText);
- }
-
- /**
- * Notifies that the ok button of this dialog has been pressed.
- * <p>
- * The <code>Dialog</code> implementation of this framework method sets
- * this dialog's return code to <code>Window.OK</code> and closes the
- * dialog. Subclasses may override.
- * </p>
- */
- protected void okPressed() {
- m_launchData.workspaceSelected(m_currentSelection);
- super.okPressed();
- }
-
- /**
- * Notifies that the cancel button of this dialog has been pressed.
- * <p>
- * The <code>Dialog</code> implementation of this framework method sets
- * this dialog's return code to <code>Window.CANCEL</code> and closes the
- * dialog. Subclasses may override if desired.
- * </p>
- */
- protected void cancelPressed() {
- m_currentSelection = null;
- m_launchData.workspaceSelected(m_currentSelection);
- super.cancelPressed();
- }
-
- /**
- * The main area of the dialog is just a row with the current selection
- * information and a drop-down of the most recently used workspaces.
- * @param parent The parent composite.
- */
- private void createWorkspaceBrowseRow(Composite parent) {
- Composite panel = new Composite(parent, SWT.NONE);
-
- GridLayout layout = new GridLayout(3, false);
- layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants
- .VERTICAL_MARGIN);
- layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants
- .HORIZONTAL_MARGIN);
- layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants
- .VERTICAL_SPACING);
- layout.horizontalSpacing = convertHorizontalDLUsToPixels(
- IDialogConstants.HORIZONTAL_SPACING);
- panel.setLayout(layout);
- panel.setLayoutData(new GridData(GridData.FILL_BOTH));
- panel.setFont(parent.getFont());
-
- Label label = new Label(panel, SWT.NONE);
- label.setText(Messages.ChooseWorkspaceDialogWorkspace);
-
- final Combo text = new Combo(panel, SWT.BORDER | SWT.LEAD
- | SWT.DROP_DOWN);
- text.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
- | GridData.FILL_HORIZONTAL));
- setInitialTextValues(text);
- text.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- m_currentSelection = text.getText();
- m_launchData.workspaceSelected(m_currentSelection);
- }
- });
- text.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- m_currentSelection = text.getText();
- m_launchData.workspaceSelected(m_currentSelection);
- }
- });
-
- Button browseButton = new Button(panel, SWT.PUSH);
- browseButton.setText(Messages.ChooseWorkspaceDialogBrowse);
- setButtonLayoutData(browseButton);
- GridData data = (GridData)browseButton.getLayoutData();
- data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_END;
- browseButton.setLayoutData(data);
- browseButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- DirectoryDialog dialog = new DirectoryDialog(getShell(),
- SWT.ON_TOP | SWT.SYSTEM_MODAL);
- dialog.setText(Messages.ChooseWorkspaceDialogSelectDir);
- dialog.setMessage(Messages.ChooseWorkspaceDialogMessaageDir);
- dialog.setFilterPath(m_currentSelection);
- String dir = dialog.open();
- if (dir != null) {
- text.setText(dir);
- m_launchData.workspaceSelected(dir);
- }
- }
- });
- }
-
- /**
- * @param text The comboBox.
- */
- private void setInitialTextValues(Combo text) {
- String[] recentWorkspaces = m_launchData.getRecentWorkspaces();
- for (int i = 0; i < recentWorkspaces.length; ++i) {
- if (recentWorkspaces[i] != null) {
- text.add(recentWorkspaces[i]);
- }
- }
- m_currentSelection = text.getItemCount() > 0
- && m_launchData.getSelection() != null
- ? m_launchData.getSelection() : m_launchData.getInitialDefault();
- text.setText(m_currentSelection);
- }
-}

Back to the top