Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'common/plugins')
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/META-INF/MANIFEST.MF1
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/gen/AbstractJptGenerateJob.java14
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/WorkbenchPageTools.java2
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/WorkbenchTools.java277
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/WorkbenchWindowTools.java2
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemStructuredStateProviderManager.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTCollectionChangeListenerWrapper.java8
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTListChangeListenerWrapper.java8
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTPropertyChangeListenerWrapper.java8
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTStateChangeListenerWrapper.java8
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/BooleanStateController.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/widgets/ComboTools.java109
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/widgets/ControlTools.java173
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/widgets/DisplayTools.java257
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/widgets/TableTools.java41
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/ControlSwitcher.java3
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/SWTUtil.java527
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/AbstractUiCommandContext.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/AsynchronousUiCommandContext.java6
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/SynchronousUiCommandContext.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/AddRemoveListPane.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/AddRemovePane.java6
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/ClassChooserPane.java39
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/ComboPane.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Dialog.java13
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/IntegerCombo.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Pane.java37
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/wizards/JavaProjectWizardPage.java6
28 files changed, 938 insertions, 635 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.ui/META-INF/MANIFEST.MF b/common/plugins/org.eclipse.jpt.common.ui/META-INF/MANIFEST.MF
index 6576ee52eb..fae37a260e 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/META-INF/MANIFEST.MF
+++ b/common/plugins/org.eclipse.jpt.common.ui/META-INF/MANIFEST.MF
@@ -11,6 +11,7 @@ Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle: org.eclipse.core.resources;bundle-version="[3.4.0,4.0.0)",
org.eclipse.draw2d;bundle-version="[3.4.0,4.0.0)",
+ org.eclipse.help;bundle-version="[3.6.0,4.0.0)",
org.eclipse.jdt.core;bundle-version="[3.4.0,4.0.0)",
org.eclipse.jdt.ui;bundle-version="[3.4.0,4.0.0)",
org.eclipse.jface;bundle-version="[3.7.0,4.0.0)",
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/gen/AbstractJptGenerateJob.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/gen/AbstractJptGenerateJob.java
index 81c3d97e14..f8f346fe0c 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/gen/AbstractJptGenerateJob.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/gen/AbstractJptGenerateJob.java
@@ -25,13 +25,13 @@ import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jpt.common.core.gen.JptGenerator;
import org.eclipse.jpt.common.core.gen.LaunchConfigListener;
import org.eclipse.jpt.common.ui.JptCommonUiMessages;
-import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.ui.internal.WorkbenchTools;
+import org.eclipse.jpt.common.ui.internal.swt.widgets.DisplayTools;
import org.eclipse.jpt.common.utility.internal.reference.SynchronizedBoolean;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
/**
@@ -110,11 +110,13 @@ public abstract class AbstractJptGenerateJob extends WorkspaceJob {
protected void openEditor(final IFile file) {
if(file != null) {
- SWTUtil.asyncExec(new Runnable() {
+ DisplayTools.asyncExec(new Runnable() {
public void run() {
try {
- IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- IDE.openEditor(page, file, true);
+ IWorkbenchPage page = WorkbenchTools.getActivePage();
+ if (page != null) {
+ IDE.openEditor(page, file, true);
+ }
}
catch (PartInitException e) {
AbstractJptGenerateJob.this.logException(e);
@@ -161,7 +163,7 @@ public abstract class AbstractJptGenerateJob extends WorkspaceJob {
}
private void displayError(final String message) {
- SWTUtil.syncExec(new Runnable() {
+ DisplayTools.syncExec(new Runnable() {
public void run() {
MessageDialog.openError(
AbstractJptGenerateJob.this.getShell(),
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/WorkbenchPageTools.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/WorkbenchPageTools.java
index 45be569f70..6b05a5274a 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/WorkbenchPageTools.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/WorkbenchPageTools.java
@@ -16,7 +16,7 @@ import org.eclipse.ui.IWorkbenchPage;
/**
* {@link IWorkbenchPage} utility methods.
*/
-public class WorkbenchPageTools {
+public final class WorkbenchPageTools {
/**
* Close all the views in the specified workbench page with the
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/WorkbenchTools.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/WorkbenchTools.java
index 55ebb29d97..d0a1d4533c 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/WorkbenchTools.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/WorkbenchTools.java
@@ -9,14 +9,254 @@
******************************************************************************/
package org.eclipse.jpt.common.ui.internal;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.help.IContext;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
/**
* {@link IWorkbench} utility methods.
*/
-public class WorkbenchTools {
+public final class WorkbenchTools {
+
+ // ********** workbench UI **********
+
+ /**
+ * Return the Eclipse UI {@link IWorkbench workbench}
+ * {@link Display display}.
+ * Return <code>null</code> if the workbench is not running.
+ * @see #getWorkbench()
+ * @see IWorkbench#getDisplay()
+ */
+ public static Display getDisplay() {
+ IWorkbench wb = getWorkbench();
+ return (wb == null) ? null : wb.getDisplay();
+ }
+
+ /**
+ * Return the currently active workbench window's shell.
+ * Return <code>null</code> if called from a non-UI thread.
+ * @see #getActiveWindow()
+ * @see #getWorkbench()
+ * @see IWorkbench#getActiveWorkbenchWindow()
+ */
+ public static Shell getActiveShell() {
+ IWorkbenchWindow ww = getActiveWindow();
+ return (ww == null) ? null : ww.getShell();
+ }
+
+ /**
+ * Return the currently active workbench window's shell.
+ * Return <code>null</code> if called from a non-UI thread.
+ * @see #getActiveWindow()
+ * @see #getWorkbench()
+ * @see IWorkbenchWindow#getActivePage()
+ * @see IWorkbench#getActiveWorkbenchWindow()
+ */
+ public static IWorkbenchPage getActivePage() {
+ IWorkbenchWindow ww = getActiveWindow();
+ return (ww == null) ? null : ww.getActivePage();
+ }
+
+ /**
+ * Return the currently active workbench window's shell.
+ * Return <code>null</code> if called from a non-UI thread.
+ * @see #getWorkbench()
+ * @see IWorkbench#getActiveWorkbenchWindow()
+ */
+ public static IWorkbenchWindow getActiveWindow() {
+ IWorkbench wb = getWorkbench();
+ return (wb == null) ? null : wb.getActiveWorkbenchWindow();
+ }
+
+ /**
+ * Return the Eclipse UI {@link IWorkbench workbench}.
+ * Return <code>null</code> if the workbench is not running
+ * (i.e. either it has not been started or it has been terminated).
+ * <p>
+ * <strong>NB:</strong> There is no guarantee the workbench will continue
+ * running after it is returned.
+ * @see PlatformUI#isWorkbenchRunning()
+ */
+ public static IWorkbench getWorkbench() {
+ return PlatformUI.isWorkbenchRunning() ? PlatformUI.getWorkbench() : null;
+ }
+
+
+ // ********** editors **********
+
+ /**
+ * Return the workbench's default editor for the specified file, as
+ * determined by the file's name <em>and</em> content.
+ * @see #getDefaultEditor(String, IContentType)
+ */
+ public static IEditorDescriptor getDefaultEditor(IFile file) {
+ return getDefaultEditor(file.getName(), IDE.getContentType(file));
+ }
+
+ /**
+ * Return the workbench's default editor for the specified file name and
+ * content type.
+ * @see #getWorkbench()
+ * @see IWorkbench#getEditorRegistry()
+ * @see org.eclipse.ui.IEditorRegistry#getDefaultEditor(String, IContentType)
+ */
+ public static IEditorDescriptor getDefaultEditor(String fileName, IContentType contentType) {
+ IWorkbench wb = getWorkbench();
+ return (wb == null) ? null : wb.getEditorRegistry().getDefaultEditor(fileName, contentType);
+ }
+
+
+ // ********** shared images **********
+
+ /**
+ * Return the specified image from the Eclipse UI {@link IWorkbench
+ * workbench}'s image registry.
+ * Return <code>null</code> if the workbench is not running.
+ * <p>
+ * <strong>NB:</strong> The returned image is managed by the workbench;
+ * clients must <em>not</em> dispose of the returned image.
+ * @see #getWorkbench()
+ * @see IWorkbench#getSharedImages()
+ * @see org.eclipse.ui.ISharedImages
+ */
+ public static Image getSharedImage(String symbolicName) {
+ IWorkbench wb = getWorkbench();
+ return (wb == null) ? null : wb.getSharedImages().getImage(symbolicName);
+ }
+
+ /**
+ * Return the specified image descriptor from the Eclipse UI
+ * {@link IWorkbench workbench}'s image registry.
+ * Return <code>null</code> if the workbench is not running.
+ * @see #getWorkbench()
+ * @see IWorkbench#getSharedImages()
+ * @see org.eclipse.ui.ISharedImages
+ */
+ public static ImageDescriptor getSharedImageDescriptor(String symbolicName) {
+ IWorkbench wb = getWorkbench();
+ return (wb == null) ? null : wb.getSharedImages().getImageDescriptor(symbolicName);
+ }
+
+
+ // ********** help **********
+
+ /**
+ * Set the specified help context ID on the specified control.
+ * @see #getWorkbench()
+ * @see IWorkbench#getHelpSystem()
+ * @see org.eclipse.ui.help.IWorkbenchHelpSystem#setHelp(Control, String)
+ */
+ public static void setHelp(Control control, String contextID) {
+ IWorkbench wb = getWorkbench();
+ if (wb != null) {
+ wb.getHelpSystem().setHelp(control, contextID);
+ }
+ }
+
+ /**
+ * Set the specified help context ID on the specified action.
+ * @see #getWorkbench()
+ * @see IWorkbench#getHelpSystem()
+ * @see org.eclipse.ui.help.IWorkbenchHelpSystem#setHelp(IAction, String)
+ */
+ public static void setHelp(IAction action, String contextID) {
+ IWorkbench wb = getWorkbench();
+ if (wb != null) {
+ wb.getHelpSystem().setHelp(action, contextID);
+ }
+ }
+
+ /**
+ * Set the specified help context ID on the specified menu.
+ * @see #getWorkbench()
+ * @see IWorkbench#getHelpSystem()
+ * @see org.eclipse.ui.help.IWorkbenchHelpSystem#setHelp(Menu, String)
+ */
+ public static void setHelp(Menu menu, String contextID) {
+ IWorkbench wb = getWorkbench();
+ if (wb != null) {
+ wb.getHelpSystem().setHelp(menu, contextID);
+ }
+ }
+
+ /**
+ * Set the specified help context ID on the specified control.
+ * @see #getWorkbench()
+ * @see IWorkbench#getHelpSystem()
+ * @see org.eclipse.ui.help.IWorkbenchHelpSystem#setHelp(MenuItem, String)
+ */
+ public static void setHelp(MenuItem item, String contextID) {
+ IWorkbench wb = getWorkbench();
+ if (wb != null) {
+ wb.getHelpSystem().setHelp(item, contextID);
+ }
+ }
+
+ /**
+ * Display the entire help bookshelf.
+ * <p>
+ * <strong>NB:</strong> Must be called from the UI thread.
+ * <p>
+ * @see #getWorkbench()
+ * @see IWorkbench#getHelpSystem()
+ * @see org.eclipse.ui.help.IWorkbenchHelpSystem#displayHelp()
+ */
+ public static void displayHelp() {
+ IWorkbench wb = getWorkbench();
+ if (wb != null) {
+ wb.getHelpSystem().displayHelp();
+ }
+ }
+
+ /**
+ * Display help for the specified context.
+ * <p>
+ * <strong>NB:</strong> Must be called from the UI thread.
+ * <p>
+ * @see #getWorkbench()
+ * @see IWorkbench#getHelpSystem()
+ * @see org.eclipse.ui.help.IWorkbenchHelpSystem#displayHelp(IContext)
+ */
+ public static void displayHelp(IContext context) {
+ IWorkbench wb = getWorkbench();
+ if (wb != null) {
+ wb.getHelpSystem().displayHelp(context);
+ }
+ }
+
+ /**
+ * Display help for the specified context ID.
+ * <p>
+ * <strong>NB:</strong> Must be called from the UI thread.
+ * <p>
+ * @see #getWorkbench()
+ * @see IWorkbench#getHelpSystem()
+ * @see org.eclipse.ui.help.IWorkbenchHelpSystem#displayHelp(String)
+ */
+ public static void displayHelp(String contextID) {
+ IWorkbench wb = getWorkbench();
+ if (wb != null) {
+ wb.getHelpSystem().displayHelp(contextID);
+ }
+ }
+
+
+ // ********** close views **********
/**
* Close all the views in the platform workbench with the specified ID.
@@ -24,7 +264,10 @@ public class WorkbenchTools {
* @see org.eclipse.ui.IWorkbenchPartSite#getId()
*/
public static void closeAllViews(String viewID) {
- closeAllViews(PlatformUI.getWorkbench(), viewID);
+ IWorkbench wb = getWorkbench();
+ if (wb != null) {
+ closeAllViews(wb, viewID);
+ }
}
/**
@@ -38,7 +281,35 @@ public class WorkbenchTools {
}
- // ********** constructor **********
+ // ********** adapters **********
+
+ /**
+ * Adapt the Eclipse UI {@link IWorkbench workbench} to the specified class.
+ * Return <code>null</code> if the workbench is not running
+ * (i.e. either it has not been started or it has been terminated).
+ * @see #getWorkbench()
+ * @see PlatformTools#getAdapter(Object, Class)
+ */
+ public static <A> A getAdapter(Class<A> adapterType) {
+ IWorkbench wb = getWorkbench();
+ return (wb == null) ? null : PlatformTools.getAdapter(wb, adapterType);
+ }
+
+ /**
+ * Return the workbench service corresponding to the specified API.
+ * Return <code>null</code> if the workbench is not running
+ * (i.e. either it has not been started or it has been terminated).
+ * @see #getWorkbench()
+ * @see org.eclipse.ui.services.IServiceLocator#getService(Class)
+ */
+ @SuppressWarnings("unchecked")
+ public static <A> A getService(Class<A> api) {
+ IWorkbench wb = getWorkbench();
+ return (wb == null) ? null : (A) wb.getService(api);
+ }
+
+
+ // ********** disabled constructor **********
/**
* Suppress default constructor, ensuring non-instantiability.
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/WorkbenchWindowTools.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/WorkbenchWindowTools.java
index 35763d2303..eb9917c4e0 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/WorkbenchWindowTools.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/WorkbenchWindowTools.java
@@ -15,7 +15,7 @@ import org.eclipse.ui.IWorkbenchWindow;
/**
* {@link IWorkbenchWindow} utility methods.
*/
-public class WorkbenchWindowTools {
+public final class WorkbenchWindowTools {
/**
* Close all the views in the specified workbench window with the
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemStructuredStateProviderManager.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemStructuredStateProviderManager.java
index 1216a703ac..1b61c007a0 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemStructuredStateProviderManager.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemStructuredStateProviderManager.java
@@ -15,7 +15,7 @@ import org.eclipse.jface.viewers.BaseLabelProvider;
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.ui.internal.swt.widgets.DisplayTools;
import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProvider;
import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
import org.eclipse.jpt.common.ui.jface.ItemStructuredContentProvider;
@@ -232,7 +232,7 @@ public abstract class AbstractItemStructuredStateProviderManager<V extends Struc
}
protected void execute(Runnable runnable) {
- SWTUtil.execute(this.viewer, runnable);
+ DisplayTools.execute(this.viewer, runnable);
}
protected boolean viewerIsAlive() {
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTCollectionChangeListenerWrapper.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTCollectionChangeListenerWrapper.java
index 8c94238d76..3f5ce0e5e1 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTCollectionChangeListenerWrapper.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTCollectionChangeListenerWrapper.java
@@ -9,7 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.common.ui.internal.listeners;
-import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.ui.internal.swt.widgets.DisplayTools;
import org.eclipse.jpt.common.utility.internal.RunnableAdapter;
import org.eclipse.jpt.common.utility.model.event.CollectionAddEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionChangeEvent;
@@ -125,12 +125,12 @@ public class SWTCollectionChangeListenerWrapper
}
/**
- * {@link SWTUtil#execute(Runnable)} seems to work OK;
- * but using {@link SWTUtil#syncExec(Runnable)} can somtimes make things
+ * {@link DisplayTools#execute(Runnable)} seems to work OK;
+ * but using {@link DisplayTools#syncExec(Runnable)} can somtimes make things
* more predictable when debugging, at the risk of deadlocks.
*/
private void execute(Runnable r) {
- SWTUtil.execute(r);
+ DisplayTools.execute(r);
// SWTUtil.syncExec(r);
}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTListChangeListenerWrapper.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTListChangeListenerWrapper.java
index 3037b60e79..5135ee83cb 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTListChangeListenerWrapper.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTListChangeListenerWrapper.java
@@ -9,7 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.common.ui.internal.listeners;
-import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.ui.internal.swt.widgets.DisplayTools;
import org.eclipse.jpt.common.utility.internal.RunnableAdapter;
import org.eclipse.jpt.common.utility.model.event.ListAddEvent;
import org.eclipse.jpt.common.utility.model.event.ListChangeEvent;
@@ -171,12 +171,12 @@ public class SWTListChangeListenerWrapper
}
/**
- * {@link SWTUtil#execute(Runnable)} seems to work OK;
- * but using {@link SWTUtil#syncExec(Runnable)} can somtimes make things
+ * {@link DisplayTools#execute(Runnable)} seems to work OK;
+ * but using {@link DisplayTools#syncExec(Runnable)} can somtimes make things
* more predictable when debugging, at the risk of deadlocks.
*/
private void execute(Runnable r) {
- SWTUtil.execute(r);
+ DisplayTools.execute(r);
// SWTUtil.syncExec(r);
}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTPropertyChangeListenerWrapper.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTPropertyChangeListenerWrapper.java
index 049a373c61..9462188cb1 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTPropertyChangeListenerWrapper.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTPropertyChangeListenerWrapper.java
@@ -9,7 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.common.ui.internal.listeners;
-import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.ui.internal.swt.widgets.DisplayTools;
import org.eclipse.jpt.common.utility.internal.RunnableAdapter;
import org.eclipse.jpt.common.utility.internal.collection.SynchronizedQueue;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
@@ -64,12 +64,12 @@ public class SWTPropertyChangeListenerWrapper
}
/**
- * {@link SWTUtil#execute(Runnable)} seems to work OK;
- * but using {@link SWTUtil#syncExec(Runnable)} can somtimes make things
+ * {@link DisplayTools#execute(Runnable)} seems to work OK;
+ * but using {@link DisplayTools#syncExec(Runnable)} can somtimes make things
* more predictable when debugging, at the risk of deadlocks.
*/
private void execute(Runnable r) {
- SWTUtil.execute(r);
+ DisplayTools.execute(r);
// SWTUtil.syncExec(r);
}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTStateChangeListenerWrapper.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTStateChangeListenerWrapper.java
index cd5c6ad980..f7b4ab3a30 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTStateChangeListenerWrapper.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTStateChangeListenerWrapper.java
@@ -9,7 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.common.ui.internal.listeners;
-import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.ui.internal.swt.widgets.DisplayTools;
import org.eclipse.jpt.common.utility.internal.RunnableAdapter;
import org.eclipse.jpt.common.utility.internal.collection.SynchronizedQueue;
import org.eclipse.jpt.common.utility.model.event.StateChangeEvent;
@@ -59,12 +59,12 @@ public class SWTStateChangeListenerWrapper
}
/**
- * {@link SWTUtil#execute(Runnable)} seems to work OK;
- * but using {@link SWTUtil#syncExec(Runnable)} can somtimes make things
+ * {@link DisplayTools#execute(Runnable)} seems to work OK;
+ * but using {@link DisplayTools#syncExec(Runnable)} can somtimes make things
* more predictable when debugging, at the risk of deadlocks.
*/
private void execute(Runnable r) {
- SWTUtil.execute(r);
+ DisplayTools.execute(r);
// SWTUtil.syncExec(r);
}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/BooleanStateController.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/BooleanStateController.java
index f3992db71d..2bcf162ea1 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/BooleanStateController.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/bind/BooleanStateController.java
@@ -11,7 +11,7 @@ package org.eclipse.jpt.common.ui.internal.swt.bind;
import org.eclipse.jpt.common.ui.internal.listeners.SWTPropertyChangeListenerWrapper;
import org.eclipse.jpt.common.ui.internal.swt.events.DisposeAdapter;
-import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.ui.internal.swt.widgets.DisplayTools;
import org.eclipse.jpt.common.utility.internal.RunnableAdapter;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
@@ -167,7 +167,7 @@ abstract class BooleanStateController {
abstract void setControlState(boolean controlState);
void setControlState(Control control, boolean controlState) {
- SWTUtil.execute(new SetControlStateRunnable(control, controlState));
+ DisplayTools.execute(new SetControlStateRunnable(control, controlState));
}
/* CU private */ class SetControlStateRunnable
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/widgets/ComboTools.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/widgets/ComboTools.java
new file mode 100644
index 0000000000..35ae0fa5e5
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/widgets/ComboTools.java
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 Oracle. 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:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.swt.widgets;
+
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Combo;
+
+/**
+ * A suite of utility methods related to the user interface.
+ *
+ * @version 2.0
+ * @since 1.0
+ */
+public final class ComboTools {
+
+ /**
+ * Tweak the specified combo-box to remove the default value when the
+ * widget receives the focus and to show the default when the widget loses
+ * the focus. The default value must be the first value in the combo-box's
+ * selection list.
+ */
+ public static void handleDefaultValue(Combo combo) {
+ ComboListener listener = new ComboListener();
+ combo.addFocusListener(listener);
+ combo.addModifyListener(listener);
+ }
+
+ /**
+ * This handler is responsible for removing the default value when the combo
+ * has the focus or when the selected item is the default value and to select
+ * it when the combo loses the focus.
+ */
+ /* CU private */ static class ComboListener
+ implements FocusListener, ModifyListener
+ {
+ public void focusGained(FocusEvent e) {
+ Combo combo = (Combo) e.widget;
+ if (combo.getSelectionIndex() == 0) {
+ // cannot modify the combo while it is notifying its listeners
+ DisplayTools.asyncExec(new SelectText(combo));
+ }
+ }
+
+ public void focusLost(FocusEvent e) {
+ // NOP
+ }
+
+ private class SelectText
+ implements Runnable
+ {
+ private final Combo combo;
+
+ SelectText(Combo combo) {
+ super();
+ this.combo = combo;
+ }
+
+ public void run() {
+ if (this.combo.isDisposed()) {
+ return;
+ }
+ String text = this.combo.getText();
+ this.combo.setSelection(new Point(0, text.length()));
+ }
+ }
+
+ public void modifyText(ModifyEvent e) {
+ Combo combo = (Combo) e.widget;
+ if (combo.isFocusControl() && (combo.getSelectionIndex() == 0)) {
+ // cannot modify the combo while it is notifying its listeners
+ DisplayTools.asyncExec(new ModifyText(combo));
+ }
+ }
+
+ private class ModifyText
+ implements Runnable
+ {
+ private final Combo combo;
+
+ ModifyText(Combo combo) {
+ super();
+ this.combo = combo;
+ }
+
+ public void run() {
+ if (this.combo.isDisposed()) {
+ return;
+ }
+ String text = this.combo.getText();
+ if (text.length() == 0) {
+ text = this.combo.getItem(0);
+ this.combo.setText(text);
+ }
+ this.combo.setSelection(new Point(0, text.length()));
+ }
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/widgets/ControlTools.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/widgets/ControlTools.java
new file mode 100644
index 0000000000..d75e5a95a7
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/widgets/ControlTools.java
@@ -0,0 +1,173 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Oracle. 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:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.swt.widgets;
+
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+import org.eclipse.ui.forms.widgets.SharedScrolledComposite;
+
+/**
+ * {@link Control} utility methods.
+ */
+public final class ControlTools {
+
+ // ********** center **********
+
+ /**
+ * Center the specified control within its display.
+ * (This is helpful for centering {@link org.eclipse.swt.widgets.Shell}s in
+ * a display.)
+ * <p>
+ * <strong>NB:</strong> This will not look too good on a dual monitor system.
+ */
+ public static void center(Control control) {
+ control.setBounds(calculateCenteredBounds(control.getBounds(), control.getDisplay().getBounds()));
+ }
+
+ /**
+ * Center the specified control within the specified parent control.
+ */
+ public static void center(Control control, Control parentControl) {
+ control.setBounds(calculateCenteredBounds(control.getBounds(), parentControl.getBounds()));
+ }
+
+ /**
+ * Calculate the bounds (within the second specified rectangle's coordinate
+ * system) that would center the first specified rectangle
+ * with respect to the second specified rectangle.
+ */
+ public static Rectangle calculateCenteredBounds(Rectangle rectangle1, Rectangle rectangle2) {
+ return calculateCenteredBounds(rectangle1.width, rectangle1.height, rectangle2.x, rectangle2.y, rectangle2.width, rectangle2.height);
+ }
+
+ /**
+ * Calculate the bounds (within the second specified rectangle's coordinate
+ * system) that would center the first specified rectangle
+ * with respect to the second specified rectangle.
+ */
+ public static Rectangle calculateCenteredBounds(Point size1, Point size2) {
+ return calculateCenteredBounds(size1.x, size1.y, size2.x, size2.y);
+ }
+
+ /**
+ * Calculate the point (within the second specified rectangle's coordinate
+ * system) that would center the first specified rectangle
+ * with respect to the second specified rectangle.
+ */
+ public static Rectangle calculateCenteredBounds(int width1, int height1, int width2, int height2) {
+ return calculateCenteredBounds(width1, height1, 0, 0, width2, height2);
+ }
+
+
+ /**
+ * Calculate the point (within the second specified rectangle's coordinate
+ * system) that would center the first specified rectangle
+ * with respect to the second specified rectangle.
+ */
+ public static Rectangle calculateCenteredBounds(int width1, int height1, int x2, int y2, int width2, int height2) {
+ return new Rectangle(x2 + ((width2 - width1) >> 1), y2 + ((height2 - height1) >> 1), width1, height1);
+ }
+
+ /**
+ * Calculate the point (within the second specified rectangle's coordinate
+ * system) that would center the first specified rectangle
+ * with respect to the second specified rectangle.
+ */
+ public static Point calculateCenteredPosition(Rectangle rectangle1, Rectangle rectangle2) {
+ return calculateCenteredPosition(rectangle1.width, rectangle1.height, rectangle2.x, rectangle2.y, rectangle2.width, rectangle2.height);
+ }
+
+ /**
+ * Calculate the point (within the second specified rectangle's coordinate
+ * system) that would center the first specified rectangle
+ * with respect to the second specified rectangle.
+ */
+ public static Point calculateCenteredPosition(Point size1, Point size2) {
+ return calculateCenteredPosition(size1.x, size1.y, size2.x, size2.y);
+ }
+
+ /**
+ * Calculate the point (within the second specified rectangle's coordinate
+ * system) that would center the first specified rectangle
+ * with respect to the second specified rectangle.
+ */
+ public static Point calculateCenteredPosition(int width1, int height1, int width2, int height2) {
+ return calculateCenteredPosition(width1, height1, 0, 0, width2, height2);
+ }
+
+ /**
+ * Calculate the point (within the second specified rectangle's coordinate
+ * system) that would center the first specified rectangle
+ * with respect to the second specified rectangle.
+ */
+ public static Point calculateCenteredPosition(int width1, int height1, int x2, int y2, int width2, int height2) {
+ return new Point(x2 + ((width2 - width1) >> 1), y2 + ((height2 - height1) >> 1));
+ }
+
+
+ // ********** reflow **********
+
+ /**
+ * Reflow the specified control and all its ancestors up its containment
+ * hierarchy.
+ * @see #reflow(Composite)
+ */
+ public static void reflow(Control control) {
+ reflow((control instanceof Composite) ? (Composite) control : control.getParent());
+ }
+
+ /**
+ * Reflow the specified composite and all its ancestors up its containment
+ * hierarchy until we reach a {@link SharedScrolledComposite} or the window
+ * (i.e. the top of the containment hierarchy).
+ * Copied from {@link org.eclipse.ui.forms.widgets.Section#reflow()}.
+ */
+ public static void reflow(Composite composite) {
+ for (Composite c = composite; c != null; ) {
+ c.setRedraw(false);
+ c = c.getParent();
+ if ((c instanceof SharedScrolledComposite) || (c instanceof Shell)) {
+ break;
+ }
+ }
+
+ for (Composite c = composite; c != null; ) {
+ c.layout(true);
+ c = c.getParent();
+ if (c instanceof SharedScrolledComposite) {
+ ((ScrolledForm) c).reflow(true);
+ break;
+ }
+ }
+
+ for (Composite c = composite; c != null; ) {
+ c.setRedraw(true);
+ c = c.getParent();
+ if ((c instanceof SharedScrolledComposite) || (c instanceof Shell)) {
+ break;
+ }
+ }
+ }
+
+
+ // ********** disabled constructor **********
+
+ /**
+ * Suppress default constructor, ensuring non-instantiability.
+ */
+ private ControlTools() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/widgets/DisplayTools.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/widgets/DisplayTools.java
new file mode 100644
index 0000000000..15b4a49994
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/widgets/DisplayTools.java
@@ -0,0 +1,257 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2013 Oracle. 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:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.swt.widgets;
+
+import org.eclipse.jface.util.OpenStrategy;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jpt.common.ui.internal.WorkbenchTools;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Widget;
+import org.eclipse.ui.IWorkbench;
+
+/**
+ * {@link Display} convenience methods.
+ */
+public final class DisplayTools {
+
+ // ********** UI thread execution **********
+
+ /**
+ * <strong>NB:</strong> The runnable will not be executed if the workbench
+ * is not running (i.e. the runnable is treated as ephemeral, and not
+ * executing it, probably during workbench shutdown, is not a problem because
+ * it is UI-related and the UI is gone).
+ * @see Display#asyncExec(Runnable)
+ * @see #syncExec(Runnable)
+ * @see #timerExec(int, Runnable)
+ * @see #execute(Runnable)
+ */
+ public static void asyncExec(Runnable runnable) {
+ Display display = getDisplay();
+ if (display != null) {
+ display.asyncExec(runnable);
+ }
+ }
+
+ /**
+ * <strong>NB:</strong> The runnable will not be executed if the workbench
+ * is not running (i.e. the runnable is treated as ephemeral, and not
+ * executing it, probably during workbench shutdown, is not a problem because
+ * it is UI-related and the UI is gone).
+ * @see Display#syncExec(Runnable)
+ * @see #asyncExec(Runnable)
+ * @see #timerExec(int, Runnable)
+ * @see #execute(Runnable)
+ */
+ public static void syncExec(Runnable runnable) {
+ Display display = getDisplay();
+ if (display != null) {
+ display.syncExec(runnable);
+ }
+ }
+
+ /**
+ * Use the standard delay.
+ * <p>
+ * <strong>NB:</strong> The runnable will not be executed if the workbench
+ * is not running (i.e. the runnable is treated as ephemeral, and not
+ * executing it, probably during workbench shutdown, is not a problem because
+ * it is UI-related and the UI is gone).
+ * @see OpenStrategy#getPostSelectionDelay()
+ * @see #timerExec(int, Runnable)
+ */
+ public static void delayedExec(Runnable runnable) {
+ timerExec(OpenStrategy.getPostSelectionDelay(), runnable);
+ }
+
+ /**
+ * <strong>NB:</strong> The runnable will not be executed if the workbench
+ * is not running (i.e. the runnable is treated as ephemeral, and not
+ * executing it, probably during workbench shutdown, is not a problem because
+ * it is UI-related and the UI is gone).
+ * @see Display#timerExec(int, Runnable)
+ * @see #asyncExec(Runnable)
+ * @see #syncExec(Runnable)
+ * @see #execute(Runnable)
+ */
+ public static void timerExec(int milliseconds, Runnable runnable) {
+ Display display = getDisplay();
+ if (display != null) {
+ display.timerExec(milliseconds, runnable);
+ }
+ }
+
+ /**
+ * Execute the specified runnable if the current thread is the UI thread;
+ * otherwise asynchrounously dispatch the runnable to the UI thread,
+ * returning immediately. This is useful for event handlers when it is not
+ * obvious whether the events are fired on the UI thread.
+ * <p>
+ * <strong>NB:</strong> The runnable will not be executed if the workbench
+ * is not running (i.e. the runnable is treated as ephemeral, and not
+ * executing it, probably during workbench shutdown, is not a problem because
+ * it is UI-related and the UI is gone).
+ * @see Display#asyncExec(Runnable)
+ * @see #asyncExec(Runnable)
+ * @see #syncExec(Runnable)
+ * @see #timerExec(int, Runnable)
+ * @see IWorkbench#getDisplay()
+ */
+ public static void execute(Runnable runnable) {
+ Display display = Display.getCurrent();
+ if (display != null) {
+ // the current thread is the UI thread
+ runnable.run();
+ } else {
+ display = WorkbenchTools.getDisplay();
+ if (display != null) {
+ display.asyncExec(runnable);
+ }
+ }
+ }
+
+ /**
+ * Execute the specified runnable if the current thread is the specified
+ * viewer's thread;
+ * otherwise asynchrounously dispatch the runnable to the viewer's thread,
+ * returning immediately. This is useful for event handlers when it is not
+ * obviously whether the events are fired on the viewer's thread.
+ * @see #execute(Runnable)
+ * @see Display#asyncExec(Runnable)
+ * @see #asyncExec(Runnable)
+ * @see #syncExec(Runnable)
+ * @see #timerExec(int, Runnable)
+ */
+ public static void execute(Viewer viewer, Runnable runnable) {
+ execute(viewer.getControl(), runnable);
+ }
+
+ /**
+ * Execute the specified runnable if the current thread is the specified
+ * control's thread;
+ * otherwise asynchrounously dispatch the runnable to the control's thread,
+ * returning immediately. This is useful for event handlers when it is not
+ * obviously whether the events are fired on the control's thread.
+ * @see #execute(Runnable)
+ * @see Display#asyncExec(Runnable)
+ * @see #asyncExec(Runnable)
+ * @see #syncExec(Runnable)
+ * @see #timerExec(int, Runnable)
+ */
+ public static void execute(Control control, Runnable runnable) {
+ execute(control.getDisplay(), runnable);
+ }
+
+ /**
+ * Execute the specified runnable if the current thread is the specified
+ * display's thread;
+ * otherwise asynchrounously dispatch the runnable to the display's thread,
+ * returning immediately. This is useful for event handlers when it is not
+ * obviously whether the events are fired on the display's thread.
+ * @see #execute(Runnable)
+ * @see Display#asyncExec(Runnable)
+ * @see #asyncExec(Runnable)
+ * @see #syncExec(Runnable)
+ * @see #timerExec(int, Runnable)
+ */
+ public static void execute(Display display, Runnable runnable) {
+ if (display.getThread() == Thread.currentThread()) {
+ // the current thread is the the UI thread
+ runnable.run();
+ } else {
+ display.asyncExec(runnable);
+ }
+ }
+
+ /**
+ * Return the current shell. Return <code>null</code> if there is none.
+ * @exception org.eclipse.swt.SWTException if not called from the UI thread
+ */
+ public static Shell getShell() {
+ Shell shell = getActiveShell();
+ return (shell != null) ? shell : WorkbenchTools.getActiveShell();
+ }
+
+ /**
+ * Return the current "active" shell, which can be the shell from any
+ * window. Return <code>null</code> if there is no display.
+ * @see Display#getActiveShell()
+ * @exception org.eclipse.swt.SWTException if not called from the UI thread
+ */
+ public static Shell getActiveShell() {
+ // Retrieve the active shell, which can be the shell from any window
+ Display display = getDisplay();
+ return (display == null) ? null : display.getActiveShell();
+ }
+
+ /**
+ * Return the most appropriate {@link Display display}; i.e. return the
+ * {@link Display#getCurrent() display associated with the current thread}
+ * if it is present; otherwise return the
+ * {@link IWorkbench#getDisplay() Eclipse workbench
+ * display} (but, <em>explicitly</em>, not the
+ * {@link Display#getDefault() "default display"} -
+ * see the comment at {@link IWorkbench#getDisplay()}).
+ * Return <code>null</code> if the workbench is not running.
+ */
+ public static Display getDisplay() {
+ Display display = Display.getCurrent();
+ return (display != null) ? display : WorkbenchTools.getDisplay();
+ }
+
+
+ // ********** UI thread **********
+
+ /**
+ * Determines if the current thread is the UI event thread.
+ *
+ * @return <code>true</code> if it's the UI event thread, <code>false</code>
+ * otherwise
+ */
+ public static boolean uiThread() {
+ return Display.getCurrent() != null;
+ }
+
+ /**
+ * Determines if the current thread is the UI event thread by using the
+ * thread from which the given viewer's display was instantiated.
+ *
+ * @param viewer The viewer used to determine if the current thread
+ * is the UI event thread
+ * @return <code>true</code> if the current thread is the UI event thread;
+ * <code>false</code> otherwise
+ */
+ public static boolean uiThread(Viewer viewer) {
+ return uiThread(viewer.getControl());
+ }
+
+ /**
+ * Determines if the current thread is the UI event thread by using the
+ * thread from which the given widget's display was instantiated.
+ *
+ * @param widget The widget used to determine if the current thread
+ * is the UI event thread
+ * @return <code>true</code> if the current thread is the UI event thread;
+ * <code>false</code> otherwise
+ */
+ public static boolean uiThread(Widget widget) {
+ return widget.getDisplay().getThread() == Thread.currentThread();
+ }
+
+
+ // ********** disabled constructor **********
+
+ private DisplayTools() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/widgets/TableTools.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/widgets/TableTools.java
new file mode 100644
index 0000000000..47487ecf36
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/widgets/TableTools.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Oracle. 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:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.swt.widgets;
+
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.swt.widgets.Table;
+
+/**
+ * {@link Table} utility methods.
+ */
+public final class TableTools {
+
+ public static int calculateHeightHint(Table table, int rowCount) {
+ if (table.getFont().equals(JFaceResources.getDefaultFont())) {
+ table.setFont(JFaceResources.getDialogFont());
+ }
+ int hint = table.getHeaderHeight() + (table.getItemHeight() * rowCount);
+ if (table.getLinesVisible()) {
+ hint += table.getGridLineWidth() * (rowCount - 1);
+ }
+ return hint;
+ }
+
+
+ // ********** disabled constructor **********
+
+ /**
+ * Suppress default constructor, ensuring non-instantiability.
+ */
+ private TableTools() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/ControlSwitcher.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/ControlSwitcher.java
index d442601e7d..932f992a54 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/ControlSwitcher.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/ControlSwitcher.java
@@ -10,6 +10,7 @@
package org.eclipse.jpt.common.ui.internal.util;
import org.eclipse.jpt.common.ui.internal.listeners.SWTPropertyChangeListenerWrapper;
+import org.eclipse.jpt.common.ui.internal.swt.widgets.ControlTools;
import org.eclipse.jpt.common.utility.internal.transformer.AbstractTransformer;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
@@ -146,7 +147,7 @@ public final class ControlSwitcher
this.pageBook.showPage(page);
// Revalidate the parents in order to update the layout
- SWTUtil.reflow(this.pageBook);
+ ControlTools.reflow(this.pageBook);
}
@SuppressWarnings("unchecked")
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/SWTUtil.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/SWTUtil.java
deleted file mode 100644
index f792eeb705..0000000000
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/SWTUtil.java
+++ /dev/null
@@ -1,527 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2012 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.ui.internal.util;
-
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.util.OpenStrategy;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.FocusListener;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.Widget;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.forms.widgets.ScrolledForm;
-
-/**
- * A suite of utility methods related to the user interface.
- *
- * @version 2.0
- * @since 1.0
- */
-public class SWTUtil {
-
- /**
- * <strong>NB:</strong> The runnable will not be executed if the workbench
- * is not running (i.e. the runnable is treated as ephemeral, and not
- * executing it, probably during workbench shutdown, is not a problem because
- * it is UI-related and the UI is gone).
- * @see Display#asyncExec(Runnable)
- * @see #syncExec(Runnable)
- * @see #timerExec(int, Runnable)
- * @see #execute(Runnable)
- */
- public static void asyncExec(Runnable runnable) {
- Display display = getDisplay();
- if (display != null) {
- display.asyncExec(runnable);
- }
- }
-
- /**
- * <strong>NB:</strong> The runnable will not be executed if the workbench
- * is not running (i.e. the runnable is treated as ephemeral, and not
- * executing it, probably during workbench shutdown, is not a problem because
- * it is UI-related and the UI is gone).
- * @see Display#syncExec(Runnable)
- * @see #asyncExec(Runnable)
- * @see #timerExec(int, Runnable)
- * @see #execute(Runnable)
- */
- public static void syncExec(Runnable runnable) {
- Display display = getDisplay();
- if (display != null) {
- display.syncExec(runnable);
- }
- }
-
- /**
- * Use the standard delay.
- * <p>
- * <strong>NB:</strong> The runnable will not be executed if the workbench
- * is not running (i.e. the runnable is treated as ephemeral, and not
- * executing it, probably during workbench shutdown, is not a problem because
- * it is UI-related and the UI is gone).
- * @see OpenStrategy#getPostSelectionDelay()
- * @see #timerExec(int, Runnable)
- */
- public static void delayedExec(Runnable runnable) {
- timerExec(OpenStrategy.getPostSelectionDelay(), runnable);
- }
-
- /**
- * <strong>NB:</strong> The runnable will not be executed if the workbench
- * is not running (i.e. the runnable is treated as ephemeral, and not
- * executing it, probably during workbench shutdown, is not a problem because
- * it is UI-related and the UI is gone).
- * @see Display#timerExec(int, Runnable)
- * @see #asyncExec(Runnable)
- * @see #syncExec(Runnable)
- * @see #execute(Runnable)
- */
- public static void timerExec(int milliseconds, Runnable runnable) {
- Display display = getDisplay();
- if (display != null) {
- display.timerExec(milliseconds, runnable);
- }
- }
-
- /**
- * Execute the specified runnable if the current thread is the UI thread;
- * otherwise asynchrounously dispatch the runnable to the UI thread,
- * returning immediately. This is useful for event handlers when it is not
- * obvious whether the events are fired on the UI thread.
- * <p>
- * <strong>NB:</strong> The runnable will not be executed if the workbench
- * is not running (i.e. the runnable is treated as ephemeral, and not
- * executing it, probably during workbench shutdown, is not a problem because
- * it is UI-related and the UI is gone).
- * @see Display#asyncExec(Runnable)
- * @see #asyncExec(Runnable)
- * @see #syncExec(Runnable)
- * @see #timerExec(int, Runnable)
- * @see IWorkbench#getDisplay()
- */
- public static void execute(Runnable runnable) {
- Display display = Display.getCurrent();
- if (display != null) {
- // the current thread is the UI thread
- runnable.run();
- } else {
- display = getWorkbenchDisplay();
- if (display != null) {
- display.asyncExec(runnable);
- }
- }
- }
-
- /**
- * Execute the specified runnable if the current thread is the specified
- * viewer's thread;
- * otherwise asynchrounously dispatch the runnable to the viewer's thread,
- * returning immediately. This is useful for event handlers when it is not
- * obviously whether the events are fired on the viewer's thread.
- * @see #execute(Runnable)
- * @see Display#asyncExec(Runnable)
- * @see #asyncExec(Runnable)
- * @see #syncExec(Runnable)
- * @see #timerExec(int, Runnable)
- */
- public static void execute(Viewer viewer, Runnable runnable) {
- execute(viewer.getControl(), runnable);
- }
-
- /**
- * Execute the specified runnable if the current thread is the specified
- * control's thread;
- * otherwise asynchrounously dispatch the runnable to the control's thread,
- * returning immediately. This is useful for event handlers when it is not
- * obviously whether the events are fired on the control's thread.
- * @see #execute(Runnable)
- * @see Display#asyncExec(Runnable)
- * @see #asyncExec(Runnable)
- * @see #syncExec(Runnable)
- * @see #timerExec(int, Runnable)
- */
- public static void execute(Control control, Runnable runnable) {
- execute(control.getDisplay(), runnable);
- }
-
- /**
- * Execute the specified runnable if the current thread is the specified
- * display's thread;
- * otherwise asynchrounously dispatch the runnable to the display's thread,
- * returning immediately. This is useful for event handlers when it is not
- * obviously whether the events are fired on the display's thread.
- * @see #execute(Runnable)
- * @see Display#asyncExec(Runnable)
- * @see #asyncExec(Runnable)
- * @see #syncExec(Runnable)
- * @see #timerExec(int, Runnable)
- */
- public static void execute(Display display, Runnable runnable) {
- if (display.getThread() == Thread.currentThread()) {
- // the current thread is the the UI thread
- runnable.run();
- } else {
- display.asyncExec(runnable);
- }
- }
-
- /**
- * Return the current shell. Return <code>null</code> if there is none.
- * @exception org.eclipse.swt.SWTException if not called from the UI thread
- */
- public static Shell getShell() {
- Shell shell = getActiveShell();
- return (shell != null) ? shell : getActiveWorkbenchShell();
- }
-
- /**
- * Return the current "active" shell, which can be the shell from any
- * window. Return <code>null</code> if there is no display.
- * @see Display#getActiveShell()
- * @exception org.eclipse.swt.SWTException if not called from the UI thread
- */
- public static Shell getActiveShell() {
- // Retrieve the active shell, which can be the shell from any window
- Display display = getDisplay();
- return (display == null) ? null : display.getActiveShell();
- }
-
- /**
- * Return the currently active workbench window's shell.
- * Return <code>null</code> if not called from the UI thread.
- * @see IWorkbench#getActiveWorkbenchWindow()
- */
- public static Shell getActiveWorkbenchShell() {
- IWorkbench wb = getWorkbench();
- if (wb == null) {
- return null;
- }
- IWorkbenchWindow ww = wb.getActiveWorkbenchWindow();
- return (ww == null) ? null : ww.getShell();
- }
-
- /**
- * Return the most appropriate {@link Display display}; i.e. return the
- * {@link Display#getCurrent() display associated with the current thread}
- * if it is present; otherwise return the
- * {@link IWorkbench#getDisplay() Eclipse workbench
- * display} (but, <em>explicitly</em>, not the
- * {@link Display#getDefault() "default display"} -
- * see the comment at {@link IWorkbench#getDisplay()}).
- * Return <code>null</code> if the workbench is not running.
- */
- public static Display getDisplay() {
- Display display = Display.getCurrent();
- return (display != null) ? display : getWorkbenchDisplay();
- }
-
- /**
- * Return the Eclipse UI {@link IWorkbench workbench}
- * {@link Display display}.
- * Return <code>null</code> if the workbench is not running.
- * @see #getWorkbench()
- */
- public static Display getWorkbenchDisplay() {
- IWorkbench wb = getWorkbench();
- return (wb == null) ? null : wb.getDisplay();
- }
-
- /**
- * Return the Eclipse UI {@link IWorkbench workbench}.
- * Return <code>null</code> if the workbench is not running
- * (i.e. either it has not been started or it has been terminated).
- * <p>
- * <strong>NB:</strong> There is no guarantee the workbench will continue
- * running after it is returned.
- * @see PlatformUI#isWorkbenchRunning()
- */
- public static IWorkbench getWorkbench() {
- return PlatformUI.isWorkbenchRunning() ? PlatformUI.getWorkbench() : null;
- }
-
- /**
- * Center the specified shell within its display.
- * <p>
- * <strong>NB:</strong> This will not look too good on a dual monitor system.
- */
- public static void center(Shell shell) {
- shell.setBounds(calculateCenteredBounds(shell.getBounds(), shell.getDisplay().getBounds()));
- }
-
- /**
- * Center the specified shell within the specified parent shell.
- */
- public static void center(Shell shell, Shell parentShell) {
- shell.setBounds(calculateCenteredBounds(shell.getBounds(), parentShell.getBounds()));
- }
-
- /**
- * Calculate the bounds (within the second specified rectangle's coordinate
- * system) that would center the first specified rectangle
- * with respect to the second specified rectangle.
- */
- public static Rectangle calculateCenteredBounds(Rectangle rectangle1, Rectangle rectangle2) {
- return calculateCenteredBounds(rectangle1.width, rectangle1.height, rectangle2.x, rectangle2.y, rectangle2.width, rectangle2.height);
- }
-
- /**
- * Calculate the bounds (within the second specified rectangle's coordinate
- * system) that would center the first specified rectangle
- * with respect to the second specified rectangle.
- */
- public static Rectangle calculateCenteredBounds(Point size1, Point size2) {
- return calculateCenteredBounds(size1.x, size1.y, size2.x, size2.y);
- }
-
- /**
- * Calculate the point (within the second specified rectangle's coordinate
- * system) that would center the first specified rectangle
- * with respect to the second specified rectangle.
- */
- public static Rectangle calculateCenteredBounds(int width1, int height1, int width2, int height2) {
- return calculateCenteredBounds(width1, height1, 0, 0, width2, height2);
- }
-
-
- /**
- * Calculate the point (within the second specified rectangle's coordinate
- * system) that would center the first specified rectangle
- * with respect to the second specified rectangle.
- */
- public static Rectangle calculateCenteredBounds(int width1, int height1, int x2, int y2, int width2, int height2) {
- return new Rectangle(x2 + ((width2 - width1) >> 1), y2 + ((height2 - height1) >> 1), width1, height1);
- }
-
- /**
- * Calculate the point (within the second specified rectangle's coordinate
- * system) that would center the first specified rectangle
- * with respect to the second specified rectangle.
- */
- public static Point calculateCenteredPosition(Rectangle rectangle1, Rectangle rectangle2) {
- return calculateCenteredPosition(rectangle1.width, rectangle1.height, rectangle2.x, rectangle2.y, rectangle2.width, rectangle2.height);
- }
-
- /**
- * Calculate the point (within the second specified rectangle's coordinate
- * system) that would center the first specified rectangle
- * with respect to the second specified rectangle.
- */
- public static Point calculateCenteredPosition(Point size1, Point size2) {
- return calculateCenteredPosition(size1.x, size1.y, size2.x, size2.y);
- }
-
- /**
- * Calculate the point (within the second specified rectangle's coordinate
- * system) that would center the first specified rectangle
- * with respect to the second specified rectangle.
- */
- public static Point calculateCenteredPosition(int width1, int height1, int width2, int height2) {
- return calculateCenteredPosition(width1, height1, 0, 0, width2, height2);
- }
-
- /**
- * Calculate the point (within the second specified rectangle's coordinate
- * system) that would center the first specified rectangle
- * with respect to the second specified rectangle.
- */
- public static Point calculateCenteredPosition(int width1, int height1, int x2, int y2, int width2, int height2) {
- return new Point(x2 + ((width2 - width1) >> 1), y2 + ((height2 - height1) >> 1));
- }
-
- /**
- * Tweaks the given <code>Combo</code> to remove the default value when the
- * widget receives the focus and to show the default when the widget loses
- * the focus.
- *
- * @param combo The widget having a default value that is always at the
- * beginning of the list
- */
- public static void attachDefaultValueHandler(Combo combo) {
- ComboHandler handler = new ComboHandler();
- combo.addFocusListener(handler);
- combo.addModifyListener(handler);
- }
-
-
- public static int getTableHeightHint(Table table, int rows) {
- if (table.getFont().equals(JFaceResources.getDefaultFont()))
- table.setFont(JFaceResources.getDialogFont());
- int result= table.getItemHeight() * rows + table.getHeaderHeight();
- if (table.getLinesVisible())
- result+= table.getGridLineWidth() * (rows - 1);
- return result;
- }
-
- /**
- * Relays out the parents of the <code>Control</code>. This was taken from
- * the widget <code>Section</code>.
- *
- * @param pane The pane to revalidate as well as its parents
- */
- public static void reflow(Composite pane) {
-
- for (Composite composite = pane; composite != null; ) {
- composite.setRedraw(false);
- composite = composite.getParent();
-
- if (composite instanceof ScrolledForm || composite instanceof Shell) {
- break;
- }
- }
-
- for (Composite composite = pane; composite != null; ) {
- composite.layout(true);
- composite = composite.getParent();
-
- if (composite instanceof ScrolledForm) {
- ((ScrolledForm) composite).reflow(true);
- break;
- }
- }
-
- for (Composite composite = pane; composite != null; ) {
- composite.setRedraw(true);
- composite = composite.getParent();
-
- if (composite instanceof ScrolledForm || composite instanceof Shell) {
- break;
- }
- }
- }
-
-
- /**
- * Determines if the current thread is the UI event thread.
- *
- * @return <code>true</code> if it's the UI event thread, <code>false</code>
- * otherwise
- */
- public static boolean uiThread() {
- return Display.getCurrent() != null;
- }
-
- /**
- * Determines if the current thread is the UI event thread by using the
- * thread from which the given viewer's display was instantiated.
- *
- * @param viewer The viewer used to determine if the current thread
- * is the UI event thread
- * @return <code>true</code> if the current thread is the UI event thread;
- * <code>false</code> otherwise
- */
- public static boolean uiThread(Viewer viewer) {
- return uiThread(viewer.getControl());
- }
-
- /**
- * Determines if the current thread is the UI event thread by using the
- * thread from which the given widget's display was instantiated.
- *
- * @param widget The widget used to determine if the current thread
- * is the UI event thread
- * @return <code>true</code> if the current thread is the UI event thread;
- * <code>false</code> otherwise
- */
- public static boolean uiThread(Widget widget) {
- return widget.getDisplay().getThread() == Thread.currentThread();
- }
-
-
- /**
- * This handler is responsible for removing the default value when the combo
- * has the focus or when the selected item is the default value and to select
- * it when the combo loses the focus.
- */
- private static class ComboHandler implements ModifyListener,
- FocusListener {
-
- public void focusGained(FocusEvent e) {
- Combo combo = (Combo) e.widget;
-
- if (combo.getSelectionIndex() == 0) {
- // The text selection has to be changed outside of the context of this
- // listener otherwise the combo won't update because it's currently
- // notifying its listeners
- asyncExec(new SelectText(combo));
- }
- }
-
- public void focusLost(FocusEvent e) {
- //do nothing
- }
-
- public void modifyText(ModifyEvent e) {
-
- Combo combo = (Combo) e.widget;
-
- if (combo.isFocusControl() &&
- combo.getSelectionIndex() == 0) {
-
- // The text has to be changed outside of the context of this
- // listener otherwise the combo won't update because it's currently
- // notifying its listeners
- asyncExec(new ModifyText(combo));
- }
- }
-
- private class ModifyText implements Runnable {
- private final Combo combo;
-
- public ModifyText(Combo combo) {
- super();
- this.combo = combo;
- }
-
- public void run() {
- if (this.combo.isDisposed()) {
- return;
- }
- String text = this.combo.getText();
-
- if (text.length() == 0) {
- text = this.combo.getItem(0);
- this.combo.setText(text);
- }
-
- this.combo.setSelection(new Point(0, text.length()));
- }
- }
-
- private class SelectText implements Runnable {
- private final Combo combo;
-
- public SelectText(Combo combo) {
- super();
- this.combo = combo;
- }
-
- public void run() {
- if (this.combo.isDisposed()) {
- return;
- }
- String text = this.combo.getText();
- this.combo.setSelection(new Point(0, text.length()));
- }
- }
- }
-}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/AbstractUiCommandContext.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/AbstractUiCommandContext.java
index c17a1660d4..1ad032683d 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/AbstractUiCommandContext.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/AbstractUiCommandContext.java
@@ -9,7 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.common.ui.internal.utility;
-import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.ui.internal.swt.widgets.DisplayTools;
import org.eclipse.jpt.common.utility.command.Command;
import org.eclipse.jpt.common.utility.command.ExtendedCommandContext;
import org.eclipse.jpt.common.utility.internal.command.CommandRunnable;
@@ -48,7 +48,7 @@ abstract class AbstractUiCommandContext
SynchronizingCommand syncCommand = new SynchronizingCommand(command);
// dispatch the sync command to the UI thread...
- SWTUtil.asyncExec(this.buildRunnable(syncCommand));
+ DisplayTools.asyncExec(this.buildRunnable(syncCommand));
// ...and wait for it to execute
try {
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/AsynchronousUiCommandContext.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/AsynchronousUiCommandContext.java
index 8b57470fb6..41a1a9ac8f 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/AsynchronousUiCommandContext.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/AsynchronousUiCommandContext.java
@@ -9,7 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.common.ui.internal.utility;
-import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.ui.internal.swt.widgets.DisplayTools;
import org.eclipse.jpt.common.utility.command.Command;
import org.eclipse.jpt.common.utility.command.ExtendedCommandContext;
@@ -35,10 +35,10 @@ public final class AsynchronousUiCommandContext
}
public void execute(Command command) {
- SWTUtil.asyncExec(this.buildRunnable(command));
+ DisplayTools.asyncExec(this.buildRunnable(command));
}
public void waitToExecute(Command command) {
- SWTUtil.syncExec(this.buildRunnable(command));
+ DisplayTools.syncExec(this.buildRunnable(command));
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/SynchronousUiCommandContext.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/SynchronousUiCommandContext.java
index d16d2c00ea..5623c937be 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/SynchronousUiCommandContext.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/SynchronousUiCommandContext.java
@@ -9,7 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.common.ui.internal.utility;
-import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.ui.internal.swt.widgets.DisplayTools;
import org.eclipse.jpt.common.utility.command.Command;
import org.eclipse.jpt.common.utility.command.ExtendedCommandContext;
@@ -35,7 +35,7 @@ public final class SynchronousUiCommandContext
}
public void execute(Command command) {
- SWTUtil.syncExec(this.buildRunnable(command));
+ DisplayTools.syncExec(this.buildRunnable(command));
}
public void waitToExecute(Command command) {
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/AddRemoveListPane.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/AddRemoveListPane.java
index 2182f293e8..cc958bc86a 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/AddRemoveListPane.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/AddRemoveListPane.java
@@ -15,7 +15,7 @@ import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jpt.common.ui.internal.swt.ColumnAdapter;
import org.eclipse.jpt.common.ui.internal.swt.TableModelAdapter;
-import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.ui.internal.swt.widgets.DisplayTools;
import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.common.utility.model.Model;
import org.eclipse.jpt.common.utility.model.event.ListAddEvent;
@@ -261,7 +261,7 @@ public class AddRemoveListPane<T extends Model, E extends Object> extends AddRem
* notified before the table has been updated (table column added or removed).
*/
private void revalidateLayout() {
- SWTUtil.asyncExec(new Runnable() { public void run() {
+ DisplayTools.asyncExec(new Runnable() { public void run() {
if (!table.isDisposed()) {
table.getParent().computeSize(SWT.DEFAULT, SWT.DEFAULT);
table.getParent().layout();
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/AddRemovePane.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/AddRemovePane.java
index 1434df5c1c..f1398740fc 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/AddRemovePane.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/AddRemovePane.java
@@ -488,11 +488,11 @@ public abstract class AddRemovePane<T extends Model, E extends Object> extends P
// Update the help topic ID
if (helpId != null) {
- getHelpSystem().setHelp(this.addButton, helpId);
- getHelpSystem().setHelp(this.removeButton, helpId);
+ this.setHelp(this.addButton, helpId);
+ this.setHelp(this.removeButton, helpId);
if (this.optionalButton != null) {
- getHelpSystem().setHelp(this.optionalButton, helpId);
+ this.setHelp(this.optionalButton, helpId);
}
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/ClassChooserPane.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/ClassChooserPane.java
index 24b6d63827..4426cd672d 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/ClassChooserPane.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/ClassChooserPane.java
@@ -18,7 +18,6 @@ import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.internal.ui.refactoring.contentassist.ControlContentAssistHelper;
import org.eclipse.jdt.internal.ui.refactoring.contentassist.JavaTypeCompletionProcessor;
@@ -38,8 +37,8 @@ import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.model.Model;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.widgets.Composite;
@@ -356,33 +355,25 @@ public abstract class ClassChooserPane<T extends Model> extends ChooserPane<T>
* cancelled the dialog
*/
protected IType chooseType() {
- IJavaElement[] elements = new IJavaElement[] { getJavaProject() };
- IJavaSearchScope scope = SearchEngine.createJavaSearchScope(elements);
- SelectionDialog typeSelectionDialog;
-
+ SelectionDialog dialog;
try {
- typeSelectionDialog = JavaUI.createTypeDialog(
- getShell(),
- PlatformUI.getWorkbench().getProgressService(),
- scope,
- getTypeDialogStyle(),
- false,
- StringTools.isBlank(getClassName()) ? "" : ClassNameTools.simpleName(getClassName())
- );
- }
- catch (JavaModelException e) {
- JptCommonUiPlugin.instance().logError(e);
+ dialog = JavaUI.createTypeDialog(
+ getShell(),
+ PlatformUI.getWorkbench().getProgressService(),
+ SearchEngine.createJavaSearchScope(new IJavaElement[] { getJavaProject() }),
+ getTypeDialogStyle(),
+ false,
+ StringTools.isBlank(getClassName()) ? StringTools.EMPTY_STRING : ClassNameTools.simpleName(getClassName())
+ );
+ } catch (JavaModelException ex) {
+ JptCommonUiPlugin.instance().logError(ex);
return null;
}
- typeSelectionDialog.setTitle(JptCommonUiMessages.CLASS_CHOOSER_PANE__DIALOG_TITLE);
- typeSelectionDialog.setMessage(JptCommonUiMessages.CLASS_CHOOSER_PANE__DIALOG_MESSAGE);
+ dialog.setTitle(JptCommonUiMessages.CLASS_CHOOSER_PANE__DIALOG_TITLE);
+ dialog.setMessage(JptCommonUiMessages.CLASS_CHOOSER_PANE__DIALOG_MESSAGE);
- if (typeSelectionDialog.open() == Window.OK) {
- return (IType) typeSelectionDialog.getResult()[0];
- }
-
- return null;
+ return (dialog.open() == Window.OK) ? (IType) dialog.getResult()[0] : null;
}
protected int getTypeDialogStyle() {
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/ComboPane.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/ComboPane.java
index 0371c4bc5d..e23c23a1c7 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/ComboPane.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/ComboPane.java
@@ -10,7 +10,7 @@
package org.eclipse.jpt.common.ui.internal.widgets;
import org.eclipse.jpt.common.ui.JptCommonUiMessages;
-import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.ui.internal.swt.widgets.ComboTools;
import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
import org.eclipse.jpt.common.utility.model.Model;
@@ -80,7 +80,7 @@ public abstract class ComboPane<T extends Model>
protected void initializeLayout(Composite container) {
this.comboBox = this.addEditableCombo(container, getHelpId());
this.comboBox.addModifyListener(this.buildModifyListener());
- SWTUtil.attachDefaultValueHandler(this.comboBox);
+ ComboTools.handleDefaultValue(this.comboBox);
}
protected ModifyListener buildModifyListener() {
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Dialog.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Dialog.java
index 9ac6812157..f5abb5a0fc 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Dialog.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Dialog.java
@@ -23,8 +23,6 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.help.IWorkbenchHelpSystem;
/**
* The abstract implementation of a dialog using a "state object" (model object)
@@ -202,17 +200,6 @@ public abstract class Dialog<T extends Node>
}
/**
- * Returns the helps system.
- *
- * @return The platform's help system
- *
- * @category Helper
- */
- protected final IWorkbenchHelpSystem getHelpSystem() {
- return PlatformUI.getWorkbench().getHelpSystem();
- }
-
- /**
* Initializes this dialog.
*/
protected void initialize() {
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/IntegerCombo.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/IntegerCombo.java
index a7128d8046..24f3626bdc 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/IntegerCombo.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/IntegerCombo.java
@@ -11,7 +11,7 @@ package org.eclipse.jpt.common.ui.internal.widgets;
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
import org.eclipse.jpt.common.ui.JptCommonUiMessages;
-import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.ui.internal.swt.widgets.ComboTools;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyListValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.TransformationModifiablePropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel;
@@ -102,7 +102,7 @@ public abstract class IntegerCombo<T extends Model>
this.comboBox.setLayoutData(gridData);
this.comboBox.addVerifyListener(this.buildVerifyListener());
- SWTUtil.attachDefaultValueHandler(this.comboBox);
+ ComboTools.handleDefaultValue(this.comboBox);
}
protected Combo addIntegerCombo(Composite container) {
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Pane.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Pane.java
index bb0ef6d17f..bd4706bc67 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Pane.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/Pane.java
@@ -18,6 +18,7 @@ import org.eclipse.jface.resource.ResourceManager;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.IBaseLabelProvider;
import org.eclipse.jpt.common.ui.WidgetFactory;
+import org.eclipse.jpt.common.ui.internal.WorkbenchTools;
import org.eclipse.jpt.common.ui.internal.listeners.SWTPropertyChangeListenerWrapper;
import org.eclipse.jpt.common.ui.internal.plugin.JptCommonUiPlugin;
import org.eclipse.jpt.common.ui.internal.swt.ComboModelAdapter;
@@ -65,11 +66,9 @@ import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.eclipse.ui.forms.widgets.Hyperlink;
import org.eclipse.ui.forms.widgets.Section;
-import org.eclipse.ui.help.IWorkbenchHelpSystem;
import org.eclipse.ui.part.PageBook;
/**
@@ -553,7 +552,7 @@ public abstract class Pane<T extends Model> {
});
if (helpId != null) {
- getHelpSystem().setHelp(button, helpId);
+ this.setHelp(button, helpId);
}
GridData gridData = new GridData();
@@ -643,7 +642,7 @@ public abstract class Pane<T extends Model> {
Combo combo = this.addUnmanagedCombo(container);
if (helpId != null) {
- getHelpSystem().setHelp(combo, helpId);
+ this.setHelp(combo, helpId);
}
this.controlEnabledState(combo);
@@ -818,7 +817,7 @@ public abstract class Pane<T extends Model> {
Combo combo = this.getWidgetFactory().createEditableCombo(container);
if (helpId != null) {
- getHelpSystem().setHelp(combo, helpId);
+ this.setHelp(combo, helpId);
}
combo.setLayoutData(getFieldGridData());
@@ -1030,7 +1029,7 @@ public abstract class Pane<T extends Model> {
SpinnerModelAdapter.adapt(numberHolder, spinner, defaultValue);
if (helpId != null) {
- getHelpSystem().setHelp(spinner, helpId);
+ this.setHelp(spinner, helpId);
}
return spinner;
@@ -1099,7 +1098,7 @@ public abstract class Pane<T extends Model> {
DateTimeModelAdapter.adapt(hoursHolder, minutesHolder, secondsHolder, dateTime);
if (helpId != null) {
- getHelpSystem().setHelp(dateTime, helpId);
+ this.setHelp(dateTime, helpId);
}
return dateTime;
@@ -1151,7 +1150,7 @@ public abstract class Pane<T extends Model> {
if (helpId != null) {
- getHelpSystem().setHelp(container, helpId);
+ this.setHelp(container, helpId);
}
return combo;
@@ -1226,7 +1225,7 @@ public abstract class Pane<T extends Model> {
list.setLayoutData(new GridData(GridData.FILL_BOTH));
if (helpId != null) {
- getHelpSystem().setHelp(list, helpId);
+ this.setHelp(list, helpId);
}
return list;
@@ -1266,7 +1265,7 @@ public abstract class Pane<T extends Model> {
adjustMultiLineTextLayout(lineCount, text, text.getLineHeight());
if (helpId != null) {
- getHelpSystem().setHelp(text, helpId);
+ this.setHelp(text, helpId);
}
return text;
@@ -1450,7 +1449,7 @@ public abstract class Pane<T extends Model> {
button.setLayoutData(new GridData());
if (helpId != null) {
- getHelpSystem().setHelp(button, helpId);
+ this.setHelp(button, helpId);
}
return button;
@@ -1704,7 +1703,7 @@ public abstract class Pane<T extends Model> {
table.setLayoutData(gridData);
if (helpId != null) {
- getHelpSystem().setHelp(table, helpId);
+ this.setHelp(table, helpId);
}
return table;
@@ -1794,7 +1793,7 @@ public abstract class Pane<T extends Model> {
Text text = this.addText(container);
if (helpId != null) {
- getHelpSystem().setHelp(text, helpId);
+ this.setHelp(text, helpId);
}
return text;
@@ -1816,7 +1815,7 @@ public abstract class Pane<T extends Model> {
Text text = this.addUnmanagedText(container);
if (helpId != null) {
- getHelpSystem().setHelp(text, helpId);
+ this.setHelp(text, helpId);
}
return text;
@@ -1950,7 +1949,7 @@ public abstract class Pane<T extends Model> {
group.setLayout(layout);
if (helpId != null) {
- getHelpSystem().setHelp(group, helpId);
+ this.setHelp(group, helpId);
}
return group;
@@ -1996,7 +1995,7 @@ public abstract class Pane<T extends Model> {
SWTBindTools.bind(booleanHolder, button);
if (helpId != null) {
- getHelpSystem().setHelp(button, helpId);
+ this.setHelp(button, helpId);
}
return button;
@@ -2073,7 +2072,7 @@ public abstract class Pane<T extends Model> {
);
if (helpId != null) {
- getHelpSystem().setHelp(checkBox.getCheckBox(), helpId);
+ this.setHelp(checkBox.getCheckBox(), helpId);
}
return checkBox;
@@ -2267,8 +2266,8 @@ public abstract class Pane<T extends Model> {
return (this.parent == null) ? this.resourceManager : this.parent.getResourceManager();
}
- protected final IWorkbenchHelpSystem getHelpSystem() {
- return PlatformUI.getWorkbench().getHelpSystem();
+ protected final void setHelp(Control control, String contextID) {
+ WorkbenchTools.setHelp(control, contextID);
}
protected final boolean isPopulating() {
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/wizards/JavaProjectWizardPage.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/wizards/JavaProjectWizardPage.java
index c45e0caae1..4dd6d50e63 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/wizards/JavaProjectWizardPage.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/wizards/JavaProjectWizardPage.java
@@ -19,6 +19,7 @@ import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.jpt.common.core.internal.utility.ProjectTools;
+import org.eclipse.jpt.common.ui.internal.WorkbenchTools;
import org.eclipse.jpt.common.utility.internal.ArrayTools;
import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
@@ -33,7 +34,6 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
-import org.eclipse.ui.PlatformUI;
/**
* JavaProjectWizardPage
@@ -174,9 +174,7 @@ public class JavaProjectWizardPage extends WizardPage {
private final class ProjectTableLabelProvider extends LabelProvider implements ITableLabelProvider {
public Image getColumnImage(Object element, int columnIndex) {
- if(columnIndex == PROJECT_NAME_COLUMN_INDEX)
- return PlatformUI.getWorkbench().getSharedImages().getImage(org.eclipse.ui.ide.IDE.SharedImages.IMG_OBJ_PROJECT);
- return null;
+ return (columnIndex == PROJECT_NAME_COLUMN_INDEX) ? WorkbenchTools.getSharedImage(org.eclipse.ui.ide.IDE.SharedImages.IMG_OBJ_PROJECT) : null;
}
public String getColumnText(Object element, int columnIndex) {

Back to the top