1 /*******************************************************************************
2 * Copyright (c) 2010 SAP AG.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * Mathias Kinzler (SAP AG) - initial implementation
10 *******************************************************************************/
11 package org
.eclipse
.egit
.ui
.internal
.repository
;
13 import java
.io
.IOException
;
14 import java
.net
.URISyntaxException
;
16 import org
.eclipse
.egit
.ui
.UIText
;
17 import org
.eclipse
.egit
.ui
.internal
.components
.RefSpecPage
;
18 import org
.eclipse
.egit
.ui
.internal
.components
.RepositorySelectionPage
;
19 import org
.eclipse
.jface
.wizard
.Wizard
;
20 import org
.eclipse
.jgit
.lib
.Repository
;
21 import org
.eclipse
.jgit
.lib
.RepositoryConfig
;
22 import org
.eclipse
.jgit
.transport
.RemoteConfig
;
23 import org
.eclipse
.osgi
.util
.NLS
;
26 * Used for "remote" configuration of a Repository
28 class ConfigureRemoteWizard
extends Wizard
{
30 final RepositoryConfig myConfiguration
;
32 final boolean pushMode
;
34 final String myRemoteName
;
39 public ConfigureRemoteWizard(Repository repository
) {
40 this(repository
, null, false);
49 public ConfigureRemoteWizard(Repository repository
, String remoteName
,
51 myConfiguration
= repository
.getConfig();
52 myRemoteName
= remoteName
;
54 if (myRemoteName
== null) {
55 // create mode: add remote name page and repository selection page
56 addPage(new SelectRemoteNamePage());
57 addPage(new RepositorySelectionPage(null));
58 setWindowTitle(UIText
.ConfigureRemoteWizard_WizardTitle_New
);
60 // edit mode: no remote name page and pre-selected repository
62 RepositorySelectionPage sp
= new RepositorySelectionPage(
63 myConfiguration
.getString(RepositoriesView
.REMOTE
,
64 myRemoteName
, RepositoriesView
.URL
));
67 // and also the corresponding configuration page
68 RefSpecPage rsp
= new RefSpecPage(repository
, pushMode
, sp
,
71 setWindowTitle(NLS
.bind(
72 UIText
.ConfigureRemoteWizard_WizardTitle_Change
,
79 * @return the configuration
82 public RepositoryConfig
getConfiguration() {
83 return myConfiguration
;
87 public boolean performFinish() {
89 String actRemoteName
= myRemoteName
;
90 if (myRemoteName
== null) {
91 SelectRemoteNamePage page
= (SelectRemoteNamePage
) getPage(SelectRemoteNamePage
.class
93 actRemoteName
= page
.remoteName
.getText();
96 RepositorySelectionPage sp
= (RepositorySelectionPage
) getPage(RepositorySelectionPage
.class
99 String uriString
= sp
.getSelection().getURI().toString();
101 myConfiguration
.setString(RepositoriesView
.REMOTE
, actRemoteName
,
102 RepositoriesView
.URL
, uriString
);
104 if (myRemoteName
!= null) {
106 RefSpecPage specPage
= (RefSpecPage
) getPage(RefSpecPage
.class
109 if (specPage
.getRefSpecs().isEmpty()) {
110 specPage
.setVisible(true);
111 specPage
.setVisible(false);
116 config
= new RemoteConfig(myConfiguration
, actRemoteName
);
117 } catch (URISyntaxException e1
) {
118 // TODO better Exception handling
123 config
.setPushRefSpecs(specPage
.getRefSpecs());
125 config
.setFetchRefSpecs(specPage
.getRefSpecs());
126 config
.setTagOpt(specPage
.getTagOpt());
128 config
.update(myConfiguration
);
132 myConfiguration
.save();
134 } catch (IOException e
) {
135 // TODO better Exception handling