Bug 552909 - Add method for using SWT images in Message Builder

This allows to use builder.image(SWT.ICON_QUESTION) instead of
builder.image(getShell().getDisplay().getSystemImage(SWT.ICON_QUESTION));

Change-Id: Id084b226cdff70288db4d66f8688c4b88cabe243
Signed-off-by: Lars Vogel <Lars.Vogel@vogella.com>
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.ui/+/182104
Tested-by: Platform Bot <platform-bot@eclipse.org>
Reviewed-by: Marcus Höpfner <marcus.hoepfner@sap.com>
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/PlainMessageDialog.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/PlainMessageDialog.java
index 93126c2..3869112 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/PlainMessageDialog.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/PlainMessageDialog.java
@@ -67,6 +67,8 @@
 		private String dialogTitle;
 		private Image titleImage;
 		private Image image;
+
+		private int iconId = -1;
 		private String message;
 		private List<String> buttonLabels = Arrays.asList(IDialogConstants.OK_LABEL);
 		private int defaultButtonIndex = 0;
@@ -100,6 +102,23 @@
 		}
 
 		/**
+		 * Sets the dialog's image (e.g. information icon).
+		 *
+		 * @param iconId SWT style of the image, see below for support styles
+		 *
+		 * @return this
+		 * @see SWT#ICON_ERROR
+		 * @see SWT#ICON_INFORMATION
+		 * @see SWT#ICON_QUESTION
+		 * @see SWT#ICON_WARNING
+		 * @see SWT#ICON_WORKING
+		 */
+		public Builder image(int iconId) {
+			this.iconId = iconId;
+			return this;
+		}
+
+		/**
 		 * Sets the dialog's message.
 		 *
 		 * @param message the message
@@ -163,7 +182,11 @@
 
 		this.title = builder.dialogTitle;
 		this.titleImage = builder.titleImage;
-		this.image = builder.image;
+		if (builder.image == null && builder.iconId != -1) {
+			this.image = builder.shell.getDisplay().getSystemImage(builder.iconId);
+		} else {
+			this.image = builder.image;
+		}
 		this.message = builder.message;
 		this.buttonLabels = builder.buttonLabels;
 		this.defaultButtonIndex = builder.defaultButtonIndex;
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/FileEditorsPreferencePage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/FileEditorsPreferencePage.java
index 0591a3e..89c72d5 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/FileEditorsPreferencePage.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/FileEditorsPreferencePage.java
@@ -128,7 +128,7 @@
 				// Same resource type not allowed!
 				PlainMessageDialog.getBuilder(getShell(),
 						WorkbenchMessages.FileEditorPreference_existsTitle)
-								.image(getShell().getDisplay().getSystemImage(SWT.ICON_INFORMATION))
+						.image(SWT.ICON_INFORMATION)
 						.message(WorkbenchMessages.FileEditorPreference_existsMessage).build().open();
 				return;
 			}