diff options
author | Susan Franklin | 2009-06-10 01:21:02 +0000 |
---|---|---|
committer | Susan Franklin | 2009-06-10 01:21:02 +0000 |
commit | 9b0f9f39c0e6621166089083807d40074b7bead6 (patch) | |
tree | cc0fdc25b330137517c9ed61fa799ad00b21c82b /bundles/org.eclipse.equinox.p2.ui/src/org/eclipse | |
parent | 3a6d6d2b688162d7e1a2e65bd426b79a0860842a (diff) | |
download | rt.equinox.p2-9b0f9f39c0e6621166089083807d40074b7bead6.tar.gz rt.equinox.p2-9b0f9f39c0e6621166089083807d40074b7bead6.tar.xz rt.equinox.p2-9b0f9f39c0e6621166089083807d40074b7bead6.zip |
Bug 217944 - [ui] Streamlined presentation for accepting multiple licenses during an install/update
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.ui/src/org/eclipse')
3 files changed, 139 insertions, 92 deletions
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 9d7d51cc9..5568fe20f 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 @@ -34,6 +34,7 @@ public class ProvUIMessages extends NLS { public static String AcceptLicensesWizardPage_RejectSingle; public static String AcceptLicensesWizardPage_ReviewExtraLicensesDescription; public static String AcceptLicensesWizardPage_ReviewLicensesDescription; + public static String AcceptLicensesWizardPage_SingleLicenseTextLabel; public static String AcceptLicensesWizardPage_Title; public static String ApplicationInRestartDialog; public static String ApplyProfileChangesDialog_ApplyChanges; 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 7f358393a..8b13a8630 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 @@ -117,13 +117,14 @@ ResolutionWizardPage_WarningInfoStatus=Your original request has been modified. AcceptLicensesWizardPage_AcceptMultiple=I &accept the terms of the license agreements AcceptLicensesWizardPage_AcceptSingle=I &accept the terms of the license agreement -AcceptLicensesWizardPage_ItemsLabel=&Items with licenses: -AcceptLicensesWizardPage_LicenseTextLabel=&License text: +AcceptLicensesWizardPage_ItemsLabel=&Licenses: +AcceptLicensesWizardPage_LicenseTextLabel=License &text: AcceptLicensesWizardPage_NoLicensesDescription=There are no licenses to review. Either the software does not specify a license, or the license has already been reviewed and approved. AcceptLicensesWizardPage_RejectMultiple=I &do not accept the terms of the license agreements AcceptLicensesWizardPage_RejectSingle=I &do not accept the terms of the license agreement AcceptLicensesWizardPage_ReviewExtraLicensesDescription=Licenses must be reviewed before the software can be installed. This includes licenses for software required to complete the install. AcceptLicensesWizardPage_ReviewLicensesDescription=Licenses must be reviewed and accepted before the software can be installed. +AcceptLicensesWizardPage_SingleLicenseTextLabel=License &text (for {0}): AcceptLicensesWizardPage_Title=Review Licenses AddRepositoryDialog_Title=Add Repository AddRepositoryDialog_DuplicateURL=Duplicate location diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/AcceptLicensesWizardPage.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/AcceptLicensesWizardPage.java index b914a5499..f8feb0026 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/AcceptLicensesWizardPage.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/AcceptLicensesWizardPage.java @@ -12,28 +12,28 @@ package org.eclipse.equinox.internal.provisional.p2.ui.dialogs; import java.util.*; import java.util.List; +import org.eclipse.equinox.internal.p2.metadata.License; import org.eclipse.equinox.internal.p2.ui.ProvUIActivator; import org.eclipse.equinox.internal.p2.ui.ProvUIMessages; import org.eclipse.equinox.internal.p2.ui.dialogs.ILayoutConstants; -import org.eclipse.equinox.internal.p2.ui.viewers.IUDetailsLabelProvider; import org.eclipse.equinox.internal.provisional.p2.director.ProvisioningPlan; import org.eclipse.equinox.internal.provisional.p2.engine.InstallableUnitOperand; import org.eclipse.equinox.internal.provisional.p2.engine.Operand; import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; import org.eclipse.equinox.internal.provisional.p2.metadata.ILicense; import org.eclipse.equinox.internal.provisional.p2.ui.IUPropertyUtils; -import org.eclipse.equinox.internal.provisional.p2.ui.model.IUElementListRoot; import org.eclipse.equinox.internal.provisional.p2.ui.policy.Policy; import org.eclipse.equinox.internal.provisional.p2.ui.viewers.IUColumnConfig; -import org.eclipse.equinox.internal.provisional.p2.ui.viewers.ProvElementContentProvider; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.viewers.*; import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.*; @@ -51,17 +51,85 @@ public class AcceptLicensesWizardPage extends WizardPage { private static final String NAME_COLUMN_WIDTH = "NameColumnWidth"; //$NON-NLS-1$ private static final String VERSION_COLUMN_WIDTH = "VersionColumnWidth"; //$NON-NLS-1$ - TableViewer iuViewer; + class LicenseContentProvider implements ITreeContentProvider { + public Object[] getChildren(Object parentElement) { + if (licensesToIUs.containsKey(parentElement)) + return ((ArrayList) licensesToIUs.get(parentElement)).toArray(); + return null; + } + + public Object getParent(Object element) { + return null; + } + + public boolean hasChildren(Object element) { + return licensesToIUs.containsKey(element); + } + + public Object[] getElements(Object inputElement) { + return licensesToIUs.keySet().toArray(); + } + + public void dispose() { + // Nothing to do + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // Nothing to do + } + } + + class LicenseLabelProvider extends LabelProvider { + public Image getImage(Object element) { + return null; + } + + public String getText(Object element) { + if (element instanceof License) { + return getFirstLine(((License) element).getBody()); + } else if (element instanceof IInstallableUnit) { + return getIUName((IInstallableUnit) element); + } + return ""; //$NON-NLS-1$ + } + + private String getFirstLine(String body) { + int i = body.indexOf('\n'); + int j = body.indexOf('\r'); + if (i > 0) { + if (j > 0) + return body.substring(0, i < j ? i : j); + return body.substring(0, i); + } else if (j > 0) { + return body.substring(0, j); + } + return body; + } + } + + TreeViewer iuViewer; Text licenseTextBox; Button acceptButton; Button declineButton; SashForm sashForm; private IInstallableUnit[] originalIUs; - private IInstallableUnit[] iusWithUnacceptedLicenses; + HashMap licensesToIUs; // License -> IU Name private Policy policy; IUColumnConfig nameColumn; IUColumnConfig versionColumn; + static String getIUName(IInstallableUnit iu) { + StringBuffer buf = new StringBuffer(); + String name = IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_NAME); + if (name != null) + buf.append(name); + else + buf.append(iu.getId()); + buf.append(" "); //$NON-NLS-1$ + buf.append(iu.getVersion().toString()); + return buf.toString(); + } + public AcceptLicensesWizardPage(Policy policy, IInstallableUnit[] ius, ProvisioningPlan plan) { super("AcceptLicenses"); //$NON-NLS-1$ setTitle(ProvUIMessages.AcceptLicensesWizardPage_Title); @@ -71,30 +139,27 @@ public class AcceptLicensesWizardPage extends WizardPage { public void createControl(Composite parent) { initializeDialogUnits(parent); - if (iusWithUnacceptedLicenses.length == 0) { + ArrayList ius; + if (licensesToIUs == null || licensesToIUs.size() == 0) { Label label = new Label(parent, SWT.NONE); setControl(label); - } else if (iusWithUnacceptedLicenses.length == 1) { - createLicenseSection(parent, true); + } else if (licensesToIUs.size() == 1 && (ius = (ArrayList) (licensesToIUs.values().iterator().next())).size() == 1) { + createLicenseContentSection(parent, (IInstallableUnit) ius.get(0)); } else { sashForm = new SashForm(parent, SWT.HORIZONTAL); sashForm.setLayout(new GridLayout()); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); sashForm.setLayoutData(gd); - createIUSection(sashForm); - createLicenseSection(sashForm, false); + createLicenseListSection(sashForm); + createLicenseContentSection(sashForm, null); sashForm.setWeights(getSashWeights()); setControl(sashForm); - - Object element = iuViewer.getElementAt(0); - if (element != null) - iuViewer.setSelection(new StructuredSelection(element)); } Dialog.applyDialogFont(getControl()); } - private void createIUSection(Composite parent) { + private void createLicenseListSection(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginWidth = 0; @@ -105,12 +170,11 @@ public class AcceptLicensesWizardPage extends WizardPage { Label label = new Label(composite, SWT.NONE); label.setText(ProvUIMessages.AcceptLicensesWizardPage_ItemsLabel); - iuViewer = new TableViewer(composite, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); - setTableColumns(iuViewer.getTable()); - iuViewer.setContentProvider(new ProvElementContentProvider()); - iuViewer.setLabelProvider(new IUDetailsLabelProvider()); + iuViewer = new TreeViewer(composite, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); + iuViewer.setContentProvider(new LicenseContentProvider()); + iuViewer.setLabelProvider(new LicenseLabelProvider()); iuViewer.setComparator(new ViewerComparator()); - iuViewer.setInput(new IUElementListRoot(iusWithUnacceptedLicenses)); + iuViewer.setInput(licensesToIUs); iuViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { @@ -149,7 +213,7 @@ public class AcceptLicensesWizardPage extends WizardPage { declineButton.setText(ProvUIMessages.AcceptLicensesWizardPage_RejectSingle); declineButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - setPageComplete(acceptButton.getSelection()); + setPageComplete(!declineButton.getSelection()); } }); @@ -157,7 +221,7 @@ public class AcceptLicensesWizardPage extends WizardPage { declineButton.setSelection(true); } - private void createLicenseSection(Composite parent, boolean singleLicense) { + private void createLicenseContentSection(Composite parent, IInstallableUnit singleIU) { Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginWidth = 0; @@ -167,7 +231,10 @@ public class AcceptLicensesWizardPage extends WizardPage { composite.setLayoutData(gd); Label label = new Label(composite, SWT.NONE); - label.setText(ProvUIMessages.AcceptLicensesWizardPage_LicenseTextLabel); + if (singleIU == null) + label.setText(ProvUIMessages.AcceptLicensesWizardPage_LicenseTextLabel); + else + label.setText(NLS.bind(ProvUIMessages.AcceptLicensesWizardPage_SingleLicenseTextLabel, getIUName(singleIU))); licenseTextBox = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.WRAP | SWT.READ_ONLY); licenseTextBox.setBackground(licenseTextBox.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); initializeDialogUnits(licenseTextBox); @@ -176,10 +243,10 @@ public class AcceptLicensesWizardPage extends WizardPage { gd.widthHint = convertWidthInCharsToPixels(ILayoutConstants.DEFAULT_COLUMN_WIDTH); licenseTextBox.setLayoutData(gd); - createLicenseAcceptSection(composite, !singleLicense); + createLicenseAcceptSection(composite, licensesToIUs.size() > 1); - if (singleLicense) { - licenseTextBox.setText(getLicenseBody(iusWithUnacceptedLicenses[0])); + if (singleIU != null) { + licenseTextBox.setText(getLicenseBody(singleIU)); setControl(composite); } } @@ -187,44 +254,30 @@ public class AcceptLicensesWizardPage extends WizardPage { void handleSelectionChanged(IStructuredSelection selection) { if (!selection.isEmpty()) { Object selected = selection.getFirstElement(); - if (selected instanceof IInstallableUnit) + if (selected instanceof License) + licenseTextBox.setText(((License) selected).getBody()); + else if (selected instanceof IInstallableUnit) licenseTextBox.setText(getLicenseBody((IInstallableUnit) selected)); } } - private void setTableColumns(Table table) { - table.setHeaderVisible(true); - nameColumn = new IUColumnConfig(ProvUIMessages.ProvUI_NameColumnTitle, IUColumnConfig.COLUMN_NAME, convertWidthInCharsToPixels(ILayoutConstants.DEFAULT_COLUMN_WIDTH)); - versionColumn = new IUColumnConfig(ProvUIMessages.ProvUI_VersionColumnTitle, IUColumnConfig.COLUMN_VERSION, convertWidthInCharsToPixels(ILayoutConstants.DEFAULT_COLUMN_WIDTH)); - initializeDialogUnits(table); - getColumnWidthsFromSettings(); - TableColumn tc = new TableColumn(table, SWT.NONE, 0); - tc.setResizable(true); - tc.setText(nameColumn.columnTitle); - tc.setWidth(nameColumn.getWidth()); - tc = new TableColumn(table, SWT.NONE, 1); - tc.setResizable(true); - tc.setText(versionColumn.columnTitle); - tc.setWidth(versionColumn.getWidth()); - } - public boolean performFinish() { rememberAcceptedLicenses(); return true; } public boolean hasLicensesToAccept() { - return iusWithUnacceptedLicenses.length > 0; + return licensesToIUs != null && licensesToIUs.size() > 0; } public void update(IInstallableUnit[] theIUs, ProvisioningPlan currentPlan) { this.originalIUs = theIUs; if (theIUs == null) - this.iusWithUnacceptedLicenses = new IInstallableUnit[0]; + licensesToIUs = new HashMap(); else - this.iusWithUnacceptedLicenses = iusWithUnacceptedLicenses(theIUs, currentPlan); + findUnacceptedLicenses(theIUs, currentPlan); setDescription(); - setPageComplete(iusWithUnacceptedLicenses.length == 0); + setPageComplete(licensesToIUs.size() == 0); if (getControl() != null) { Composite parent = getControl().getParent(); getControl().dispose(); @@ -242,7 +295,7 @@ public class AcceptLicensesWizardPage extends WizardPage { return ""; //$NON-NLS-1$ } - private IInstallableUnit[] iusWithUnacceptedLicenses(IInstallableUnit[] selectedIUs, ProvisioningPlan currentPlan) { + private void findUnacceptedLicenses(IInstallableUnit[] selectedIUs, ProvisioningPlan currentPlan) { IInstallableUnit[] iusToCheck; if (currentPlan == null) iusToCheck = selectedIUs; @@ -262,51 +315,58 @@ public class AcceptLicensesWizardPage extends WizardPage { // Current metadata generation can result with a feature group IU and the feature jar IU // having the same name and license. We will weed out duplicates if the license and name are both // the same. - // Note this algorithm is not generalized...we only save the first iu of any name found and this - // algorithm would allow duplicates if subsequent licenses found for an iu name did not match the - // first license yet still duplicated each other. Since this is not likely to happen we keep it - // simple. The UI for licenses will soon be reworked. - HashMap licensesByIUName = new HashMap();//map of String(iu name)->License - List unaccepted = new ArrayList(); - // We can't be sure that the viewer is created or the right label provider has been installed, so make another one. - IUDetailsLabelProvider labelProvider = new IUDetailsLabelProvider(); + licensesToIUs = new HashMap();//map of License->ArrayList of IUs with that license + HashMap namesSeen = new HashMap(); // map of License->HashSet of names with that license for (int i = 0; i < iusToCheck.length; i++) { IInstallableUnit iu = iusToCheck[i]; - String name = labelProvider.getText(iu); ILicense license = IUPropertyUtils.getLicense(iu); // It has a license, is it already accepted? if (license != null) { if (!policy.getLicenseManager().isAccepted(iu)) { - // Have we already found a license with this IU name? - ILicense potentialDuplicate = (ILicense) licensesByIUName.get(name); - // If we have no duplicate or the duplicate license doesn't match, add it - if (potentialDuplicate == null || !potentialDuplicate.equals(license)) - unaccepted.add(iu); - // We didn't have a duplicate, need to record this one - if (potentialDuplicate == null) - licensesByIUName.put(name, license); + String name = IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_NAME); + if (name == null) + name = iu.getId(); + // Have we already found this license? + if (licensesToIUs.containsKey(license)) { + HashSet names = (HashSet) namesSeen.get(license); + if (!names.contains(name)) { + names.add(name); + ((ArrayList) licensesToIUs.get(license)).add(iu); + } + } else { + ArrayList list = new ArrayList(1); + list.add(iu); + licensesToIUs.put(license, list); + HashSet names = new HashSet(1); + names.add(name); + namesSeen.put(license, names); + } } } } - // Wasn't that fun? - return (IInstallableUnit[]) unaccepted.toArray(new IInstallableUnit[unaccepted.size()]); } private void rememberAcceptedLicenses() { - for (int i = 0; i < iusWithUnacceptedLicenses.length; i++) { - policy.getLicenseManager().accept(iusWithUnacceptedLicenses[i]); + if (licensesToIUs == null) + return; + Iterator iter = licensesToIUs.keySet().iterator(); + while (iter.hasNext()) { + License license = (License) iter.next(); + ArrayList iusWithThisLicense = (ArrayList) licensesToIUs.get(license); + for (int i = 0; i < iusWithThisLicense.size(); i++) + policy.getLicenseManager().accept((IInstallableUnit) iusWithThisLicense.get(i)); } } private void setDescription() { // No licenses but the page is open. Shouldn't happen, but just in case... - if (iusWithUnacceptedLicenses.length == 0) + if (licensesToIUs == null || licensesToIUs.size() == 0) setDescription(ProvUIMessages.AcceptLicensesWizardPage_NoLicensesDescription); - // We have licenses. Use a generic message if we think we aren't showing + // We have licenses. Use a generic message if we think we aren't showing extra // licenses from required IU's. This check is not entirely accurate, for example // one root IU could have no license and the next one has two different // IU's with different licenses. But this cheaply catches the common cases. - else if (iusWithUnacceptedLicenses.length <= originalIUs.length) + else if (licensesToIUs.size() <= originalIUs.length) setDescription(ProvUIMessages.AcceptLicensesWizardPage_ReviewLicensesDescription); else { // Without a doubt we know we are showing extra licenses. @@ -319,15 +379,15 @@ public class AcceptLicensesWizardPage extends WizardPage { } public void saveBoundsRelatedSettings() { - if (iuViewer == null || iuViewer.getTable().isDisposed()) + if (iuViewer == null || iuViewer.getTree().isDisposed()) return; IDialogSettings settings = ProvUIActivator.getDefault().getDialogSettings(); IDialogSettings section = settings.getSection(getDialogSettingsName()); if (section == null) { section = settings.addNewSection(getDialogSettingsName()); } - section.put(NAME_COLUMN_WIDTH, iuViewer.getTable().getColumn(0).getWidth()); - section.put(VERSION_COLUMN_WIDTH, iuViewer.getTable().getColumn(1).getWidth()); + section.put(NAME_COLUMN_WIDTH, iuViewer.getTree().getColumn(0).getWidth()); + section.put(VERSION_COLUMN_WIDTH, iuViewer.getTree().getColumn(1).getWidth()); if (sashForm == null || sashForm.isDisposed()) return; @@ -336,21 +396,6 @@ public class AcceptLicensesWizardPage extends WizardPage { section.put(LICENSE_WEIGHT, weights[1]); } - private void getColumnWidthsFromSettings() { - IDialogSettings settings = ProvUIActivator.getDefault().getDialogSettings(); - IDialogSettings section = settings.getSection(getDialogSettingsName()); - if (section != null) { - try { - if (section.get(NAME_COLUMN_WIDTH) != null) - nameColumn.columnWidth = section.getInt(NAME_COLUMN_WIDTH); - if (section.get(VERSION_COLUMN_WIDTH) != null) - versionColumn.columnWidth = section.getInt(VERSION_COLUMN_WIDTH); - } catch (NumberFormatException e) { - // Ignore if there actually was a value that didn't parse. - } - } - } - private int[] getSashWeights() { IDialogSettings settings = ProvUIActivator.getDefault().getDialogSettings(); IDialogSettings section = settings.getSection(getDialogSettingsName()); |