summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHamdan Msheik2013-02-13 15:41:30 (EST)
committer Pascal Rapicault2013-02-14 11:08:44 (EST)
commit09c95b56130c94ebde8da0ed19d8f3655e5699f9 (patch)
tree2ad338cb4e4c83aaeb42324f4f2c53fda8d578a7
parentde316a4651789c05fdc946d395b31eec50772eab (diff)
downloadrt.equinox.p2-09c95b56130c94ebde8da0ed19d8f3655e5699f9.zip
rt.equinox.p2-09c95b56130c94ebde8da0ed19d8f3655e5699f9.tar.gz
rt.equinox.p2-09c95b56130c94ebde8da0ed19d8f3655e5699f9.tar.bz2
fix for bugs 398932 and 400134
-rw-r--r--bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdateScheduler.java108
-rw-r--r--bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/ProvUIMessages.java14
-rw-r--r--bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AbstractImportPage_c.java127
-rw-r--r--bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AbstractPage_c.java781
-rw-r--r--bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/ImportFromInstallationPage_c.java437
-rw-r--r--bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/ImportFromInstallationWizard_c.java71
-rw-r--r--bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/messages.properties15
7 files changed, 1533 insertions, 20 deletions
diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdateScheduler.java b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdateScheduler.java
index 3e84a3a..07e0134 100644
--- a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdateScheduler.java
+++ b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdateScheduler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2013 IBM Corporation and others.
+ * Copyright (c) 2008, 2011 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,13 +7,20 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
- * Ericsson AB - ongoing development
+ * Ericsson AB - (Pascal Rapicault)
+ * Ericsson AB (Hamdan Msheik) - Bug 398833
*******************************************************************************/
package org.eclipse.equinox.internal.p2.ui.sdk.scheduler;
+import org.eclipse.equinox.internal.p2.ui.dialogs.AbstractPage_c;
+import org.eclipse.equinox.internal.p2.ui.dialogs.ImportFromInstallationWizard_c;
+
import com.ibm.icu.util.Calendar;
import com.ibm.icu.util.ULocale;
+import java.util.Set;
import org.eclipse.core.runtime.*;
+import org.eclipse.core.runtime.preferences.ConfigurationScope;
+import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.internal.p2.garbagecollector.GarbageCollector;
import org.eclipse.equinox.internal.provisional.p2.updatechecker.*;
@@ -21,10 +28,11 @@ import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.IProfileRegistry;
import org.eclipse.equinox.p2.engine.query.IUProfilePropertyQuery;
+import org.eclipse.equinox.p2.engine.query.UserVisibleRootQuery;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.query.IQuery;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.*;
@@ -32,7 +40,7 @@ import org.eclipse.ui.statushandlers.StatusManager;
/**
* This plug-in is loaded on startup to register with the update checker.
- *
+ *
* @since 3.5
*/
public class AutomaticUpdateScheduler implements IStartup {
@@ -82,10 +90,58 @@ public class AutomaticUpdateScheduler implements IStartup {
}
public void earlyStartup() {
- if (baseChanged())
- return;
- garbageCollect();
- scheduleUpdate();
+
+ IProvisioningAgent agent = (IProvisioningAgent) ServiceHelper.getService(AutomaticUpdatePlugin.getContext(), IProvisioningAgent.SERVICE_NAME);
+ IProfileRegistry registry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
+ IProfile currentProfile = registry.getProfile(profileId);
+
+ boolean testing = System.getProperty("ignoreMigrationWizard") == null ? false : System.getProperty("ignoreMigrationWizard").equalsIgnoreCase("true") == true ? true : false;
+
+ if (baseChanged(agent, registry, currentProfile) && !testing) {
+
+ IScopeContext[] contexts = new IScopeContext[] {ConfigurationScope.INSTANCE};
+ boolean remindMeLater = Platform.getPreferencesService().getBoolean("org.eclipse.equinox.p2.ui", AbstractPage_c.REMIND_ME_LATER, true, contexts);
+
+ final IProfile previousProfile = findProfileBeforeReset(registry, currentProfile);
+
+ if (previousProfile != null && currentProfile != null) {
+ if (isCurrentProfileLacksUnitsFromPrevious(previousProfile, currentProfile)) {
+ if (remindMeLater) {
+ openMigrationWizard(previousProfile);
+ }
+ }
+ }
+
+ } else {
+ garbageCollect();
+ scheduleUpdate();
+ }
+ }
+
+ /**
+ * @param previousProfile is the profile used previous to the current one
+ * @param currentProfile is the current profile used by eclipse.
+ * @return true if set difference between previousProfile units and currentProfile units not empty, otherwise false
+ */
+ private boolean isCurrentProfileLacksUnitsFromPrevious(IProfile previousProfile, IProfile currentProfile) {
+
+ Set<IInstallableUnit> previousProfileUnits = previousProfile.query(new UserVisibleRootQuery(), null).toSet();
+ Set<IInstallableUnit> currentProfileUnits = currentProfile.available(new UserVisibleRootQuery(), null).toSet();
+ previousProfileUnits.removeAll(currentProfileUnits);
+ return !previousProfileUnits.isEmpty();
+
+ }
+
+ private void openMigrationWizard(final IProfile inputProfile) {
+
+ Display d = Display.getDefault();
+ d.asyncExec(new Runnable() {
+ public void run() {
+ WizardDialog migrateWizard = new WizardDialog(getWorkbenchWindowShell(), new ImportFromInstallationWizard_c(inputProfile));
+ migrateWizard.create();
+ migrateWizard.open();
+ }
+ });
}
Shell getWorkbenchWindowShell() {
@@ -94,9 +150,8 @@ public class AutomaticUpdateScheduler implements IStartup {
}
- private boolean baseChanged() {
- IProvisioningAgent agent = (IProvisioningAgent) ServiceHelper.getService(AutomaticUpdatePlugin.getContext(), IProvisioningAgent.SERVICE_NAME);
- IProfileRegistry registry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
+ private boolean baseChanged(IProvisioningAgent agent, IProfileRegistry registry, IProfile profile) {
+
//Access the running profile to force its reinitialization if it has not been done.
registry.getProfile(IProfileRegistry.SELF);
String resetState = (String) agent.getService(IProfileRegistry.SERVICE_SHARED_INSTALL_NEW_TIMESTAMP);
@@ -113,17 +168,30 @@ public class AutomaticUpdateScheduler implements IStartup {
AutomaticUpdatePlugin.getDefault().getPreferenceStore().setValue(PREF_MIGRATION_DIALOG_SHOWN, resetState);
AutomaticUpdatePlugin.getDefault().savePreferences();
- Display d = Display.getDefault();
- d.asyncExec(new Runnable() {
- public void run() {
- MessageDialog.openWarning(getWorkbenchWindowShell(), "Installation modified", "An upgrade of the eclipse installation you are using has been performed. The plugins you had installed have been uninstalled. Look for more improvements to this dialog in Kepler M6 (http://bugs.eclipse.org/398833"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- });
+ // Display d = Display.getDefault();
+ // d.asyncExec(new Runnable() {
+ // public void run() {
+ // MessageDialog.openWarning(getWorkbenchWindowShell(), "Installation modified", "An upgrade of the eclipse installation you are using has been performed. The plugins you had installed have been uninstalled. Look for more improvements to this dialog in Kepler M6 (http://bugs.eclipse.org/398833"); //$NON-NLS-1$ //$NON-NLS-2$
+ // }
+ // });
return true;
}
+ private IProfile findProfileBeforeReset(IProfileRegistry registry, IProfile profile) {
+
+ long[] history = registry.listProfileTimestamps(profile.getProfileId());
+ int index = history.length - 1;
+ boolean found = false;
+ while (!(found = IProfile.STATE_SHARED_INSTALL_VALUE_BEFOREFLUSH.equals(registry.getProfileStateProperties(profile.getProfileId(), history[index]).get(IProfile.STATE_PROP_SHARED_INSTALL))) && index > 0) {
+ index--;
+ }
+ if (!found)
+ return null;
+ return registry.getProfile(profile.getProfileId(), history[index]);
+ }
+
/**
- * Invokes the garbage collector to discard unused plugins, if specified by a
+ * Invokes the garbage collector to discard unused plugins, if specified by a
* corresponding preference.
*/
private void garbageCollect() {
@@ -179,7 +247,7 @@ public class AutomaticUpdateScheduler implements IStartup {
delay = computeDelay(pref);
poll = computePoll(pref);
}
- // We do not access the AutomaticUpdater directly when we register
+ // We do not access the AutomaticUpdater directly when we register
// the listener. This prevents the UI classes from being started up
// too soon.
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=227582
@@ -195,7 +263,7 @@ public class AutomaticUpdateScheduler implements IStartup {
private IQuery<IInstallableUnit> getProfileQuery() {
// We specifically avoid using the default policy's root property so that we don't load all the
- // p2 UI classes in doing so.
+ // p2 UI classes in doing so.
return new IUProfilePropertyQuery(IProfile.PROP_PROFILE_ROOT_IU, Boolean.TRUE.toString());
}
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/ProvUIMessages.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/ProvUIMessages.java
index eb62ed9..9a66141 100644
--- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/ProvUIMessages.java
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/ProvUIMessages.java
@@ -258,4 +258,18 @@ public class ProvUIMessages extends NLS {
public static String UserValidationDialog_SavePasswordButton;
public static String UserValidationDialog_UsernameLabel;
+ public static String AbstractImportPage_HigherVersionInstalled;
+ public static String AbstractImportPage_SameVersionInstalled;
+ public static String Column_Id;
+ public static String Column_Name;
+ public static String Column_Version;
+ public static String AbstractPage_ButtonSelectAll;
+ public static String AbstractPage_ButtonDeselectAll;
+ public static String PAGE_NOINSTALLTION_ERROR;
+ public static String ImportFromInstallationPage_DIALOG_DESCRIPTION;
+ public static String ImportFromInstallationPage_SELECT_COMPONENT;
+ public static String ImportFromInstallationPage_DIALOG_TITLE;
+ public static String ImportWizard_WINDOWTITLE;
+ public static String ImportFromInstallationPage_INVALID_DESTINATION;
+ public static String REMIND_ME_TO_MIGRATE_LATER;
}
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AbstractImportPage_c.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AbstractImportPage_c.java
new file mode 100644
index 0000000..e17a425
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AbstractImportPage_c.java
@@ -0,0 +1,127 @@
+/*******************************************************************************
+ * Copyright (c) 2011 WindRiver 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * WindRiver Corporation - initial API and implementation
+ * Ericsson AB (Pascal Rapicault) - Bug 395210
+ * Ericsson AB (Hamdan Msheik) - Bug 398833
+ *******************************************************************************/
+package org.eclipse.equinox.internal.p2.ui.dialogs;
+
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.equinox.internal.p2.ui.ProvUI;
+import org.eclipse.equinox.internal.p2.ui.ProvUIMessages;
+import org.eclipse.equinox.p2.engine.IProfile;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.VersionRange;
+import org.eclipse.equinox.p2.query.IQueryResult;
+import org.eclipse.equinox.p2.query.QueryUtil;
+import org.eclipse.equinox.p2.ui.ProvisioningUI;
+import org.eclipse.jface.viewers.ICheckStateProvider;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.*;
+
+public abstract class AbstractImportPage_c extends AbstractPage_c {
+
+ IProfile profile = null;
+ private final ProvisioningOperationWizard wizard;
+ private final ProvisioningUI ui;
+
+ public AbstractImportPage_c(String pageName, ProvisioningUI ui, ProvisioningOperationWizard wizard) {
+ super(pageName);
+ this.wizard = wizard;
+ this.ui = ui;
+ profile = getSelfProfile();
+ }
+
+ protected ProvisioningOperationWizard getProvisioningWizard() {
+ return wizard;
+ }
+
+ protected ProvisioningUI getProvisioningUI() {
+ return ui;
+ }
+
+ @Override
+ protected void createInstallationTable(Composite parent) {
+ super.createInstallationTable(parent);
+ viewer.getTree().addListener(SWT.Selection, new Listener() {
+
+ public void handleEvent(Event event) {
+ if (event.detail == SWT.CHECK) {
+ if (hasInstalled(ProvUI.getAdapter(event.item.getData(), IInstallableUnit.class))) {
+ viewer.getTree().setRedraw(false);
+ ((TreeItem) event.item).setChecked(false);
+ viewer.getTree().setRedraw(true);
+ }
+ }
+ updatePageCompletion();
+ }
+ });
+ }
+
+ public boolean hasInstalled(IInstallableUnit iu) {
+ IQueryResult<IInstallableUnit> results = profile.query(QueryUtil.createIUQuery(iu.getId(), new VersionRange(iu.getVersion(), true, null, false)), null);
+ return !results.isEmpty();
+ }
+
+ public String getIUNameWithDetail(IInstallableUnit iu) {
+ IQueryResult<IInstallableUnit> results = profile.query(QueryUtil.createIUQuery(iu.getId(), new VersionRange(iu.getVersion(), true, null, false)), null);
+ String text = iu.getProperty(IProfile.PROP_NAME, null);
+ text = (text != null) ? text : iu.getId();
+ if (!results.isEmpty()) {
+ boolean hasHigherVersion = false;
+ boolean hasEqualVersion = false;
+ for (IInstallableUnit installedIU : results.toSet()) {
+ int compareValue = installedIU.getVersion().compareTo(iu.getVersion());
+ if (compareValue > 0) {
+ hasHigherVersion = true;
+ break;
+ } else if (compareValue == 0)
+ hasEqualVersion = true;
+ }
+ if (hasHigherVersion)
+ return NLS.bind(ProvUIMessages.AbstractImportPage_HigherVersionInstalled, text);
+ else if (hasEqualVersion)
+ return NLS.bind(ProvUIMessages.AbstractImportPage_SameVersionInstalled, text);
+ }
+ return text;
+ }
+
+ @Override
+ protected ICheckStateProvider getViewerDefaultState() {
+ return new ICheckStateProvider() {
+
+ public boolean isGrayed(Object element) {
+ return false;
+ }
+
+ public boolean isChecked(Object element) {
+ if (profile != null) {
+ IInstallableUnit iu = ProvUI.getAdapter(element, IInstallableUnit.class);
+ IQueryResult<IInstallableUnit> collector = profile.query(QueryUtil.createIUQuery(iu.getId(), new VersionRange(iu.getVersion(), true, null, false)), new NullProgressMonitor());
+ if (collector.isEmpty()) {
+ return true;
+ }
+ }
+ return false;
+ }
+ };
+ }
+
+ @Override
+ protected void doFinish() throws Exception {
+ // do nothing
+ }
+
+ @Override
+ public boolean canFlipToNextPage() {
+ return isPageComplete();
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AbstractPage_c.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AbstractPage_c.java
new file mode 100644
index 0000000..9ba8020
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AbstractPage_c.java
@@ -0,0 +1,781 @@
+/*******************************************************************************
+ * Copyright (c) 2011 WindRiver 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * WindRiver Corporation - initial API and implementation
+ * IBM Corporation - Ongoing development
+ * Ericsson AB (Pascal Rapicault) - Bug 387115 - Allow to export everything
+ * Ericsson AB (Hamdan Msheik) - Bug 398833
+ *******************************************************************************/
+package org.eclipse.equinox.internal.p2.ui.dialogs;
+
+import java.util.*;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+import org.eclipse.core.runtime.preferences.ConfigurationScope;
+import org.eclipse.equinox.internal.p2.ui.*;
+import org.eclipse.equinox.internal.p2.ui.model.InstalledIUElement;
+import org.eclipse.equinox.internal.p2.ui.viewers.*;
+import org.eclipse.equinox.p2.core.IProvisioningAgent;
+import org.eclipse.equinox.p2.engine.IProfile;
+import org.eclipse.equinox.p2.engine.IProfileRegistry;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.*;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.*;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.ui.dialogs.FilteredTree;
+import org.eclipse.ui.dialogs.PatternFilter;
+import org.eclipse.ui.progress.DeferredTreeContentManager;
+import org.eclipse.ui.progress.WorkbenchJob;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.prefs.BackingStoreException;
+import org.osgi.service.prefs.Preferences;
+import org.osgi.util.tracker.ServiceTracker;
+
+public abstract class AbstractPage_c extends WizardPage implements Listener {
+
+ protected String currentMessage;
+ // protected Button destinationBrowseButton;
+ protected Button remindMeButton;
+ protected CheckboxTreeViewer viewer = null;
+ protected Exception finishException;
+ protected boolean entryChanged = false;
+ protected static IProfileRegistry profileRegistry = null;
+ static IProvisioningAgent agent = null;
+
+ public static final String REMIND_ME_LATER = "remindMeToMigrateLater";
+ // dialog store id constants
+ // private static final String STORE_DESTINATION_NAMES_ID = "P2ImportExportPage.STORE_DESTINATION_NAMES_ID";//$NON-NLS-1$
+
+ protected static final int COMBO_HISTORY_LENGTH = 5;
+
+ /**
+ * {@link DelayedFilterCheckboxTree} has a timing bug to prevent restoring the check state,
+ * the methods {@link DeferredTreeContentManager}'s runClearPlaceholderJob and
+ * DelayedFilterCheckboxTree.doCreateRefreshJob().new JobChangeAdapter() {...}.done(IJobChangeEvent) has timing issue,
+ * I can't find a way to guarantee the first job is executed firstly
+ *
+ */
+ final class ImportExportFilteredTree extends FilteredTree {
+ ArrayList<Object> checkState = new ArrayList<Object>();
+
+ ImportExportFilteredTree(Composite parent, int treeStyle, PatternFilter filter, boolean useNewLook) {
+ super(parent, treeStyle, filter, useNewLook);
+ }
+
+ @Override
+ protected TreeViewer doCreateTreeViewer(Composite composite, int style) {
+ return new CheckboxTreeViewer(composite, style);
+ }
+
+ @Override
+ protected WorkbenchJob doCreateRefreshJob() {
+ WorkbenchJob job = super.doCreateRefreshJob();
+ job.addJobChangeListener(new JobChangeAdapter() {
+ @Override
+ public void aboutToRun(IJobChangeEvent event) {
+ Display.getDefault().syncExec(new Runnable() {
+
+ public void run() {
+ Object[] checked = viewer.getCheckedElements();
+ if (checkState == null)
+ checkState = new ArrayList<Object>(checked.length);
+ for (int i = 0; i < checked.length; i++)
+ if (!viewer.getGrayed(checked[i]))
+ if (!checkState.contains(checked[i]))
+ checkState.add(checked[i]);
+ }
+ });
+ }
+
+ @Override
+ public void done(IJobChangeEvent event) {
+ if (event.getResult().isOK()) {
+ Display.getDefault().asyncExec(new Runnable() {
+
+ public void run() {
+ if (viewer == null || viewer.getTree().isDisposed())
+ return;
+ if (checkState == null)
+ return;
+
+ viewer.setCheckedElements(new Object[0]);
+ viewer.setGrayedElements(new Object[0]);
+ // Now we are only going to set the check state of the leaf nodes
+ // and rely on our container checked code to update the parents properly.
+ Iterator<Object> iter = checkState.iterator();
+ while (iter.hasNext()) {
+ viewer.setChecked(iter.next(), true);
+ }
+
+ updatePageCompletion();
+ }
+ });
+ }
+ }
+ });
+ return job;
+ }
+ }
+
+ class TreeViewerComparator extends ViewerComparator {
+ private int sortColumn = 0;
+ private int lastSortColumn = 0;
+ private boolean ascending = false;
+ private boolean lastAscending = false;
+
+ @Override
+ public int compare(Viewer viewer1, Object e1, Object e2) {
+ IInstallableUnit iu1 = ProvUI.getAdapter(e1, IInstallableUnit.class);
+ IInstallableUnit iu2 = ProvUI.getAdapter(e2, IInstallableUnit.class);
+ if (iu1 != null && iu2 != null) {
+ if (viewer1 instanceof TreeViewer) {
+ TreeViewer treeViewer = (TreeViewer) viewer1;
+ IBaseLabelProvider baseLabel = treeViewer.getLabelProvider();
+ if (baseLabel instanceof ITableLabelProvider) {
+ ITableLabelProvider tableProvider = (ITableLabelProvider) baseLabel;
+ String e1p = tableProvider.getColumnText(e1, getSortColumn());
+ String e2p = tableProvider.getColumnText(e2, getSortColumn());
+ @SuppressWarnings("unchecked")
+ int result = getComparator().compare(e1p, e2p);
+ // Secondary column sort
+ if (result == 0) {
+ e1p = tableProvider.getColumnText(e1, lastSortColumn);
+ e2p = tableProvider.getColumnText(e2, lastSortColumn);
+ @SuppressWarnings("unchecked")
+ int result2 = getComparator().compare(e1p, e2p);
+ return lastAscending ? result2 : (-1) * result2;
+ }
+ return isAscending() ? result : (-1) * result;
+ }
+ }
+ // we couldn't determine a secondary sort, call it equal
+ return 0;
+ }
+ return super.compare(viewer1, e1, e2);
+ }
+
+ /**
+ * @return Returns the sortColumn.
+ */
+ public int getSortColumn() {
+ return sortColumn;
+ }
+
+ /**
+ * @param sortColumn
+ * The sortColumn to set.
+ */
+ public void setSortColumn(int sortColumn) {
+ if (this.sortColumn != sortColumn) {
+ lastSortColumn = this.sortColumn;
+ lastAscending = this.ascending;
+ this.sortColumn = sortColumn;
+ }
+ }
+
+ /**
+ * @return Returns the ascending.
+ */
+ public boolean isAscending() {
+ return ascending;
+ }
+
+ /**
+ * @param ascending
+ * The ascending to set.
+ */
+ public void setAscending(boolean ascending) {
+ this.ascending = ascending;
+ }
+ }
+
+ static {
+ BundleContext context = Platform.getBundle(ProvUIActivator.PLUGIN_ID).getBundleContext();
+ ServiceTracker<IProvisioningAgent, IProvisioningAgent> tracker = new ServiceTracker<IProvisioningAgent, IProvisioningAgent>(context, IProvisioningAgent.class, null);
+ tracker.open();
+ agent = tracker.getService();
+ tracker.close();
+ if (agent != null)
+ profileRegistry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
+ }
+
+ public AbstractPage_c(String pageName) {
+ super(pageName);
+ }
+
+ public AbstractPage_c(String pageName, String title, ImageDescriptor titleImage) {
+ super(pageName, title, titleImage);
+ }
+
+ protected IProfile getSelfProfile() {
+ if (profileRegistry != null) {
+ String selfID = System.getProperty("eclipse.p2.profile"); //$NON-NLS-1$
+ if (selfID == null)
+ selfID = IProfileRegistry.SELF;
+ return profileRegistry.getProfile(selfID);
+ }
+ return null;
+ }
+
+ private void createColumns(TreeViewer treeViewer) {
+ String[] titles = {ProvUIMessages.Column_Name, ProvUIMessages.Column_Version, ProvUIMessages.Column_Id};
+ for (int i = 0; i < titles.length; i++) {
+ TreeViewerColumn column = new TreeViewerColumn(treeViewer, SWT.NONE);
+ column.getColumn().setText(titles[i]);
+ column.getColumn().setResizable(true);
+ column.getColumn().setMoveable(true);
+ if (ProvUIMessages.Column_Name.equals(titles[i]))
+ updateTableSorting(i);
+ final int columnIndex = i;
+ column.getColumn().addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ updateTableSorting(columnIndex);
+ }
+ });
+ }
+ }
+
+ protected void updateTableSorting(int columnIndex) {
+ TreeViewerComparator comparator = (TreeViewerComparator) viewer.getComparator();
+ // toggle direction if it's the same column
+ if (columnIndex == comparator.getSortColumn()) {
+ comparator.setAscending(!comparator.isAscending());
+ }
+ comparator.setSortColumn(columnIndex);
+ viewer.getTree().setSortColumn(viewer.getTree().getColumn(columnIndex));
+ viewer.getTree().setSortDirection(comparator.isAscending() ? SWT.UP : SWT.DOWN);
+ viewer.refresh(false);
+ }
+
+ protected abstract void createContents(Composite composite);
+
+ public void createControl(Composite parent) {
+ initializeDialogUnits(parent);
+ // initializeService();
+ Composite composite = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout(1, true);
+ layout.horizontalSpacing = 0;
+ layout.verticalSpacing = 5;
+ composite.setLayout(layout);
+ composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL));
+
+ createContents(composite);
+
+ // can not finish initially, but don't want to start with an error
+ // message either
+ if (!(validateOptionsGroup())) {
+ setPageComplete(false);
+ }
+
+ setControl(composite);
+ // giveFocusToDestination();
+ Dialog.applyDialogFont(composite);
+ }
+
+ protected void createRemindMeGroup(Composite parent) {
+
+ remindMeButton = new Button(parent, SWT.CHECK);
+ remindMeButton.setText(ProvUIMessages.REMIND_ME_TO_MIGRATE_LATER);
+ remindMeButton.setSelection(true);
+ GridData dataRemindMeButton = new GridData();
+ dataRemindMeButton.horizontalSpan = 3;
+ remindMeButton.setLayoutData(dataRemindMeButton);
+
+ remindMeButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+
+ Preferences prefs = ConfigurationScope.INSTANCE.getNode("org.eclipse.equinox.p2.ui"); //$NON-NLS-1$
+ prefs.putBoolean(REMIND_ME_LATER, ((Button) (e.widget)).getSelection());
+
+ try {
+ prefs.flush();
+ } catch (BackingStoreException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ }
+ });
+
+ }
+
+ // protected void createDestinationGroup(Composite parent, boolean includeButton) {
+ // Composite composite = new Composite(parent, SWT.BORDER);
+ // GridLayout layout = new GridLayout();
+ // layout.numColumns = 3;
+ // composite.setLayout(layout);
+ // composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
+ //
+ // Label label = new Label(composite, SWT.NONE);
+ // label.setText(getDestinationLabel());
+ //
+ // destinationNameField = new Combo(composite, SWT.SINGLE | SWT.BORDER);
+ // restoreWidgetValues();
+ // GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
+ // destinationNameField.setLayoutData(data);
+ // destinationNameField.addSelectionListener(new SelectionAdapter() {
+ // public void widgetSelected(SelectionEvent e) {
+ // handleDestinationChanged(getDestinationValue());
+ // }
+ // });
+ // destinationNameField.addKeyListener(new KeyListener() {
+ //
+ // /*
+ // * @see KeyListener.keyPressed
+ // */
+ // public void keyPressed(KeyEvent e) {
+ // if (e.character == SWT.CR) {
+ // entryChanged = false;
+ // handleDestinationChanged(getDestinationValue());
+ // }
+ // }
+ //
+ // public void keyReleased(KeyEvent e) {
+ // // do nothing
+ // }
+ // });
+ // destinationNameField.addModifyListener(new ModifyListener() {
+ // public void modifyText(ModifyEvent e) {
+ // entryChanged = true;
+ // }
+ // });
+ // destinationNameField.addFocusListener(new FocusListener() {
+ // /*
+ // * @see FocusListener.focusGained(FocusEvent)
+ // */
+ // public void focusGained(FocusEvent e) {
+ // //Do nothing when getting focus
+ // }
+ //
+ // /*
+ // * @see FocusListener.focusLost(FocusEvent)
+ // */
+ // public void focusLost(FocusEvent e) {
+ // //Clear the flag to prevent constant update
+ // if (entryChanged) {
+ // entryChanged = false;
+ // handleDestinationChanged(getDestinationValue());
+ // }
+ //
+ // }
+ // });
+ //
+ // destinationBrowseButton = new Button(composite, SWT.PUSH);
+ // destinationBrowseButton.setText(Messages.Page_BUTTON_BROWSER);
+ // destinationBrowseButton.addListener(SWT.Selection, this);
+ // destinationBrowseButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
+ //
+ // if (includeButton) {
+ // includeAllButton = new Button(composite, SWT.CHECK);
+ // includeAllButton.setText(Messages.ExportPage_EntriesNotInRepo);
+ // includeAllButton.setSelection(allowExportWithoutRepositoryReference());
+ // GridData dataIncludeButton = new GridData();
+ // dataIncludeButton.horizontalSpan = 3;
+ // includeAllButton.setLayoutData(dataIncludeButton);
+ // }
+ // }
+ //
+ // private boolean allowExportWithoutRepositoryReference() {
+ // return Platform.getPreferencesService().getBoolean(Constants.Bundle_ID, Constants.PREF_IU_WITHOUT_REPO, false, new IScopeContext[] {DefaultScope.INSTANCE});
+ // }
+
+ protected IUColumnConfig[] getColumnConfig() {
+ return new IUColumnConfig[] {new IUColumnConfig(ProvUIMessages.ProvUI_NameColumnTitle, IUColumnConfig.COLUMN_NAME, ILayoutConstants.DEFAULT_PRIMARY_COLUMN_WIDTH), new IUColumnConfig(ProvUIMessages.ProvUI_VersionColumnTitle, IUColumnConfig.COLUMN_VERSION, ILayoutConstants.DEFAULT_SMALL_COLUMN_WIDTH), new IUColumnConfig(ProvUIMessages.ProvUI_IdColumnTitle, IUColumnConfig.COLUMN_ID, ILayoutConstants.DEFAULT_COLUMN_WIDTH)};
+ }
+
+ protected void createInstallationTable(final Composite parent) {
+ Group group = new Group(parent, SWT.NONE);
+ GridData griddata = new GridData(GridData.FILL, GridData.FILL, true, true);
+ griddata.verticalSpan = griddata.horizontalSpan = 0;
+ group.setLayoutData(griddata);
+ group.setLayout(new GridLayout(1, false));
+ PatternFilter filter = getPatternFilter();
+ filter.setIncludeLeadingWildcard(true);
+ final ImportExportFilteredTree filteredTree = new ImportExportFilteredTree(group, SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, filter, true);
+ viewer = (CheckboxTreeViewer) filteredTree.getViewer();
+ final Tree tree = viewer.getTree();
+ tree.setHeaderVisible(true);
+ tree.setLinesVisible(false);
+ viewer.setComparator(new TreeViewerComparator());
+ viewer.setComparer(new ProvElementComparer());
+ createColumns(viewer);
+ final ITreeContentProvider contentProvider = getContentProvider();
+ viewer.setContentProvider(contentProvider);
+ viewer.setLabelProvider(getLabelProvider());
+ viewer.addCheckStateListener(new ICheckStateListener() {
+
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ if (!event.getChecked() && filteredTree.checkState != null) {
+ ArrayList<Object> toRemove = new ArrayList<Object>(1);
+ // See bug 258117. Ideally we would get check state changes
+ // for children when the parent state changed, but we aren't, so
+ // we need to remove all children from the additive check state
+ // cache.
+ if (contentProvider.hasChildren(event.getElement())) {
+ Set<Object> unchecked = new HashSet<Object>();
+ Object[] children = contentProvider.getChildren(event.getElement());
+ for (int i = 0; i < children.length; i++) {
+ unchecked.add(children[i]);
+ }
+ Iterator<Object> iter = filteredTree.checkState.iterator();
+ while (iter.hasNext()) {
+ Object current = iter.next();
+ if (current != null && unchecked.contains(current)) {
+ toRemove.add(current);
+ }
+ }
+ } else {
+ for (Object element : filteredTree.checkState) {
+ if (viewer.getComparer().equals(element, event.getElement())) {
+ toRemove.add(element);
+ // Do not break out of the loop. We may have duplicate equal
+ // elements in the cache. Since the cache is additive, we want
+ // to be sure we've gotten everything.
+ }
+ }
+ }
+ filteredTree.checkState.removeAll(toRemove);
+ }
+ }
+ });
+ parent.addControlListener(new ControlAdapter() {
+ private final int[] columnRate = new int[] {6, 2, 2};
+
+ @Override
+ public void controlResized(ControlEvent e) {
+ Rectangle area = parent.getClientArea();
+ Point size = tree.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ ScrollBar vBar = tree.getVerticalBar();
+ int width = area.width - tree.computeTrim(0, 0, 0, 0).width - vBar.getSize().x;
+ if (size.y > area.height + tree.getHeaderHeight()) {
+ // Subtract the scrollbar width from the total column width
+ // if a vertical scrollbar will be required
+ Point vBarSize = vBar.getSize();
+ width -= vBarSize.x;
+ }
+ Point oldSize = tree.getSize();
+ TreeColumn[] columns = tree.getColumns();
+ int hasUsed = 0, i = 0;
+ if (oldSize.x > area.width) {
+ // table is getting smaller so make the columns
+ // smaller first and then resize the table to
+ // match the client area width
+ for (; i < columns.length - 1; i++) {
+ columns[i].setWidth(width * columnRate[i] / 10);
+ hasUsed += columns[i].getWidth();
+ }
+ columns[columns.length - 1].setWidth(width - hasUsed);
+ tree.setSize(area.width, area.height);
+ } else {
+ // table is getting bigger so make the table
+ // bigger first and then make the columns wider
+ // to match the client area width
+ tree.setSize(area.width, area.height);
+ for (; i < columns.length - 1; i++) {
+ columns[i].setWidth(width * columnRate[i] / 10);
+ hasUsed += columns[i].getWidth();
+ }
+ columns[columns.length - 1].setWidth(width - hasUsed);
+ }
+ }
+ });
+ ICheckStateProvider provider = getViewerDefaultState();
+ if (provider != null)
+ viewer.setCheckStateProvider(provider);
+ else
+ viewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ updatePageCompletion();
+ }
+ });
+ viewer.getControl().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
+ viewer.getControl().setSize(300, 200);
+ viewer.setInput(getInput());
+ Composite buttons = new Composite(group, SWT.NONE);
+ buttons.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
+ buttons.setLayout(new RowLayout(SWT.HORIZONTAL));
+ Button selectAll = new Button(buttons, SWT.PUSH);
+ selectAll.setText(ProvUIMessages.AbstractPage_ButtonSelectAll);
+ selectAll.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ for (TreeItem item : viewer.getTree().getItems()) {
+ if (!item.getChecked()) {
+ item.setChecked(true);
+ Event event = new Event();
+ event.widget = item.getParent();
+ event.detail = SWT.CHECK;
+ event.item = item;
+ event.type = SWT.Selection;
+ viewer.getTree().notifyListeners(SWT.Selection, event);
+ }
+ }
+ updatePageCompletion();
+ }
+ });
+ Button deselectAll = new Button(buttons, SWT.PUSH);
+ deselectAll.setText(ProvUIMessages.AbstractPage_ButtonDeselectAll);
+ deselectAll.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ for (TreeItem item : viewer.getTree().getItems()) {
+ viewer.setSubtreeChecked(item.getData(), false);
+ }
+ updatePageCompletion();
+ }
+ });
+ }
+
+ protected PatternFilter getPatternFilter() {
+ return new AvailableIUPatternFilter(getColumnConfig());
+ }
+
+ protected ICheckStateProvider getViewerDefaultState() {
+ return null;
+ }
+
+ protected ITableLabelProvider getLabelProvider() {
+ return new IUDetailsLabelProvider(null, getColumnConfig(), null);
+ }
+
+ protected ITreeContentProvider getContentProvider() {
+ ProvElementContentProvider provider = new ProvElementContentProvider() {
+ @Override
+ public boolean hasChildren(Object element) {
+ if (element instanceof InstalledIUElement)
+ return false;
+ return super.hasChildren(element);
+ }
+
+ @Override
+ public Object[] getChildren(Object parent) {
+ if (parent instanceof InstalledIUElement)
+ return new Object[0];
+ return super.getChildren(parent);
+ }
+ };
+ return provider;
+ }
+
+ protected boolean determinePageCompletion() {
+ currentMessage = null;
+ // validate groups in order of priority so error message is the most important one
+ boolean complete = validateOptionsGroup();
+
+ // Avoid draw flicker by not clearing the error
+ // message unless all is valid.
+ if (complete) {
+ setErrorMessage(null);
+ } else {
+ setErrorMessage(currentMessage);
+ }
+
+ return complete;
+ }
+
+ protected abstract void doFinish() throws Exception;
+
+ protected int getBrowseDialogStyle() {
+ return SWT.OPEN;
+ }
+
+ // /**
+ // * returns the destination label
+ // * @return non null string
+ // */
+ // protected abstract String getDestinationLabel();
+
+ // /**
+ // * Answer the contents of self's destination specification widget
+ // *
+ // * @return java.lang.String
+ // */
+ // protected String getDestinationValue() {
+ // return destinationNameField.getText().trim();
+ // }
+
+ /**
+ * return the title of dialog
+ * @return non null string
+ */
+ protected abstract String getDialogTitle();
+
+ protected abstract Object getInput();
+
+ protected abstract String getInvalidDestinationMessage();
+
+ protected String getNoOptionsMessage() {
+ return ProvUIMessages.PAGE_NOINSTALLTION_ERROR;
+ }
+
+ // protected abstract void giveFocusToDestination();
+
+ // /**
+ // * Open an appropriate destination browser so that the user can specify a
+ // * source to import from
+ // */
+ // protected void handleDestinationBrowseButtonPressed() {
+ // FileDialog dialog = new FileDialog(getContainer().getShell(), getBrowseDialogStyle() | SWT.SHEET);
+ // dialog.setText(getDialogTitle());
+ // dialog.setFilterPath(getDestinationValue());
+ // dialog.setFilterExtensions(new String[] {Messages.EXTENSION_p2F, Messages.EXTENSION_ALL});
+ // dialog.setFilterNames(new String[] {Messages.EXTENSION_p2F_NAME, Messages.EXTENSION_ALL_NAME});
+ // String selectedFileName = dialog.open();
+ //
+ // if (selectedFileName != null) {
+ // if (!selectedFileName.endsWith(Messages.EXTENSION_p2F.substring(1)))
+ // selectedFileName += Messages.EXTENSION_p2F.substring(1);
+ // setDestinationValue(selectedFileName);
+ // handleDestinationChanged(selectedFileName);
+ // }
+ // }
+
+ //TODO remove the implementation of Listener
+ public void handleEvent(Event event) {
+ // Widget source = event.widget;
+ //
+ // if (source == destinationBrowseButton) {
+ // handleDestinationBrowseButtonPressed();
+ // }
+ // updatePageCompletion();
+ }
+
+ // protected void handleDestinationChanged(String newDestination) {
+ // // do nothing
+ // }
+
+ // protected void initializeService() {
+ // ServiceTracker<P2ImportExport, P2ImportExport> tracker = new ServiceTracker<P2ImportExport, P2ImportExport>(Platform.getBundle(Constants.Bundle_ID).getBundleContext(), P2ImportExport.class.getName(), null);
+ // tracker.open();
+ // importexportService = tracker.getService();
+ // tracker.close();
+ // }
+
+ // protected void setDestinationValue(String selectedFileName) {
+ // destinationNameField.setText(selectedFileName);
+ // }
+
+ /**
+ * Determine if the page is complete and update the page appropriately.
+ */
+ protected void updatePageCompletion() {
+ boolean pageComplete = determinePageCompletion();
+ setPageComplete(pageComplete);
+ if (pageComplete) {
+ // if (this instanceof AbstractImportPage_c)
+ // saveWidgetValues();
+ setMessage(null);
+ }
+ }
+
+ // /**
+ // * Validate the destination group.
+ // * @return <code>true</code> if the group is valid. If
+ // * not set the error message and return <code>false</code>.
+ // */
+ // protected boolean validateDestinationGroup() {
+ // if (!validDestination()) {
+ // currentMessage = getInvalidDestinationMessage();
+ // return false;
+ // }
+ //
+ // return true;
+ // }
+
+ protected boolean validateOptionsGroup() {
+ if (viewer == null || viewer.getCheckedElements().length > 0)
+ return true;
+
+ currentMessage = getNoOptionsMessage();
+ return false;
+ }
+
+ // protected boolean validDestination() {
+ // if (this.destinationNameField == null)
+ // return true;
+ // File file = new File(getDestinationValue());
+ // return !(file.getPath().length() <= 0 || file.isDirectory());
+ // }
+
+ // protected void saveWidgetValues() {
+ // IDialogSettings settings = getDialogSettings();
+ // if (settings != null) {
+ // String[] directoryNames = settings.getArray(STORE_DESTINATION_NAMES_ID);
+ // if (directoryNames == null) {
+ // directoryNames = new String[0];
+ // }
+ //
+ // directoryNames = addToHistory(directoryNames, getDestinationValue());
+ // settings.put(STORE_DESTINATION_NAMES_ID, directoryNames);
+ // }
+ // }
+
+ // protected String[] addToHistory(String[] history, String newEntry) {
+ // List<String> l = new ArrayList<String>(Arrays.asList(history));
+ // addToHistory(l, newEntry);
+ // String[] r = new String[l.size()];
+ // l.toArray(r);
+ // return r;
+ // }
+ //
+ // protected void addToHistory(List<String> history, String newEntry) {
+ // history.remove(newEntry);
+ // history.add(0, newEntry);
+ //
+ // // since only one new item was added, we can be over the limit
+ // // by at most one item
+ // if (history.size() > COMBO_HISTORY_LENGTH) {
+ // history.remove(COMBO_HISTORY_LENGTH);
+ // }
+ // }
+
+ // /**
+ // * Hook method for restoring widget values to the values that they held last
+ // * time this wizard was used to completion.
+ // */
+ // protected void restoreWidgetValues() {
+ //
+ // IDialogSettings settings = getDialogSettings();
+ //
+ // if (settings != null) {
+ // String[] directoryNames = settings.getArray(STORE_DESTINATION_NAMES_ID);
+ // if (directoryNames != null) {
+ // // destination
+ // setDestinationValue(directoryNames[0]);
+ // for (int i = 0; i < directoryNames.length; i++) {
+ // addDestinationItem(directoryNames[i]);
+ // }
+ //
+ // setDestinationValue(""); //$NON-NLS-1$
+ // }
+ // }
+ // }
+
+ // /**
+ // * Add the passed value to self's destination widget's history
+ // *
+ // * @param value
+ // * java.lang.String
+ // */
+ // protected void addDestinationItem(String value) {
+ // destinationNameField.add(value);
+ // }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/ImportFromInstallationPage_c.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/ImportFromInstallationPage_c.java
new file mode 100644
index 0000000..b0571df
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/ImportFromInstallationPage_c.java
@@ -0,0 +1,437 @@
+/*******************************************************************************
+ * Copyright (c) 2011 WindRiver 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * WindRiver Corporation - initial API and implementation
+ * Ericsson AB (Pascal Rapicault) - Bug 387115 - Allow to export everything
+ * Ericsson AB (Hamdan Msheik) - Bug 398833
+ *******************************************************************************/
+package org.eclipse.equinox.internal.p2.ui.dialogs;
+
+
+import java.net.URI;
+import org.eclipse.equinox.internal.p2.ui.ProvUI;
+import org.eclipse.equinox.internal.p2.ui.ProvUIMessages;
+import org.eclipse.equinox.internal.p2.ui.model.ProfileElement;
+import org.eclipse.equinox.internal.p2.ui.viewers.IUDetailsLabelProvider;
+import org.eclipse.equinox.p2.core.IProvisioningAgent;
+import org.eclipse.equinox.p2.engine.IProfile;
+import org.eclipse.equinox.p2.engine.ProvisioningContext;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
+import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
+import org.eclipse.equinox.p2.ui.ProvisioningUI;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+
+public class ImportFromInstallationPage_c extends AbstractImportPage_c implements ISelectableIUsPage {
+
+ protected IProvisioningAgent otherInstanceAgent = null;
+ private IProfile toBeImportedProfile = null;
+ // private File instancePath = null;
+ private URI[] metaURIs = null;
+ private URI[] artiURIs = null;
+
+ // private IProvisioningAgentProvider agentProvider;
+
+ public ImportFromInstallationPage_c(ProvisioningUI ui, ProvisioningOperationWizard wizard) {
+ super("importfrominstancepage", ui, wizard); //$NON-NLS-1$
+ setTitle(ProvUIMessages.ImportFromInstallationPage_DIALOG_TITLE);
+ // setDescription(ProvUIMessages.ImportFromInstallationPage_DIALOG_DESCRIPTION);
+ }
+
+ public ImportFromInstallationPage_c(ProvisioningUI ui, ImportFromInstallationWizard_c wizard, IProfile toImportFrom) {
+ super("importfrominstancepage", ui, wizard); //$NON-NLS-1$
+ setTitle(ProvUIMessages.ImportFromInstallationPage_DIALOG_TITLE);
+ // setDescription(ProvUIMessages.ImportFromInstallationPage_DIALOG_DESCRIPTION);
+ toBeImportedProfile = toImportFrom;
+ }
+
+ @Override
+ protected void createContents(Composite composite) {
+ createRemindMeGroup(composite);
+ createInstallationTable(composite);
+ }
+
+ // private void showProfile() {
+ //
+ // //TODO remove already installed installable units from the profile to be imported
+ // IQueryResult<IInstallableUnit> result = profile.available(null, null);
+ // Profile p1 = (Profile) profile;
+ // while (iterator)
+ // for (IInstallableUnit unit : result.iterator()) {
+ //
+ // }
+ // final ProfileElement element = new ProfileElement(null, toBeImportedProfile.getProfileId()) {
+ // @Override
+ // public org.eclipse.equinox.p2.query.IQueryable<?> getQueryable() {
+ // return toBeImportedProfile;
+ // }
+ // };
+ // element.setQueryable(toBeImportedProfile);
+ //
+ // viewer.setInput(element);
+ // updatePageCompletion();
+ // }
+
+ // @Override
+ // protected String getDestinationLabel() {
+ // return Messages.ImportFromInstallationPage_DESTINATION_LABEL;
+ // }
+
+ @Override
+ protected String getDialogTitle() {
+ return ProvUIMessages.ImportFromInstallationPage_DIALOG_TITLE;
+ }
+
+ @Override
+ protected Object getInput() {
+
+ Object input = null;
+
+ if (toBeImportedProfile != null) {
+ final ProfileElement element = new ProfileElement(null, toBeImportedProfile.getProfileId()) {
+ @Override
+ public org.eclipse.equinox.p2.query.IQueryable<?> getQueryable() {
+ return toBeImportedProfile;
+ }
+ };
+ element.setQueryable(toBeImportedProfile);
+ input = element;
+ } else {
+ input = new IInstallableUnit[0];
+ }
+
+ return input;
+ }
+
+ @Override
+ protected String getInvalidDestinationMessage() {
+ return ProvUIMessages.ImportFromInstallationPage_INVALID_DESTINATION;
+ }
+
+ @Override
+ protected String getNoOptionsMessage() {
+ return ProvUIMessages.ImportFromInstallationPage_SELECT_COMPONENT;
+ }
+
+ // @Override
+ // protected boolean validateDestinationGroup() {
+ // return validateDestinationGroup(new NullProgressMonitor());
+ // }
+
+ // private IProvisioningAgentProvider getAgentProvider() {
+ // if (agentProvider == null) {
+ // ServiceTracker<IProvisioningAgentProvider, IProvisioningAgentProvider> tracker = new ServiceTracker<IProvisioningAgentProvider, IProvisioningAgentProvider>(Platform.getBundle(Constants.Bundle_ID).getBundleContext(), IProvisioningAgentProvider.class, null);
+ // tracker.open();
+ // agentProvider = tracker.getService();
+ // tracker.close();
+ // }
+ // return agentProvider;
+ // }
+
+ // boolean validateDestinationGroup(IProgressMonitor monitor) {
+ // SubMonitor progress = SubMonitor.convert(monitor, 100);
+ //
+ // boolean rt;
+ // if (Display.findDisplay(Thread.currentThread()) == null) {
+ // Callable<Boolean> getSuperValidateDest = new Callable<Boolean>() {
+ // Boolean validated;
+ //
+ // public Boolean call() throws Exception {
+ // Display.getDefault().syncExec(new Runnable() {
+ // public void run() {
+ // validated = ImportFromInstallationPage_c.super.validateDestinationGroup();
+ // }
+ // });
+ // return validated;
+ // }
+ // };
+ // ExecutorService executor = Executors.newSingleThreadScheduledExecutor();
+ // Future<Boolean> getSuperDestTask = executor.submit(getSuperValidateDest);
+ //
+ // try {
+ // rt = getSuperDestTask.get().booleanValue();
+ // } catch (Exception e) {
+ // return false;
+ // } finally {
+ // executor.shutdown();
+ // }
+ // } else
+ // rt = super.validateDestinationGroup();
+ //
+ // if (rt) {
+ // try {
+ // String destination;
+ // if (Display.findDisplay(Thread.currentThread()) == null) {
+ // Callable<String> getDestinationValue = new Callable<String>() {
+ // String des;
+ //
+ // public String call() throws Exception {
+ // if (Display.findDisplay(Thread.currentThread()) == null) {
+ // Display.getDefault().syncExec(new Runnable() {
+ // public void run() {
+ // des = getDestinationValue();
+ // }
+ // });
+ // } else
+ // des = getDestinationValue();
+ // return des;
+ // }
+ // };
+ // ExecutorService executor = Executors.newSingleThreadScheduledExecutor();
+ // Future<String> getDestTask = executor.submit(getDestinationValue);
+ // try {
+ // destination = getDestTask.get();
+ // } finally {
+ // executor.shutdown();
+ // }
+ // } else
+ // destination = getDestinationValue();
+ //
+ // String toBeImportedProfileId = null;
+ // try {
+ // File config = new File(destination, "configuration/config.ini"); //$NON-NLS-1$
+ // URI configArea = config.getParentFile().toURI();
+ // InputStream is = null;
+ // // default area
+ // File p2DataArea = new File(destination, "p2"); //$NON-NLS-1$
+ // try {
+ // Properties props = new Properties();
+ // is = new FileInputStream(config);
+ // props.load(is);
+ // toBeImportedProfileId = props.getProperty("eclipse.p2.profile"); //$NON-NLS-1$
+ // String url = props.getProperty("eclipse.p2.data.area"); //$NON-NLS-1$
+ // if (url != null) {
+ // final String CONFIG_DIR = "@config.dir/"; //$NON-NLS-1$
+ // final String FILE_PROTOCOL = "file:"; //$NON-NLS-1$
+ // if (url.startsWith(CONFIG_DIR))
+ // url = FILE_PROTOCOL + url.substring(CONFIG_DIR.length());
+ // p2DataArea = new File(URIUtil.makeAbsolute(URIUtil.fromString(new File(url.substring(FILE_PROTOCOL.length())).isAbsolute() ? url : url.substring(FILE_PROTOCOL.length())), configArea));
+ // }
+ // } catch (IOException ioe) {
+ // //ignore
+ // } finally {
+ // try {
+ // is.close();
+ // } catch (IOException ioe) {
+ // //ignore
+ // }
+ // is = null;
+ // }
+ // if (p2DataArea.exists()) {
+ // boolean createAgent = true;
+ // if (otherInstanceAgent != null) {
+ // // don't create agent again if the selection is not changed
+ // if (!p2DataArea.equals(instancePath)) {
+ // otherInstanceAgent.stop();
+ // otherInstanceAgent = null;
+ // // update cached specified path by users
+ // instancePath = p2DataArea;
+ // cleanLocalRepository();
+ // } else
+ // createAgent = false;
+ // }
+ // if (createAgent)
+ // otherInstanceAgent = getAgentProvider().createAgent(p2DataArea.toURI());
+ // ArtifactRepositoryFactory factory = new ExtensionLocationArtifactRepositoryFactory();
+ // factory.setAgent(agent);
+ // IArtifactRepository artiRepo = factory.load(new File(destination).toURI(), 0, progress.newChild(50));
+ // artiURIs = new URI[] {artiRepo.getLocation()};
+ // MetadataRepositoryFactory metaFatory = new ExtensionLocationMetadataRepositoryFactory();
+ // metaFatory.setAgent(agent);
+ // IMetadataRepository metaRepo = metaFatory.load(new File(destination).toURI(), 0, progress.newChild(50));
+ // metaURIs = new URI[] {metaRepo.getLocation()};
+ //
+ // } else
+ // throw new FileNotFoundException();
+ // } catch (ProvisionException e) {
+ // if (otherInstanceAgent != null) {
+ // toBeImportedProfile = null;
+ // IMetadataRepositoryManager manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
+ // IArtifactRepositoryManager artifactManager = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME);
+ // IProfileRegistry registry = (IProfileRegistry) otherInstanceAgent.getService(IProfileRegistry.SERVICE_NAME);
+ // if (toBeImportedProfileId != null)
+ // toBeImportedProfile = registry.getProfile(toBeImportedProfileId);
+ // if (toBeImportedProfile == null) {
+ // IProfile[] existingProfiles = registry.getProfiles();
+ // if (existingProfiles.length == 1) {
+ // toBeImportedProfile = existingProfiles[0];
+ // } else {
+ // for (IProfile existingProfile : existingProfiles) {
+ // if (toBeImportedProfile == null)
+ // toBeImportedProfile = existingProfile;
+ // else if ((toBeImportedProfile.getTimestamp() < existingProfile.getTimestamp())) // assuming last modified one is we are looking for
+ // toBeImportedProfile = existingProfile;
+ // }
+ // }
+ // }
+ // IAgentLocation location = (IAgentLocation) otherInstanceAgent.getService(IAgentLocation.SERVICE_NAME);
+ // URI engineDataArea = location.getDataArea("org.eclipse.equinox.p2.engine"); //$NON-NLS-1$
+ // progress.setWorkRemaining(50);
+ // IMetadataRepository metaRepo = manager.loadRepository(engineDataArea.resolve("profileRegistry/" + toBeImportedProfile.getProfileId() + ".profile"), progress.newChild(25)); //$NON-NLS-1$//$NON-NLS-2$
+ // metaURIs = new URI[] {metaRepo.getLocation()};
+ // IArtifactRepository artiRepo = artifactManager.loadRepository(new File(destination).toURI(), progress.newChild(25));
+ // artiURIs = new URI[] {artiRepo.getLocation()};
+ // } else
+ // throw new Exception();
+ // }
+ // } catch (Exception e) {
+ // Display.getDefault().asyncExec(new Runnable() {
+ // public void run() {
+ // setErrorMessage(getInvalidDestinationMessage());
+ // }
+ // });
+ // rt = false;
+ // if (otherInstanceAgent != null)
+ // otherInstanceAgent.stop();
+ // otherInstanceAgent = null;
+ // toBeImportedProfile = null;
+ // cleanLocalRepository();
+ // } finally {
+ // monitor.done();
+ // }
+ // }
+ // return rt;
+ // }
+
+ // @Override
+ // protected void giveFocusToDestination() {
+ // destinationBrowseButton.setFocus();
+ // }
+
+ // @Override
+ // protected void handleDestinationBrowseButtonPressed() {
+ // DirectoryDialog dialog = new DirectoryDialog(getContainer().getShell());
+ // dialog.setText(getDialogTitle());
+ // dialog.setFilterPath(getDestinationValue());
+ // final String selectedFileName = dialog.open();
+ //
+ // if (selectedFileName != null) {
+ // setDestinationValue(selectedFileName);
+ // handleDestinationChanged(selectedFileName);
+ // }
+ // }
+
+ // @Override
+ // protected void handleDestinationChanged(String newDestination) {
+ // try {
+ // getContainer().run(true, false, new IRunnableWithProgress() {
+ //
+ // public void run(IProgressMonitor monitor) {
+ // Object input = null;
+ // if (validateDestinationGroup(monitor)) {
+ // final IProfile currentProfile = toBeImportedProfile;
+ // final ProfileElement element = new ProfileElement(null, currentProfile.getProfileId()) {
+ // @Override
+ // public org.eclipse.equinox.p2.query.IQueryable<?> getQueryable() {
+ // return currentProfile;
+ // }
+ // };
+ // element.setQueryable(currentProfile);
+ // input = element;
+ //
+ // }
+ // final Object viewerInput = input;
+ // Display.getDefault().asyncExec(new Runnable() {
+ //
+ // public void run() {
+ // viewer.setInput(viewerInput);
+ // updatePageCompletion();
+ // }
+ // });
+ // }
+ // });
+ // } catch (InvocationTargetException e) {
+ // setErrorMessage(e.getLocalizedMessage());
+ // setPageComplete(false);
+ // } catch (InterruptedException e) {
+ // // won't happen
+ // }
+ // }
+
+ // @Override
+ // protected boolean validDestination() {
+ // if (this.destinationNameField == null)
+ // return true;
+ // File file = new File(getDestinationValue());
+ // return file.exists() && file.isDirectory();
+ // }
+
+ class ImportFromInstallationLabelProvider extends IUDetailsLabelProvider {
+ @Override
+ public String getColumnText(Object element, int columnIndex) {
+ String text = super.getColumnText(element, columnIndex);
+ // it's the order of label provider
+ if (columnIndex == 0) {
+ IInstallableUnit iu = ProvUI.getAdapter(element, IInstallableUnit.class);
+ return getIUNameWithDetail(iu);
+ }
+ return text;
+ }
+
+ @Override
+ public Color getForeground(Object element) {
+ IInstallableUnit iu = ProvUI.getAdapter(element, IInstallableUnit.class);
+ if (hasInstalled(iu))
+ return Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
+ return super.getForeground(element);
+ }
+ }
+
+ @Override
+ protected ITableLabelProvider getLabelProvider() {
+ return new ImportFromInstallationLabelProvider();
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ if (otherInstanceAgent != null) {
+ otherInstanceAgent.stop();
+ otherInstanceAgent = null;
+ toBeImportedProfile = null;
+ }
+ if (getWizard().performCancel())
+ cleanLocalRepository();
+ }
+
+ public void cleanLocalRepository() {
+ if (metaURIs != null && metaURIs.length > 0) {
+ IProvisioningAgent runningAgent = getProvisioningUI().getSession().getProvisioningAgent();
+ IMetadataRepositoryManager manager = (IMetadataRepositoryManager) runningAgent.getService(IMetadataRepositoryManager.SERVICE_NAME);
+ for (URI uri : metaURIs)
+ manager.removeRepository(uri);
+ IArtifactRepositoryManager artifactManager = (IArtifactRepositoryManager) runningAgent.getService(IArtifactRepositoryManager.SERVICE_NAME);
+ for (URI uri : artiURIs)
+ artifactManager.removeRepository(uri);
+ }
+ }
+
+ public Object[] getCheckedIUElements() {
+ return viewer.getCheckedElements();
+ }
+
+ public Object[] getSelectedIUElements() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void setCheckedElements(Object[] elements) {
+ new UnsupportedOperationException();
+ }
+
+ public ProvisioningContext getProvisioningContext() {
+ ProvisioningContext context = new ProvisioningContext(getProvisioningUI().getSession().getProvisioningAgent());
+ context.setArtifactRepositories(artiURIs);
+ context.setMetadataRepositories(metaURIs);
+ return context;
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/ImportFromInstallationWizard_c.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/ImportFromInstallationWizard_c.java
new file mode 100644
index 0000000..1c76010
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/ImportFromInstallationWizard_c.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2011 WindRiver 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * WindRiver Corporation - initial API and implementation
+ * Ericsson AB (Hamdan Msheik) - Bug 398833
+ *******************************************************************************/
+package org.eclipse.equinox.internal.p2.ui.dialogs;
+
+import java.util.Collection;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.equinox.internal.p2.ui.ProvUIActivator;
+import org.eclipse.equinox.internal.p2.ui.ProvUIMessages;
+import org.eclipse.equinox.internal.p2.ui.model.IUElementListRoot;
+import org.eclipse.equinox.p2.engine.IProfile;
+import org.eclipse.equinox.p2.engine.ProvisioningContext;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.operations.InstallOperation;
+import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
+import org.eclipse.equinox.p2.ui.ProvisioningUI;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IImportWizard;
+import org.eclipse.ui.IWorkbench;
+
+public class ImportFromInstallationWizard_c extends InstallWizard implements IImportWizard {
+ private IProfile toImportFrom;
+
+ public ImportFromInstallationWizard_c() {
+ this(ProvisioningUI.getDefaultUI(), null, null, null);
+ }
+
+ public ImportFromInstallationWizard_c(IProfile toImportFrom) {
+ this(ProvisioningUI.getDefaultUI(), null, null, null);
+ this.toImportFrom = toImportFrom;
+ }
+
+ public ImportFromInstallationWizard_c(ProvisioningUI ui, InstallOperation operation, Collection<IInstallableUnit> initialSelections, LoadMetadataRepositoryJob preloadJob) {
+ super(ui, operation, initialSelections, preloadJob);
+ IDialogSettings workbenchSettings = ProvUIActivator.getDefault().getDialogSettings();
+ String sectionName = "ImportFromInstallationWizard"; //$NON-NLS-1$
+ IDialogSettings section = workbenchSettings.getSection(sectionName);
+ if (section == null) {
+ section = workbenchSettings.addNewSection(sectionName);
+ }
+ setDialogSettings(section);
+ }
+
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ setWindowTitle(ProvUIMessages.ImportWizard_WINDOWTITLE);
+ setDefaultPageImageDescriptor(ImageDescriptor.createFromURL(Platform.getBundle(ProvUIActivator.PLUGIN_ID).getEntry("icons/install_wiz.gif"))); //$NON-NLS-1$
+ setNeedsProgressMonitor(true);
+ }
+
+ @Override
+ protected ISelectableIUsPage createMainPage(IUElementListRoot input, Object[] selections) {
+ if (toImportFrom != null)
+ return new ImportFromInstallationPage_c(ui, this, toImportFrom);
+ return new ImportFromInstallationPage_c(ui, this);
+ }
+
+ @Override
+ protected ProvisioningContext getProvisioningContext() {
+ return ((ImportFromInstallationPage_c) mainPage).getProvisioningContext();
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/messages.properties b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/messages.properties
index 8abcaa4..5067e6a 100644
--- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/messages.properties
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/messages.properties
@@ -244,3 +244,18 @@ RollbackProfileElement_CurrentInstallation=Current Installation
TrustCertificateDialog_Details=Details
TrustCertificateDialog_Title=Do you trust these certificates?
+
+AbstractImportPage_HigherVersionInstalled={0} (Disabled because a higher version is already installed)
+AbstractImportPage_SameVersionInstalled={0} (Disabled - item already installed)
+Column_Id=Id
+Column_Name=Name
+Column_Version=Version
+AbstractPage_ButtonSelectAll=&Select All
+AbstractPage_ButtonDeselectAll=&Deselect All
+PAGE_NOINSTALLTION_ERROR=Select at least one available element to be installed.
+ImportFromInstallationPage_DIALOG_DESCRIPTION=Import software items from the existing application installation.
+ImportFromInstallationPage_SELECT_COMPONENT=Select at least one available element to be installed.
+ImportWizard_WINDOWTITLE=Import
+ImportFromInstallationPage_INVALID_DESTINATION=Specify the path to a valid application installation.
+ImportFromInstallationPage_DIALOG_TITLE=A new profile has been created due to a detected change in your base. Eclipse will try to import your previous profile features into the new one.
+REMIND_ME_TO_MIGRATE_LATER= Remind me later.