Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (C) 2009, Mykola Nikishov <mn@mn.com.ua> |
3 |
* |
4 |
* All rights reserved. This program and the accompanying materials |
5 |
* are made available under the terms of the Eclipse Public License v1.0 |
6 |
* which accompanies this distribution, and is available at |
7 |
* http://www.eclipse.org/legal/epl-v10.html |
8 |
*******************************************************************************/ |
9 |
package org.eclipse.team.internal.ui.commands; |
10 |
|
11 |
import org.eclipse.core.commands.*; |
12 |
import org.eclipse.core.resources.IProject; |
13 |
import org.eclipse.core.resources.ResourcesPlugin; |
14 |
import org.eclipse.core.runtime.*; |
15 |
import org.eclipse.swt.widgets.Shell; |
16 |
import org.eclipse.team.internal.ui.wizards.ConfigureProjectWizard; |
17 |
import org.eclipse.team.ui.IConfigurationWizard; |
18 |
import org.eclipse.ui.IWorkbench; |
19 |
import org.eclipse.ui.handlers.HandlerUtil; |
20 |
|
21 |
/** |
22 |
* Provides a handler for the Share Project command. This can then be bound to |
23 |
* whatever keybinding the user prefers. |
24 |
*/ |
25 |
public class ShareSingleProjectCommand extends AbstractHandler { |
26 |
|
27 |
private static final String TEAM_WIZARD_NAME_PARAMETER = "org.eclipse.team.internal.ui.commands.TeamProviderNameParameter"; //$NON-NLS-1$ |
28 |
|
29 |
private static final String PROJECT_NAME_PARAMETER = "org.eclipse.team.internal.ui.commands.ProjectNameParameter"; //$NON-NLS-1$ |
30 |
|
31 |
static final String TEAM_UI_CONFIGURATION_WIZARD_EXTENSION = "org.eclipse.team.ui.configurationWizards"; //$NON-NLS-1$ |
32 |
|
33 |
/** |
34 |
* Invokes a wizard dialog which associates a project with a given team |
35 |
* provider. Wizard dialog must be declared in |
36 |
* org.eclipse.team.ui.configurationWizards extension point and extend |
37 |
* {@link IConfigurationWizard}. |
38 |
* |
39 |
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
40 |
*/ |
41 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
42 |
final String projectName = event.getParameter(PROJECT_NAME_PARAMETER); |
43 |
final IProject projectToShare = ResourcesPlugin.getWorkspace() |
44 |
.getRoot().getProject(projectName); |
45 |
IWorkbench workbench = HandlerUtil.getActiveWorkbenchWindow(event) |
46 |
.getWorkbench(); |
47 |
final IExtensionRegistry extensionRegistry = Platform |
48 |
.getExtensionRegistry(); |
49 |
final IExtensionPoint extension = extensionRegistry |
50 |
.getExtensionPoint(ShareSingleProjectCommand.TEAM_UI_CONFIGURATION_WIZARD_EXTENSION); |
51 |
IConfigurationElement[] configurationElements = extension |
52 |
.getConfigurationElements(); |
53 |
try { |
54 |
IConfigurationWizard wizard = findAndInstantiateWizard(event, |
55 |
configurationElements); |
56 |
wizard.init(workbench, projectToShare); |
57 |
final Shell shell = HandlerUtil.getActiveShell(event); |
58 |
ConfigureProjectWizard.openWizard(shell, wizard); |
59 |
} catch (CoreException e) { |
60 |
// TODO Auto-generated catch block |
61 |
e.printStackTrace(); |
62 |
} |
63 |
return null; |
64 |
} |
65 |
|
66 |
private IConfigurationWizard findAndInstantiateWizard(ExecutionEvent event, |
67 |
IConfigurationElement[] configurationElements) throws CoreException { |
68 |
for (int i = 0; i < configurationElements.length; i++) { |
69 |
IConfigurationElement element = configurationElements[i]; |
70 |
final String id = element.getAttribute("id"); //$NON-NLS-1$ |
71 |
if (id != null |
72 |
&& id |
73 |
.equals(event |
74 |
.getParameter(TEAM_WIZARD_NAME_PARAMETER))) { |
75 |
|
76 |
return (IConfigurationWizard) element |
77 |
.createExecutableExtension("class"); //$NON-NLS-1$ |
78 |
} |
79 |
} |
80 |
return null; |
81 |
} |
82 |
} |