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.AbstractHandler; |
12 |
import org.eclipse.core.commands.ExecutionEvent; |
13 |
import org.eclipse.core.commands.ExecutionException; |
14 |
import org.eclipse.core.resources.IProject; |
15 |
import org.eclipse.core.resources.ResourcesPlugin; |
16 |
import org.eclipse.core.runtime.CoreException; |
17 |
import org.eclipse.core.runtime.IConfigurationElement; |
18 |
import org.eclipse.core.runtime.IExtensionPoint; |
19 |
import org.eclipse.core.runtime.IExtensionRegistry; |
20 |
import org.eclipse.core.runtime.Platform; |
21 |
import org.eclipse.swt.widgets.Shell; |
22 |
import org.eclipse.team.internal.ui.wizards.ConfigureProjectWizard; |
23 |
import org.eclipse.team.ui.IConfigurationWizard; |
24 |
import org.eclipse.ui.IWorkbench; |
25 |
import org.eclipse.ui.handlers.HandlerUtil; |
26 |
|
27 |
/** |
28 |
* Provides a handler for the Share Project command. This can then be bound to |
29 |
* whatever keybinding the user prefers. |
30 |
*/ |
31 |
public class ShareSingleProjectCommand extends AbstractHandler { |
32 |
|
33 |
private static final String TEAM_WIZARD_NAME_PARAMETER = "org.eclipse.team.internal.ui.commands.TeamProviderNameParameter"; //$NON-NLS-1$ |
34 |
|
35 |
private static final String PROJECT_NAME_PARAMETER = "org.eclipse.team.internal.ui.commands.ProjectNameParameter"; //$NON-NLS-1$ |
36 |
|
37 |
static final String TEAM_UI_CONFIGURATION_WIZARD_EXTENSION = "org.eclipse.team.ui.configurationWizards"; //$NON-NLS-1$ |
38 |
|
39 |
/** |
40 |
* Invokes a wizard dialog which associates a project with a given team |
41 |
* provider. Wizard dialog must be declared in |
42 |
* org.eclipse.team.ui.configurationWizards extension point and extend |
43 |
* {@link IConfigurationWizard}. |
44 |
* |
45 |
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
46 |
*/ |
47 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
48 |
final String projectName = event.getParameter(PROJECT_NAME_PARAMETER); |
49 |
final IProject projectToShare = ResourcesPlugin.getWorkspace() |
50 |
.getRoot().getProject(projectName); |
51 |
IWorkbench workbench = HandlerUtil.getActiveWorkbenchWindow(event) |
52 |
.getWorkbench(); |
53 |
final IExtensionRegistry extensionRegistry = Platform |
54 |
.getExtensionRegistry(); |
55 |
final IExtensionPoint extension = extensionRegistry |
56 |
.getExtensionPoint(ShareSingleProjectCommand.TEAM_UI_CONFIGURATION_WIZARD_EXTENSION); |
57 |
IConfigurationElement[] configurationElements = extension |
58 |
.getConfigurationElements(); |
59 |
try { |
60 |
IConfigurationWizard wizard = findAndInstantiateWizard(event, |
61 |
configurationElements); |
62 |
wizard.init(workbench, projectToShare); |
63 |
final Shell shell = HandlerUtil.getActiveShell(event); |
64 |
ConfigureProjectWizard.openWizard(shell, wizard); |
65 |
} catch (CoreException e) { |
66 |
// TODO Auto-generated catch block |
67 |
e.printStackTrace(); |
68 |
} |
69 |
return null; |
70 |
} |
71 |
|
72 |
private IConfigurationWizard findAndInstantiateWizard(ExecutionEvent event, |
73 |
IConfigurationElement[] configurationElements) throws CoreException { |
74 |
for (int i = 0; i < configurationElements.length; i++) { |
75 |
IConfigurationElement element = configurationElements[i]; |
76 |
final String id = element.getAttribute("id"); |
77 |
if (id != null |
78 |
&& id |
79 |
.equals(event |
80 |
.getParameter(TEAM_WIZARD_NAME_PARAMETER))) { |
81 |
|
82 |
return (IConfigurationWizard) element |
83 |
.createExecutableExtension("class"); //$NON-NLS-1$ |
84 |
} |
85 |
} |
86 |
return null; |
87 |
} |
88 |
} |