From 92ed7a697cfced51f367b4a7172ab153d8c233da Mon Sep 17 00:00:00 2001 From: DJ Houghton Date: Mon, 21 Mar 2011 18:14:37 +0000 Subject: Bug 322477 - Support for elevated privileges for updates in shared install --- .../equinox/internal/p2/ui/ProvUIMessages.java | 3 +- .../p2/ui/dialogs/ResolutionStatusPage.java | 38 +++++++++++++++++--- .../internal/p2/ui/dialogs/SelectableIUsPage.java | 42 +++++++++++++++++++--- .../internal/p2/ui/dialogs/UpdateWizard.java | 25 ++++++++++++- .../equinox/internal/p2/ui/messages.properties | 3 +- .../p2/ui/model/AvailableUpdateElement.java | 26 ++++++++++++-- .../equinox/internal/p2/ui/model/ElementUtils.java | 4 +++ .../org/eclipse/equinox/p2/ui/ProvisioningUI.java | 4 +++ 8 files changed, 129 insertions(+), 16 deletions(-) (limited to 'bundles/org.eclipse.equinox.p2.ui') 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 501412e82..7ef68c6ab 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 IBM Corporation and others. + * Copyright (c) 2007, 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 @@ -158,6 +158,7 @@ public class ProvUIMessages extends NLS { public static String ResolutionWizardPage_ErrorStatus; public static String ResolutionWizardPage_NoSelections; public static String ResolutionWizardPage_WarningInfoStatus; + public static String ResolutionStatusPage_ErrorIULocked; // Dialogs public static String AddRepositoryDialog_InvalidURL; diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/ResolutionStatusPage.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/ResolutionStatusPage.java index f1af3f817..cdd7c6734 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/ResolutionStatusPage.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/ResolutionStatusPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 IBM Corporation and others. + * Copyright (c) 2009, 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 @@ -13,13 +13,14 @@ package org.eclipse.equinox.internal.p2.ui.dialogs; import org.eclipse.core.runtime.IStatus; import org.eclipse.equinox.internal.p2.ui.*; -import org.eclipse.equinox.internal.p2.ui.model.IUElementListRoot; +import org.eclipse.equinox.internal.p2.ui.model.*; import org.eclipse.equinox.internal.p2.ui.viewers.IUColumnConfig; import org.eclipse.equinox.p2.metadata.IInstallableUnit; import org.eclipse.equinox.p2.operations.ProfileChangeOperation; import org.eclipse.equinox.p2.ui.ProvisioningUI; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.dialogs.IMessageProvider; +import org.eclipse.osgi.util.NLS; import org.eclipse.swt.custom.SashForm; import org.eclipse.ui.statushandlers.StatusManager; @@ -60,6 +61,8 @@ public abstract class ResolutionStatusPage extends ProvisioningWizardPage { protected abstract IInstallableUnit getSelectedIU(); + protected abstract Object[] getSelectedElements(); + /** * Update the status area of the wizard to report the results of the operation. * @@ -110,6 +113,17 @@ public abstract class ResolutionStatusPage extends ProvisioningWizardPage { return description; } + protected String getIUDescription(AvailableIUElement element) { + IInstallableUnit iu = element.getIU(); + + String description = getIUDescription(iu); + + if (isLocked(element)) { + description = NLS.bind(ProvUIMessages.ResolutionStatusPage_ErrorIULocked, description); + } + return description; + } + String getMessageText(IStatus currentStatus) { if (currentStatus == null || currentStatus.isOK()) return getDescription(); @@ -122,7 +136,8 @@ public abstract class ResolutionStatusPage extends ProvisioningWizardPage { void setDetailText(ProfileChangeOperation resolvedOperation) { String detail = null; - IInstallableUnit selectedIU = getSelectedIU(); + AvailableIUElement selectedElement = (AvailableIUElement) getSelectedElement(); + IInstallableUnit selectedIU = ElementUtils.elementToIU(selectedElement); IUDetailsGroup detailsGroup = getDetailsGroup(); // We either haven't resolved, or we failed to resolve and reported some error @@ -134,7 +149,7 @@ public abstract class ResolutionStatusPage extends ProvisioningWizardPage { detail = currentStatus.getMessage(); detailsGroup.enablePropertyLink(false); } else if (selectedIU != null) { - detail = getIUDescription(selectedIU); + detail = getIUDescription(selectedElement); detailsGroup.enablePropertyLink(true); } else { detail = ""; //$NON-NLS-1$ @@ -165,7 +180,7 @@ public abstract class ResolutionStatusPage extends ProvisioningWizardPage { // The overall status is not an error, or else there was no explanatory text for an error. // We may as well just show info about this iu. detailsGroup.enablePropertyLink(true); - detailsGroup.setDetailText(getIUDescription(selectedIU)); + detailsGroup.setDetailText(getIUDescription(selectedElement)); return; } @@ -177,6 +192,13 @@ public abstract class ResolutionStatusPage extends ProvisioningWizardPage { detailsGroup.setDetailText(detail); } + private Object getSelectedElement() { + Object[] elements = getSelectedElements(); + if (elements.length == 0) + return null; + return elements[0]; + } + protected abstract String getDialogSettingsName(); protected abstract SashForm getSashForm(); @@ -269,4 +291,10 @@ public abstract class ResolutionStatusPage extends ProvisioningWizardPage { getColumnWidthsFromSettings(); return new IUColumnConfig[] {nameColumn, versionColumn, idColumn}; } + + private boolean isLocked(AvailableIUElement elementToBeUpdated) { + if (elementToBeUpdated instanceof AvailableUpdateElement) + return ((AvailableUpdateElement) elementToBeUpdated).isLocked(); + return false; + } } diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/SelectableIUsPage.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/SelectableIUsPage.java index 6817c764f..897df3669 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/SelectableIUsPage.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/SelectableIUsPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 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 @@ -12,10 +12,10 @@ *******************************************************************************/ package org.eclipse.equinox.internal.p2.ui.dialogs; +import java.util.ArrayList; import org.eclipse.equinox.internal.p2.ui.ProvUI; import org.eclipse.equinox.internal.p2.ui.ProvUIMessages; -import org.eclipse.equinox.internal.p2.ui.model.ElementUtils; -import org.eclipse.equinox.internal.p2.ui.model.IUElementListRoot; +import org.eclipse.equinox.internal.p2.ui.model.*; import org.eclipse.equinox.internal.p2.ui.viewers.*; import org.eclipse.equinox.p2.metadata.IInstallableUnit; import org.eclipse.equinox.p2.operations.ProfileChangeOperation; @@ -109,6 +109,24 @@ public class SelectableIUsPage extends ResolutionStatusPage implements IResoluti tableViewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { + // If the checkEvent is on a locked update element, uncheck it and select it. + if (event.getElement() instanceof AvailableUpdateElement) { + AvailableUpdateElement checkedElement = (AvailableUpdateElement) event.getElement(); + if (checkedElement.isLocked()) { + event.getCheckable().setChecked(checkedElement, false); + // Select the element so that the locked description is displayed + CheckboxTableViewer viewer = ((CheckboxTableViewer) event.getSource()); + int itemCount = viewer.getTable().getItemCount(); + for (int i = 0; i < itemCount; i++) { + if (viewer.getElementAt(i).equals(checkedElement)) { + viewer.getTable().deselectAll(); + viewer.getTable().select(i); + setDetailText(resolvedOperation); + break; + } + } + } + } updateSelection(); } }); @@ -210,8 +228,22 @@ public class SelectableIUsPage extends ResolutionStatusPage implements IResoluti } protected void setInitialCheckState() { - if (initialSelections != null) - tableViewer.setCheckedElements(initialSelections); + if (initialSelections == null) { + return; + } + + ArrayList selections = new ArrayList(initialSelections.length); + + for (int i = 0; i < initialSelections.length; i++) { + if (initialSelections[i] instanceof AvailableUpdateElement) { + AvailableUpdateElement element = (AvailableUpdateElement) initialSelections[i]; + if (element.isLocked()) { + continue; + } + } + selections.add(initialSelections[i]); + } + tableViewer.setCheckedElements(selections.toArray(new Object[selections.size()])); } /* diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/UpdateWizard.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/UpdateWizard.java index ee3c10e24..c421f7cef 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/UpdateWizard.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/UpdateWizard.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 IBM Corporation and others. + * Copyright (c) 2007, 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 @@ -18,6 +18,8 @@ import org.eclipse.equinox.internal.p2.ui.ProvUIImages; import org.eclipse.equinox.internal.p2.ui.ProvUIMessages; import org.eclipse.equinox.internal.p2.ui.model.AvailableUpdateElement; import org.eclipse.equinox.internal.p2.ui.model.IUElementListRoot; +import org.eclipse.equinox.p2.engine.IProfile; +import org.eclipse.equinox.p2.engine.IProfileRegistry; import org.eclipse.equinox.p2.metadata.IInstallableUnit; import org.eclipse.equinox.p2.operations.*; import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob; @@ -31,6 +33,7 @@ public class UpdateWizard extends WizardWithLicenses { IInstallableUnit[] iusToReplace; boolean skipSelectionsPage = false; IUElementListRoot firstPageRoot; + Update[] initialSelections; public static Collection getIUsToReplace(Object[] elements) { Set iusToReplace = new HashSet(); @@ -73,11 +76,31 @@ public class UpdateWizard extends WizardWithLicenses { */ public UpdateWizard(ProvisioningUI ui, UpdateOperation operation, Object[] initialSelections, LoadMetadataRepositoryJob preloadJob) { super(ui, operation, initialSelections, preloadJob); + this.initialSelections = (Update[]) initialSelections; Assert.isLegal(operation.hasResolved(), "Cannot create an update wizard on an unresolved operation"); //$NON-NLS-1$ setWindowTitle(ProvUIMessages.UpdateAction_UpdatesAvailableTitle); setDefaultPageImageDescriptor(ProvUIImages.getImageDescriptor(ProvUIImages.WIZARD_BANNER_UPDATE)); } + private boolean isLocked(IProfile profile, IInstallableUnit iuToBeUpdated) { + return Boolean.valueOf(profile.getInstallableUnitProperty(iuToBeUpdated, IProfile.PROP_PROFILE_LOCKED_IU)).booleanValue(); + } + + public void deselectLockedIUs() { + IProfileRegistry profileRegistry = (IProfileRegistry) ui.getSession().getProvisioningAgent().getService(IProfileRegistry.SERVICE_NAME); + IProfile profile = profileRegistry.getProfile(ui.getProfileId()); + + ArrayList newSelection = new ArrayList(initialSelections.length); + for (int i = 0; i < initialSelections.length; i++) { + if (!isLocked(profile, initialSelections[i].toUpdate)) { + newSelection.add(initialSelections[i]); + } + } + + ((UpdateOperation) operation).setSelectedUpdates(newSelection.toArray(new Update[newSelection.size()])); + recomputePlan(getContainer()); + } + protected ISelectableIUsPage createMainPage(IUElementListRoot input, Object[] selections) { mainPage = new SelectableIUsPage(ui, this, getAllPossibleUpdatesRoot(), selections); mainPage.setTitle(ProvUIMessages.UpdateAction_UpdatesAvailableTitle); 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 4289016c8..791937713 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 @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2007, 2010 IBM Corporation and others. +# Copyright (c) 2007, 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 @@ -106,6 +106,7 @@ ResolutionWizardPage_Canceled=The operation was cancelled. ResolutionWizardPage_ErrorStatus=The operation cannot be completed. See the details. ResolutionWizardPage_NoSelections=There were no installable units selected when the plan was computed. ResolutionWizardPage_WarningInfoStatus=Your original request has been modified. See the details. +ResolutionStatusPage_ErrorIULocked=Insufficient access privileges to apply this update.\n\n{0} AcceptLicensesWizardPage_AcceptMultiple=I &accept the terms of the license agreements AcceptLicensesWizardPage_AcceptSingle=I &accept the terms of the license agreement diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/AvailableUpdateElement.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/AvailableUpdateElement.java index f04063350..bc7afe2b2 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/AvailableUpdateElement.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/AvailableUpdateElement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 IBM Corporation and others. + * Copyright (c) 2007, 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 @@ -13,8 +13,8 @@ package org.eclipse.equinox.internal.p2.ui.model; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest; -import org.eclipse.equinox.p2.engine.IProvisioningPlan; -import org.eclipse.equinox.p2.engine.ProvisioningContext; +import org.eclipse.equinox.internal.p2.ui.ProvUIImages; +import org.eclipse.equinox.p2.engine.*; import org.eclipse.equinox.p2.metadata.IInstallableUnit; import org.eclipse.equinox.p2.operations.Update; import org.eclipse.equinox.p2.planner.IPlanner; @@ -30,11 +30,24 @@ import org.eclipse.equinox.p2.planner.IProfileChangeRequest; public class AvailableUpdateElement extends AvailableIUElement { IInstallableUnit iuToBeUpdated; + boolean isLocked = false; public AvailableUpdateElement(Object parent, IInstallableUnit iu, IInstallableUnit iuToBeUpdated, String profileID, boolean shouldShowChildren) { super(parent, iu, profileID, shouldShowChildren); setIsInstalled(false); this.iuToBeUpdated = iuToBeUpdated; + init(); + + } + + private void init() { + IProfileRegistry profileRegistry = (IProfileRegistry) getProvisioningUI().getSession().getProvisioningAgent().getService(IProfileRegistry.SERVICE_NAME); + IProfile profile = profileRegistry.getProfile(profileID); + isLocked = profile.getInstallableUnitProperty(iuToBeUpdated, IProfile.PROP_PROFILE_LOCKED_IU) != null; + } + + public boolean isLocked() { + return isLocked; } public IInstallableUnit getIUToBeUpdated() { @@ -76,4 +89,11 @@ public class AvailableUpdateElement extends AvailableIUElement { public Update getUpdate() { return new Update(iuToBeUpdated, getIU()); } + + protected String getImageId(Object obj) { + String imageId = super.getImageId(obj); + if (ProvUIImages.IMG_IU.equals(imageId) && isLocked()) + return ProvUIImages.IMG_DISABLED_IU; + return imageId; + } } diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/ElementUtils.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/ElementUtils.java index 8fa52a46f..3ad63b418 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/ElementUtils.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/model/ElementUtils.java @@ -113,6 +113,10 @@ public class ElementUtils { return theIUs; } + public static IInstallableUnit elementToIU(Object selectedElement) { + return ProvUI.getAdapter(selectedElement, IInstallableUnit.class); + } + static boolean containsURI(URI[] locations, URI url) { for (int i = 0; i < locations.length; i++) if (locations[i].equals(url)) diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/ProvisioningUI.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/ProvisioningUI.java index adf22fb54..6b8625647 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/ProvisioningUI.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/ProvisioningUI.java @@ -15,6 +15,7 @@ package org.eclipse.equinox.p2.ui; import java.net.URI; import java.util.Collection; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.p2.core.helpers.Tracing; @@ -238,6 +239,9 @@ public class ProvisioningUI { WizardDialog dialog = new ProvisioningWizardDialog(ProvUI.getDefaultParentShell(), wizard); dialog.create(); PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), IProvHelpContextIds.UPDATE_WIZARD); + if (wizard.getCurrentStatus().getSeverity() == IStatus.ERROR) { + wizard.deselectLockedIUs(); + } return dialog.open(); } -- cgit v1.2.3