1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.atlassian.theplugin.idea;
18
19 import com.atlassian.theplugin.LoginDataProvided;
20 import com.atlassian.theplugin.commons.cfg.ServerCfg;
21 import com.atlassian.theplugin.commons.remoteapi.ProductServerFacade;
22 import com.atlassian.theplugin.idea.config.serverconfig.ProductConnector;
23 import com.intellij.uiDesigner.core.GridConstraints;
24 import com.intellij.uiDesigner.core.GridLayoutManager;
25
26 import javax.swing.*;
27 import java.awt.*;
28 import java.awt.event.ActionEvent;
29 import java.awt.event.ActionListener;
30 import java.awt.event.KeyEvent;
31 import java.awt.event.WindowAdapter;
32 import java.awt.event.WindowEvent;
33
34 public class PasswordDialog extends JDialog implements LoginDataProvided {
35
36 private JPanel passwordPanel;
37 private JCheckBox chkRememberPassword;
38 private JPasswordField passwordField;
39 private JButton testConnectionButton;
40 private JLabel lblCommand;
41 private JTextField userName;
42 private transient ServerCfg server;
43
44 public PasswordDialog(final ServerCfg server, final ProductServerFacade serverFacade) {
45 this.server = server;
46 setContentPane(passwordPanel);
47 setModal(true);
48
49 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
50 addWindowListener(new WindowAdapter() {
51 @Override
52 public void windowClosing(WindowEvent e) {
53 onCancel();
54 }
55 });
56 lblCommand.setText("<html><p>Please provide password to connect \"" + this.server.getName() + "\" server:</p> <p><i>"
57 + this.server.getUrl() + "</i></p></html>");
58 userName.setText(server.getUsername());
59
60 passwordPanel.registerKeyboardAction(new ActionListener() {
61 public void actionPerformed(ActionEvent e) {
62 onCancel();
63 }
64 }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
65
66 testConnectionButton.addActionListener(new TestConnectionListener(null, new ProductConnector(serverFacade), this));
67 }
68
69 private void onCancel() {
70
71 dispose();
72 }
73
74
75 public JPanel getPasswordPanel() {
76 return passwordPanel;
77 }
78
79 public String getPasswordString() {
80 return String.valueOf(passwordField.getPassword());
81 }
82
83 public Boolean getShouldPasswordBeStored() {
84 return chkRememberPassword.isSelected();
85 }
86
87 public String getUserName() {
88 return this.userName.getText();
89 }
90
91 private void createUIComponents() {
92
93 }
94
95 public String getServerUrl() {
96 return server.getUrl();
97 }
98
99 public String getPassword() {
100 return getPasswordString();
101 }
102
103 {
104
105
106
107 $$$setupUI$$$();
108 }
109
110
111
112
113
114
115
116
117 private void $$$setupUI$$$() {
118 passwordPanel = new JPanel();
119 passwordPanel.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1));
120 final JPanel panel1 = new JPanel();
121 panel1.setLayout(new GridLayoutManager(5, 2, new Insets(0, 0, 0, 0), -1, -1));
122 passwordPanel.add(panel1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
123 passwordField = new JPasswordField();
124 panel1.add(passwordField, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
125 testConnectionButton = new JButton();
126 testConnectionButton.setText("Test connection");
127 testConnectionButton.setMnemonic('T');
128 testConnectionButton.setDisplayedMnemonicIndex(0);
129 panel1.add(testConnectionButton, new GridConstraints(3, 1, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
130 chkRememberPassword = new JCheckBox();
131 chkRememberPassword.setEnabled(true);
132 chkRememberPassword.setSelected(false);
133 chkRememberPassword.setText("Store password in configuration");
134 panel1.add(chkRememberPassword, new GridConstraints(4, 1, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
135 lblCommand = new JLabel();
136 lblCommand.setText("");
137 panel1.add(lblCommand, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
138 final JLabel label1 = new JLabel();
139 label1.setText("Password");
140 panel1.add(label1, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
141 final JLabel label2 = new JLabel();
142 label2.setText("User Name");
143 panel1.add(label2, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
144 userName = new JTextField();
145 panel1.add(userName, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
146 label1.setLabelFor(passwordField);
147 label2.setLabelFor(userName);
148 }
149
150
151
152
153 public JComponent $$$getRootComponent$$$() {
154 return passwordPanel;
155 }
156 }