Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSusan Franklin2010-03-17 22:38:31 +0000
committerSusan Franklin2010-03-17 22:38:31 +0000
commit03c23af445058b710b5bf75e86ac97658c4ee721 (patch)
treec6b8903114e82505d90d1f2750d6e8836b8d3347
parent3ef4a70e5ecf0c7e4c23da47208c7df9bc41408d (diff)
downloadrt.equinox.p2-03c23af445058b710b5bf75e86ac97658c4ee721.tar.gz
rt.equinox.p2-03c23af445058b710b5bf75e86ac97658c4ee721.tar.xz
rt.equinox.p2-03c23af445058b710b5bf75e86ac97658c4ee721.zip
Bug 290972 - [ui] Updates wizard should optimize layout for the "only one thing to update" case
-rw-r--r--bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/UpdateSingleIUPage.java93
-rw-r--r--bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/UpdateSingleIUWizard.java103
2 files changed, 196 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/UpdateSingleIUPage.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/UpdateSingleIUPage.java
new file mode 100644
index 000000000..81f88212b
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/UpdateSingleIUPage.java
@@ -0,0 +1,93 @@
+package org.eclipse.equinox.internal.p2.ui.dialogs;
+
+import java.net.MalformedURLException;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.URIUtil;
+import org.eclipse.equinox.internal.p2.ui.model.AvailableUpdateElement;
+import org.eclipse.equinox.internal.p2.ui.viewers.IUDetailsLabelProvider;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.operations.Update;
+import org.eclipse.equinox.p2.operations.UpdateOperation;
+import org.eclipse.equinox.p2.ui.ProvisioningUI;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.SWTError;
+import org.eclipse.swt.browser.Browser;
+import org.eclipse.swt.widgets.*;
+
+public class UpdateSingleIUPage extends ProvisioningWizardPage implements ISelectableIUsPage {
+
+ UpdateOperation operation;
+
+ protected UpdateSingleIUPage(UpdateOperation operation, ProvisioningUI ui, ProvisioningOperationWizard wizard) {
+ super("UpdateSingleIUPage", ui, wizard); //$NON-NLS-1$
+ Assert.isNotNull(operation);
+ Assert.isTrue(operation.hasResolved());
+ Assert.isTrue(operation.getSelectedUpdates().length == 1);
+ Assert.isTrue(operation.getResolutionResult().isOK());
+ this.operation = operation;
+ }
+
+ public void createControl(Composite parent) {
+ IInstallableUnit updateIU = getUpdate().replacement;
+ String url = null;
+ if (updateIU.getUpdateDescriptor().getLocation() != null)
+ try {
+ url = URIUtil.toURL(updateIU.getUpdateDescriptor().getLocation()).toExternalForm();
+ } catch (MalformedURLException e) {
+ // ignore and null URL will be ignored below
+ }
+ if (url != null) {
+ Browser browser = null;
+ try {
+ browser = new Browser(parent, SWT.NONE);
+ browser.setUrl(url);
+ return;
+ } catch (SWTError e) {
+ // Fall through to backup plan.
+ }
+ }
+ // Create a text description of the update.
+ Text text = new Text(parent, SWT.MULTI | SWT.V_SCROLL);
+ text.setText(getUpdateText(updateIU));
+ }
+
+ private String getUpdateText(IInstallableUnit iu) {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(new IUDetailsLabelProvider().getClipboardText(getCheckedIUElements()[0], CopyUtils.DELIMITER));
+ buffer.append(CopyUtils.NEWLINE);
+ buffer.append(CopyUtils.NEWLINE);
+ String text = iu.getUpdateDescriptor().getDescription();
+ if (text != null)
+ buffer.append(text);
+ else {
+ text = iu.getProperty(IInstallableUnit.PROP_DESCRIPTION);
+ if (text != null)
+ buffer.append(text);
+ }
+ return buffer.toString();
+
+ }
+
+ public Object[] getCheckedIUElements() {
+ Update update = getUpdate();
+ return new Object[] {new AvailableUpdateElement(null, update.replacement, update.toUpdate, getProfileId(), false)};
+ }
+
+ public Object[] getSelectedIUElements() {
+ return getCheckedIUElements();
+ }
+
+ public void setCheckedElements(Object[] elements) {
+ // ignored
+ }
+
+ @Override
+ protected String getClipboardText(Control control) {
+ return getUpdate().toString();
+ }
+
+ private Update getUpdate() {
+ return operation.getSelectedUpdates()[0];
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/UpdateSingleIUWizard.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/UpdateSingleIUWizard.java
new file mode 100644
index 000000000..9aade4866
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/UpdateSingleIUWizard.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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
+ *******************************************************************************/
+package org.eclipse.equinox.internal.p2.ui.dialogs;
+
+import java.util.ArrayList;
+import org.eclipse.equinox.internal.p2.ui.ProvUIImages;
+import org.eclipse.equinox.internal.p2.ui.ProvUIMessages;
+import org.eclipse.equinox.internal.p2.ui.model.*;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.operations.*;
+import org.eclipse.equinox.p2.ui.AcceptLicensesWizardPage;
+import org.eclipse.equinox.p2.ui.ProvisioningUI;
+
+/**
+ * An update wizard that is invoked when there is only one thing to update, only
+ * one update to choose, and the resolution is known to be successful.
+ *
+ * @since 3.6
+ */
+public class UpdateSingleIUWizard extends WizardWithLicenses {
+
+ public static boolean validFor(UpdateOperation operation) {
+ return operation.hasResolved() && operation.getResolutionResult().isOK() && operation.getSelectedUpdates().length == 1;
+ }
+
+ public UpdateSingleIUWizard(ProvisioningUI ui, UpdateOperation operation) {
+ super(ui, operation, null, null);
+ setWindowTitle(ProvUIMessages.UpdateIUOperationLabel);
+ setDefaultPageImageDescriptor(ProvUIImages.getImageDescriptor(ProvUIImages.WIZARD_BANNER_UPDATE));
+ }
+
+ protected ISelectableIUsPage createMainPage() {
+ mainPage = new UpdateSingleIUPage((UpdateOperation) operation, ui, this);
+ mainPage.setTitle(ProvUIMessages.PreselectedIUInstallWizard_Title);
+ mainPage.setDescription(ProvUIMessages.PreselectedIUInstallWizard_Description);
+ return mainPage;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.wizard.Wizard#addPages()
+ */
+ public void addPages() {
+ mainPage = createMainPage();
+ addPage(mainPage);
+ AcceptLicensesWizardPage page = createLicensesPage();
+ page.update(null, operation);
+ if (page.hasLicensesToAccept())
+ addPage(page);
+ }
+
+ protected void initializeResolutionModelElements(Object[] selectedElements) {
+ root = new IUElementListRoot();
+ ArrayList<AvailableIUElement> list = new ArrayList<AvailableIUElement>(selectedElements.length);
+ ArrayList<AvailableIUElement> selected = new ArrayList<AvailableIUElement>(selectedElements.length);
+ for (int i = 0; i < selectedElements.length; i++) {
+ IInstallableUnit iu = ElementUtils.getIU(selectedElements[i]);
+ if (iu != null) {
+ AvailableIUElement element = new AvailableIUElement(root, iu, getProfileId(), shouldShowProvisioningPlanChildren());
+ list.add(element);
+ selected.add(element);
+ }
+ }
+ root.setChildren(list.toArray());
+ planSelections = selected.toArray();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.equinox.internal.p2.ui.dialogs.ProvisioningOperationWizard#getErrorReportingPage()
+ */
+ protected IResolutionErrorReportingPage createErrorReportingPage() {
+ return (IResolutionErrorReportingPage) mainPage;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.equinox.internal.p2.ui.dialogs.ProvisioningOperationWizard#getProfileChangeOperation(java.lang.Object[])
+ */
+ protected ProfileChangeOperation getProfileChangeOperation(Object[] elements) {
+ InstallOperation op = new InstallOperation(ui.getSession(), ElementUtils.elementsToIUs(elements));
+ op.setProfileId(getProfileId());
+ // op.setRootMarkerKey(getRootMarkerKey());
+ op.setProvisioningContext(getProvisioningContext());
+ return op;
+ }
+
+ @Override
+ protected ISelectableIUsPage createMainPage(IUElementListRoot input, Object[] selections) {
+ return createMainPage();
+ }
+
+ @Override
+ protected ResolutionResultsWizardPage createResolutionPage() {
+ return null;
+ }
+}

Back to the top