From eebd88c4be122c5f4c6e0f84c2c88a995a4f5d00 Mon Sep 17 00:00:00 2001 From: Hamdan Msheik Date: Thu, 28 Feb 2013 18:14:26 -0500 Subject: Cancel import wizard confirmation dialog with remind me later button bug Bug 400854 --- .../ui/sdk/scheduler/AutomaticUpdateScheduler.java | 19 +++++++-- .../ui/sdk/scheduler/migration/AbstractPage_c.java | 35 ---------------- .../migration/ImportFromInstallationPage_c.java | 4 +- .../migration/ImportFromInstallationWizard_c.java | 47 +++++++++++++++++++++- .../ui/sdk/scheduler/migration/ProvUIMessages.java | 2 + .../ui/sdk/scheduler/migration/messages.properties | 4 +- 6 files changed, 68 insertions(+), 43 deletions(-) (limited to 'bundles/org.eclipse.equinox.p2.ui.sdk.scheduler') 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 330b2252b..11b675675 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 @@ -19,10 +19,12 @@ import java.net.URI; import java.util.Iterator; import java.util.Set; import org.eclipse.core.runtime.*; +import org.eclipse.core.runtime.preferences.ConfigurationScope; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.p2.engine.EngineActivator; import org.eclipse.equinox.internal.p2.garbagecollector.GarbageCollector; import org.eclipse.equinox.internal.p2.metadata.query.UpdateQuery; +import org.eclipse.equinox.internal.p2.ui.sdk.scheduler.migration.AbstractPage_c; import org.eclipse.equinox.internal.p2.ui.sdk.scheduler.migration.ImportFromInstallationWizard_c; import org.eclipse.equinox.internal.provisional.p2.updatechecker.*; import org.eclipse.equinox.p2.core.IProvisioningAgent; @@ -42,6 +44,7 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.*; import org.eclipse.ui.statushandlers.StatusManager; +import org.osgi.service.prefs.Preferences; /** * This plug-in is loaded on startup to register with the update checker. @@ -51,7 +54,7 @@ import org.eclipse.ui.statushandlers.StatusManager; public class AutomaticUpdateScheduler implements IStartup { private static final String ECLIPSE_P2_SKIP_MIGRATION_WIZARD = "eclipse.p2.skipMigrationWizard"; //$NON-NLS-1$ - private static final String ECLIPSE_P2_SKIP_MOVED_INSTALL_DETECTION = "eclipse.p2.skipMovedInstallDetection"; //$NON-NLS-1$ + // private static final String ECLIPSE_P2_SKIP_MOVED_INSTALL_DETECTION = "eclipse.p2.skipMovedInstallDetection"; //$NON-NLS-1$ public static final String MIGRATION_DIALOG_SHOWN = "migrationDialogShown"; //$NON-NLS-1$ // values are to be picked up from the arrays DAYS and HOURS @@ -110,7 +113,7 @@ public class AutomaticUpdateScheduler implements IStartup { scheduleUpdate(); } - //The return value indicates if the migration dialog has been shown or not. It does not indicate whether the migration has completed. + //The return value indicates if the migration dialog has been shown or not. It does not indicate whether the migration has completed. private boolean performMigration(IProvisioningAgent agent, IProfileRegistry registry, IProfile currentProfile) { boolean skipWizard = Boolean.TRUE.toString().equalsIgnoreCase(System.getProperty(ECLIPSE_P2_SKIP_MIGRATION_WIZARD)); if (skipWizard) @@ -143,12 +146,22 @@ public class AutomaticUpdateScheduler implements IStartup { if (previousProfile == null) return false; + if (!remindMeLater()) + return false; + if (needsMigration(previousProfile, currentProfile)) { openMigrationWizard(previousProfile); } return true; } + + private boolean remindMeLater() { + Preferences prefs = ConfigurationScope.INSTANCE.getNode("org.eclipse.equinox.p2.ui"); + return prefs.getBoolean(AbstractPage_c.REMIND_ME_LATER, true); + + } + private File getInstallFolder() { Location configurationLocation = (Location) ServiceHelper.getService(EngineActivator.getContext(), Location.class.getName(), Location.INSTALL_FILTER); return new File(configurationLocation.getURL().getPath()); @@ -242,7 +255,7 @@ public class AutomaticUpdateScheduler implements IStartup { return lastShownMigration < lastReset.getTimestamp(); } - //Get the timestamp that we migrated from + //Get the timestamp that we migrated from private long getLastShownMigration() { return AutomaticUpdatePlugin.getDefault().getPreferenceStore().getLong(MIGRATION_DIALOG_SHOWN); } diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/AbstractPage_c.java b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/AbstractPage_c.java index b78dbf5c8..72a435082 100644 --- a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/AbstractPage_c.java +++ b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/AbstractPage_c.java @@ -17,7 +17,6 @@ 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.ProvUI; import org.eclipse.equinox.internal.p2.ui.ProvUIActivator; import org.eclipse.equinox.internal.p2.ui.dialogs.*; @@ -42,15 +41,12 @@ 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; @@ -288,37 +284,6 @@ public abstract class AbstractPage_c extends WizardPage implements Listener { 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(); diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/ImportFromInstallationPage_c.java b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/ImportFromInstallationPage_c.java index 53bef0a51..6aa83b326 100644 --- a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/ImportFromInstallationPage_c.java +++ b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/ImportFromInstallationPage_c.java @@ -56,7 +56,6 @@ public class ImportFromInstallationPage_c extends AbstractImportPage_c implement @Override protected void createContents(Composite composite) { - createRemindMeGroup(composite); createInstallationTable(composite); } @@ -399,8 +398,7 @@ public class ImportFromInstallationPage_c extends AbstractImportPage_c implement otherInstanceAgent = null; toBeImportedProfile = null; } - if (getWizard().performCancel()) - cleanLocalRepository(); + cleanLocalRepository(); } public void cleanLocalRepository() { diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/ImportFromInstallationWizard_c.java b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/ImportFromInstallationWizard_c.java index 852a6c8c8..e860d5887 100644 --- a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/ImportFromInstallationWizard_c.java +++ b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/ImportFromInstallationWizard_c.java @@ -12,7 +12,8 @@ package org.eclipse.equinox.internal.p2.ui.sdk.scheduler.migration; import java.util.Collection; -import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.*; +import org.eclipse.core.runtime.preferences.ConfigurationScope; import org.eclipse.equinox.internal.p2.ui.ProvUIActivator; import org.eclipse.equinox.internal.p2.ui.dialogs.ISelectableIUsPage; import org.eclipse.equinox.internal.p2.ui.dialogs.InstallWizard; @@ -26,10 +27,14 @@ 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.dialogs.MessageDialog; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IImportWizard; import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.statushandlers.StatusManager; +import org.osgi.service.prefs.BackingStoreException; +import org.osgi.service.prefs.Preferences; public class ImportFromInstallationWizard_c extends InstallWizard implements IImportWizard { private IProfile toImportFrom; @@ -82,6 +87,13 @@ public class ImportFromInstallationWizard_c extends InstallWizard implements IIm //Remember the timestamp that we migrated from. private void rememberShownMigration(long timestamp) { AutomaticUpdatePlugin.getDefault().getPreferenceStore().setValue(AutomaticUpdateScheduler.MIGRATION_DIALOG_SHOWN, timestamp); + try { + Preferences prefs = ConfigurationScope.INSTANCE.getNode("org.eclipse.equinox.p2.ui"); //$NON-NLS-1$ + prefs.putBoolean(AbstractPage_c.REMIND_ME_LATER, true); + prefs.flush(); + } catch (BackingStoreException e) { + StatusManager.getManager().handle(new Status(IStatus.ERROR, AutomaticUpdatePlugin.PLUGIN_ID, 0, ProvUIMessages.ERROR_SAVING_PREFERENCES, e), StatusManager.LOG); + } } //Purge the profile registry from all the entries that are no longer relevant @@ -98,4 +110,37 @@ public class ImportFromInstallationWizard_c extends InstallWizard implements IIm } } } + + public boolean performCancel() { + + Preferences prefs = ConfigurationScope.INSTANCE.getNode("org.eclipse.equinox.p2.ui"); //$NON-NLS-1$ + boolean result = false; + MessageDialog dialog = new MessageDialog(getShell(), "Migration dialaog", null, ProvUIMessages.ImportFromInstallationPage_CONFIRMATION_DIALOG, MessageDialog.QUESTION, new String[] {"Yes", "Yes, but remind me later", "No"}, 2); + + int answer = dialog.open(); + try { + switch (answer) { + case -1 : // if the user closes the dialog without clicking any button. + break; + case 0 : + result = true; + prefs.putBoolean(AbstractPage_c.REMIND_ME_LATER, false); + prefs.flush(); + break; + case 1 : + result = true; + prefs.putBoolean(AbstractPage_c.REMIND_ME_LATER, true); + prefs.flush(); + break; + case 2 : + result = false; + break; + } + } catch (BackingStoreException e) { + StatusManager.getManager().handle(new Status(IStatus.ERROR, AutomaticUpdatePlugin.PLUGIN_ID, 0, ProvUIMessages.ERROR_SAVING_PREFERENCES, e), StatusManager.LOG); + } + return result; + + } + } diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/ProvUIMessages.java b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/ProvUIMessages.java index e67ae700b..08f1d1574 100644 --- a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/ProvUIMessages.java +++ b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/ProvUIMessages.java @@ -33,4 +33,6 @@ public class ProvUIMessages extends NLS { public static String ImportWizard_WINDOWTITLE; public static String ImportFromInstallationPage_INVALID_DESTINATION; public static String REMIND_ME_TO_MIGRATE_LATER; + public static String ERROR_SAVING_PREFERENCES; + public static String ImportFromInstallationPage_CONFIRMATION_DIALOG; } diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/messages.properties b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/messages.properties index 056175166..696fca8ea 100644 --- a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/messages.properties +++ b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/messages.properties @@ -10,5 +10,7 @@ ImportFromInstallationPage_DIALOG_DESCRIPTION=Import software items from the exi 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=The application you are running has been updated which caused the plugins you had installed to have been disabled.\nMigrate the software you had previously installed. +ImportFromInstallationPage_DIALOG_TITLE=Eclipse has been updated. Consequently, the plugins you have installed are disabled. This wizard allows you to migrate the software you had previously installed. +ImportFromInstallationPage_CONFIRMATION_DIALOG= Canceling this migration wizard will make you loose the ability to import your plugins if eclipse has been update again. Are you sure you want to cancel? REMIND_ME_TO_MIGRATE_LATER= Remind me later. +ERROR_SAVING_PREFERENCES=Error saving preferences. -- cgit v1.2.3