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.ConnectionWrapper;
20 import com.atlassian.theplugin.commons.cfg.ServerCfg;
21 import com.atlassian.theplugin.commons.remoteapi.ProductServerFacade;
22 import com.atlassian.theplugin.commons.remoteapi.ServerData;
23 import com.atlassian.theplugin.idea.config.serverconfig.ProductConnector;
24 import com.intellij.openapi.project.Project;
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 TestConnectionListener.ServerDataProvider {
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 ServerCfg server;
41
42 public PasswordDialog(final ServerCfg server, final ProductServerFacade serverFacade, final Project project) {
43 this.server = server;
44 setContentPane(passwordPanel);
45 setModal(true);
46
47 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
48 addWindowListener(new WindowAdapter() {
49 @Override
50 public void windowClosing(WindowEvent e) {
51 onCancel();
52 }
53 });
54 lblCommand.setText("<html><p>Please provide password to connect \"" + this.server.getName() + "\" server:</p> <p><i>"
55 + this.server.getUrl() + "</i></p></html>");
56 userName.setText(server.getUserName());
57
58 passwordPanel.registerKeyboardAction(new ActionListener() {
59 public void actionPerformed(ActionEvent e) {
60 onCancel();
61 }
62 }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
63
64 testConnectionButton.addActionListener(
65 new TestConnectionListener(project, new ProductConnector(serverFacade), this, new TestConnectionProcessor() {
66 public void setConnectionResult(final ConnectionWrapper.ConnectionState result) {
67 }
68
69 public void onSuccess() {
70 }
71
72 public void onError(final String errorMessage) {
73 }
74 }));
75 }
76
77 private void onCancel() {
78 dispose();
79 }
80
81 public ServerData getServer() {
82 return new ServerData(server.getName(), server.getServerId().toString(), getUserName(), getPasswordString(),
83 server.getUrl());
84 }
85
86 public JPanel getPasswordPanel() {
87 return passwordPanel;
88 }
89
90 public String getPasswordString() {
91 return String.valueOf(passwordField.getPassword());
92 }
93
94 public Boolean getShouldPasswordBeStored() {
95 return chkRememberPassword.isSelected();
96 }
97
98 public String getUserName() {
99 return this.userName.getText();
100 }
101
102 private void createUIComponents() {
103 }
104
105
106 {
107
108
109
110 $$$setupUI$$$();
111 }
112
113
114
115
116
117
118
119
120 private void $$$setupUI$$$() {
121 passwordPanel = new JPanel();
122 passwordPanel.setLayout(new GridLayoutManager(2, 1, new Insets(10, 10, 10, 10), -1, -1));
123 final JPanel panel1 = new JPanel();
124 panel1.setLayout(new GridLayoutManager(5, 2, new Insets(0, 0, 0, 0), -1, -1));
125 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));
126 passwordField = new JPasswordField();
127 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));
128 testConnectionButton = new JButton();
129 testConnectionButton.setText("Test connection");
130 testConnectionButton.setMnemonic('T');
131 testConnectionButton.setDisplayedMnemonicIndex(0);
132 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));
133 chkRememberPassword = new JCheckBox();
134 chkRememberPassword.setEnabled(true);
135 chkRememberPassword.setSelected(false);
136 chkRememberPassword.setText("Store password in configuration");
137 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));
138 lblCommand = new JLabel();
139 lblCommand.setText("");
140 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));
141 final JLabel label1 = new JLabel();
142 label1.setText("Password");
143 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));
144 final JLabel label2 = new JLabel();
145 label2.setText("User Name");
146 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));
147 userName = new JTextField();
148 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));
149 label1.setLabelFor(passwordField);
150 label2.setLabelFor(userName);
151 }
152
153
154
155
156 public JComponent $$$getRootComponent$$$() {
157 return passwordPanel;
158 }
159 }