453246: Make Company a navigable link in MPC entries

Bug: 453246
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=453246
diff --git a/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/wizards/DiscoveryItem.java b/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/wizards/DiscoveryItem.java
index ee259d2..ec1edc3 100644
--- a/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/wizards/DiscoveryItem.java
+++ b/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/wizards/DiscoveryItem.java
@@ -63,7 +63,6 @@
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Link;
 import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Widget;
@@ -87,6 +86,8 @@
 
 	private static final String INFO_HREF = "info"; //$NON-NLS-1$
 
+	private static final String PROVIDER_PLACEHOLDER = "@PROVIDER@"; //$NON-NLS-1$
+
 	private static final int DESCRIPTION_MARGIN_LEFT = 8;
 
 	private static final int DESCRIPTION_MARGIN_TOP = 8;
@@ -642,20 +643,50 @@
 	}
 
 	protected void createProviderLabel(Composite parent) {
-		Link providerLabel = new Link(parent, SWT.NONE);
-		setWidgetId(providerLabel, WIDGET_ID_PROVIDER);
+		StyledText providerLink = createStyledTextLabel(parent);
+		//Link providerLink = new Link(parent, SWT.NONE);
+		setWidgetId(providerLink, WIDGET_ID_PROVIDER);
 
+		providerLink.setEditable(false);
 		GridDataFactory.fillDefaults()
 		.indent(DESCRIPTION_MARGIN_LEFT, DESCRIPTION_MARGIN_TOP)
 		.span(3, 1)
 		.align(SWT.BEGINNING, SWT.CENTER)
 		.grab(true, false)
-		.applyTo(providerLabel);
+		.applyTo(providerLink);
 		// always disabled color to make it less prominent
-		providerLabel.setForeground(resources.getColorDisabled());
+		providerLink.setForeground(resources.getColorDisabled());
 
-		providerLabel.setText(NLS.bind(Messages.DiscoveryItem_byProviderLicense, connector.getProvider(),
+		providerLink.setText(NLS.bind(Messages.DiscoveryItem_byProviderLicense, PROVIDER_PLACEHOLDER,
 				connector.getLicense()));
+		int providerPos = providerLink.getText().indexOf(PROVIDER_PLACEHOLDER);
+		if (providerPos != -1) {
+			String providerName = connector.getProvider();
+			StyleRange range = new StyleRange(0, 0, providerLink.getForeground(), null, SWT.NONE);
+			if (providerName == null) {
+				providerName = Messages.DiscoveryItem_UnknownProvider;
+				range.fontStyle = range.fontStyle | SWT.ITALIC;
+			} else {
+				range.underline = true;
+				range.underlineStyle = SWT.UNDERLINE_LINK;
+				hookLinkListener(providerLink, new LinkListener() {
+
+					@Override
+					protected void selected(String href) {
+						String searchTerm = href;
+						if (searchTerm.contains(" ")) { //$NON-NLS-1$
+							searchTerm = "\"" + searchTerm + "\""; //$NON-NLS-1$//$NON-NLS-2$
+						}
+						viewer.search(searchTerm);
+					}
+				});
+			}
+			range.start = providerPos;
+			range.length = providerName.length();
+			range.data = providerName;
+			providerLink.replaceTextRange(providerPos, PROVIDER_PLACEHOLDER.length(), providerName);
+			providerLink.replaceStyleRanges(providerPos, range.length, new StyleRange[] { range });
+		}
 	}
 
 	protected void createTagsLabel(Composite parent) {
diff --git a/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/wizards/MarketplaceViewer.java b/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/wizards/MarketplaceViewer.java
index 80d9193..c8f260e 100644
--- a/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/wizards/MarketplaceViewer.java
+++ b/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/wizards/MarketplaceViewer.java
@@ -32,6 +32,7 @@
 import org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalog;
 import org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCategory;
 import org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCategory.Contents;
+import org.eclipse.epp.internal.mpc.ui.wizards.MarketplaceWizard.WizardState;
 import org.eclipse.epp.mpc.core.model.ICategory;
 import org.eclipse.epp.mpc.core.model.IIdentifiable;
 import org.eclipse.epp.mpc.core.model.IMarket;
@@ -260,18 +261,21 @@
 		doQuery(null, null, null, nodes);
 	}
 
-	public void search(IMarket market, ICategory category, String query) {
-		ContentType newContentType = ContentType.SEARCH;
-		ContentType oldContentType = contentType;
-		contentType = newContentType;
-		fireContentTypeChange(oldContentType, newContentType);
+	public void search(String query) {
+		search(getQueryMarket(), getQueryCategory(), query);
+	}
 
+	public void search(IMarket market, ICategory category, String query) {
 		setFilters(market, category, query);
 		queryMarket = market;
 		queryCategory = category;
 		queryText = query;
 
-		doQuery(market, category, query, null);
+		updateContent(contentType, new Runnable() {
+			public void run() {
+				doQuery(queryMarket, queryCategory, queryText, null);
+			}
+		});
 	}
 
 	private void setFilters(IMarket market, ICategory category, String query) {
@@ -505,14 +509,22 @@
 	}
 
 	private void doSetContentType(final ContentType contentType) {
-		ContentType oldContentType = this.contentType;
+		updateContent(contentType, new Runnable() {
+			public void run() {
+				doQuery();
+			}
+		});
+	}
+
+	private void updateContent(final ContentType contentType, final Runnable queryCall) {
+		final ContentType oldContentType = this.contentType;
 		this.contentType = contentType;
-		fireContentTypeChange(oldContentType, contentType);
 		runUpdate(new Runnable() {
 
 			public void run() {
+				fireContentTypeChange(oldContentType, contentType);
 				setHeaderVisible(contentType == ContentType.SEARCH || contentType == ContentType.SELECTION);
-				doQuery();
+				queryCall.run();
 			}
 		});
 	}
@@ -619,6 +631,10 @@
 		if (getWizard().wantInitializeInitialSelection()) {
 			try {
 				getWizard().initializeInitialSelection();
+				WizardState initialState = getWizard().getInitialState();
+				if (initialState != null) {
+					getWizard().getCatalogPage().initialize(initialState);
+				}
 				catalogUpdated(false, false);
 			} catch (CoreException e) {
 				boolean wasCancelled = e.getStatus().getSeverity() == IStatus.CANCEL;
diff --git a/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/wizards/MarketplaceWizard.java b/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/wizards/MarketplaceWizard.java
index 12e90b2..b4ce51a 100644
--- a/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/wizards/MarketplaceWizard.java
+++ b/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/wizards/MarketplaceWizard.java
@@ -266,10 +266,6 @@
 				}
 			}
 		}
-		WizardState initialState = getInitialState();
-		if (initialState != null && getStartingPage() == getCatalogPage()) {
-			getCatalogPage().initialize(initialState);
-		}
 	}
 
 	boolean wantInitializeInitialSelection() {
diff --git a/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/wizards/Messages.java b/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/wizards/Messages.java
index baedaa7..8f9dc14 100644
--- a/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/wizards/Messages.java
+++ b/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/wizards/Messages.java
@@ -65,6 +65,8 @@
 
 	public static String DiscoveryItem_Unknown_Installs;
 
+	public static String DiscoveryItem_UnknownProvider;
+
 	public static String FeatureSelectionWizardPage_confirmSelectedFeatures;
 
 	public static String FeatureSelectionWizardPage_confirmSelectedFeatures_description;
diff --git a/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/wizards/messages.properties b/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/wizards/messages.properties
index 643fd2a..64f72e3 100644
--- a/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/wizards/messages.properties
+++ b/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/internal/mpc/ui/wizards/messages.properties
@@ -33,6 +33,7 @@
 DiscoveryItem_truncatedTextSuffix=...
 DiscoveryItem_Unknown_Favorites=0
 DiscoveryItem_Unknown_Installs=?
+DiscoveryItem_UnknownProvider=Unknown
 FeatureSelectionWizardPage_confirmSelectedFeatures=Confirm Selected Features
 FeatureSelectionWizardPage_confirmSelectedFeatures_description=Confirm the features to include in this provisioning operation. Or go back to choose more solutions to install.
 FeatureSelectionWizardPage_details=Details