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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/*******************************************************************************
* Copyright (c) 2008, 2018 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.text.NumberFormat;
import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.equinox.internal.p2.ui.ProvUI;
import org.eclipse.equinox.internal.p2.ui.ProvUIMessages;
import org.eclipse.equinox.internal.p2.ui.model.IUElementListRoot;
import org.eclipse.equinox.p2.engine.IProvisioningPlan;
import org.eclipse.equinox.p2.engine.ProvisioningContext;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.operations.ProfileChangeOperation;
import org.eclipse.equinox.p2.query.IQueryable;
import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
import org.eclipse.equinox.p2.ui.ProvisioningUI;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
/**
*
* @since 3.5
*/
public abstract class SizeComputingWizardPage extends ResolutionResultsWizardPage {
protected Label sizeInfo;
protected long size;
Job sizingJob;
private IProvisioningPlan lastComputedPlan = null;
protected SizeComputingWizardPage(ProvisioningUI ui, ProvisioningOperationWizard wizard, IUElementListRoot root, ProfileChangeOperation initialResolution) {
super(ui, wizard, root, initialResolution);
// Compute size immediately if a plan is available. This may or may not finish before
// the widgetry is created.
if (initialResolution != null && initialResolution.hasResolved())
computeSizing(initialResolution.getProvisioningPlan(), initialResolution.getProvisioningContext());
else
// Set the size to indicate there is no size yet.
size = ProvUI.SIZE_NOTAPPLICABLE;
}
protected void computeSizing(final IProvisioningPlan plan, final ProvisioningContext provisioningContext) {
if (plan == lastComputedPlan)
return;
lastComputedPlan = plan;
size = ProvUI.SIZE_UNKNOWN;
updateSizingInfo();
if (sizingJob != null)
sizingJob.cancel();
sizingJob = new Job(ProvUIMessages.SizeComputingWizardPage_SizeJobTitle) {
@Override
protected IStatus run(IProgressMonitor monitor) {
size = ProvUI.getSize(ProvUI.getEngine(getProvisioningUI().getSession()), plan, provisioningContext, monitor);
if (monitor.isCanceled())
return Status.CANCEL_STATUS;
if (display != null) {
display.asyncExec(() -> updateSizingInfo());
}
return Status.OK_STATUS;
}
};
sizingJob.setUser(false);
sizingJob.setSystem(true);
sizingJob.setProperty(LoadMetadataRepositoryJob.SUPPRESS_AUTHENTICATION_JOB_MARKER, Boolean.toString(true));
sizingJob.schedule();
}
@Override
protected void createSizingInfo(Composite parent) {
sizeInfo = new Label(parent, SWT.NONE);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
sizeInfo.setLayoutData(data);
updateSizingInfo();
}
protected void updateSizingInfo() {
if (sizeInfo != null && !sizeInfo.isDisposed()) {
if (size == ProvUI.SIZE_NOTAPPLICABLE)
sizeInfo.setVisible(false);
else {
sizeInfo.setText(NLS.bind(ProvUIMessages.UpdateOrInstallWizardPage_Size, getFormattedSize()));
sizeInfo.setVisible(true);
}
}
}
protected String getFormattedSize() {
if (size == ProvUI.SIZE_UNKNOWN || size == ProvUI.SIZE_UNAVAILABLE)
return ProvUIMessages.IUDetailsLabelProvider_Unknown;
if (size > 1000L) {
long kb = size / 1000L;
return NLS.bind(ProvUIMessages.IUDetailsLabelProvider_KB, NumberFormat.getInstance().format(new Long(kb)));
}
return NLS.bind(ProvUIMessages.IUDetailsLabelProvider_Bytes, NumberFormat.getInstance().format(new Long(size)));
}
@Override
public void dispose() {
if (sizingJob != null) {
sizingJob.cancel();
sizingJob = null;
}
}
@Override
public void updateStatus(IUElementListRoot root, ProfileChangeOperation op) {
super.updateStatus(root, op);
if (op != null && op.getProvisioningPlan() != null)
computeSizing(op.getProvisioningPlan(), op.getProvisioningContext());
}
@Override
protected IQueryable<IInstallableUnit> getQueryable(IProvisioningPlan plan) {
return plan.getAdditions();
}
}
|