2 * Copyright 2000-2008 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 import com
.intellij
.openapi
.project
.Project
;
19 import com
.intellij
.openapi
.ui
.DialogWrapper
;
20 import com
.intellij
.openapi
.vfs
.VirtualFile
;
21 import com
.intellij
.ui
.DocumentAdapter
;
22 import git4idea
.commands
.GitHandler
;
23 import git4idea
.commands
.GitLineHandler
;
24 import git4idea
.i18n
.GitBundle
;
27 import javax
.swing
.event
.DocumentEvent
;
28 import java
.awt
.event
.ActionEvent
;
29 import java
.awt
.event
.ActionListener
;
30 import java
.util
.List
;
33 * Fetch dialog. It represents most of the parameters for "git fetch" operation.
35 public class GitFetchDialog
extends DialogWrapper
{
39 private JComboBox myGitRoot
;
41 * Reference specification panel
43 private GitRefspecPanel myRefspecs
;
47 private JComboBox myFetchTagsComboBox
;
49 * Force reference updates
51 private JCheckBox myForceReferencesUpdateCheckBox
;
55 private JComboBox myRemote
;
59 private JPanel myPanel
;
61 * The project for the dialog
63 private final Project myProject
;
65 * Fetch tags for fetched commits (default)
67 private static final String TAGS_POLICY_FOR_FETCHED_COMMITS
= GitBundle
.getString("fetch.tags.policy.for.fetched.commits");
69 * Fetch all tags policy
71 private static final String TAGS_POLICY_ALL
= GitBundle
.getString("fetch.tags.policy.all");
73 * Fetch no tags except explicitly listed
75 private static final String TAGS_POLICY_NONE
= GitBundle
.getString("fetch.tags.policy.none");
80 * @param project the project
81 * @param roots the list of the roots
82 * @param defaultRoot the default root to select
84 public GitFetchDialog(final Project project
, final List
<VirtualFile
> roots
, final VirtualFile defaultRoot
) {
86 setTitle(GitBundle
.getString("fetch.title"));
87 setOKButtonText(GitBundle
.getString("fetch.button"));
88 GitUIUtil
.setupRootChooser(project
, roots
, defaultRoot
, myGitRoot
, null);
90 myRefspecs
.setProject(project
);
91 myRefspecs
.setReferenceSource(GitRefspecPanel
.ReferenceSource
.FETCH
);
93 setupFetchTagsPolicy();
100 * Setup validation for combobox
102 private void setupValidation() {
103 final JTextField remoteTextField
= getRemoteTextField();
104 final DocumentAdapter listener
= new DocumentAdapter() {
105 protected void textChanged(final DocumentEvent e
) {
106 if (remoteTextField
.getText().length() == 0) {
107 setOKActionEnabled(false);
111 final String result
= myRefspecs
.validateFields();
112 if (result
!= null) {
113 setOKActionEnabled(false);
114 setErrorText(result
.length() == 0 ?
null : result
);
117 setOKActionEnabled(true);
121 remoteTextField
.getDocument().addDocumentListener(listener
);
122 myRefspecs
.addValidationRequiredListener(new ActionListener() {
123 public void actionPerformed(final ActionEvent e
) {
124 listener
.changedUpdate(null);
127 listener
.changedUpdate(null);
131 * Setup fetch tags policy combobox
133 private void setupFetchTagsPolicy() {
134 myFetchTagsComboBox
.addItem(TAGS_POLICY_FOR_FETCHED_COMMITS
);
135 myFetchTagsComboBox
.addItem(TAGS_POLICY_ALL
);
136 myFetchTagsComboBox
.addItem(TAGS_POLICY_NONE
);
137 myFetchTagsComboBox
.setSelectedIndex(0);
142 * Setup drop down with remotes
144 private void setupRemotes() {
145 final ActionListener actionListener
= new ActionListener() {
146 public void actionPerformed(final ActionEvent e
) {
147 myRefspecs
.setGitRoot(getGitRoot());
151 myGitRoot
.addActionListener(actionListener
);
152 actionListener
.actionPerformed(null);
153 final JTextField textField
= getRemoteTextField();
154 final DocumentAdapter remoteListener
= new DocumentAdapter() {
155 protected void textChanged(final DocumentEvent e
) {
156 myRefspecs
.setRemote(textField
.getText());
159 textField
.getDocument().addDocumentListener(remoteListener
);
160 remoteListener
.changedUpdate(null);
164 * @return text field for {@link #myRemote}
166 private JTextField
getRemoteTextField() {
167 return (JTextField
)myRemote
.getEditor().getEditorComponent();
173 private void updateRemotes() {
174 GitUIUtil
.setupRemotes(myProject
, getGitRoot(), myRemote
);
178 * @return get current git root
180 protected VirtualFile
getGitRoot() {
181 return (VirtualFile
)myGitRoot
.getSelectedItem();
187 protected JComponent
createCenterPanel() {
192 * @return the handler for the fetch operation
194 public GitLineHandler
fetchHandler() {
195 GitLineHandler h
= new GitLineHandler(myProject
, getGitRoot(), GitHandler
.FETCH
);
196 h
.addParameters("-v");
197 if (myForceReferencesUpdateCheckBox
.isSelected()) {
198 h
.addParameters("--force");
200 String tagsPolicy
= (String
)myFetchTagsComboBox
.getSelectedItem();
201 if (TAGS_POLICY_ALL
.equals(tagsPolicy
)) {
202 h
.addParameters("--tags");
204 else if (TAGS_POLICY_NONE
.equals(tagsPolicy
)) {
205 h
.addParameters("--no-tags");
207 h
.addParameters(getRemote());
208 h
.addParameters(myRefspecs
.getReferences());
213 * @return remote name or URL
215 public String
getRemote() {
216 return getRemoteTextField().getText();
223 protected String
getDimensionServiceKey() {
224 return getClass().getName();
231 protected String
getHelpId() {
232 return "reference.VersionControl.Git.Fetch";