PageRenderTime 83ms CodeModel.GetById 40ms app.highlight 8ms RepoModel.GetById 32ms app.codeStats 0ms

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

https://bitbucket.org/atlassian/jetbrains-bitbucket-connector/
Java | 109 lines | 83 code | 21 blank | 5 comment | 3 complexity | bb27038f6c3924543a70eb5be9ffd2e2 MD5 | raw file
  1package org.bitbucket.connectors.jetbrains.ui;
  2
  3import com.intellij.openapi.project.Project;
  4import com.intellij.openapi.util.text.StringUtil;
  5
  6import javax.swing.*;
  7import java.util.Set;
  8import java.util.regex.Pattern;
  9
 10/**
 11 * User: leha2000
 12 * Date: Apr 16, 2011
 13 * Time: 11:07:02 AM
 14 */
 15public class BitbucketShareDialog extends BitbucketDialog {
 16
 17    private static final Pattern REPO_NAME_PATTERN = Pattern.compile("[a-zA-Z0-9_-]+([ ]+[a-zA-Z0-9_-]+)*");
 18
 19    private Set<String> myRepositories;
 20    private BitbucketSharePanel myPanel;
 21
 22    public BitbucketShareDialog(Project project, Set<String> existingRepositories, boolean canCreatePrivate) {
 23        super(project);
 24
 25        myPanel = new BitbucketSharePanel(this);
 26        myRepositories = existingRepositories;
 27        init();
 28
 29        setTitle(BitbucketBundle.message("share-project-on-bitbucket"));
 30        setOKButtonText(BitbucketBundle.message("share"));
 31        myPanel.setRepositoryName(project.getName());
 32        myPanel.setCanCreatePrivate(canCreatePrivate);
 33        init();
 34        updateOkButton();
 35    }
 36
 37    protected Action[] createActions() {
 38        return new Action[]{getOKAction(), getCancelAction()};
 39    }
 40
 41    @Override
 42    protected String getHelpId() {
 43        return null;
 44    }
 45
 46    @Override
 47    protected JComponent createCenterPanel() {
 48        return myPanel.getPanel();
 49    }
 50
 51    @Override
 52    public JComponent getPreferredFocusedComponent() {
 53        return myPanel.getPreferredFocusComponent();
 54    }
 55
 56    public void updateOkButton() {
 57        final String repositoryName = getRepositoryName();
 58        if (StringUtil.isEmpty(repositoryName)) {
 59            setErrorText(BitbucketBundle.message("no-repository-name"));
 60            setOKActionEnabled(false);
 61            return;
 62        }
 63        if (myRepositories.contains(repositoryName)) {
 64            setErrorText(BitbucketBundle.message("repository-exists"));
 65            setOKActionEnabled(false);
 66            return;
 67        }
 68        if (!REPO_NAME_PATTERN.matcher(repositoryName).matches()) {
 69            setErrorText(BitbucketBundle.message("invalid-repository-name"));
 70            setOKActionEnabled(false);
 71            return;
 72        }
 73        setErrorText(null);
 74        setOKActionEnabled(true);
 75    }
 76
 77    public String getRepositoryName() {
 78        return myPanel.getRepositoryName();
 79    }
 80
 81    public boolean isPrivate() {
 82        return myPanel.isPrivate();
 83    }
 84
 85    public boolean isSshRepositoryAccess() {
 86        return myPanel.isSshRepositoryAccess();
 87    }
 88
 89    public String getDescription() {
 90        return myPanel.getDescription();
 91    }
 92
 93    @Override
 94    public boolean isUseSsh() {
 95        return myPanel.isSshRepositoryAccess();
 96    }
 97
 98    public boolean isGit() {
 99        return myPanel.isGit();
100    }
101
102    public void setGit(boolean select) {
103        myPanel.setGit(select);
104    }
105
106    public void enableGit(boolean enable) {
107        myPanel.enableGit(enable);
108    }
109}