Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6c61ea1513e16633761da6c3178f73822c8b0e97 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package org.eclipse.equinox.internal.p2.ui.dialogs;

import java.net.MalformedURLException;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.ui.ProvUIMessages;
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.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTError;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.statushandlers.StatusManager;

public class UpdateSingleIUPage extends ProvisioningWizardPage {

	UpdateOperation operation;

	protected UpdateSingleIUPage(UpdateOperation operation, ProvisioningUI ui) {
		super("UpdateSingleIUPage", ui, null); //$NON-NLS-1$
		setTitle(ProvUIMessages.UpdateAction_UpdatesAvailableTitle);
		IProduct product = Platform.getProduct();
		String productName = product != null && product.getName() != null ? product.getName() : ProvUIMessages.ApplicationInRestartDialog;
		setDescription(NLS.bind(ProvUIMessages.UpdateSingleIUPage_SingleUpdateDescription, productName));
		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);
				browser.setBackground(parent.getBackground());
				Point size = getProvisioningUI().getPolicy().getUpdateDetailsPreferredSize();
				if (size != null) {
					browser.setSize(size);
				}
				setControl(browser);
				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 | SWT.READ_ONLY);
		text.setBackground(parent.getBackground());
		text.setText(getUpdateText(updateIU));
		setControl(text);
	}

	private String getUpdateText(IInstallableUnit iu) {
		StringBuffer buffer = new StringBuffer();
		buffer.append(new IUDetailsLabelProvider().getClipboardText(getUpdate().replacement, 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 boolean performFinish() {
		if (operation.getResolutionResult().getSeverity() != IStatus.ERROR) {
			getProvisioningUI().schedule(operation.getProvisioningJob(null), StatusManager.SHOW | StatusManager.LOG);
			return true;
		}
		return false;
	}

	@Override
	protected String getClipboardText(Control control) {
		return getUpdate().toString();
	}

	private Update getUpdate() {
		return operation.getSelectedUpdates()[0];
	}

}

Back to the top