From 65512b3154161a233cee773c6ddda56201ade3ca Mon Sep 17 00:00:00 2001 From: Brian Vosburgh Date: Wed, 10 Apr 2013 14:41:39 -0400 Subject: clean up some of the common.ui utilities --- .../org.eclipse.jpt.common.ui/META-INF/MANIFEST.MF | 1 + .../jpt/common/ui/gen/AbstractJptGenerateJob.java | 14 +- .../jpt/common/ui/internal/WorkbenchPageTools.java | 2 +- .../jpt/common/ui/internal/WorkbenchTools.java | 277 ++++++++++- .../common/ui/internal/WorkbenchWindowTools.java | 2 +- ...AbstractItemStructuredStateProviderManager.java | 4 +- .../SWTCollectionChangeListenerWrapper.java | 8 +- .../listeners/SWTListChangeListenerWrapper.java | 8 +- .../SWTPropertyChangeListenerWrapper.java | 8 +- .../listeners/SWTStateChangeListenerWrapper.java | 8 +- .../internal/swt/bind/BooleanStateController.java | 4 +- .../common/ui/internal/swt/widgets/ComboTools.java | 109 +++++ .../ui/internal/swt/widgets/ControlTools.java | 173 +++++++ .../ui/internal/swt/widgets/DisplayTools.java | 257 ++++++++++ .../common/ui/internal/swt/widgets/TableTools.java | 41 ++ .../common/ui/internal/util/ControlSwitcher.java | 3 +- .../jpt/common/ui/internal/util/SWTUtil.java | 527 --------------------- .../internal/utility/AbstractUiCommandContext.java | 4 +- .../utility/AsynchronousUiCommandContext.java | 6 +- .../utility/SynchronousUiCommandContext.java | 4 +- .../ui/internal/widgets/AddRemoveListPane.java | 4 +- .../common/ui/internal/widgets/AddRemovePane.java | 6 +- .../ui/internal/widgets/ClassChooserPane.java | 39 +- .../jpt/common/ui/internal/widgets/ComboPane.java | 4 +- .../jpt/common/ui/internal/widgets/Dialog.java | 13 - .../common/ui/internal/widgets/IntegerCombo.java | 4 +- .../jpt/common/ui/internal/widgets/Pane.java | 37 +- .../ui/internal/wizards/JavaProjectWizardPage.java | 6 +- 28 files changed, 938 insertions(+), 635 deletions(-) create mode 100644 common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/widgets/ComboTools.java create mode 100644 common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/widgets/ControlTools.java create mode 100644 common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/widgets/DisplayTools.java create mode 100644 common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/widgets/TableTools.java delete mode 100644 common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/SWTUtil.java (limited to 'common/plugins/org.eclipse.jpt.common.ui') 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 null 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 null 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 null 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 null 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 null if the workbench is not running + * (i.e. either it has not been started or it has been terminated). + *

+ * NB: 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 and 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 null if the workbench is not running. + *

+ * NB: The returned image is managed by the workbench; + * clients must not 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 null 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. + *

+ * NB: Must be called from the UI thread. + *

+ * @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. + *

+ * NB: Must be called from the UI thread. + *

+ * @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. + *

+ * NB: Must be called from the UI thread. + *

+ * @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 null 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 getAdapter(Class adapterType) { + IWorkbench wb = getWorkbench(); + return (wb == null) ? null : PlatformTools.getAdapter(wb, adapterType); + } + + /** + * Return the workbench service corresponding to the specified API. + * Return null 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 getService(Class 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 + * NB: 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 ********** + + /** + * NB: 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); + } + } + + /** + * NB: 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. + *

+ * NB: 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); + } + + /** + * NB: 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. + *

+ * NB: 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 null 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 null 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, explicitly, not the + * {@link Display#getDefault() "default display"} - + * see the comment at {@link IWorkbench#getDisplay()}). + * Return null 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 true if it's the UI event thread, false + * 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 true if the current thread is the UI event thread; + * false 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 true if the current thread is the UI event thread; + * false 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 { - - /** - * NB: 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); - } - } - - /** - * NB: 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. - *

- * NB: 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); - } - - /** - * NB: 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. - *

- * NB: 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 null 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 null 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 null 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, explicitly, not the - * {@link Display#getDefault() "default display"} - - * see the comment at {@link IWorkbench#getDisplay()}). - * Return null 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 null 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 null if the workbench is not running - * (i.e. either it has not been started or it has been terminated). - *

- * NB: 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. - *

- * NB: 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 Combo 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 Control. This was taken from - * the widget Section. - * - * @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 true if it's the UI event thread, false - * 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 true if the current thread is the UI event thread; - * false 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 true if the current thread is the UI event thread; - * false 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 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 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 extends ChooserPane * 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 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) @@ -201,17 +199,6 @@ public abstract class Dialog return false; } - /** - * Returns the helps system. - * - * @return The platform's help system - * - * @category Helper - */ - protected final IWorkbenchHelpSystem getHelpSystem() { - return PlatformUI.getWorkbench().getHelpSystem(); - } - /** * Initializes this dialog. */ 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 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 { }); if (helpId != null) { - getHelpSystem().setHelp(button, helpId); + this.setHelp(button, helpId); } GridData gridData = new GridData(); @@ -643,7 +642,7 @@ public abstract class Pane { 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 { 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 { 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 { 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 { if (helpId != null) { - getHelpSystem().setHelp(container, helpId); + this.setHelp(container, helpId); } return combo; @@ -1226,7 +1225,7 @@ public abstract class Pane { 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 { 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 { 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 { table.setLayoutData(gridData); if (helpId != null) { - getHelpSystem().setHelp(table, helpId); + this.setHelp(table, helpId); } return table; @@ -1794,7 +1793,7 @@ public abstract class Pane { 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 { 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 { group.setLayout(layout); if (helpId != null) { - getHelpSystem().setHelp(group, helpId); + this.setHelp(group, helpId); } return group; @@ -1996,7 +1995,7 @@ public abstract class Pane { 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 { ); if (helpId != null) { - getHelpSystem().setHelp(checkBox.getCheckBox(), helpId); + this.setHelp(checkBox.getCheckBox(), helpId); } return checkBox; @@ -2267,8 +2266,8 @@ public abstract class Pane { 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) { -- cgit v1.2.3