root / tmp / org.txm.rcp.p2.ui / tmp / UpdateWizard.java @ 2721
Historique | Voir | Annoter | Télécharger (8,51 ko)
1 |
/*******************************************************************************
|
---|---|
2 |
* Copyright (c) 2007, 2013 IBM Corporation and others.
|
3 |
* All rights reserved. This program and the accompanying materials
|
4 |
* are made available under the terms of the Eclipse Public License v1.0
|
5 |
* which accompanies this distribution, and is available at
|
6 |
* http://www.eclipse.org/legal/epl-v10.html
|
7 |
*
|
8 |
* Contributors:
|
9 |
* IBM Corporation - initial API and implementation
|
10 |
* Genuitec, LLC - added license support
|
11 |
* Sonatype, Inc. - ongoing development
|
12 |
* Red Hat, Inc. - support for remediation page
|
13 |
*******************************************************************************/
|
14 |
package org.eclipse.equinox.internal.p2.ui.dialogs; |
15 |
|
16 |
import java.util.*; |
17 |
import org.eclipse.core.runtime.Assert; |
18 |
import org.eclipse.equinox.internal.p2.ui.ProvUIImages; |
19 |
import org.eclipse.equinox.internal.p2.ui.ProvUIMessages; |
20 |
import org.eclipse.equinox.internal.p2.ui.model.*; |
21 |
import org.eclipse.equinox.p2.engine.IProfile; |
22 |
import org.eclipse.equinox.p2.engine.IProfileRegistry; |
23 |
import org.eclipse.equinox.p2.metadata.IInstallableUnit; |
24 |
import org.eclipse.equinox.p2.operations.*; |
25 |
import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob; |
26 |
import org.eclipse.equinox.p2.ui.ProvisioningUI; |
27 |
import org.eclipse.jface.wizard.IWizardPage; |
28 |
|
29 |
/**
|
30 |
* @since 3.4
|
31 |
*/
|
32 |
public class UpdateWizard extends WizardWithLicenses { |
33 |
IInstallableUnit[] iusToReplace;
|
34 |
boolean skipSelectionsPage = false; |
35 |
IUElementListRoot firstPageRoot; |
36 |
Update[] initialSelections;
|
37 |
|
38 |
public static Collection<IInstallableUnit> getIUsToReplace(Object[] elements) { |
39 |
Set<IInstallableUnit> iusToReplace = new HashSet<IInstallableUnit>(); |
40 |
for (int i = 0; i < elements.length; i++) { |
41 |
if (elements[i] instanceof AvailableUpdateElement) { |
42 |
iusToReplace.add(((AvailableUpdateElement) elements[i]).getIUToBeUpdated()); |
43 |
} |
44 |
} |
45 |
return iusToReplace;
|
46 |
} |
47 |
|
48 |
public static IInstallableUnit[] getReplacementIUs(Object[] elements) { |
49 |
Set<IInstallableUnit> replacements = new HashSet<IInstallableUnit>(); |
50 |
for (int i = 0; i < elements.length; i++) { |
51 |
if (elements[i] instanceof AvailableUpdateElement) { |
52 |
replacements.add(((AvailableUpdateElement) elements[i]).getIU()); |
53 |
} |
54 |
} |
55 |
return replacements.toArray(new IInstallableUnit[replacements.size()]); |
56 |
} |
57 |
|
58 |
public static Update[] makeUpdatesFromElements(Object[] elements) { |
59 |
Set<Update> updates = new HashSet<Update>(); |
60 |
for (int i = 0; i < elements.length; i++) { |
61 |
if (elements[i] instanceof AvailableUpdateElement) { |
62 |
updates.add(((AvailableUpdateElement) elements[i]).getUpdate()); |
63 |
} |
64 |
} |
65 |
return updates.toArray(new Update[updates.size()]); |
66 |
} |
67 |
|
68 |
/**
|
69 |
* Open an update wizard. For update wizards, the operation must have been resolved in advanced.
|
70 |
* This prevents searching for updates in the UI thread.
|
71 |
*
|
72 |
* @param ui the provisioning UI
|
73 |
* @param operation the update operation. Must already be resolved!
|
74 |
* @param initialSelections initial selections for the wizard (can be null)
|
75 |
* @param preloadJob a job that has been used to preload metadata repositories (can be null)
|
76 |
*/
|
77 |
public UpdateWizard(ProvisioningUI ui, UpdateOperation operation, Object[] initialSelections, LoadMetadataRepositoryJob preloadJob) { |
78 |
super(ui, operation, initialSelections, preloadJob);
|
79 |
this.initialSelections = (Update[]) initialSelections; |
80 |
Assert.isLegal(operation.hasResolved(), "Cannot create an update wizard on an unresolved operation"); //$NON-NLS-1$ |
81 |
setWindowTitle(ProvUIMessages.UpdateAction_UpdatesAvailableTitle); |
82 |
setDefaultPageImageDescriptor(ProvUIImages.getImageDescriptor(ProvUIImages.WIZARD_BANNER_UPDATE)); |
83 |
} |
84 |
|
85 |
private boolean isLocked(IProfile profile, IInstallableUnit iuToBeUpdated) { |
86 |
return Boolean.valueOf(profile.getInstallableUnitProperty(iuToBeUpdated, IProfile.PROP_PROFILE_LOCKED_IU)).booleanValue(); |
87 |
} |
88 |
|
89 |
public void deselectLockedIUs() { |
90 |
IProfileRegistry profileRegistry = (IProfileRegistry) ui.getSession().getProvisioningAgent().getService(IProfileRegistry.SERVICE_NAME); |
91 |
IProfile profile = profileRegistry.getProfile(ui.getProfileId()); |
92 |
|
93 |
ArrayList<Update> newSelection = new ArrayList<Update>(initialSelections.length); |
94 |
for (int i = 0; i < initialSelections.length; i++) { |
95 |
if (!isLocked(profile, initialSelections[i].toUpdate)) {
|
96 |
newSelection.add(initialSelections[i]); |
97 |
} |
98 |
} |
99 |
|
100 |
((UpdateOperation) operation).setSelectedUpdates(newSelection.toArray(new Update[newSelection.size()]));
|
101 |
recomputePlan(getContainer()); |
102 |
} |
103 |
|
104 |
protected ISelectableIUsPage createMainPage(IUElementListRoot input, Object[] selections) { |
105 |
mainPage = new SelectableIUsPage(ui, this, getAllPossibleUpdatesRoot(), selections); |
106 |
mainPage.setTitle(ProvUIMessages.UpdateAction_UpdatesAvailableTitle+" - TXM");
|
107 |
mainPage.setDescription(ProvUIMessages.UpdateAction_UpdatesAvailableMessage); |
108 |
((SelectableIUsPage) mainPage).updateStatus(getAllPossibleUpdatesRoot(), operation); |
109 |
return mainPage;
|
110 |
} |
111 |
|
112 |
protected ResolutionResultsWizardPage createResolutionPage() {
|
113 |
return new UpdateWizardPage(ui, this, root, (UpdateOperation) operation); |
114 |
} |
115 |
|
116 |
protected void initializeResolutionModelElements(Object[] selectedElements) { |
117 |
if (selectedElements == null) |
118 |
return;
|
119 |
root = new IUElementListRoot();
|
120 |
if (operation instanceof RemediationOperation) { |
121 |
AvailableIUElement[] elements = ElementUtils.requestToElement(((RemediationOperation) operation).getCurrentRemedy(), false); |
122 |
root.setChildren(elements); |
123 |
//planSelections = elements;
|
124 |
} else {
|
125 |
ArrayList<AvailableUpdateElement> list = new ArrayList<AvailableUpdateElement>(selectedElements.length); |
126 |
ArrayList<AvailableUpdateElement> selected = new ArrayList<AvailableUpdateElement>(selectedElements.length); |
127 |
for (int i = 0; i < selectedElements.length; i++) { |
128 |
if (selectedElements[i] instanceof AvailableUpdateElement) { |
129 |
AvailableUpdateElement element = (AvailableUpdateElement) selectedElements[i]; |
130 |
AvailableUpdateElement newElement = new AvailableUpdateElement(root, element.getIU(), element.getIUToBeUpdated(), getProfileId(), shouldShowProvisioningPlanChildren());
|
131 |
list.add(newElement); |
132 |
selected.add(newElement); |
133 |
} else if (selectedElements[i] instanceof Update) { |
134 |
Update update = (Update) selectedElements[i]; |
135 |
AvailableUpdateElement newElement = new AvailableUpdateElement(root, update.replacement, update.toUpdate, getProfileId(), shouldShowProvisioningPlanChildren());
|
136 |
list.add(newElement); |
137 |
selected.add(newElement); |
138 |
} |
139 |
} |
140 |
root.setChildren(list.toArray()); |
141 |
planSelections = selected.toArray(); |
142 |
} |
143 |
} |
144 |
|
145 |
protected IResolutionErrorReportingPage createErrorReportingPage() {
|
146 |
return (SelectableIUsPage) mainPage;
|
147 |
} |
148 |
|
149 |
public void setSkipSelectionsPage(boolean skipSelectionsPage) { |
150 |
this.skipSelectionsPage = skipSelectionsPage;
|
151 |
} |
152 |
|
153 |
public IWizardPage getStartingPage() {
|
154 |
//if (skipSelectionsPage) {
|
155 |
// TODO see https://bugs.eclipse.org/bugs/show_bug.cgi?id=276963
|
156 |
IWizardPage page = getNextPage(mainPage); |
157 |
if (page != null) |
158 |
return page;
|
159 |
else
|
160 |
return mainPage;
|
161 |
// }
|
162 |
// return mainPage;
|
163 |
} |
164 |
|
165 |
/* (non-Javadoc)
|
166 |
* @see org.eclipse.equinox.internal.p2.ui.dialogs.ProvisioningOperationWizard#getProfileChangeOperation(java.lang.Object[])
|
167 |
*/
|
168 |
protected ProfileChangeOperation getProfileChangeOperation(Object[] elements) { |
169 |
if (operation == null) { |
170 |
operation = new UpdateOperation(ui.getSession(), getIUsToReplace(elements));
|
171 |
operation.setProfileId(getProfileId()); |
172 |
// operation.setRootMarkerKey(getRootMarkerKey());
|
173 |
} else {
|
174 |
((UpdateOperation) operation).setSelectedUpdates(makeUpdatesFromElements(elements)); |
175 |
} |
176 |
return operation;
|
177 |
} |
178 |
|
179 |
private IUElementListRoot getAllPossibleUpdatesRoot() {
|
180 |
if (firstPageRoot == null) { |
181 |
firstPageRoot = new IUElementListRoot();
|
182 |
if (operation != null && operation instanceof UpdateOperation) { |
183 |
Update[] updates;
|
184 |
if (getPolicy().getShowLatestVersionsOnly()) {
|
185 |
updates = ((UpdateOperation) operation).getSelectedUpdates(); |
186 |
} else {
|
187 |
updates = ((UpdateOperation) operation).getPossibleUpdates(); |
188 |
} |
189 |
ArrayList<AvailableUpdateElement> allPossible = new ArrayList<AvailableUpdateElement>(updates.length); |
190 |
for (int i = 0; i < updates.length; i++) { |
191 |
AvailableUpdateElement newElement = new AvailableUpdateElement(firstPageRoot, updates[i].replacement, updates[i].toUpdate, getProfileId(), shouldShowProvisioningPlanChildren());
|
192 |
allPossible.add(newElement); |
193 |
} |
194 |
firstPageRoot.setChildren(allPossible.toArray()); |
195 |
} |
196 |
} |
197 |
return firstPageRoot;
|
198 |
} |
199 |
|
200 |
@Override
|
201 |
protected RemediationPage createRemediationPage() {
|
202 |
remediationPage = new RemediationPage(ui, this, root, operation); |
203 |
return remediationPage;
|
204 |
} |
205 |
|
206 |
} |