1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package com.mindtree.techworks.insight.gui.preferences;
25
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28
29 import javax.swing.JCheckBox;
30 import javax.swing.JLabel;
31 import javax.swing.JPasswordField;
32 import javax.swing.JTextField;
33
34 import com.mindtree.techworks.insight.InsightConstants;
35
36
37
38
39
40
41
42
43
44
45
46
47
48 public class ProxyUIPanel extends AbstractPreferencesUIPanel implements ActionListener {
49
50
51
52
53 private static final long serialVersionUID = -5481226146152529345L;
54
55
56
57
58 private static final String HTTP_PROXY_HOST = "http.proxy.host";
59 private static final String HTTP_PROXY_PORT = "http.proxy.port";
60
61
62
63
64 private static final String AUTHENTICATION = "authentication";
65 private static final String USER = "user";
66 private static final String PASSWORD = "password";
67
68
69
70
71 private static final String TRUE = "true";
72 private static final String FALSE = "false";
73
74
75
76
77 private JTextField httpProxyHostField;
78 private JTextField httpProxyPortField;
79
80
81
82
83 private JCheckBox requiresAuthentication;
84 private JTextField userField;
85 private JPasswordField passwordField;
86
87
88
89
90 public ProxyUIPanel() {
91 }
92
93
94
95
96
97 public void actionPerformed(ActionEvent arg0) {
98 checkAuthenticationEnable();
99 }
100
101
102
103
104
105 protected void initializeDisplay() {
106
107 addComponent(new JLabel(InsightConstants.getLiteral("HTTP_PROXY_HOST")),0,0,0,0,1,1);
108 this.httpProxyHostField = new JTextField();
109 addComponent(httpProxyHostField,1,0,1,0, 1, 1);
110 addComponent(new JLabel(InsightConstants.getLiteral("PROXY_PORT")),2,0,0,0,1,1);
111 this.httpProxyPortField = new JTextField();
112 addComponent(httpProxyPortField,3,0,1,0, 1, 1);
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130 this.requiresAuthentication = new JCheckBox(InsightConstants.getLiteral("REQUIRES_AUTHENTICATION"));
131 this.requiresAuthentication.addActionListener(this);
132 addComponent(requiresAuthentication,0,3,1,0, 4, 1);
133 addComponent(new JLabel(InsightConstants.getLiteral("USER")),0,4,0,0,1,1);
134 this.userField = new JTextField();
135 addComponent(userField,1,4,1,0, 1, 1);
136 addComponent(new JLabel(InsightConstants.getLiteral("PASSWORD")),2,4,0,0,1,1);
137 this.passwordField = new JPasswordField();
138 addComponent(passwordField,3,4,1,0, 1, 1);
139
140
141 addComponent(new JLabel(),0,5,1,1,4,1);
142
143 this.requiresAuthentication.setSelected(this.preference.
144 getPreferenceAttributeById(AUTHENTICATION).getValue().equalsIgnoreCase(TRUE));
145 this.httpProxyHostField.setText(this.preference.getPreferenceAttributeById(HTTP_PROXY_HOST).getValue());
146 this.httpProxyPortField.setText(this.preference.getPreferenceAttributeById(HTTP_PROXY_PORT).getValue());
147
148
149
150
151
152
153 checkAuthenticationEnable();
154 }
155
156
157
158
159
160 protected void setPreferenceValues() {
161 this.preference.getPreferenceAttributeById(HTTP_PROXY_HOST).setValue(this.httpProxyHostField.getText());
162 this.preference.getPreferenceAttributeById(HTTP_PROXY_PORT).setValue(this.httpProxyPortField.getText());
163
164
165
166
167
168
169 this.preference.getPreferenceAttributeById(AUTHENTICATION).setValue(this.requiresAuthentication.isSelected() ? TRUE: FALSE);
170 this.preference.getPreferenceAttributeById(USER).setValue(this.userField.getText());
171 this.preference.getPreferenceAttributeById(PASSWORD).setValue(new String(this.passwordField.getPassword()));
172 }
173
174
175
176
177 private void checkAuthenticationEnable() {
178 boolean authenticationEnabled = this.requiresAuthentication.isSelected();
179 this.userField.setEditable(authenticationEnabled);
180 this.passwordField.setEditable(authenticationEnabled);
181 this.userField.setEnabled(authenticationEnabled);
182 this.passwordField.setEnabled(authenticationEnabled);
183 this.userField.setText(authenticationEnabled ? this.preference.getPreferenceAttributeById(USER).getValue() : "");
184 this.passwordField.setText(authenticationEnabled ? this.preference.getPreferenceAttributeById(PASSWORD).getValue() : "");
185 }
186
187 }