Bug 396420: Control a number of p2 install checkboxes via plugin_customization
diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/ProvSDKUIActivator.java b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/ProvSDKUIActivator.java
index 61ea6c7..c6d6acd 100644
--- a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/ProvSDKUIActivator.java
+++ b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/ProvSDKUIActivator.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2010 IBM Corporation and others.
+ * Copyright (c) 2007, 2012 IBM Corporation and others.
  * 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
@@ -7,6 +7,7 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     Ericsson AB (Hamdan Msheik) - Bug 396420 - Control Install dialog through preference customization
  *******************************************************************************/
 package org.eclipse.equinox.internal.p2.ui.sdk;
 
@@ -120,7 +121,24 @@
 	}
 
 	void updateWithPreferences(Policy policy) {
-		policy.setShowLatestVersionsOnly(getPreferenceStore().getBoolean(PreferenceConstants.PREF_SHOW_LATEST_VERSION));
+
+		IPreferenceStore store = getPreferenceStore();
+
+		String value = store.getString(PreferenceConstants.PREF_SHOW_LATEST_VERSION);
+		policy.setShowLatestVersionsOnly(!IPreferenceStore.STRING_DEFAULT_DEFAULT.equals(value) ? store.getBoolean(PreferenceConstants.PREF_SHOW_LATEST_VERSION) : policy.getShowLatestVersionsOnly());
+
+		value = store.getString(PreferenceConstants.PREF_HIDE_INSTALLED);
+		policy.setHideAlreadyInstalled(!IPreferenceStore.STRING_DEFAULT_DEFAULT.equals(value) ? store.getBoolean(PreferenceConstants.PREF_HIDE_INSTALLED) : policy.getHideAlreadyInstalled());
+
+		value = store.getString(PreferenceConstants.PREF_FILTER_ON_ENV);
+		policy.setFilterOnEnv(!IPreferenceStore.STRING_DEFAULT_DEFAULT.equals(value) ? store.getBoolean(PreferenceConstants.PREF_FILTER_ON_ENV) : policy.getFilterOnEnv());
+
+		value = store.getString(PreferenceConstants.PREF_CONTACT_ALL_SITES);
+		policy.setContactAllSites(!IPreferenceStore.STRING_DEFAULT_DEFAULT.equals(value) ? store.getBoolean(PreferenceConstants.PREF_CONTACT_ALL_SITES) : policy.getContactAllSites());
+
+		value = store.getString(PreferenceConstants.PREF_GROUP_BY_CATEGORY);
+		policy.setGroupByCategory(!IPreferenceStore.STRING_DEFAULT_DEFAULT.equals(value) ? store.getBoolean(PreferenceConstants.PREF_GROUP_BY_CATEGORY) : policy.getGroupByCategory());
+
 	}
 
 	/*
diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/prefs/PreferenceConstants.java b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/prefs/PreferenceConstants.java
index 144ac50..06f35c4 100644
--- a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/prefs/PreferenceConstants.java
+++ b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/prefs/PreferenceConstants.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- *  Copyright (c) 2007, 2010 IBM Corporation and others.
+ *  Copyright (c) 2007, 2012 IBM Corporation and others.
  *  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
@@ -7,6 +7,7 @@
  * 
  *  Contributors:
  *     IBM Corporation - initial API and implementation
+ *     Ericsson AB (Hamdan Msheik) - Bug 396420 - Control Install dialog through preference customization
  *******************************************************************************/
 package org.eclipse.equinox.internal.p2.ui.sdk.prefs;
 
@@ -17,6 +18,10 @@
 	public static final String PREF_PAGE_PROVISIONING = "org.eclipse.equinox.internal.p2.ui.sdk.ProvisioningPreferencePage"; //$NON-NLS-1$
 	public static final String PREF_PAGE_SITES = "org.eclipse.equinox.internal.p2.ui.sdk.SitesPreferencePage"; //$NON-NLS-1$
 	public static final String PREF_SHOW_LATEST_VERSION = "showLatestVersion"; //$NON-NLS-1$
+	public static final String PREF_GROUP_BY_CATEGORY = "groupByCategory"; //$NON-NLS-1$
+	public static final String PREF_FILTER_ON_ENV = "filterOnEnv"; //$NON-NLS-1$
+	public static final String PREF_CONTACT_ALL_SITES = "contactAllSites"; //$NON-NLS-1$
+	public static final String PREF_HIDE_INSTALLED = "hideAlreadyInstalled"; //$NON-NLS-1$
 	public static final String PREF_OPEN_WIZARD_ON_ERROR_PLAN = "allowNonOKPlan"; //$NON-NLS-1$
 	public static final String PREF_LICENSE_DIGESTS = "licenseDigestList"; //$NON-NLS-1$
 }
diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/prefs/PreferenceInitializer.java b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/prefs/PreferenceInitializer.java
index d1bfc9b..9a3ce6e 100644
--- a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/prefs/PreferenceInitializer.java
+++ b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/prefs/PreferenceInitializer.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- *  Copyright (c) 2007, 2010 IBM Corporation and others.
+ *  Copyright (c) 2007, 2012 IBM Corporation and others.
  *  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
@@ -7,6 +7,7 @@
  * 
  *  Contributors:
  *     IBM Corporation - initial API and implementation
+ *     Ericsson AB (Hamdan Msheik) - Bug 396420 - Control Install dialog through preference customization
  *******************************************************************************/
 package org.eclipse.equinox.internal.p2.ui.sdk.prefs;
 
@@ -38,7 +39,12 @@
 				// don't migrate everything.  Some of the preferences moved to
 				// another bundle.
 				pref.put(PreferenceConstants.PREF_OPEN_WIZARD_ON_ERROR_PLAN, oldPref.get(PreferenceConstants.PREF_OPEN_WIZARD_ON_ERROR_PLAN, MessageDialogWithToggle.PROMPT));
-				pref.putBoolean(PreferenceConstants.PREF_SHOW_LATEST_VERSION, oldPref.getBoolean(PreferenceConstants.PREF_SHOW_LATEST_VERSION, true));
+
+				// if the preference value associated with PREF_SHOW_LATEST_VERSION does not exist do not initialize it
+				String showLatestVersionString = oldPref.get(PreferenceConstants.PREF_SHOW_LATEST_VERSION, null);
+				if (showLatestVersionString != null) {
+					pref.putBoolean(PreferenceConstants.PREF_SHOW_LATEST_VERSION, Boolean.TRUE.toString().equalsIgnoreCase(showLatestVersionString));
+				}
 				pref.flush();
 			}
 		} catch (BackingStoreException e) {
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 e37c2ff..c194b8c 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
@@ -1,5 +1,5 @@
 /*******************************************************************************
- *  Copyright (c) 2007, 2011 IBM Corporation and others.
+ *  Copyright (c) 2007, 2012 IBM Corporation and others.
  *  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
@@ -7,6 +7,7 @@
  * 
  *  Contributors:
  *     IBM Corporation - initial API and implementation
+ *     Ericsson AB (Hamdan Msheik) - Bug 396420 - Control Install dialog through preference customization
  *******************************************************************************/
 
 package org.eclipse.equinox.internal.p2.ui;
@@ -118,11 +119,15 @@
 
 	}
 
