Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7a8b046b0c974b992b46e78bdd2024c2940f005c (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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
/*******************************************************************************
 * Copyright (c) 2008, 2012 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
 *     Ericsson AB (Hamdan Msheik) - Bug 396420 - Control Install dialog through preference customization
 *******************************************************************************/
package org.eclipse.equinox.p2.ui;

import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.internal.p2.ui.ProvUI;
import org.eclipse.equinox.p2.engine.query.UserVisibleRootQuery;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.operations.ProfileChangeOperation;
import org.eclipse.equinox.p2.operations.UpdateOperation;
import org.eclipse.equinox.p2.query.IQuery;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.statushandlers.StatusManager;

/**
 * The Policy class is used to specify application specific policies that
 * should be used in the standard p2 UI class libraries.   The default policy
 * is acquired using the OSGi service model.
 * 
 * Policy allows clients to specify things such as how repositories 
 * are manipulated in the standard wizards and dialogs, and how the repositories
 * or the installation itself should be traversed when displaying content.
 * 
 * In some cases, the Policy is used only to define a default value that can
 * be overridden by user choice and subsequently stored in dialog settings.
 * 
 * Client applications should ensure that their Policy is registered before
 * any of the p2 UI objects access the default Policy.  
 * 
 * @since 2.0
 */
public class Policy {

	/**
	 * A constant indicating that restart should be forced (without
	 * confirmation) immediately after completion of a provisioning operation.
	 * 
	 */
	public static final int RESTART_POLICY_FORCE = 1;

	/**
	 * A constant indicating that the changes should be applied dynamically
	 * to the profile (without confirmation) immediately after completion of 
	 * a provisioning operation.
	 */
	public static final int RESTART_POLICY_FORCE_APPLY = 2;

	/**
	 * A constant indicating that the user should be prompted to
	 * restart after completion of a provisioning operation.
	 */
	public static final int RESTART_POLICY_PROMPT = 3;

	/**
	 * A constant indicating that, where possible, the user should 
	 * be given the option to restart or dynamically apply the changes
	 * after completion of a provisioning operation.
	 */
	public static final int RESTART_POLICY_PROMPT_RESTART_OR_APPLY = 4;

	/**
	 * A constant indicating that the user should be presented with an
	 * update wizard that shows a list of IUs that can be updated.
	 * Even when only one update is available, a list showing the single
	 * update will be used.  This option is recommended when the user's view
	 * of the system is a set of component updates and the user is expected
	 * to have knowledge of the composition of the system.
	 * 
	 * @since 2.1
	 */
	public static final int UPDATE_STYLE_MULTIPLE_IUS = 1;

	/**
	 * A constant indicating that the user should be presented with an
	 * update wizard that shows detail about a single IU that can be
	 * updated.  If more than one IU can be updated, the user will be shown
	 * a list; however, this option is recommended to be used only when
	 * the user's view of the system is a single application that can be 
	 * updated, and only one IU is expected to be available for update.
	 * 
	 * @since 2.1
	 */
	public static final int UPDATE_STYLE_SINGLE_IUS = 2;

	private IQuery<IInstallableUnit> visibleAvailableIUQuery = QueryUtil.createIUGroupQuery();
	private IQuery<IInstallableUnit> visibleInstalledIUQuery = new UserVisibleRootQuery();
	private boolean groupByCategory = true;
	private boolean allowDrilldown = true;
	private boolean repositoriesVisible = true;
	private boolean contactAllSites = true;
	private boolean hideAlreadyInstalled = true;
	private boolean showLatestVersionsOnly = true;
	private int restartPolicy = RESTART_POLICY_PROMPT;
	private String repoPrefPageId;
	private String repoPrefPageName;
	private boolean filterOnEnv = false;
	private int updateWizardStyle = UPDATE_STYLE_MULTIPLE_IUS;
	private Point wizardDetailsPreferredSize = null;

	/**
	 * Answer a boolean indicating whether the caller should continue to work with the
	 * specified operation.  This method is used when an operation has been resolved, but
	 * the UI may have further restrictions on continuing with it.
	 * 
	 * @param operation the operation in question.  It must already be resolved.
	 * @param shell the shell to use for any interaction with the user
	 * @return <code>true</code> if processing of the operation should continue, <code>false</code> if
	 * not.  It is up to the implementor to report any errors to the user when answering <code>false</code>.
	 */
	public boolean continueWorkingWithOperation(ProfileChangeOperation operation, Shell shell) {
		Assert.isTrue(operation.getResolutionResult() != null);
		IStatus status = operation.getResolutionResult();
		// user cancelled
		if (status.getSeverity() == IStatus.CANCEL)
			return false;

		// Special case those statuses where we would never want to open a wizard
		if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
			ProvUI.reportStatus(status, StatusManager.BLOCK);
			return false;
		}

		// there is no plan, so we can't continue.  Report any reason found
		if (operation.getProvisioningPlan() == null && !status.isOK()) {
			StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.SHOW);
			return false;
		}

		// Allow the wizard to open otherwise.
		return true;
	}

	/**
	 * Return a status that can be used to describe the failure to
	 * retrieve a profile.
	 * @return a status describing a failure to retrieve a profile,
	 * or <code>null</code> if there is no such status.
	 */
	public IStatus getNoProfileChosenStatus() {
		return null;
	}

	/**
	 * Return a query that can be used to obtain the IInstallableUnits that
	 * should be presented to the user from the software repositories.
	 * 
	 * @return the query used to retrieve user visible available IUs
	 */
	public IQuery<IInstallableUnit> getVisibleAvailableIUQuery() {
		return visibleAvailableIUQuery;
	}

	/**
	 * Set the query that can be used to obtain the IInstallableUnits that
	 * should be presented to the user.
	 * 
	 * @param query the query used to retrieve user visible available IUs
	 */
	public void setVisibleAvailableIUQuery(IQuery<IInstallableUnit> query) {
		visibleAvailableIUQuery = query;
	}

	/**
	 * Return a query that can be used to obtain the IInstallableUnits in
	 * the profile that should be presented to the user.
	 * 
	 * @return the query used to retrieve user visible installed IUs
	 */
	public IQuery<IInstallableUnit> getVisibleInstalledIUQuery() {
		return visibleInstalledIUQuery;
	}

	/**
	 * Set the query that can be used to obtain the IInstallableUnits in
	 * the profile that should be presented to the user.
	 * 
	 * @param query the query used to retrieve user visible installed IUs
	 */
	public void setVisibleInstalledIUQuery(IQuery<IInstallableUnit> query) {
		visibleInstalledIUQuery = query;
	}

	/**
	 * Get the restart policy that should be used when the provisioning UI
	 * determines that a restart is required.
	 * 
	 * @return an integer constant describing the restart policy
	 * 
	 * @see #RESTART_POLICY_FORCE
	 * @see #RESTART_POLICY_FORCE_APPLY
	 * @see #RESTART_POLICY_PROMPT
	 * @see #RESTART_POLICY_PROMPT_RESTART_OR_APPLY
	 */
	public int getRestartPolicy() {
		return restartPolicy;
	}

	/**
	 * Set the restart policy that should be used when the provisioning UI
	 * determines that a restart is required.
	 * 
	 * @param restartPolicy an integer constant describing the restart policy
	 * 
	 * @see #RESTART_POLICY_FORCE
	 * @see #RESTART_POLICY_FORCE_APPLY
	 * @see #RESTART_POLICY_PROMPT
	 * @see #RESTART_POLICY_PROMPT_RESTART_OR_APPLY
	 */
	public void setRestartPolicy(int restartPolicy) {
		this.restartPolicy = restartPolicy;
	}

	/**
	 * Return a boolean indicating whether the repositories should
	 * be visible to the user, such that the user can add, remove, and
	 * otherwise manipulate the software site list.
	 * 
	 * @return <code>true</code> if repositories are visible to the end
	 * user, <code>false</code> if they are not.
	 */
	public boolean getRepositoriesVisible() {
		return repositoriesVisible;
	}

	/**
	 * Set a boolean indicating whether the repositories should
	 * be visible to the user, such that the user can add, remove, and
	 * otherwise manipulate the software site list.
	 * 
	 * @param visible <code>true</code> if repositories are visible to the end
	 * user, <code>false</code> if they are not.
	 */
	public void setRepositoriesVisible(boolean visible) {
		this.repositoriesVisible = visible;
	}

	/**
	 * Return a boolean indicating whether only the latest versions of
	 * updates and available software should be shown to the user.
	 * 
	 * @return <code>true</code> if only the latest versions are shown,
	 * <code>false</code> if all versions should be shown.
	 */
	public boolean getShowLatestVersionsOnly() {
		return showLatestVersionsOnly;
	}

	/**
	 * Set a boolean indicating whether only the latest versions of
	 * updates and available software should be shown to the user.
	 * 
	 * @param showLatest <code>true</code> if only the latest versions are shown,
	 * <code>false</code> if all versions should be shown.
	 */
	public void setShowLatestVersionsOnly(boolean showLatest) {
		this.showLatestVersionsOnly = showLatest;
	}

	/**
	 * Return a boolean indicating whether the user should be allowed drill
	 * down from a visible update or installed item into the requirements.
	 * 
	 * @return <code>true</code> if drilldown is allowed,
	 * <code>false</code> if it is not.
	 */
	public boolean getShowDrilldownRequirements() {
		return allowDrilldown;
	}

	/**
	 * Set a boolean indicating whether the user should be allowed drill
	 * down from a visible update or installed item into the requirements.
	 * 
	 * @param drilldown <code>true</code> if drilldown is allowed,
	 * <code>false</code> if it is not.
	 */
	public void setShowDrilldownRequirements(boolean drilldown) {
		this.allowDrilldown = drilldown;
	}

	/**
	 * Return a boolean value indicating whether or not the list of available
	 * software should be filtered based on the environment settings of the profile.
	 * 
	 * @return <code>true</code> if the results should be filtered 
	 * and <code>false</code> otherwise.
	 * @since 2.1
	 */
	public boolean getFilterOnEnv() {
		return filterOnEnv;
	}

	/**
	 * Set a boolean value indicating whether or not the list of available
	 * software should be filtered based on the environment settings of the profile.
	 * 
	 * @param filterOnEnv <code>true</code> if the results should be filtered 
	 * and <code>false</code> otherwise.
	 * @since 2.1
	 */
	public void setFilterOnEnv(boolean filterOnEnv) {
		this.filterOnEnv = filterOnEnv;
	}

	/**
	 * Return a boolean indicating whether available software should be
	 * grouped by category.
	 * 
	 * @return <code>true</code> if items should be grouped by category,
	 * <code>false</code> if categories should not be shown.
	 */
	public boolean getGroupByCategory() {
		return groupByCategory;
	}

	/**
	 * Set a boolean indicating whether available software should be
	 * grouped by category.
	 * 
	 * @param group <code>true</code> if items should be grouped by category,
	 * <code>false</code> if categories should not be shown.
	 */
	public void setGroupByCategory(boolean group) {
		this.groupByCategory = group;
	}

	/**
	 * Get the id of the preference page that should be used to link to the
	 * software sites page.
	 * 
	 * @return the preference page id, or <code>null</code> if there is no
	 * preference page id showing the software sites.
	 */
	public String getRepositoryPreferencePageId() {
		return repoPrefPageId;
	}

	/**
	 * Set the id of the preference page that should be used to link to the
	 * software sites page.
	 * 
	 * @param id the preference page id, or <code>null</code> if there is no
	 * preference page id showing the software sites.
	 */

	public void setRepositoryPreferencePageId(String id) {
		this.repoPrefPageId = id;
	}

	/**
	 * Get the localized name of the preference page that should be displayed in
	 * links to the software sites page.
	 * 
	 * @return the preference page name, or <code>null</code> if there is no
	 * preference page.
	 */
	public String getRepositoryPreferencePageName() {
		return repoPrefPageName;
	}

	/**
	 * Set the localized name of the preference page that should be displayed in
	 * links to the software sites page.  This name is ignored if no id is specified
	 * for the preference page.
	 * 
	 * @param name the preference page name, or <code>null</code> if there is no
	 * preference page.
	 * 
	 * @see Policy#setRepositoryPreferencePageId(String)
	 */

	public void setRepositoryPreferencePageName(String name) {
		this.repoPrefPageName = name;
	}

	/**
	 * Get the update wizard style that should be used to determine
	 * what to show the user when updates are available.
	 * 
	 * @return an integer constant describing the update wizard style
	 * 
	 * @see #UPDATE_STYLE_SINGLE_IUS
	 * @see #UPDATE_STYLE_MULTIPLE_IUS
	 * 
	 * @since 2.1
	 */

	public int getUpdateWizardStyle() {
		return updateWizardStyle;
	}

	/**
	 * Get the update wizard style that should be used to determine
	 * what to show the user when updates are available.
	 * 
	 * @param updateWizardStyle an integer constant describing the update wizard style
	 * 
	 * @see #UPDATE_STYLE_SINGLE_IUS
	 * @see #UPDATE_STYLE_MULTIPLE_IUS
	 * 
	 * @since 2.1
	 */

	public void setUpdateWizardStyle(int updateWizardStyle) {
		this.updateWizardStyle = updateWizardStyle;
	}

	/**
	 * Get a point describing the preferred size of the details area
	 * shown in single IU update wizards.  This value may be null, in which case
	 * the wizard may compute a default size.  
	 * 
	 * @return a Point describing the preferred size of the update wizard details area.
	 * 
	 * @see #UPDATE_STYLE_SINGLE_IUS
	 *
	 * @since 2.1
	 */

	public Point getUpdateDetailsPreferredSize() {
		return wizardDetailsPreferredSize;
	}

	/**
	 * Set the preferred size of the details area shown in update wizards which
	 * notify the user of a single update.  Clients can use this value to ensure
	 * that their product's branded update notifier is sized to fit the expected
	 * content.
	 * 
	 * @param preferredSize a Point describing the preferred size
	 * 
	 * @see #UPDATE_STYLE_SINGLE_IUS
	 * 
	 * @since 2.1
	 */

	public void setUpdateDetailsPreferredSize(Point preferredSize) {
		this.wizardDetailsPreferredSize = preferredSize;
	}

	/**
	 * Get a boolean value indicating whether to contact all sites. 
	 * 
	 * @return <code>true</code> true if all sites need to be contacted,
	 * <code>false</code> otherwise.
	 *
	 * @since 2.3
	 */
	public boolean getContactAllSites() {
		return this.contactAllSites;
	}

	/**
	 * Set a boolean indicating whether all sites need to be contacted.
	 * 
	 * @param contactAll <code>true</code> if all sites need to be contacted,
	 * <code>false</code> otherwise.
	 *
	 * @since 2.3
	 */
	public void setContactAllSites(boolean contactAll) {
		this.contactAllSites = contactAll;
	}

	/**
	 * Get a boolean value indicating whether to hide already installed units.
	 * 
	 * @return <code>true</code> if already installed units are to be hidden,
	 * <code>false</code> otherwise.
	 *
	 * @since 2.3
	 */
	public boolean getHideAlreadyInstalled() {
		return this.hideAlreadyInstalled;
	}

	/**
	 * Set a boolean indicating whether to hide already installed units.
	 *
	 * @param hide <code>true</code> if already installed units need to be hidden,
	 * <code>false</code> otherwise.
	 *
	 * @since 2.3
	 */
	public void setHideAlreadyInstalled(boolean hide) {
		this.hideAlreadyInstalled = hide;
	}
}

Back to the top