KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ide > dialogs > RemoveCapabilityStep


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.ui.internal.ide.dialogs;
12
13 import org.eclipse.core.resources.IProject;
14 import org.eclipse.jface.viewers.StructuredSelection;
15 import org.eclipse.jface.wizard.IWizard;
16 import org.eclipse.osgi.util.NLS;
17 import org.eclipse.ui.ICapabilityUninstallWizard;
18 import org.eclipse.ui.PlatformUI;
19 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
20 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
21 import org.eclipse.ui.internal.ide.registry.Capability;
22 import org.eclipse.ui.internal.ide.registry.CapabilityRegistry;
23
24 /**
25  * Represents the removal of a capability step in a multi-step
26  * wizard.
27  */

28 public class RemoveCapabilityStep extends WizardStep {
29     private Capability capability;
30
31     private String JavaDoc[] natureIds;
32
33     private IProject project;
34
35     private ICapabilityUninstallWizard wizard;
36
37     /**
38      * Creates the remove capability step
39      *
40      * @param number step order number
41      * @param capability the capability to be removed
42      * @param natureIds the list of nature ids to remove on the project
43      * @param project the project to remove the capability from
44      */

45     public RemoveCapabilityStep(int number, Capability capability,
46             String JavaDoc[] natureIds, IProject project) {
47         super(number);
48         this.capability = capability;
49         this.natureIds = natureIds;
50         this.project = project;
51     }
52
53     /* (non-Javadoc)
54      * Method declared on WizardStep.
55      */

56     public String JavaDoc getLabel() {
57         return NLS.bind(IDEWorkbenchMessages.RemoveCapabilityStep_label, capability.getName());
58     }
59
60     /* (non-Javadoc)
61      * Method declared on WizardStep.
62      */

63     public String JavaDoc getDetails() {
64         String JavaDoc details = capability.getUninstallDetails();
65         if (details == null) {
66             if (natureIds.length == 1) {
67                 details = NLS.bind(IDEWorkbenchMessages.RemoveCapabilityStep_defaultDescription0, capability.getName());
68             } else if (natureIds.length == 2) {
69                 CapabilityRegistry reg = IDEWorkbenchPlugin.getDefault()
70                         .getCapabilityRegistry();
71                 Capability otherCapability = reg
72                         .getCapabilityForNature(natureIds[1]);
73                 if (otherCapability == capability)
74                     otherCapability = reg.getCapabilityForNature(natureIds[0]);
75                 details = NLS.bind(IDEWorkbenchMessages.RemoveCapabilityStep_defaultDescription1, capability.getName(), otherCapability.getName());
76             } else {
77                 StringBuffer JavaDoc msg = new StringBuffer JavaDoc();
78                 CapabilityRegistry reg = IDEWorkbenchPlugin.getDefault()
79                         .getCapabilityRegistry();
80                 for (int i = 0; i < natureIds.length; i++) {
81                     Capability cap = reg.getCapabilityForNature(natureIds[i]);
82                     if (cap != capability) {
83                         msg.append("\n "); //$NON-NLS-1$
84
msg.append(cap.getName());
85                     }
86                 }
87                 details = NLS.bind(IDEWorkbenchMessages.RemoveCapabilityStep_defaultDescription2, capability.getName(), msg);
88             }
89         }
90
91         return details;
92     }
93
94     /* (non-Javadoc)
95      * Method declared on WizardStep.
96      */

97     public IWizard getWizard() {
98         if (wizard == null) {
99             wizard = capability.getUninstallWizard();
100             if (wizard == null)
101                 wizard = new RemoveCapabilityWizard();
102             if (wizard != null) {
103                 wizard.init(PlatformUI.getWorkbench(),
104                         StructuredSelection.EMPTY, project, natureIds);
105                 wizard.addPages();
106             }
107         }
108
109         return wizard;
110     }
111
112 }
113
Popular Tags