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.Server;
21 import com.atlassian.theplugin.commons.exception.ThePluginException;
22 import com.atlassian.theplugin.commons.remoteapi.ProductServerFacade;
23 import com.atlassian.theplugin.commons.remoteapi.RemoteApiException;
24 import com.atlassian.theplugin.util.Connector;
25 import com.intellij.uiDesigner.core.GridConstraints;
26 import com.intellij.uiDesigner.core.GridLayoutManager;
27
28 import javax.swing.*;
29 import java.awt.*;
30 import java.awt.event.*;
31
32 public class PasswordDialog extends JDialog implements LoginDataProvided {
33
34 private JPanel passwordPanel;
35 private JCheckBox chkRememberPassword;
36 private JPasswordField passwordField;
37 private JButton testConnectionButton;
38 private JLabel lblCommand;
39 private JTextField userName;
40 private transient Server server;
41
42 public PasswordDialog(final Server server, final ProductServerFacade serverFacade) {
43 this.server = server;
44 setContentPane(passwordPanel);
45 setModal(true);
46
47 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
48 addWindowListener(new WindowAdapter() {
49 public void windowClosing(WindowEvent e) {
50 onCancel();
51 }
52 });
53 lblCommand.setText("<html><p>Please provide password to connect \"" + this.server.getName() + "\" server:</p> <p><i>" + this.server.getUrlString() + "</i></p></html>");
54
55 passwordPanel.registerKeyboardAction(new ActionListener() {
56 public void actionPerformed(ActionEvent e) {
57 onCancel();
58 }
59 }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
60
61 testConnectionButton.addActionListener(new TestConnectionListener(new Connector() {
62
63 public void connect() throws ThePluginException {
64 this.validate();
65 try {
66 serverFacade.testServerConnection(
67 super.getUrl(), super.getUserName(), super.getPassword());
68 } catch (RemoteApiException e) {
69 throw new ThePluginException("Error connecting server.", e);
70 }
71 }
72
73 }, this));
74 }
75
76 private void onCancel() {
77
78 dispose();
79 }
80
81
82 public JPanel getPasswordPanel() {
83 return passwordPanel;
84 }
85
86 public String getPasswordString() {
87 return String.valueOf(passwordField.getPassword());
88 }
89
90 public Boolean getShouldPasswordBeStored() {
91 return chkRememberPassword.isSelected();
92 }
93
94 public void setUserName(String anUsername) {
95 this.userName.setText(anUsername);
96 }
97
98 public String getUserName() {
99 return this.userName.getText();
100 }
101
102 private void createUIComponents() {
103
104 }
105
106 public String getServerUrl() {
107 return server.getUrlString();
108 }
109
110 public String getPassword() {
111 return getPasswordString();
112 }
113
114 {
115
116
117
118 $$$setupUI$$$();
119 }
120
121
122
123
124
125
126
127
128 private void $$$setupUI$$$() {
129 passwordPanel = new JPanel();
130 passwordPanel.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1));
131 final JPanel panel1 = new JPanel();
132 panel1.setLayout(new GridLayoutManager(5, 2, new Insets(0, 0, 0, 0), -1, -1));
133 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));
134 passwordField = new JPasswordField();
135 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));
136 testConnectionButton = new JButton();
137 testConnectionButton.setText("Test connection");
138 testConnectionButton.setMnemonic('T');
139 testConnectionButton.setDisplayedMnemonicIndex(0);
140 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));
141 chkRememberPassword = new JCheckBox();
142 chkRememberPassword.setEnabled(true);
143 chkRememberPassword.setSelected(false);
144 chkRememberPassword.setText("Store password in configuration");
145 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));
146 lblCommand = new JLabel();
147 lblCommand.setText("");
148 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));
149 final JLabel label1 = new JLabel();
150 label1.setText("Password");
151 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));
152 final JLabel label2 = new JLabel();
153 label2.setText("User Name");
154 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));
155 userName = new JTextField();
156 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));
157 label1.setLabelFor(passwordField);
158 label2.setLabelFor(userName);
159 }
160
161
162
163
164 public JComponent $$$getRootComponent$$$() {
165 return passwordPanel;
166 }
167 }