Bug 483644: improve "no updates were found" dialog.

Gives hint and link to suggest edition of available sites to user.

Change-Id: If02a8d7436dc3e9f7fdffab6b28eed988c4d44a2
Signed-off-by: Mickael Istria <mistria@redhat.com>
diff --git a/bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/internal/p2/operations/messages.properties b/bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/internal/p2/operations/messages.properties
index 4148611..adbaba4 100644
--- a/bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/internal/p2/operations/messages.properties
+++ b/bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/internal/p2/operations/messages.properties
@@ -28,7 +28,7 @@
 PlanAnalyzer_ImpliedUpdate="{0}" is already installed, so an update will be performed instead.
 PlanAnalyzer_Items=Items
 PlanAnalyzer_NothingToDo=Cannot complete the request.  See the error log for details.
-PlanAnalyzer_NoUpdates=No updates were found.
+PlanAnalyzer_NoUpdates=No updates were found in <A>available software sites</A>.
 PlanAnalyzer_AlreadyInstalled="{0}" will be ignored because it is already installed.
 PlanAnalyzer_AnotherOperationInProgress=Cannot continue the operation.  There is another install operation in progress.
 PlanAnalyzer_RequestAltered=Your original request has been modified.
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/MessageDialogWithLink.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/MessageDialogWithLink.java
new file mode 100644
index 0000000..9a1240c
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/MessageDialogWithLink.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ *  Copyright (c) 2015 Red Hat Inc.
+ *  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:
+ *     Mickael Istria (Red Hat Inc.) - 483644 Improve "No updates found" dialog
+ *******************************************************************************/
+package org.eclipse.equinox.internal.p2.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.*;
+
+public class MessageDialogWithLink extends MessageDialog {
+
+	protected String linkMessage;
+	protected Link link;
+	protected List<SelectionListener> linkListeners = new ArrayList<SelectionListener>();
+
+	public MessageDialogWithLink(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage, int dialogImageType, String[] dialogButtonLabels, int defaultIndex) {
+		super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, defaultIndex);
+		this.message = null;
+		this.linkMessage = dialogMessage;
+	}
+
+	public MessageDialogWithLink(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage, int dialogImageType, int defaultIndex, String... dialogButtonLabels) {
+		this(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, defaultIndex);
+	}
+
+	@Override
+	protected Control createMessageArea(Composite composite) {
+		super.createMessageArea(composite);
+		// create message
+		if (linkMessage != null) {
+			this.link = new Link(composite, getMessageLabelStyle());
+			this.link.setText(this.linkMessage);
+			GridDataFactory.fillDefaults().align(SWT.FILL, SWT.BEGINNING).grab(true, false).hint(convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH), SWT.DEFAULT).applyTo(this.link);
+			for (SelectionListener linkListener : this.linkListeners) {
+				this.link.addSelectionListener(linkListener);
+			}
+		}
+		return composite;
+	}
+
+	public void addSelectionListener(SelectionListener listener) {
+		if (link != null && !link.isDisposed()) {
+			link.addSelectionListener(listener);
+		}
+		this.linkListeners.add(listener);
+	}
+
+	public void removeSelectionListener(SelectionListener listener) {
+		if (link != null && !link.isDisposed()) {
+			link.removeSelectionListener(listener);
+		}
+		this.linkListeners.add(listener);
+	}
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/ProvUI.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/ProvUI.java
index 1d78b0c..8b0ad09 100644
--- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/ProvUI.java
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/ProvUI.java
@@ -9,6 +9,7 @@
  *     IBM Corporation - initial API and implementation
  *     Ericsson AB (Hamdan Msheik) - Bug 396420 - Control Install dialog through preference customization
  *     Red Hat Inc. - Bug 460967
+ *     Mickael Istria (Red Hat Inc.) - 483644 Improve "No updates found" dialog
  *******************************************************************************/
 
 package org.eclipse.equinox.internal.p2.ui;
@@ -28,7 +29,11 @@
 import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
 import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
 import org.eclipse.equinox.p2.ui.Policy;
+import org.eclipse.equinox.p2.ui.ProvisioningUI;
+import org.eclipse.jface.dialogs.IDialogConstants;
 import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.PlatformUI;
@@ -93,7 +98,16 @@
 		// blocking right.
 		if ((style & StatusManager.BLOCK) == StatusManager.BLOCK || (style & StatusManager.SHOW) == StatusManager.SHOW) {
 			if (status.getSeverity() == IStatus.INFO) {
-				MessageDialog.openInformation(ProvUI.getDefaultParentShell(), ProvUIMessages.ProvUI_InformationTitle, status.getMessage());
+				final MessageDialogWithLink dialog = new MessageDialogWithLink(ProvUI.getDefaultParentShell(), ProvUIMessages.ProvUI_InformationTitle, null, status.getMessage(), MessageDialog.INFORMATION, 0, IDialogConstants.OK_LABEL);
+				if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
+					dialog.addSelectionListener(new SelectionAdapter() {
+						@Override
+						public void widgetSelected(SelectionEvent e) {
+							ProvisioningUI.getDefaultUI().manipulateRepositories(dialog.getShell());
+						}
+					});
+				}
+				dialog.open();
 				// unset the dialog bits
 				style = style & ~StatusManager.BLOCK;
 				style = style & ~StatusManager.SHOW;