PageRenderTime 16ms CodeModel.GetById 11ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/atlassian/jetbrains-bitbucket-connector/
Java | 66 lines | 48 code | 13 blank | 5 comment | 2 complexity | b49191544a6d34c0bbd05174cddc58a7 MD5 | raw file
 1package org.bitbucket.connectors.jetbrains.ui;
 2
 3import com.intellij.openapi.project.Project;
 4import com.intellij.openapi.ui.DialogWrapper;
 5import org.bitbucket.connectors.jetbrains.BitbucketSettings;
 6import org.bitbucket.connectors.jetbrains.BitbucketUtil;
 7
 8import javax.swing.*;
 9
10/**
11 * User: leha2000
12 * Date: Apr 15, 2011
13 * Time: 10:12:26 AM
14 */
15public class BitbucketLoginDialog extends DialogWrapper {
16
17    private BitbucketLoginPanel myPanel;
18    private Project myProject;
19
20    public BitbucketLoginDialog(Project project) {
21        super(project, true);
22        myProject = project;
23
24        myPanel = new BitbucketLoginPanel(this);
25
26        BitbucketSettings settings = BitbucketSettings.getInstance();
27        myPanel.setLogin(settings.getLogin());
28        myPanel.setPassword(settings.getPassword());
29
30        setTitle(BitbucketBundle.message("login-bitbucket"));
31        setOKButtonText(BitbucketBundle.message("login"));
32        init();
33    }
34
35    @Override
36    protected JComponent createCenterPanel() {
37        return myPanel.getPanel();
38    }
39
40    protected Action[] createActions() {
41        return new Action[]{getOKAction(), getCancelAction()};
42    }
43
44    @Override
45    public JComponent getPreferredFocusedComponent() {
46      return myPanel.getPreferrableFocusComponent();
47    }
48
49    @Override
50    protected void doOKAction() {
51      String login = myPanel.getLogin();
52      String password = myPanel.getPassword();
53      if (BitbucketUtil.checkCredentials(myProject, login, password)) {
54        BitbucketSettings settings = BitbucketSettings.getInstance();
55        settings.setLogin(login);
56        settings.setPassword(password);
57        super.doOKAction();
58      } else {
59        setErrorText(BitbucketBundle.message("cannot-login"));
60      }
61    }
62
63    public void clearErrors() {
64      setErrorText(null);
65    }
66}