-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathFirstLoginDialog.java
More file actions
331 lines (287 loc) · 16.1 KB
/
FirstLoginDialog.java
File metadata and controls
331 lines (287 loc) · 16.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/*
* Copyright (c) Mirth Corporation. All rights reserved.
*
* http://www.mirthcorp.com
*
* The software in this package is published under the terms of the MPL license a copy of which has
* been included with this distribution in the LICENSE.txt file.
*/
package com.mirth.connect.client.ui;
import static com.mirth.connect.client.core.BrandingConstants.CENTRAL_USER_REGISTRATION;
import static com.mirth.connect.client.core.BrandingConstants.MANDATORY_USER_REGISTRATION;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.prefs.Preferences;
import javax.swing.JDialog;
import javax.swing.event.HyperlinkEvent.EventType;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import com.mirth.connect.client.core.ClientException;
import com.mirth.connect.client.ui.util.DisplayUtil;
import com.mirth.connect.model.User;
/**
* A dialog for creating a new user or editing a current user
*/
public class FirstLoginDialog extends javax.swing.JDialog implements UserDialogInterface {
private Frame parent;
private boolean result = false;
private static Preferences preferences;
/** Creates new form UserDialog */
public FirstLoginDialog(User currentUser) {
super(PlatformUI.MIRTH_FRAME);
this.parent = PlatformUI.MIRTH_FRAME;
initComponents();
DisplayUtil.setResizable(this, false);
finishButton.setEnabled(false);
userEditPanel.setUser(this, currentUser);
final boolean isRegistrationMandatory = CENTRAL_USER_REGISTRATION && MANDATORY_USER_REGISTRATION && currentUser.getId() == 1;
registerCheckBox.setSelected(isRegistrationMandatory);
registerCheckBox.setEnabled(!isRegistrationMandatory);
registerCheckBox.setVisible(CENTRAL_USER_REGISTRATION);
registerCheckBoxActionPerformed(null);
userConsentCheckBox.setVisible(CENTRAL_USER_REGISTRATION);
contentTextPane.setVisible(CENTRAL_USER_REGISTRATION);
jLabel2.setForeground(UIConstants.HEADER_TITLE_TEXT_COLOR);
setModal(true);
setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
parent.logout(false, true);
}
});
pack();
Dimension dlgSize = getPreferredSize();
Dimension frmSize = parent.getSize();
Point loc = parent.getLocation();
if ((frmSize.width == 0 && frmSize.height == 0) || (loc.x == 0 && loc.y == 0)) {
setLocationRelativeTo(null);
} else {
setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
}
setVisible(true);
}
public void setFinishButtonEnabled(boolean enabled) {
finishButton.setEnabled(enabled);
}
public void triggerFinishButton() {
finishButtonActionPerformed(null);
}
// @formatter:off
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
channelOverview = new javax.swing.JPanel();
finishButton = new javax.swing.JButton();
jSeparator1 = new javax.swing.JSeparator();
mirthHeadingPanel1 = new com.mirth.connect.client.ui.MirthHeadingPanel();
jLabel2 = new javax.swing.JLabel();
userEditPanel = new com.mirth.connect.client.ui.UserEditPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextPane1 = new javax.swing.JTextPane();
registerCheckBox = new javax.swing.JCheckBox();
userConsentCheckBox = new javax.swing.JCheckBox();
contentTextPane = new javax.swing.JTextPane();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle(String.format("Welcome to %s", BrandingConstants.PRODUCT_NAME));
channelOverview.setBackground(new java.awt.Color(255, 255, 255));
channelOverview.setName(""); // NOI18N
finishButton.setText("Finish");
finishButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
finishButtonActionPerformed(evt);
}
});
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
jLabel2.setForeground(new java.awt.Color(255, 255, 255));
jLabel2.setText(String.format("<html>Welcome to %s</html>", BrandingConstants.PRODUCT_NAME));
javax.swing.GroupLayout mirthHeadingPanel1Layout = new javax.swing.GroupLayout(mirthHeadingPanel1);
mirthHeadingPanel1.setLayout(mirthHeadingPanel1Layout);
mirthHeadingPanel1Layout.setHorizontalGroup(
mirthHeadingPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mirthHeadingPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE)
.addContainerGap())
);
mirthHeadingPanel1Layout.setVerticalGroup(
mirthHeadingPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mirthHeadingPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
.addContainerGap())
);
jTextPane1.setEditable(false);
jTextPane1.setBackground(new java.awt.Color(250, 250, 210));
jTextPane1.setText(String.format("You may now customize your %s user account information. You also have the option of changing your account password.", BrandingConstants.PRODUCT_NAME));
jTextPane1.setAutoscrolls(false);
jTextPane1.setDisabledTextColor(new java.awt.Color(0, 0, 0));
jTextPane1.setEnabled(false);
jScrollPane1.setViewportView(jTextPane1);
registerCheckBox.setBackground(new java.awt.Color(255, 255, 255));
registerCheckBox.setText(String.format("Register user with %s", BrandingConstants.COMPANY_NAME));
registerCheckBox.setToolTipText(String.format("<html>Register your user information with %s to help us<br>improve the product and provide better service.</html>", BrandingConstants.COMPANY_NAME));
registerCheckBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
registerCheckBoxActionPerformed(evt);
}
});
userConsentCheckBox.setBackground(new java.awt.Color(255, 255, 255));
userConsentCheckBox.setText(String.format("I consent to receive email updates and marketing messages from %s.", BrandingConstants.COMPANY_NAME));
userConsentCheckBox.setToolTipText("<html></html>");
contentTextPane.setContentType("text/html");
contentTextPane.setText(String.format("<html> For more information on the processing of your personal data, click <a href=\"%s\">here to find our Privacy Policy.</a></html>", BrandingConstants.PRIVACY_URL));
MutableAttributeSet set = new SimpleAttributeSet();
StyleConstants.setLineSpacing(set, 1);
StyleConstants.setFontSize(set, 10);
StyleConstants.setFontFamily(set, "Tahoma");
StyledDocument doc = contentTextPane.getStyledDocument();
doc.setCharacterAttributes(0, doc.getLength() + 1, set, false);
contentTextPane.setParagraphAttributes(set, true);
contentTextPane.setEditable(false);
contentTextPane.addHyperlinkListener(event -> {
if (event.getEventType() == EventType.ACTIVATED) {
BareBonesBrowserLaunch.openURL(event.getURL().toString());
}
});
javax.swing.GroupLayout channelOverviewLayout = new javax.swing.GroupLayout(channelOverview);
channelOverview.setLayout(channelOverviewLayout);
channelOverviewLayout.setHorizontalGroup(
channelOverviewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, channelOverviewLayout.createSequentialGroup()
.addContainerGap(305, Short.MAX_VALUE)
.addComponent(finishButton)
.addGap(9, 9, 9))
.addComponent(mirthHeadingPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 431, Short.MAX_VALUE)
.addGroup(channelOverviewLayout.createSequentialGroup()
.addContainerGap()
.addGroup(channelOverviewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE)
.addGroup(channelOverviewLayout.createSequentialGroup()
.addGroup(channelOverviewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(registerCheckBox)
.addComponent(userConsentCheckBox)
.addComponent(contentTextPane)
.addComponent(userEditPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 19, Short.MAX_VALUE)))
.addContainerGap())
);
channelOverviewLayout.setVerticalGroup(
channelOverviewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, channelOverviewLayout.createSequentialGroup()
.addComponent(mirthHeadingPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(userEditPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(registerCheckBox)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(userConsentCheckBox)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(contentTextPane)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(finishButton)
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(channelOverview, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(channelOverview, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
// @formatter:on
/**
* An action for when the finish button is pressed. Checks and saves all of the information.
*/
private void finishButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_finishButtonActionPerformed
finishButton.requestFocus();
String validateUserMessage = userEditPanel.validateUser();
if (validateUserMessage != null) {
parent.alertWarning(this, validateUserMessage);
} else {
User user = userEditPanel.getUser();
if (userConsentCheckBox.isSelected()) {
user.setUserConsent(true);
}
boolean success = false;
success = parent.updateCurrentUser(this, user, userEditPanel.getPassword());
if (!success) {
return;
}
if (registerCheckBox.isSelected() && CENTRAL_USER_REGISTRATION) {
parent.registerUser(user);
}
try {
User currentUser = parent.getCurrentUser(parent);
parent.mirthClient.setUserPreference(currentUser.getId(), "firstlogin", "false");
// if the above doesn't error and this is user 1, create string to put in OS preferences
if (Integer.valueOf(currentUser.getId()) == 1) {
String userInfo = currentUser.getUsername() + "," +
currentUser.getFirstName() + "," +
currentUser.getLastName() + "," +
currentUser.getEmail() + "," +
currentUser.getCountry() + "," +
currentUser.getStateTerritory() + "," +
currentUser.getPhoneNumber() + "," +
currentUser.getOrganization() + "," +
currentUser.getRole() + "," +
currentUser.getIndustry() + "," +
currentUser.getDescription() + ",END";
preferences = Preferences.userNodeForPackage(Mirth.class);
preferences.put("userLoginInfo", userInfo);
// used for debugging original first login screen
//preferences.remove("userLoginInfo");
}
} catch (ClientException e) {
parent.alertThrowable(this, e);
}
result = true;
this.dispose();
}
}//GEN-LAST:event_finishButtonActionPerformed
private void registerCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_registerCheckBoxActionPerformed
boolean allRequired = registerCheckBox.isSelected();
if (allRequired) {
userConsentCheckBox.setSelected(true);
userConsentCheckBox.setEnabled(true);
} else {
userConsentCheckBox.setSelected(false);
userConsentCheckBox.setEnabled(false);
}
userEditPanel.setRequiredFields(allRequired, true);
}//GEN-LAST:event_registerCheckBoxActionPerformed
public boolean getResult() {
return this.result;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel channelOverview;
private javax.swing.JButton finishButton;
private javax.swing.JLabel jLabel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JTextPane jTextPane1;
private com.mirth.connect.client.ui.MirthHeadingPanel mirthHeadingPanel1;
private javax.swing.JCheckBox registerCheckBox;
private javax.swing.JCheckBox userConsentCheckBox;
private com.mirth.connect.client.ui.UserEditPanel userEditPanel;
private javax.swing.JTextPane contentTextPane;
// End of variables declaration//GEN-END:variables
}