Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: fd2e56fea62e141d6dd2d1f593139fa31824a092 (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
/*******************************************************************************
 * Copyright (c) 2011, 2012 Wind River Systems, Inc. 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:
 * Wind River Systems - initial API and implementation
 * Tobias Schwarz (Wind River) - [368243] [UI] Allow dynamic new wizard contributions
 *******************************************************************************/
package org.eclipse.tcf.te.ui.wizards.newWizard;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.tcf.te.ui.activator.UIPlugin;
import org.eclipse.tcf.te.ui.wizards.interfaces.INewWizardProvider;
import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
import org.eclipse.ui.internal.wizards.AbstractExtensionWizardRegistry;
import org.eclipse.ui.wizards.IWizardCategory;
import org.eclipse.ui.wizards.IWizardDescriptor;

/**
 * New wizard registry.
 *
 * @see org.eclipse.ui.internal.wizards.NewWizardRegistry
 */
@SuppressWarnings("restriction")
public final class NewWizardRegistry extends AbstractExtensionWizardRegistry {

	private List<INewWizardProvider> newWizardProvider = new ArrayList<INewWizardProvider>();

	/*
	 * Thread save singleton instance creation.
	 */
	private static class LazyInstance {
		public static NewWizardRegistry instance = new NewWizardRegistry();
	}

	/**
	 * Constructor.
	 */
	/* default */ NewWizardRegistry() {
		super();
	}

	/**
	 * Returns the singleton instance of the wizard registry.
	 */
	public static NewWizardRegistry getInstance() {
		return LazyInstance.instance;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.internal.wizards.AbstractExtensionWizardRegistry#doInitialize()
	 */
	@Override
	protected void doInitialize() {
		super.doInitialize();
		IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(getPlugin(), "wizardProviders"); //$NON-NLS-1$
		for (IConfigurationElement element : point.getConfigurationElements()) {
			if (element.getName().equals("wizardProvider")) { //$NON-NLS-1$
				try {
					INewWizardProvider provider = (INewWizardProvider)element.createExecutableExtension("class"); //$NON-NLS-1$
					newWizardProvider.add(provider);
				}
				catch (CoreException e) {
				}
			}
		}

	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.internal.wizards.AbstractExtensionWizardRegistry#getExtensionPoint()
	 */
	@Override
	protected String getExtensionPoint() {
		return IWorkbenchRegistryConstants.PL_NEW;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.internal.wizards.AbstractExtensionWizardRegistry#getPlugin()
	 */
	@Override
	protected String getPlugin() {
		return UIPlugin.getUniqueIdentifier();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.internal.wizards.AbstractWizardRegistry#findWizard(java.lang.String)
	 */
	@Override
	public IWizardDescriptor findWizard(String id) {
		return getRootCategory().findWizard(id);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.internal.wizards.AbstractWizardRegistry#getPrimaryWizards()
	 */
	@Override
	public IWizardDescriptor [] getPrimaryWizards() {
		return super.getPrimaryWizards();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.internal.wizards.AbstractWizardRegistry#findCategory(java.lang.String)
	 */
	@Override
	public IWizardCategory findCategory(String id) {
		IWizardCategory root = getRootCategory();
		if (root instanceof NewWizardCategory) {
			((NewWizardCategory)root).findCategory(id);
		}
		return super.findCategory(id);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.internal.wizards.AbstractWizardRegistry#getRootCategory()
	 */
	@Override
	public IWizardCategory getRootCategory() {
		initialize();
		if (!newWizardProvider.isEmpty()) {
			NewWizardCategory root = new NewWizardCategory(super.getRootCategory());

			for (INewWizardProvider provider : newWizardProvider) {
				for (IWizardCategory category : provider.getCategories()) {
					root.addCategory(category);
				}
			}

			return root;
		}

		return super.getRootCategory();
	}

	/**
	 * Get the list of common wizards for the given selection.
	 *
	 * @param selection The current selection.
	 * @return The list of common wizards.
	 */
	public IWizardDescriptor[] getCommonWizards(ISelection selection) {
		initialize();
		List<IWizardDescriptor> allWizards = new ArrayList<IWizardDescriptor>();

		for (INewWizardProvider provider : newWizardProvider) {
			IWizardDescriptor[] wizards = provider.getCommonWizards(selection);
			if (wizards != null && wizards.length > 0) {
				allWizards.addAll(Arrays.asList(wizards));
			}
		}

		return allWizards.toArray(new IWizardDescriptor[allWizards.size()]);
	}
}

Back to the top