+	//Factory method returning a new instance of a IUViewQueryContext
 	public static IUViewQueryContext getQueryContext(Policy policy) {
 		IUViewQueryContext queryContext = new IUViewQueryContext(policy.getGroupByCategory() ? IUViewQueryContext.AVAILABLE_VIEW_BY_CATEGORY : IUViewQueryContext.AVAILABLE_VIEW_FLAT);
-		queryContext.setShowLatestVersionsOnly(policy.getShowLatestVersionsOnly());
 		queryContext.setShowInstallChildren(policy.getShowDrilldownRequirements());
 		queryContext.setShowProvisioningPlanChildren(policy.getShowDrilldownRequirements());
+
+		//among other things the 4 calls below are used to control the available software dialog (AvailableIUPage)
+		queryContext.setShowLatestVersionsOnly(policy.getShowLatestVersionsOnly());
+		queryContext.setHideAlreadyInstalled(policy.getHideAlreadyInstalled());
 		queryContext.setUseCategories(policy.getGroupByCategory());
 		queryContext.setFilterOnEnv(policy.getFilterOnEnv());
 		return queryContext;
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AvailableIUsPage.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AvailableIUsPage.java
index 84f5e93..e72bcc4 100644
--- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AvailableIUsPage.java
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AvailableIUsPage.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2011 IBM Corporation and others.
+ * Copyright (c) 2007, 2012 IBM Corporation and others.
  * 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
@@ -9,6 +9,7 @@
  *     IBM Corporation - initial API and implementation
  *     EclipseSource - ongoing development
  *     Sonatype, Inc. - ongoing development
+ *     Ericsson AB (Hamdan Msheik) - Bug 396420 - Control Install dialog through preference customization
  *******************************************************************************/
 package org.eclipse.equinox.internal.p2.ui.dialogs;
 
@@ -41,6 +42,7 @@
 	private static final String SHOW_LATEST_VERSIONS_ONLY = "ShowLatestVersionsOnly"; //$NON-NLS-1$
 	private static final String HIDE_INSTALLED_IUS = "HideInstalledContent"; //$NON-NLS-1$
 	private static final String RESOLVE_ALL = "ResolveInstallWithAllSites"; //$NON-NLS-1$
+	private static final String FILTER_ON_ENV = "FilterOnEnv"; //$NON-NLS-1$
 	private static final String NAME_COLUMN_WIDTH = "AvailableNameColumnWidth"; //$NON-NLS-1$
 	private static final String VERSION_COLUMN_WIDTH = "AvailableVersionColumnWidth"; //$NON-NLS-1$
 	private static final String LIST_WEIGHT = "AvailableListSashWeight"; //$NON-NLS-1$
@@ -353,12 +355,7 @@
 
 	void updateQueryContext() {
 		queryContext.setShowLatestVersionsOnly(showLatestVersionsCheckbox.getSelection());
-		if (hideInstalledCheckbox.getSelection())
-			queryContext.hideAlreadyInstalled(getProfileId());
-		else {
-			queryContext.showAlreadyInstalled();
-			queryContext.setInstalledProfileId(getProfileId());
-		}
+		queryContext.setHideAlreadyInstalled(hideInstalledCheckbox.getSelection());
 		if (useCategoriesCheckbox.getSelection())
 			queryContext.setViewType(IUViewQueryContext.AVAILABLE_VIEW_BY_CATEGORY);
 		else
@@ -430,26 +427,22 @@
 			IDialogSettings settings = ProvUIActivator.getDefault().getDialogSettings();
 			IDialogSettings section = settings.getSection(DIALOG_SETTINGS_SECTION);
 			String value = null;
-			if (section != null)
+
+			if (section != null) {
 				value = section.get(RESOLVE_ALL);
-			// no section or no value in the section
-			if (value == null)
-				resolveAllCheckbox.setSelection(true);
-			else
 				resolveAllCheckbox.setSelection(section.getBoolean(RESOLVE_ALL));
+			}
+			// no section or no value in the section
+			if (value == null) {
+				resolveAllCheckbox.setSelection(getPolicy().getContactAllSites());
+			}
 		}
 	}
 
 	private void makeQueryContext() {
-		// Make a local query context that is based on the default.
-		IUViewQueryContext defaultQueryContext = ProvUI.getQueryContext(getPolicy());
-		queryContext = new IUViewQueryContext(defaultQueryContext.getViewType());
-		if (defaultQueryContext.getHideAlreadyInstalled()) {
-			queryContext.hideAlreadyInstalled(getProfileId());
-		} else {
-			queryContext.setInstalledProfileId(getProfileId());
-		}
-		queryContext.setShowLatestVersionsOnly(defaultQueryContext.getShowLatestVersionsOnly());
+		queryContext = ProvUI.getQueryContext(getPolicy());
+		queryContext.setInstalledProfileId(getProfileId());
+
 		// Now check for saved away dialog settings
 		IDialogSettings settings = ProvUIActivator.getDefault().getDialogSettings();
 		IDialogSettings section = settings.getSection(DIALOG_SETTINGS_SECTION);
@@ -471,13 +464,11 @@
 				queryContext.setShowLatestVersionsOnly(section.getBoolean(SHOW_LATEST_VERSIONS_ONLY));
 
 			// Hide installed content
-			boolean hideContent = section.getBoolean(HIDE_INSTALLED_IUS);
-			if (hideContent)
-				queryContext.hideAlreadyInstalled(getProfileId());
-			else {
-				queryContext.setInstalledProfileId(getProfileId());
-				queryContext.showAlreadyInstalled();
-			}
+			if (section.get(HIDE_INSTALLED_IUS) != null)
+				queryContext.setHideAlreadyInstalled(section.getBoolean(HIDE_INSTALLED_IUS));
+
+			if (section.get(FILTER_ON_ENV) != null)
+				queryContext.setFilterOnEnv(section.getBoolean(FILTER_ON_ENV));
 		}
 	}
 
