diff options
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.ui.sdk/src')
9 files changed, 241 insertions, 237 deletions
diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/InstallNewSoftwareHandler.java b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/InstallNewSoftwareHandler.java index 28c17299c..20f281b10 100644 --- a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/InstallNewSoftwareHandler.java +++ b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/InstallNewSoftwareHandler.java @@ -11,12 +11,7 @@ package org.eclipse.equinox.internal.p2.ui.sdk; import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.equinox.internal.provisional.p2.ui.*; -import org.eclipse.equinox.internal.provisional.p2.ui.dialogs.InstallWizard; -import org.eclipse.equinox.internal.provisional.p2.ui.dialogs.ProvisioningWizardDialog; -import org.eclipse.equinox.internal.provisional.p2.ui.policy.Policy; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.ui.PlatformUI; +import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob; /** * InstallNewSoftwareHandler invokes the install wizard @@ -32,29 +27,25 @@ public class InstallNewSoftwareHandler extends PreloadingRepositoryHandler { super(); } - protected void doExecute(String profileId, QueryableMetadataRepositoryManager manager) { - InstallWizard wizard = new InstallWizard(Policy.getDefault(), profileId, null, null, manager); - WizardDialog dialog = new ProvisioningWizardDialog(getShell(), wizard); - dialog.create(); - PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), IProvHelpContextIds.INSTALL_WIZARD); - - dialog.open(); + protected void doExecute(LoadMetadataRepositoryJob job) { + getProvisioningUI().openInstallWizard(getShell(), null, null, job); } protected boolean waitForPreload() { - // If there is no way for the user to manipulate repositories, - // then we may as well wait for existing repos to load so that - // content is available. If the user can manipulate the - // repositories, then we don't wait, because we don't know which - // ones they want to work with. - return Policy.getDefault().getRepositoryManipulator() == null; + // If the user cannot see repositories, then we may as well wait + // for existing repos to load so that content is available. + // If the user can manipulate the repositories, then we don't wait, + // because we don't know which ones they want to work with. + return !getProvisioningUI().getPolicy().getRepositoriesVisible(); } protected void setLoadJobProperties(Job loadJob) { + super.setLoadJobProperties(loadJob); // If we are doing a background load, we do not wish to authenticate, as the // user is unaware that loading was needed if (!waitForPreload()) { - loadJob.setProperty(ValidationDialogServiceUI.SUPPRESS_AUTHENTICATION_JOB_MARKER, Boolean.toString(true)); + loadJob.setProperty(LoadMetadataRepositoryJob.SUPPRESS_AUTHENTICATION_JOB_MARKER, Boolean.toString(true)); + loadJob.setProperty(LoadMetadataRepositoryJob.SUPPRESS_REPOSITORY_EVENTS, Boolean.toString(true)); } } } diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/PreloadingRepositoryHandler.java b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/PreloadingRepositoryHandler.java index 585207890..73655e87d 100644 --- a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/PreloadingRepositoryHandler.java +++ b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/PreloadingRepositoryHandler.java @@ -12,17 +12,11 @@ package org.eclipse.equinox.internal.p2.ui.sdk; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.jobs.*; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.ui.ProvUI; -import org.eclipse.equinox.internal.provisional.p2.ui.QueryableMetadataRepositoryManager; -import org.eclipse.equinox.internal.provisional.p2.ui.policy.Policy; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob; +import org.eclipse.equinox.p2.ui.ProvisioningUI; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.statushandlers.StatusManager; /** * PreloadingRepositoryHandler provides background loading of @@ -32,8 +26,6 @@ import org.eclipse.ui.statushandlers.StatusManager; */ abstract class PreloadingRepositoryHandler extends AbstractHandler { - Object LOAD_FAMILY = new Object(); - /** * The constructor. */ @@ -45,38 +37,15 @@ abstract class PreloadingRepositoryHandler extends AbstractHandler { * Execute the command. */ public Object execute(ExecutionEvent event) { - try { - final String profileId = ProvSDKUIActivator.getSelfProfileId(); - BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() { - public void run() { - doExecuteAndLoad(profileId, preloadRepositories()); - } - }); - - } catch (ProvisionException e) { - MessageDialog.openInformation(null, ProvSDKMessages.Handler_SDKUpdateUIMessageTitle, ProvSDKMessages.Handler_CannotLaunchUI); - ProvUI.handleException(e, null, StatusManager.LOG); - } + doExecuteAndLoad(); return null; } - void doExecuteAndLoad(final String profileId, boolean preloadRepositories) { - //cancel any load that is already running - Job.getJobManager().cancel(LOAD_FAMILY); - final QueryableMetadataRepositoryManager queryableManager = new QueryableMetadataRepositoryManager(Policy.getDefault().getQueryContext(), false); - if (preloadRepositories) { - Job loadJob = new Job(ProvSDKMessages.InstallNewSoftwareHandler_LoadRepositoryJobLabel) { - - protected IStatus run(IProgressMonitor monitor) { - queryableManager.loadAll(monitor); - return Status.OK_STATUS; - } - - public boolean belongsTo(Object family) { - return family == LOAD_FAMILY; - } - - }; + void doExecuteAndLoad() { + if (preloadRepositories()) { + //cancel any load that is already running + Job.getJobManager().cancel(LoadMetadataRepositoryJob.LOAD_FAMILY); + final LoadMetadataRepositoryJob loadJob = new LoadMetadataRepositoryJob(getProvisioningUI()); setLoadJobProperties(loadJob); if (waitForPreload()) { loadJob.addJobChangeListener(new JobChangeAdapter() { @@ -85,7 +54,7 @@ abstract class PreloadingRepositoryHandler extends AbstractHandler { if (event.getResult().isOK()) { PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { public void run() { - doExecute(profileId, queryableManager); + doExecute(loadJob); } }); } @@ -98,14 +67,14 @@ abstract class PreloadingRepositoryHandler extends AbstractHandler { loadJob.setSystem(true); loadJob.setUser(false); loadJob.schedule(); - doExecute(profileId, queryableManager); + doExecute(null); } } else { - doExecute(profileId, queryableManager); + doExecute(null); } } - protected abstract void doExecute(String profileId, QueryableMetadataRepositoryManager manager); + protected abstract void doExecute(LoadMetadataRepositoryJob job); protected boolean preloadRepositories() { return true; @@ -116,7 +85,11 @@ abstract class PreloadingRepositoryHandler extends AbstractHandler { } protected void setLoadJobProperties(Job loadJob) { - // nothing to do by default + loadJob.setProperty(LoadMetadataRepositoryJob.ACCUMULATE_LOAD_ERRORS, Boolean.toString(true)); + } + + protected ProvisioningUI getProvisioningUI() { + return ProvisioningUI.getDefaultUI(); } /** @@ -124,6 +97,6 @@ abstract class PreloadingRepositoryHandler extends AbstractHandler { * @return a Shell */ protected Shell getShell() { - return ProvUI.getDefaultParentShell(); + return getProvisioningUI().getDefaultParentShell(); } } diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/ProvSDKMessages.java b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/ProvSDKMessages.java index cab15b6b0..f6ad748bb 100644 --- a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/ProvSDKMessages.java +++ b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/ProvSDKMessages.java @@ -24,9 +24,6 @@ public class ProvSDKMessages extends NLS { // load message values from bundle file NLS.initializeMessages(BUNDLE_NAME, ProvSDKMessages.class); } - public static String Handler_CannotLaunchUI; - public static String Handler_SDKUpdateUIMessageTitle; - public static String InstallNewSoftwareHandler_LoadRepositoryJobLabel; public static String PreferenceInitializer_Error; public static String ProvisioningPreferencePage_AlwaysOpenWizard; public static String ProvisioningPreferencePage_BrowsingPrefsGroup; @@ -41,7 +38,7 @@ public class ProvSDKMessages extends NLS { public static String ProvSDKUIActivator_NoSelfProfile; public static String ProvSDKUIActivator_OpenWizardAnyway; public static String ProvSDKUIActivator_Question; - public static String ProvSDKUIActivator_SitePrefLink; + public static String ProvUILicenseManager_ParsingError; public static String UpdateHandler_NoSitesMessage; public static String UpdateHandler_NoSitesTitle; } 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 a9b53c10b..1c24767c2 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 @@ -10,20 +10,18 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.ui.sdk; +import org.eclipse.equinox.p2.ui.LicenseManager; + import java.io.*; import org.eclipse.core.runtime.*; +import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.p2.ui.sdk.prefs.PreferenceConstants; import org.eclipse.equinox.internal.p2.ui.sdk.prefs.PreferenceInitializer; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus; -import org.eclipse.equinox.internal.provisional.p2.engine.*; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; -import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager; -import org.eclipse.equinox.internal.provisional.p2.ui.ProfileFactory; -import org.eclipse.equinox.internal.provisional.p2.ui.ProvUI; -import org.eclipse.equinox.internal.provisional.p2.ui.operations.ProvisioningUtil; -import org.eclipse.equinox.internal.provisional.p2.ui.policy.IUViewQueryContext; -import org.eclipse.equinox.internal.provisional.p2.ui.policy.Policy; +import org.eclipse.equinox.p2.engine.IProfileRegistry; +import org.eclipse.equinox.p2.engine.ProfileScope; +import org.eclipse.equinox.p2.ui.Policy; +import org.eclipse.equinox.p2.ui.ProvisioningUI; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.util.IPropertyChangeListener; @@ -39,8 +37,6 @@ import org.osgi.framework.ServiceReference; */ public class ProvSDKUIActivator extends AbstractUIPlugin { - public static final boolean ANY_PROFILE = false; - private static final String DEFAULT_PROFILE_ID = "DefaultProfile"; //$NON-NLS-1$ private static final String LICENSE_STORAGE = "licenses.xml"; //$NON-NLS-1$ private static ProvSDKUIActivator plugin; private static BundleContext context; @@ -97,40 +93,56 @@ public class ProvSDKUIActivator extends AbstractUIPlugin { if (preferenceListener == null) { preferenceListener = new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { - updateWithPreferences(Policy.getDefault().getQueryContext()); + updateWithPreferences(getPolicy()); } }; } return preferenceListener; } + public ProvisioningUI getProvisioningUI() { + return ProvisioningUI.getDefaultUI(); + } + + private Policy getPolicy() { + return getProvisioningUI().getPolicy(); + } + + private LicenseManager getLicenseManager() { + return (LicenseManager) ServiceHelper.getService(getContext(), LicenseManager.class.getName()); + } + private void readLicenseRegistry() { + if (getLicenseManager() == null) + return; IPath location = getStateLocation().append(LICENSE_STORAGE); File f = location.toFile(); BufferedInputStream stream = null; if (f.exists()) { try { stream = new BufferedInputStream(new FileInputStream(f)); - Policy.getDefault().getLicenseManager().read(stream); + getLicenseManager().read(stream); stream.close(); } catch (IOException e) { - ProvUI.reportStatus(new Status(IStatus.ERROR, PLUGIN_ID, 0, ProvSDKMessages.ProvSDKUIActivator_LicenseManagerReadError, e), StatusManager.LOG); + StatusManager.getManager().handle(new Status(IStatus.ERROR, PLUGIN_ID, 0, ProvSDKMessages.ProvSDKUIActivator_LicenseManagerReadError, e), StatusManager.LOG); } } } private void writeLicenseRegistry() { - if (!Policy.getDefault().getLicenseManager().hasAcceptedLicenses()) + if (getLicenseManager() == null) + return; + if (!getLicenseManager().hasAcceptedLicenses()) return; IPath location = getStateLocation().append(LICENSE_STORAGE); File f = location.toFile(); BufferedOutputStream stream = null; try { stream = new BufferedOutputStream(new FileOutputStream(f, false)); - Policy.getDefault().getLicenseManager().write(stream); + getLicenseManager().write(stream); stream.close(); } catch (IOException e) { - ProvUI.reportStatus(new Status(IStatus.ERROR, PLUGIN_ID, 0, ProvSDKMessages.ProvSDKUIActivator_ErrorWritingLicenseRegistry, e), StatusManager.LOG); + StatusManager.getManager().handle(new Status(IStatus.ERROR, PLUGIN_ID, 0, ProvSDKMessages.ProvSDKUIActivator_ErrorWritingLicenseRegistry, e), StatusManager.LOG); } } @@ -148,39 +160,12 @@ public class ProvSDKUIActivator extends AbstractUIPlugin { return (IProvisioningEventBus) context.getService(busReference); } - /** - * Get the id of the profile for the running system. Throw a ProvisionException - * if no self profile is available, unless configured to answer any - * profile. Getting any profile allows testing of the - * UI even when the system is not self hosting. - */ - public static String getSelfProfileId() throws ProvisionException { - // Get the profile of the running system. - IProfile profile = ProvisioningUtil.getProfile(IProfileRegistry.SELF); - if (profile == null) { - if (ANY_PROFILE) { - ProvUI.reportStatus(getNoSelfProfileStatus(), StatusManager.LOG); - IProfile[] profiles = ProvisioningUtil.getProfiles(); - if (profiles.length > 0) - return profiles[0].getProfileId(); - return ProfileFactory.makeProfile(DEFAULT_PROFILE_ID).getProfileId(); - } - throw new ProvisionException(getNoSelfProfileStatus()); - } - return profile.getProfileId(); - } - static IStatus getNoSelfProfileStatus() { return new Status(IStatus.WARNING, PLUGIN_ID, ProvSDKMessages.ProvSDKUIActivator_NoSelfProfile); } - void updateWithPreferences(IUViewQueryContext queryContext) { - queryContext.setShowLatestVersionsOnly(getPreferenceStore().getBoolean(PreferenceConstants.PREF_SHOW_LATEST_VERSION)); - queryContext.setVisibleAvailableIUProperty(IInstallableUnit.PROP_TYPE_GROUP); - // If this ever changes, we must change AutomaticUpdateSchedule.getProfileQuery() - queryContext.setVisibleInstalledIUProperty(IInstallableUnit.PROP_PROFILE_ROOT_IU); - queryContext.setArtifactRepositoryFlags(IRepositoryManager.REPOSITORIES_NON_SYSTEM); - queryContext.setMetadataRepositoryFlags(IRepositoryManager.REPOSITORIES_NON_SYSTEM); + void updateWithPreferences(Policy policy) { + policy.setShowLatestVersionsOnly(getPreferenceStore().getBoolean(PreferenceConstants.PREF_SHOW_LATEST_VERSION)); } /* @@ -201,7 +186,7 @@ public class ProvSDKUIActivator extends AbstractUIPlugin { try { preferenceStore.save(); } catch (IOException e) { - ProvUI.handleException(e, ProvSDKMessages.ProvSDKUIActivator_ErrorSavingPrefs, StatusManager.LOG | StatusManager.SHOW); + StatusManager.getManager().handle(new Status(IStatus.ERROR, PLUGIN_ID, 0, ProvSDKMessages.ProvSDKUIActivator_ErrorSavingPrefs, e), StatusManager.LOG | StatusManager.SHOW); } } } diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/SDKPolicy.java b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/SDKPolicy.java index 9a1a02d44..e8c70626f 100644 --- a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/SDKPolicy.java +++ b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/SDKPolicy.java @@ -12,11 +12,11 @@ package org.eclipse.equinox.internal.p2.ui.sdk; import org.eclipse.core.runtime.IStatus; import org.eclipse.equinox.internal.p2.ui.sdk.prefs.PreferenceConstants; -import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -import org.eclipse.equinox.internal.provisional.p2.director.ProvisioningPlan; -import org.eclipse.equinox.internal.provisional.p2.ui.IStatusCodes; -import org.eclipse.equinox.internal.provisional.p2.ui.ProvUI; -import org.eclipse.equinox.internal.provisional.p2.ui.policy.*; +import org.eclipse.equinox.p2.engine.IProvisioningPlan; +import org.eclipse.equinox.p2.engine.query.UserVisibleRootQuery; +import org.eclipse.equinox.p2.metadata.query.GroupQuery; +import org.eclipse.equinox.p2.operations.ProfileChangeOperation; +import org.eclipse.equinox.p2.ui.Policy; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialogWithToggle; import org.eclipse.jface.preference.IPreferenceStore; @@ -28,67 +28,47 @@ import org.eclipse.ui.statushandlers.StatusManager; * p2 UI. The policy is declared as an OSGi service in * the policy_component.xml file. * - * @since 3.5 + * @since 3.6 */ public class SDKPolicy extends Policy { + public SDKPolicy() { - setProfileChooser(new IProfileChooser() { - public String getProfileId(Shell shell) { - try { - return ProvSDKUIActivator.getSelfProfileId(); - } catch (ProvisionException e) { - ProvUI.handleException(e, e.getStatus().getMessage(), StatusManager.LOG); - return null; - } - } - }); - setRepositoryManipulator(new ColocatedRepositoryManipulator(this, PreferenceConstants.PREF_PAGE_SITES) { - public String getManipulatorLinkLabel() { - return ProvSDKMessages.ProvSDKUIActivator_SitePrefLink; - } - }); - setPlanValidator(new PlanValidator() { - public boolean continueWorkingWithPlan(ProvisioningPlan plan, Shell shell) { - if (plan == null) - return false; - if (plan.getStatus().getSeverity() == IStatus.CANCEL) - return false; + // initialize for our values + setVisibleAvailableIUQuery(new GroupQuery()); + // If this ever changes, we must change AutomaticUpdateSchedule.getProfileQuery() + setVisibleInstalledIUQuery(new UserVisibleRootQuery()); + ProvSDKUIActivator.getDefault().updateWithPreferences(this); + } - // Special case those statuses where we would never want to open a wizard - if (plan.getStatus().getCode() == IStatusCodes.NOTHING_TO_UPDATE) { - ProvUI.reportStatus(plan.getStatus(), StatusManager.BLOCK); - return false; - } + public IStatus getNoProfileChosenStatus() { + return ProvSDKUIActivator.getNoSelfProfileStatus(); + } - // Allow the wizard to open if there is no error - if (plan.getStatus().getSeverity() != IStatus.ERROR) - return true; + public boolean continueWorkingOperation(ProfileChangeOperation operation, Shell shell) { + // don't continue if superclass has already identified problem scenarios + boolean ok = super.continueWorkingWithOperation(operation, shell); + if (!ok) + return false; - // There is an error. Check the preference to see whether to continue. - IPreferenceStore prefs = ProvSDKUIActivator.getDefault().getPreferenceStore(); - String openPlan = prefs.getString(PreferenceConstants.PREF_OPEN_WIZARD_ON_ERROR_PLAN); - if (MessageDialogWithToggle.ALWAYS.equals(openPlan)) { - return true; - } - if (MessageDialogWithToggle.NEVER.equals(openPlan)) { - ProvUI.reportStatus(plan.getStatus(), StatusManager.SHOW | StatusManager.LOG); - return false; - } - MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion(shell, ProvSDKMessages.ProvSDKUIActivator_Question, ProvSDKMessages.ProvSDKUIActivator_OpenWizardAnyway, null, false, prefs, PreferenceConstants.PREF_OPEN_WIZARD_ON_ERROR_PLAN); + IProvisioningPlan plan = operation.getProvisioningPlan(); + if (plan == null) + return false; - // Any answer but yes will stop the performance of the plan, but NO is interpreted to mean, show me the error. - if (dialog.getReturnCode() == IDialogConstants.NO_ID) - ProvUI.reportStatus(plan.getStatus(), StatusManager.SHOW | StatusManager.LOG); - return dialog.getReturnCode() == IDialogConstants.YES_ID; - } - }); - // Start with the default query context and configure some settings - IUViewQueryContext queryContext = new IUViewQueryContext(IUViewQueryContext.AVAILABLE_VIEW_BY_CATEGORY); - setQueryContext(queryContext); - ProvSDKUIActivator.getDefault().updateWithPreferences(queryContext); - } + // Check the preference to see whether to continue. + IPreferenceStore prefs = ProvSDKUIActivator.getDefault().getPreferenceStore(); + String openPlan = prefs.getString(PreferenceConstants.PREF_OPEN_WIZARD_ON_ERROR_PLAN); + if (MessageDialogWithToggle.ALWAYS.equals(openPlan)) { + return true; + } + if (MessageDialogWithToggle.NEVER.equals(openPlan)) { + StatusManager.getManager().handle(plan.getStatus(), StatusManager.SHOW | StatusManager.LOG); + return false; + } + MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion(shell, ProvSDKMessages.ProvSDKUIActivator_Question, ProvSDKMessages.ProvSDKUIActivator_OpenWizardAnyway, null, false, prefs, PreferenceConstants.PREF_OPEN_WIZARD_ON_ERROR_PLAN); - public IStatus getNoProfileChosenStatus() { - return ProvSDKUIActivator.getNoSelfProfileStatus(); + // Any answer but yes will stop the performance of the plan, but NO is interpreted to mean, show me the error. + if (dialog.getReturnCode() == IDialogConstants.NO_ID) + StatusManager.getManager().handle(plan.getStatus(), StatusManager.SHOW | StatusManager.LOG); + return dialog.getReturnCode() == IDialogConstants.YES_ID; } } diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/SimpleLicenseManager.java b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/SimpleLicenseManager.java new file mode 100644 index 000000000..a30f2d0ed --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/SimpleLicenseManager.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2007, 2008 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Genuitec, LLC - added license support + *******************************************************************************/ +package org.eclipse.equinox.internal.p2.ui.sdk; + +import java.io.*; +import java.util.*; +import javax.xml.parsers.*; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.equinox.p2.metadata.ILicense; +import org.eclipse.equinox.p2.ui.LicenseManager; +import org.eclipse.ui.statushandlers.StatusManager; +import org.w3c.dom.*; +import org.xml.sax.SAXException; + +/** + * SimpleLicenseManager is a license manager that keeps track of + * IInstallableUnit licenses by using the digests of the IU's licenses. + * It can read and write its accepted list to a stream. + * + * @since 3.4 + */ +public class SimpleLicenseManager extends LicenseManager { + java.util.Set accepted = new HashSet(); + + public boolean accept(ILicense license) { + accepted.add(license.getUUID()); + return true; + } + + public boolean reject(ILicense license) { + accepted.remove(license.getUUID()); + return true; + } + + public boolean isAccepted(ILicense license) { + return accepted.contains(license.getUUID()); + } + + public boolean hasAcceptedLicenses() { + return !accepted.isEmpty(); + } + + public void read(InputStream stream) throws IOException { + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + DocumentBuilder parser = factory.newDocumentBuilder(); + Document doc = parser.parse(stream); + Node root = doc.getDocumentElement(); + processRoot(root, accepted); + } catch (ParserConfigurationException e) { + handleException(e, ProvSDKMessages.ProvUILicenseManager_ParsingError, StatusManager.LOG); + } catch (SAXException e) { + handleException(e, ProvSDKMessages.ProvUILicenseManager_ParsingError, StatusManager.LOG); + } + } + + private void handleException(Throwable t, String message, int style) { + if (message == null && t != null) { + message = t.getMessage(); + } + IStatus status = new Status(IStatus.ERROR, ProvSDKUIActivator.PLUGIN_ID, 0, message, t); + StatusManager.getManager().handle(status, style); + } + + public void write(OutputStream stream) throws IOException { + OutputStreamWriter osw = null; + PrintWriter writer = null; + try { + osw = new OutputStreamWriter(stream, "UTF8"); //$NON-NLS-1$ + writer = new PrintWriter(osw); + writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); //$NON-NLS-1$ + writer.println("<licenses>"); //$NON-NLS-1$ + for (Iterator i = accepted.iterator(); i.hasNext();) { + String digest = (String) i.next(); + writer.print(" " + "<license digest=\"" + digest + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + } finally { + writer.println("</licenses>"); //$NON-NLS-1$ + writer.flush(); + writer.close(); + if (osw != null) + osw.close(); + } + } + + private void processRoot(Node root, Set licenses) { + if (root.getNodeName().equals("licenses")) { //$NON-NLS-1$ + NodeList children = root.getChildNodes(); + processChildren(children, licenses); + } + } + + private void processChildren(NodeList children, Set licenses) { + for (int i = 0; i < children.getLength(); i++) { + Node child = children.item(i); + if (child.getNodeType() == Node.ELEMENT_NODE) { + if (child.getNodeName().equals("license")) { //$NON-NLS-1$ + NamedNodeMap atts = child.getAttributes(); + Node digestAtt = atts.getNamedItem("digest"); //$NON-NLS-1$ + if (digestAtt != null) { + licenses.add(digestAtt.getNodeValue()); + } + } + } + } + } +} diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/UpdateHandler.java b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/UpdateHandler.java index 924632b7d..df76f1d72 100644 --- a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/UpdateHandler.java +++ b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/UpdateHandler.java @@ -10,16 +10,10 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.ui.sdk; -import java.util.Collection; -import java.util.Iterator; -import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; -import org.eclipse.equinox.internal.provisional.p2.ui.*; -import org.eclipse.equinox.internal.provisional.p2.ui.actions.UpdateAction; -import org.eclipse.equinox.internal.provisional.p2.ui.model.ProfileElement; -import org.eclipse.equinox.internal.provisional.p2.ui.policy.Policy; -import org.eclipse.equinox.internal.provisional.p2.ui.policy.RepositoryManipulator; +import org.eclipse.equinox.p2.operations.RepositoryTracker; +import org.eclipse.equinox.p2.operations.UpdateOperation; +import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob; import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.*; /** * UpdateHandler invokes the check for updates UI @@ -30,59 +24,28 @@ public class UpdateHandler extends PreloadingRepositoryHandler { boolean hasNoRepos = false; - /** - * The constructor. - */ - public UpdateHandler() { - // constructor - } - - protected void doExecute(String profileId, QueryableMetadataRepositoryManager manager) { + protected void doExecute(LoadMetadataRepositoryJob job) { if (hasNoRepos) { - boolean goToSites = MessageDialog.openQuestion(getShell(), ProvSDKMessages.UpdateHandler_NoSitesTitle, ProvSDKMessages.UpdateHandler_NoSitesMessage); - if (goToSites) { - Policy.getDefault().getRepositoryManipulator().manipulateRepositories(getShell()); + if (getProvisioningUI().getPolicy().getRepositoriesVisible()) { + boolean goToSites = MessageDialog.openQuestion(getShell(), ProvSDKMessages.UpdateHandler_NoSitesTitle, ProvSDKMessages.UpdateHandler_NoSitesMessage); + if (goToSites) { + getProvisioningUI().manipulateRepositories(getShell()); + } } return; } - // get the profile roots - ElementQueryDescriptor queryDescriptor = Policy.getDefault().getQueryProvider().getQueryDescriptor(new ProfileElement(null, profileId)); - Collection collection = queryDescriptor.performQuery(null); - final IInstallableUnit[] roots = new IInstallableUnit[collection.size()]; - Iterator iter = collection.iterator(); - int i = 0; - while (iter.hasNext()) { - roots[i] = (IInstallableUnit) ProvUI.getAdapter(iter.next(), IInstallableUnit.class); - i++; + UpdateOperation operation = getProvisioningUI().getUpdateOperation(null, null); + // check for updates + operation.resolveModal(null); + if (getProvisioningUI().getPolicy().continueWorkingWithOperation(operation, getShell())) { + getProvisioningUI().openUpdateWizard(getShell(), true, operation, job); } - // now create an update action whose selection is all the roots - UpdateAction action = new UpdateAction(Policy.getDefault(), new ISelectionProvider() { - - public void addSelectionChangedListener(ISelectionChangedListener listener) { - // not dynamic - } - - public ISelection getSelection() { - return new StructuredSelection(roots); - } - - public void removeSelectionChangedListener(ISelectionChangedListener listener) { - // not dynamic - } - - public void setSelection(ISelection selection) { - // not mutable - - } - }, profileId, false); - action.setRepositoryManager(manager); - action.run(); } protected boolean preloadRepositories() { hasNoRepos = false; - RepositoryManipulator repoMan = Policy.getDefault().getRepositoryManipulator(); - if (repoMan != null && repoMan.getKnownRepositories().length == 0) { + RepositoryTracker repoMan = getProvisioningUI().getRepositoryTracker(); + if (repoMan.getKnownRepositories(getProvisioningUI().getSession()).length == 0) { hasNoRepos = true; return false; } diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/messages.properties b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/messages.properties index 3ad993dae..3431a70d8 100644 --- a/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/messages.properties +++ b/bundles/org.eclipse.equinox.p2.ui.sdk/src/org/eclipse/equinox/internal/p2/ui/sdk/messages.properties @@ -9,10 +9,6 @@ # IBM Corporation - initial API and implementation ############################################################################### - -Handler_CannotLaunchUI=Cannot complete the request. This installation has not been configured properly for Software Updates. -Handler_SDKUpdateUIMessageTitle=Software Updates -InstallNewSoftwareHandler_LoadRepositoryJobLabel=Contacting Software Sites PreferenceInitializer_Error=Error accessing preferences. ProvSDKUIActivator_ErrorSavingPrefs=Error saving update preferences ProvSDKUIActivator_ErrorWritingLicenseRegistry=Error writing license registry. Accepted licenses will not be remembered. @@ -20,7 +16,6 @@ ProvSDKUIActivator_LicenseManagerReadError=Error reading license registry. Acce ProvSDKUIActivator_NoSelfProfile=Could not locate the running profile instance. The eclipse.p2.data.area and eclipse.p2.profile properties may not be set correctly in this application's config.ini file. ProvSDKUIActivator_OpenWizardAnyway=The software items you selected may not be valid with your current installation. Do you want to open the wizard anyway to review the selections? ProvSDKUIActivator_Question=Question -ProvSDKUIActivator_SitePrefLink=Find more software by working with the <a>'Available Software Sites'</a> preferences. ProvisioningPreferencePage_AlwaysOpenWizard=&Open the wizard anyway to review or change selections ProvisioningPreferencePage_BrowsingPrefsGroup=Browsing for updates ProvisioningPreferencePage_ShowLatestVersions=Show only the &latest versions of available software @@ -28,5 +23,6 @@ ProvisioningPreferencePage_ShowAllVersions=Show all &versions of available softw ProvisioningPreferencePage_NeverOpenWizard=&Report the problems and do not open the wizard ProvisioningPreferencePage_OpenWizardIfInvalid=When software selected for an install wizard may not be compatible ProvisioningPreferencePage_PromptToOpenWizard=As&k me what to do when it happens +ProvUILicenseManager_ParsingError=Error parsing the accepted license registry UpdateHandler_NoSitesMessage=There are no update sites to search. Do you wish to open the "Available Software Sites" preferences? UpdateHandler_NoSitesTitle=No Updates Found
\ No newline at end of file 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 bf829f3e6..bc0369fa0 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 @@ -10,12 +10,13 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.ui.sdk.prefs; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.preferences.*; import org.eclipse.equinox.internal.p2.ui.sdk.ProvSDKMessages; import org.eclipse.equinox.internal.p2.ui.sdk.ProvSDKUIActivator; -import org.eclipse.equinox.internal.provisional.p2.engine.IProfileRegistry; -import org.eclipse.equinox.internal.provisional.p2.engine.ProfileScope; -import org.eclipse.equinox.internal.provisional.p2.ui.ProvUI; +import org.eclipse.equinox.p2.engine.IProfileRegistry; +import org.eclipse.equinox.p2.engine.ProfileScope; import org.eclipse.jface.dialogs.MessageDialogWithToggle; import org.eclipse.ui.statushandlers.StatusManager; import org.osgi.service.prefs.BackingStoreException; @@ -39,7 +40,7 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer { pref.flush(); } } catch (BackingStoreException e) { - ProvUI.handleException(e, ProvSDKMessages.PreferenceInitializer_Error, StatusManager.LOG); + StatusManager.getManager().handle(new Status(IStatus.ERROR, ProvSDKUIActivator.PLUGIN_ID, 0, ProvSDKMessages.PreferenceInitializer_Error, e), StatusManager.LOG); } } |