1 // Copyright 2008-2010 Victor Iacoban
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software distributed under
10 // the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11 // either express or implied. See the License for the specific language governing permissions and
12 // limitations under the License.
13 package org.zmlx.hg4idea.ui;
15 import com.intellij.openapi.application.ApplicationManager;
16 import com.intellij.openapi.project.Project;
17 import com.intellij.openapi.ui.DialogWrapper;
18 import com.intellij.openapi.vfs.VirtualFile;
19 import com.intellij.util.ui.UIUtil;
20 import org.apache.commons.lang.StringUtils;
21 import org.zmlx.hg4idea.command.HgShowConfigCommand;
24 import javax.swing.event.DocumentEvent;
25 import javax.swing.event.DocumentListener;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28 import java.util.Collection;
30 public class HgPullDialog extends DialogWrapper {
32 private final Project project;
33 private HgRepositorySelectorComponent hgRepositorySelector;
34 private JTextField sourceTxt;
35 private JPanel mainPanel;
37 public HgPullDialog(Project project) {
38 super(project, false);
39 this.project = project;
40 hgRepositorySelector.setTitle("Select repository to pull changesets for");
41 hgRepositorySelector.addActionListener(new ActionListener() {
42 public void actionPerformed(ActionEvent e) {
46 DocumentListener documentListener = new DocumentListener() {
47 public void insertUpdate(DocumentEvent e) {
51 public void removeUpdate(DocumentEvent e) {
55 public void changedUpdate(DocumentEvent e) {
59 sourceTxt.getDocument().addDocumentListener(documentListener);
64 public VirtualFile getRepository() {
65 return hgRepositorySelector.getRepository();
68 public String getSource() {
69 return sourceTxt.getText();
72 public void setRoots(Collection<VirtualFile> repos) {
73 hgRepositorySelector.setRoots(repos);
77 protected JComponent createCenterPanel() {
82 protected String getHelpId() {
83 return "reference.mercurial.pull.dialog";
86 private void onChangeRepository() {
87 ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
90 VirtualFile repo = hgRepositorySelector.getRepository();
91 HgShowConfigCommand configCommand = new HgShowConfigCommand(project);
92 final String defaultPath = configCommand.getDefaultPath(repo);
93 UIUtil.invokeAndWaitIfNeeded(new Runnable() {
96 sourceTxt.setText(defaultPath);
100 onChangePullSource();
105 private void onChangePullSource() {
106 setOKActionEnabled(StringUtils.isNotBlank(sourceTxt.getText()));