git4idea: IDEA-22561: renamed OK buttons to appropriate names in dialogs
[fedora-idea.git] / plugins / git4idea / src / git4idea / ui / GitFetchDialog.java
blob0b28f51fb05817e300c0dce3dcf92e4bc3a93160
1 /*
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.
16 package git4idea.ui;
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;
26 import javax.swing.*;
27 import javax.swing.event.DocumentEvent;
28 import java.awt.event.ActionEvent;
29 import java.awt.event.ActionListener;
30 import java.util.List;
32 /**
33 * Fetch dialog. It represents most of the parameters for "git fetch" operation.
35 public class GitFetchDialog extends DialogWrapper {
36 /**
37 * The git root
39 private JComboBox myGitRoot;
40 /**
41 * Reference specification panel
43 private GitRefspecPanel myRefspecs;
44 /**
45 * Fetch tags policy
47 private JComboBox myFetchTagsComboBox;
48 /**
49 * Force reference updates
51 private JCheckBox myForceReferencesUpdateCheckBox;
52 /**
53 * Remote name/url
55 private JComboBox myRemote;
56 /**
57 * The root panel
59 private JPanel myPanel;
60 /**
61 * The project for the dialog
63 private final Project myProject;
64 /**
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");
68 /**
69 * Fetch all tags policy
71 private static final String TAGS_POLICY_ALL = GitBundle.getString("fetch.tags.policy.all");
72 /**
73 * Fetch no tags except explicitly listed
75 private static final String TAGS_POLICY_NONE = GitBundle.getString("fetch.tags.policy.none");
77 /**
78 * A constructor
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) {
85 super(project, true);
86 setTitle(GitBundle.getString("fetch.title"));
87 setOKButtonText(GitBundle.getString("fetch.button"));
88 GitUIUtil.setupRootChooser(project, roots, defaultRoot, myGitRoot, null);
89 myProject = project;
90 myRefspecs.setProject(project);
91 myRefspecs.setReferenceSource(GitRefspecPanel.ReferenceSource.FETCH);
92 setupRemotes();
93 setupFetchTagsPolicy();
94 init();
95 setupValidation();
99 /**
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);
108 setErrorText(null);
109 return;
111 final String result = myRefspecs.validateFields();
112 if (result != null) {
113 setOKActionEnabled(false);
114 setErrorText(result.length() == 0 ? null : result);
115 return;
117 setOKActionEnabled(true);
118 setErrorText(null);
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());
148 updateRemotes();
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();
171 * Update remotes
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();
185 * {@inheritDoc}
187 protected JComponent createCenterPanel() {
188 return myPanel;
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());
209 return h;
213 * @return remote name or URL
215 public String getRemote() {
216 return getRemoteTextField().getText();
220 * {@inheritDoc}
222 @Override
223 protected String getDimensionServiceKey() {
224 return getClass().getName();
228 * {@inheritDoc}
230 @Override
231 protected String getHelpId() {
232 return "reference.VersionControl.Git.Fetch";