Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0bc443a7701952abe11d2aeac5175a17d04b4025 (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
/*******************************************************************************
 * Copyright (c) 2000, 2007 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.team.internal.ui.wizards;


import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.*;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.team.internal.ui.TeamUIPlugin;
import org.eclipse.team.ui.IConfigurationWizard;
import org.eclipse.team.ui.IConfigurationWizardExtension;
import org.eclipse.ui.*;
import org.eclipse.ui.model.IWorkbenchAdapter;
import org.eclipse.ui.model.WorkbenchAdapter;

/**
 * ConfigurationWizardElement represents an item in the configuration wizard table,
 * declared by an extension to the configurationWizards extension point.
 */
public class ConfigurationWizardElement extends WorkbenchAdapter implements IAdaptable, IPluginContribution  {
	private String id;
	private String name;
	private ImageDescriptor imageDescriptor;
	private IConfigurationElement configurationElement;

	/**
	 *	Creates a new instance of this class
	 *
	 *	@param name  the name of the element
	 */
	public ConfigurationWizardElement(String name) {
		this.name = name;
	}
	/**
	 * Create an the instance of the object described by the configuration
	 * element. That is, create the instance of the class the isv supplied in
	 * the extension point.
	 * @return the instance of the configuration wizard of type {@link IConfigurationWizard}
	 *
	 * @throws CoreException if an error occurs creating the extension
	 */
	public Object createExecutableExtension() throws CoreException {
		return TeamUIPlugin.createExtension(configurationElement, ConfigureProjectWizard.ATT_CLASS);
	}

	/**
	 * Creates the instance of the wizard and initializes with the given input.
	 * @param projects the projects being shared by this wizard
	 * @return the wizard instance of type {@link IConfigurationWizard}
	 * @throws CoreException if an error occurs creating the extension
	 */
	public IWizard createExecutableExtension(IProject[] projects) throws CoreException {
		IWorkbench workbench = PlatformUI.getWorkbench();
		IConfigurationWizard wizard = (IConfigurationWizard)createExecutableExtension();
		IConfigurationWizardExtension extension = (IConfigurationWizardExtension)Adapters.adapt(wizard, IConfigurationWizardExtension.class);
		if (extension == null) {
			if (projects.length == 1) {
				wizard.init(workbench, projects[0]);
			} else {
				// Dispose of the created wizard, just in case
				try {
					wizard.dispose();
				} catch (RuntimeException e) {
					// If a general exception occurred here, log it and continue
					TeamUIPlugin.log(IStatus.ERROR, "An internal error occurred", e); //$NON-NLS-1$
				}
				IWizard multiWizard = new ConfigureMultipleProjectsWizard(projects, this);
				return multiWizard;
			}
		} else {
			extension.init(workbench, projects);
		}
		return wizard;
	}

	/*
	 * Method declared on IAdaptable.
	 */
	@Override
	public Object getAdapter(Class adapter) {
		if (adapter == IWorkbenchAdapter.class) {
			return this;
		}
		return Platform.getAdapterManager().getAdapter(this, adapter);
	}
	/**
	 * Returns the configuration element
	 *
	 * @return the configuration element
	 */
	public IConfigurationElement getConfigurationElement() {
		return configurationElement;
	}
	/**
	 * Returns the image for the given element
	 *
	 * @param element  the element to get the image for
	 * @return the image for the given element
	 */
	@Override
	public ImageDescriptor getImageDescriptor(Object element) {
		return imageDescriptor;
	}
	/**
	 * Returns the label for the given element
	 *
	 * @param element  the element to get the label for
	 * @return the label for the given element
	 */
	@Override
	public String getLabel(Object element) {
		return name;
	}
	/**
	 * Returns the id as specified in the extension.
	 *
	 * @return java.lang.String
	 */
	public String getID() {
		return id;
	}
	/**
	 * Returns the image for this element.
	 *
	 * @return the image for this element
	 */
	public ImageDescriptor getImageDescriptor() {
		return imageDescriptor;
	}
	/**
	 * Set the configuration element
	 *
	 * @param newConfigurationElement  the new configuration element
	 */
	public void setConfigurationElement(IConfigurationElement newConfigurationElement) {
		configurationElement = newConfigurationElement;
	}
	/**
	 * Set the description parameter of this element
	 *
	 * @param value  the new description
	 */
	public void setDescription(String value) {
		// Not used
	}
	/**
	 * Sets the id parameter of this element
	 *
	 * @param value  the new ID
	 */
	public void setID(String value) {
		id = value;
	}
	/**
	 * Sets the image for this element.
	 *
	 * @param value  the new image
	 */
	public void setImageDescriptor(ImageDescriptor value) {
		imageDescriptor = value;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.IPluginContribution#getLocalId()
	 */
	@Override
	public String getLocalId() {
		return configurationElement.getAttribute(ConfigureProjectWizard.ATT_ID);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.IPluginContribution#getPluginId()
	 */
	@Override
	public String getPluginId() {
		return configurationElement.getNamespaceIdentifier();
	}

	/**
	 * Return whether the wizard created for this element has pages.
	 * Unfortunately, the only way to find this out is to create the wizard.
	 * @param projects the projects being shared
	 * @return whether the resulting wizard has pages
	 */
	public boolean wizardHasPages(IProject[] projects) {
		try {
			IWizard wizard = (IWizard)createExecutableExtension(projects);
			try {
				wizard.addPages();
				return (wizard.getPageCount() > 0);
			} finally {
				wizard.dispose();
			}
		} catch (CoreException e) {
			TeamUIPlugin.log(e);
		} catch (RuntimeException e) {
			// If a general exception occurred here, log it and continue
			TeamUIPlugin.log(IStatus.ERROR, "An internal error occurred", e); //$NON-NLS-1$
		}
		return false;
	}
}

Back to the top