@@ -529,6 +520,7 @@
 		section.put(HIDE_INSTALLED_IUS, hideInstalledCheckbox.getSelection());
 		if (resolveAllCheckbox != null)
 			section.put(RESOLVE_ALL, resolveAllCheckbox.getSelection());
+		section.put(FILTER_ON_ENV, filterOnEnvCheckBox.getSelection());
 
 		TreeColumn col = availableIUGroup.getCheckboxTreeViewer().getTree().getColumn(0);
 		section.put(NAME_COLUMN_WIDTH, col.getWidth());
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/query/IUViewQueryContext.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/query/IUViewQueryContext.java
index 8f36fb5..3be0c0e 100644
--- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/query/IUViewQueryContext.java
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/query/IUViewQueryContext.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- *  Copyright (c) 2008, 2010 IBM Corporation and others.
+ *  Copyright (c) 2008, 2012 IBM Corporation and others.
  *  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
@@ -7,6 +7,7 @@
  * 
  *  Contributors:
  *     IBM Corporation - initial API and implementation
+ *     Ericsson AB (Hamdan Msheik) - Bug 396420 - Control Install dialog through preference customization
  *******************************************************************************/
 package org.eclipse.equinox.internal.p2.ui.query;
 
@@ -81,13 +82,8 @@
 		showLatestVersionsOnly = showLatest;
 	}
 
-	public void hideAlreadyInstalled(String installedProfileId) {
-		profileId = installedProfileId;
-		hideAlreadyInstalled = true;
-	}
-
-	public void showAlreadyInstalled() {
-		hideAlreadyInstalled = false;
+	public void setHideAlreadyInstalled(boolean hide) {
+		hideAlreadyInstalled = hide;
 	}
 
 	public boolean getHideAlreadyInstalled() {
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/Policy.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/Policy.java
index 7ffab9d..a944b5f 100644
--- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/Policy.java
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/Policy.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2008, 2011 IBM Corporation and others.
+ * Copyright (c) 2008, 2012 IBM Corporation and others.
  * 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
@@ -7,6 +7,7 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     Ericsson AB (Hamdan Msheik) - Bug 396420 - Control Install dialog through preference customization
  *******************************************************************************/
 package org.eclipse.equinox.p2.ui;
 
@@ -98,6 +99,8 @@
 	private boolean groupByCategory = true;
 	private boolean allowDrilldown = true;
 	private boolean repositoriesVisible = true;
+	private boolean contactAllSites = true;
+	private boolean hideAlreadyInstalled = true;
 	private boolean showLatestVersionsOnly = true;
 	private int restartPolicy = RESTART_POLICY_PROMPT;
 	private String repoPrefPageId;
@@ -446,4 +449,52 @@
 	public void setUpdateDetailsPreferredSize(Point preferredSize) {
 		this.wizardDetailsPreferredSize = preferredSize;
 	}
+
+	/**
+	 * Get a boolean value indicating whether to contact all sites. 
+	 * 
+	 * @return <code>true</code> true if all sites need to be contacted,
+	 * <code>false</code> otherwise.
+	 *
+	 * @since 4.3
+	 */
+	public boolean getContactAllSites() {
+		return this.contactAllSites;
+	}
+
+	/**
+	 * Set a boolean indicating whether all sites need to be contacted.
+	 * 
+	 * @param contactAll <code>true</code> if all sites need to be contacted,
+	 * <code>false</code> otherwise.
+	 *
+	 *  @since 4.3
+	 */
+	public void setContactAllSites(boolean contactAll) {
+		this.contactAllSites = contactAll;
+	}
+
+	/**
+	 * Get a boolean value indicating whether to hide already installed units.
+	 * 
+	 * @return <code>true</code> if already installed units are to be hidden,
+	 * <code>false</code> otherwise.
+	 *
+	 * @since 4.3
+	 */
+	public boolean getHideAlreadyInstalled() {
+		return this.hideAlreadyInstalled;
+	}
+
+	/**
+	 * Set a boolean indicating whether to hide already installed units.
+	 *
+	 * @param hide <code>true</code> if already installed units need to be hidden,
+	 * <code>false</code> otherwise.
+	 *
+	 *  @since 4.3
+	 */
+	public void setHideAlreadyInstalled(boolean hide) {
+		this.hideAlreadyInstalled = hide;
+	}
 }