Initial EGit contribution to eclipse.org
[egit.git] / org.eclipse.egit.ui / src / org / eclipse / egit / ui / internal / sharing / SharingWizard.java
blob7d0ee6992717f16d5e14e0a02e643790435052e3
1 /*******************************************************************************
2 * Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
3 * Copyright (C) 2007, Shawn O. Pearce <spearce@spearce.org>
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
9 *******************************************************************************/
10 package org.eclipse.egit.ui.internal.sharing;
12 import java.lang.reflect.InvocationTargetException;
14 import org.eclipse.core.resources.IProject;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.core.runtime.Status;
19 import org.eclipse.egit.core.op.ConnectProviderOperation;
20 import org.eclipse.egit.ui.Activator;
21 import org.eclipse.egit.ui.UIText;
22 import org.eclipse.jface.dialogs.ErrorDialog;
23 import org.eclipse.jface.operation.IRunnableWithProgress;
24 import org.eclipse.jface.wizard.Wizard;
25 import org.eclipse.team.ui.IConfigurationWizard;
26 import org.eclipse.team.ui.IConfigurationWizardExtension;
27 import org.eclipse.ui.IWorkbench;
29 /**
30 * The dialog used for activating Team>Share, i.e. to create a new
31 * Git repository or associate projects with one.
33 public class SharingWizard extends Wizard implements IConfigurationWizard,
34 IConfigurationWizardExtension {
35 IProject[] projects;
37 private ExistingOrNewPage existingPage;
39 /**
40 * Construct the Git Sharing Wizard for connecting Git project to Eclipse
42 public SharingWizard() {
43 setWindowTitle(UIText.SharingWizard_windowTitle);
44 setNeedsProgressMonitor(true);
47 public void init(IWorkbench workbench, IProject[] p) {
48 this.projects = new IProject[p.length];
49 System.arraycopy(p, 0, this.projects, 0, p.length);
52 public void init(final IWorkbench workbench, final IProject p) {
53 projects = new IProject[] { p };
56 public void addPages() {
57 existingPage = new ExistingOrNewPage(this);
58 addPage(existingPage);
61 public boolean performFinish() {
62 final ConnectProviderOperation op = new ConnectProviderOperation(
63 existingPage.getProjects());
64 try {
65 getContainer().run(true, false, new IRunnableWithProgress() {
66 public void run(final IProgressMonitor monitor)
67 throws InvocationTargetException {
68 try {
69 op.run(monitor);
70 } catch (CoreException ce) {
71 throw new InvocationTargetException(ce);
74 });
75 return true;
76 } catch (Throwable e) {
77 if (e instanceof InvocationTargetException) {
78 e = e.getCause();
80 final IStatus status;
81 if (e instanceof CoreException) {
82 status = ((CoreException) e).getStatus();
83 e = status.getException();
84 } else {
85 status = new Status(IStatus.ERROR, Activator.getPluginId(), 1,
86 UIText.SharingWizard_failed, e);
88 Activator.logError(UIText.SharingWizard_failed, e);
89 ErrorDialog.openError(getContainer().getShell(), getWindowTitle(),
90 UIText.SharingWizard_failed, status, status.getSeverity());
91 return false;
95 @Override
96 public boolean canFinish() {
97 return existingPage.isPageComplete();