KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > ui > views > InstallOptionalFeatureAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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  *******************************************************************************/

11 package org.eclipse.update.internal.ui.views;
12
13 import java.net.*;
14
15 import org.eclipse.core.runtime.*;
16 import org.eclipse.jface.action.*;
17 import org.eclipse.jface.dialogs.*;
18 import org.eclipse.jface.wizard.*;
19 import org.eclipse.swt.custom.*;
20 import org.eclipse.swt.widgets.*;
21 import org.eclipse.update.core.*;
22 import org.eclipse.update.internal.search.*;
23 import org.eclipse.update.internal.ui.*;
24 import org.eclipse.update.internal.ui.model.*;
25 import org.eclipse.update.internal.ui.wizards.*;
26 import org.eclipse.update.operations.*;
27 import org.eclipse.update.search.*;
28
29
30 public class InstallOptionalFeatureAction extends Action {
31     private MissingFeature missingFeature;
32     private Shell shell;
33
34     public InstallOptionalFeatureAction(Shell shell, String JavaDoc text) {
35         super(text);
36         this.shell = shell;
37     }
38
39     public void setFeature(MissingFeature feature) {
40         this.missingFeature = feature;
41     }
42
43     public void run() {
44         if (missingFeature == null)
45             return;
46         
47         IStatus status = OperationsManager.getValidator().validatePlatformConfigValid();
48         if (status != null) {
49             ErrorDialog.openError(shell, null, null, status);
50             return;
51         }
52         
53         // If current config is broken, confirm with the user to continue
54
if (OperationsManager.getValidator().validateCurrentState() != null &&
55                 !confirm(UpdateUIMessages.Actions_brokenConfigQuestion))
56             return;
57             
58         
59         VersionedIdentifier vid = missingFeature.getVersionedIdentifier();
60         URL originatingURL = missingFeature.getOriginatingSiteURL();
61
62         UpdateSearchScope scope = new UpdateSearchScope();
63         scope.addSearchSite(originatingURL.toString(), originatingURL, null);
64
65         OptionalFeatureSearchCategory category = new OptionalFeatureSearchCategory();
66         category.addVersionedIdentifier(vid);
67         final UpdateSearchRequest searchRequest =
68             new UpdateSearchRequest(category, scope);
69
70         BusyIndicator.showWhile(shell.getDisplay(), new Runnable JavaDoc() {
71             public void run() {
72                 openWizard(searchRequest);
73             }
74         });
75     }
76     private void openWizard(UpdateSearchRequest searchRequest) {
77         if (InstallWizard.isRunning()) {
78             MessageDialog.openInformation(shell, UpdateUIMessages.InstallWizard_isRunningTitle, UpdateUIMessages.InstallWizard_isRunningInfo);
79             return;
80         }
81         InstallWizard wizard = new InstallWizard(searchRequest);
82         WizardDialog dialog = new ResizableInstallWizardDialog(shell, wizard, UpdateUIMessages.FeaturePage_optionalInstall_title);
83         dialog.create();
84         dialog.open();
85     }
86     
87     private boolean confirm(String JavaDoc message) {
88         return MessageDialog.openConfirm(
89             shell,
90             UpdateUIMessages.FeatureStateAction_dialogTitle,
91             message);
92     }
93 }
94
Popular Tags