PageRenderTime 42ms CodeModel.GetById 20ms app.highlight 9ms RepoModel.GetById 11ms app.codeStats 0ms

/src/org/bitbucket/connectors/jetbrains/ui/BitbucketCloneProjectDialog.java

https://bitbucket.org/atlassian/jetbrains-bitbucket-connector/
Java | 107 lines | 90 code | 17 blank | 0 comment | 13 complexity | c56b3a0b49cadc6785933f65cd07c96f MD5 | raw file
  1package org.bitbucket.connectors.jetbrains.ui;
  2
  3import com.intellij.openapi.project.Project;
  4import com.intellij.openapi.util.text.StringUtil;
  5import com.intellij.openapi.vfs.LocalFileSystem;
  6import com.intellij.openapi.vfs.VirtualFile;
  7import org.bitbucket.connectors.jetbrains.BitbucketUtil;
  8import org.bitbucket.connectors.jetbrains.RepositoryInfo;
  9
 10import javax.swing.*;
 11import java.util.List;
 12
 13public class BitbucketCloneProjectDialog extends BitbucketDialog {
 14
 15    private BitbucketCloneProjectPanel myPanel;
 16
 17    public BitbucketCloneProjectDialog(final Project project, final List<RepositoryInfo> repos) {
 18        super(project);
 19        myPanel = new BitbucketCloneProjectPanel(this);
 20        setTitle(BitbucketBundle.message("select-clone-repository"));
 21        setOKButtonText(BitbucketBundle.message("clone"));
 22        myPanel.setAvailableRepos(repos);
 23        init();
 24        setOKActionEnabled(false);
 25    }
 26
 27    @Override
 28    protected JComponent createCenterPanel() {
 29        return myPanel.getPanel();
 30    }
 31
 32    @Override
 33    protected String getHelpId() {
 34        return BitbucketUtil.BITBUCKET;
 35    }
 36
 37    @Override
 38    public JComponent getPreferredFocusedComponent() {
 39        return myPanel.getPreferrableFocusComponent();
 40    }
 41
 42    public void updateOkButton() {
 43        if (isRepositoryUrl()) {
 44            if (StringUtil.isEmpty(getRepositoryUrl())) {
 45                setErrorText(BitbucketBundle.message("no-repository-url"));
 46                setOKActionEnabled(false);
 47                return;
 48            }
 49        } else {
 50            if (getSelectedRepository() == null) {
 51                setErrorText(BitbucketBundle.message("no-repository-selected"));
 52                setOKActionEnabled(false);
 53                return;
 54            }
 55        }
 56        String path = getSelectedPath();
 57        if (path == null) {
 58            setErrorText(BitbucketBundle.message("select-clone-folder"));
 59            setOKActionEnabled(false);
 60            return;
 61        }
 62        VirtualFile file = LocalFileSystem.getInstance().findFileByPath(path);
 63        if (file == null || !file.exists() || !file.isDirectory()) {
 64            setErrorText(BitbucketBundle.message("no-selected-folder"));
 65            setOKActionEnabled(false);
 66            return;
 67        }
 68        String projectName = getProjectName();
 69        if (file.findChild(projectName) != null) {
 70            setErrorText(BitbucketBundle.message("folder-exists", projectName));
 71            setOKActionEnabled(false);
 72            return;
 73        }
 74
 75        setErrorText(null);
 76        setOKActionEnabled(true);
 77    }
 78
 79    public String getProjectName() {
 80        return myPanel.getProjectName();
 81    }
 82
 83    public RepositoryInfo getSelectedRepository() {
 84        return myPanel.getSelectedRepository();
 85    }
 86
 87    public boolean isRepositoryUrl() {
 88        return myPanel.isRepositoryUrl();
 89    }
 90
 91    public String getRepositoryUrl() {
 92        return myPanel.getRepositoryUrl();
 93    }
 94
 95    @Override
 96    public boolean isUseSsh() {
 97        return BitbucketUtil.isSshUrl(myPanel.getRepositoryUrl());
 98    }
 99
100    public String getSelectedPath() {
101        return myPanel.getSelectedPath();
102    }
103
104    public void setSelectedPath(final String path) {
105        myPanel.setSelectedPath(path);
106    }
107}