PageRenderTime 122ms CodeModel.GetById 60ms app.highlight 7ms RepoModel.GetById 54ms app.codeStats 0ms

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

https://bitbucket.org/atlassian/jetbrains-bitbucket-connector/
Java | 77 lines | 58 code | 14 blank | 5 comment | 2 complexity | bd7204702af270392e6f24c24de5dac1 MD5 | raw file
 1package org.bitbucket.connectors.jetbrains.ui;
 2
 3import com.intellij.ide.BrowserUtil;
 4import com.intellij.openapi.project.ProjectManager;
 5import com.intellij.openapi.ui.Messages;
 6import org.bitbucket.connectors.jetbrains.BitbucketUtil;
 7
 8import javax.swing.*;
 9import javax.swing.event.HyperlinkEvent;
10import javax.swing.event.HyperlinkListener;
11import java.awt.event.ActionEvent;
12import java.awt.event.ActionListener;
13
14/**
15 * User: leha2000
16 * Date: Apr 7, 2011
17 * Time: 2:03:43 PM
18 */
19public class BitbucketSettingsPanel {
20
21    private JPanel myPane;
22
23    private JTextField myLoginTextField;
24    private JPasswordField myPasswordField;
25
26    private JButton myTestButton;
27    private JTextPane mySignupPane;
28    private JButton myAddSSHKeyButton;
29
30    public BitbucketSettingsPanel() {
31        String msg = BitbucketBundle.message("signup-on-bitbucket", "https://bitbucket.org/account/signup/");
32        mySignupPane.setText(msg);
33        mySignupPane.setBackground(myPane.getBackground());
34        mySignupPane.addHyperlinkListener(new HyperlinkListener() {
35            public void hyperlinkUpdate(HyperlinkEvent e) {
36                if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
37                    BrowserUtil.launchBrowser(e.getURL().toExternalForm());
38                }
39            }
40        });
41
42        myTestButton.addActionListener(new ActionListener() {
43            public void actionPerformed(ActionEvent e) {
44                boolean result = BitbucketUtil.checkCredentials(ProjectManager.getInstance().getDefaultProject(), getLogin(), getPassword());
45                Messages.showInfoMessage(
46                        result ? BitbucketBundle.message("connection-success") : BitbucketBundle.message("cannot-login"),
47                        result ? BitbucketBundle.message("success") : BitbucketBundle.message("failure"));
48            }
49        });
50
51        myAddSSHKeyButton.addActionListener(new ActionListener() {
52            public void actionPerformed(ActionEvent e) {
53                BitbucketUtil.addSshKey(ProjectManager.getInstance().getDefaultProject(), myPane, getLogin(), getPassword());
54            }
55        });
56    }
57
58    public JComponent getPanel() {
59        return myPane;
60    }
61
62    public void setLogin(String login) {
63        myLoginTextField.setText(login);
64    }
65
66    public void setPassword(String password) {
67        myPasswordField.setText(password);
68    }
69
70    public String getLogin() {
71        return myLoginTextField.getText().trim();
72    }
73
74    public String getPassword() {
75        return String.valueOf(myPasswordField.getPassword());
76    }
77}