Subversion Repository Public Repository

Aurocare_27_07_2018

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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bestray.healthcareemr.Views;

import com.bestray.healthcarecommonutil.exception.ProcessingException;
import com.bestray.healthcarecommonutil.util.ButtonType;
import com.bestray.healthcarecommonutil.util.CheckListManager;
import com.bestray.healthcarecommonutil.util.StandardButton;
import com.bestray.healthcarecommonutil.util.TextPrompt;
import com.bestray.healthcarecommonutil.util.Theme;
import com.bestray.healthcarecommonutil.vo.TPermission;
import com.bestray.healthcarecommonutil.vo.TRole;
import com.bestray.healthcarecommonutil.vo.TRolePermission;
import com.bestray.healthcareemr.Controller.UserSetupController;
import com.bestray.healthcareemr.Util.MessageProperties;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.event.KeyEvent;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author user3
 */
public class UserSecurityPanel extends javax.swing.JPanel {

    /**
     * Creates new form UserSecurityPanel
     */
    public UserSecurityPanel() {
        populate();
        initComponents();
        changecolumnlength();
        //assignedpermissionpanel.setVisible(false);
        TextPrompt tp7 = new TextPrompt("Search For Role Name", rolenamesearchfield);
        tp7.setForeground( Color.RED );
        tp7.changeAlpha(0.5f);
        tp7.changeStyle(Font.BOLD);
        TextPrompt tp8 = new TextPrompt("Add New Role", addnewroletextbox);
        tp8.setForeground( Color.RED );
        tp8.changeAlpha(0.5f);
        tp8.changeStyle(Font.BOLD);
        updateRoleTable();
        //permissionlist.setModel(permissionmodel);
        //checkListManager = new CheckListManager(permissionlist); 
    }
    CheckListManager checkListManager;
    /**
     * 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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        permissiontable = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        rolenamesearchfield = new javax.swing.JTextField();
        searchbutton = new StandardButton("My List", Theme.STANDARD_NAVYBLUE_THEME,ButtonType.BUTTON_RECTANGULAR);
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        roletable = new javax.swing.JTable(){
            public boolean isCellEditable(int row, int column){
                return false;
            }
            public Component prepareRenderer(TableCellRenderer renderer, int rowIndex, int vColIndex) {
                Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
                if (rowIndex % 2 == 0 && !isCellSelected(rowIndex, vColIndex)) {
                    c.setForeground(Color.BLACK);
                    c.setBackground(new Color(200, 225, 250));
                }
                else if(rowIndex % 2 == 0 && isCellSelected(rowIndex, vColIndex)){
                    c.setForeground(Color.WHITE);
                    c.setBackground(Color.BLUE);
                }
                else if(rowIndex % 2 != 0 && isCellSelected(rowIndex, vColIndex)){
                    c.setForeground(Color.WHITE);
                    c.setBackground(Color.BLUE);
                }
                else {
                    c.setForeground(Color.BLACK);
                    c.setBackground(getBackground());
                }
                return c;
            }
        };
        assignedpermissionpanel = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        assignedpermissionlist = new javax.swing.JList();
        removepermissionbutton = new StandardButton("My List", Theme.STANDARD_SILVER_THEME,ButtonType.BUTTON_RECTANGULAR);
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        permissionlist = new javax.swing.JList();
        addpermissionbutton = new StandardButton("My List", Theme.STANDARD_SILVER_THEME,ButtonType.BUTTON_RECTANGULAR);
        addnewroletextbox = new javax.swing.JTextField();
        addrolebutton = new StandardButton("My List", Theme.STANDARD_SILVER_THEME,ButtonType.BUTTON_RECTANGULAR);
        jPanel5 = new javax.swing.JPanel();

        jButton1.setText("Add Permissions");

        jButton2.setText("Add");

        jButton3.setText("Edit");

        permissiontable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Permission Name"
            }
        ));
        permissiontable.setRowHeight(23);
        permissiontable.setRowMargin(0);
        jScrollPane2.setViewportView(permissiontable);

        setBorder(javax.swing.BorderFactory.createEtchedBorder());
        setOpaque(false);

        jPanel1.setBackground(new java.awt.Color(0, 153, 255));

        jLabel1.setFont(new java.awt.Font("SansSerif", 1, 14)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("User Permission");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(jLabel1)
                .addGap(0, 0, 0))
        );

        rolenamesearchfield.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                rolenamesearchfieldKeyPressed(evt);
            }
        });

        searchbutton.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N
        searchbutton.setText("Search");
        searchbutton.setOpaque(false);
        searchbutton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchbuttonActionPerformed(evt);
            }
        });

        jPanel2.setLayout(new java.awt.BorderLayout());

        roletable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Role Id", "Role Name"
            }
        ));
        roletable.setRowHeight(23);
        roletable.getTableHeader().setReorderingAllowed(false);
        roletable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                roletableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(roletable);

        jPanel2.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        assignedpermissionpanel.setOpaque(false);

        jPanel6.setBackground(new java.awt.Color(153, 204, 255));
        jPanel6.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));

        jLabel3.setFont(new java.awt.Font("SansSerif", 1, 13)); // NOI18N
        jLabel3.setText("Assigned Permissions");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(jLabel3)
                .addGap(0, 0, 0))
        );

        assignedpermissionlist.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N
        assignedpermissionlist.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane4.setViewportView(assignedpermissionlist);

        removepermissionbutton.setText("Remove Permission");
        removepermissionbutton.setOpaque(false);
        removepermissionbutton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removepermissionbuttonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout assignedpermissionpanelLayout = new javax.swing.GroupLayout(assignedpermissionpanel);
        assignedpermissionpanel.setLayout(assignedpermissionpanelLayout);
        assignedpermissionpanelLayout.setHorizontalGroup(
            assignedpermissionpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 318, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, assignedpermissionpanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(removepermissionbutton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        assignedpermissionpanelLayout.setVerticalGroup(
            assignedpermissionpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(assignedpermissionpanelLayout.createSequentialGroup()
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(removepermissionbutton)
                .addContainerGap())
        );

        jPanel3.setOpaque(false);

        jPanel4.setBackground(new java.awt.Color(153, 204, 255));
        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));

        jLabel2.setFont(new java.awt.Font("SansSerif", 1, 13)); // NOI18N
        jLabel2.setText("All Permissions");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(jLabel2)
                .addGap(0, 0, 0))
        );

        permissionlist.setFont(new java.awt.Font("SansSerif", 0, 13)); // NOI18N
        permissionlist.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane3.setViewportView(permissionlist);

        addpermissionbutton.setText("Add Permissions");
        addpermissionbutton.setOpaque(false);
        addpermissionbutton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addpermissionbuttonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(addpermissionbutton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(addpermissionbutton)
                .addContainerGap())
        );

        addrolebutton.setText("Add Role");
        addrolebutton.setOpaque(false);
        addrolebutton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addrolebuttonActionPerformed(evt);
            }
        });

        jPanel5.setOpaque(false);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 161, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 269, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(addnewroletextbox, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(addrolebutton))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(rolenamesearchfield, javax.swing.GroupLayout.PREFERRED_SIZE, 194, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(searchbutton)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(assignedpermissionpanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(rolenamesearchfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(searchbutton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(assignedpermissionpanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 327, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(58, 58, 58)
                                .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(addnewroletextbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(addrolebutton))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void searchbuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchbuttonActionPerformed
        String rolename = rolenamesearchfield.getText();
        if(rolename.trim().length()>0){
            try {
                List<TRole> rolelist = userSetupController.getRolesByName(rolename);
                roletable.setModel(new javax.swing.table.DefaultTableModel(new Object [][] {},new String [] {"Role Id", "Role Name"}));
                changecolumnlength();
                model = (DefaultTableModel)roletable.getModel();
                for(TRole role:rolelist){
                    addObject = new Vector<Object>();
                    addObject.add(role.getId());
                    addObject.add(role.getRoleName());
                    model.addRow(addObject);
                }
                
            } catch (ProcessingException ex) {
                Logger.getLogger(UserSecurityPanel.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_searchbuttonActionPerformed
    private Long roleid=0L;
    private void roletableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_roletableMouseClicked
        int row = roletable.getSelectedRow();
        if(row!=-1){
            roleid = Long.valueOf(roletable.getValueAt(row,0).toString());
            assignedpermissionmodel = new DefaultListModel();
            try {
                TRole role = userSetupController.getRoleByRoleId(roleid);
                List<TPermission> permissions = userSetupController.getPermissionListByRole(role);
                for(TPermission permission:permissions){
                    assignedpermissionmodel.addElement(permission);
                }
                assignedpermissionlist.setModel(assignedpermissionmodel);
                permissionList = userSetupController.getAllPermissions();
                permissionmodel = new DefaultListModel();
                
                for(int i=0;i<assignedpermissionmodel.getSize();i++){
                    if(permissionList.contains(assignedpermissionmodel.get(i))){
                        TPermission p = (TPermission)assignedpermissionmodel.get(i);
                        permissionList.remove(p);
                    }
                }
                for(TPermission permission:permissionList){
                    permissionmodel.addElement(permission);
                }
                permissionlist.setModel(permissionmodel);
               
            } catch (ProcessingException ex) {
                Logger.getLogger(UserSecurityPanel.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_roletableMouseClicked

    private void rolenamesearchfieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_rolenamesearchfieldKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            searchbutton.doClick();
        }
    }//GEN-LAST:event_rolenamesearchfieldKeyPressed

    private void addrolebuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addrolebuttonActionPerformed
        if(validRole()){
            newrole.setRoleName(addnewroletextbox.getText().toUpperCase());
            try {
                userSetupController.addRole(newrole);
                addnewroletextbox.setText(null);
                JOptionPane.showMessageDialog(null, "Role Added");
                updateRoleTable();
            } catch (ProcessingException ex) {
                Logger.getLogger(UserSecurityPanel.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_addrolebuttonActionPerformed

    private void addpermissionbuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addpermissionbuttonActionPerformed
        try { 
            int row = roletable.getSelectedRow();
            if(row!=-1){
            roleid = Long.valueOf(roletable.getValueAt(row,0).toString());
            }
            TRole role = userSetupController.getRoleByRoleId(roleid);
            if(role!=null && row !=-1){
                if(!permissionlist.isSelectionEmpty()){
                    TPermission selectedpermission = (TPermission)permissionlist.getSelectedValue();
                    if(assignedpermissionmodel.contains(selectedpermission)){
                        JOptionPane.showMessageDialog(null, "Permission Already Exist");
                    }else{
                            newrolepermission.setRoleId(role);
                            newrolepermission.setPermissionId(selectedpermission);
                            assignedpermissionmodel.addElement(selectedpermission);
                            permissionmodel.removeElement(selectedpermission);
                            userSetupController.saveRoleWithPermission(newrolepermission);
                    }
            }else{
                    JOptionPane.showMessageDialog(null, "Select permission from list to be added");
                }
            }else{
                JOptionPane.showMessageDialog(null, "Select role first");
            }
        } catch (ProcessingException ex) {
            Logger.getLogger(UserSecurityPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_addpermissionbuttonActionPerformed

    private void removepermissionbuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removepermissionbuttonActionPerformed
       try { 
            int row = roletable.getSelectedRow();
            if(row!=-1){
            roleid = Long.valueOf(roletable.getValueAt(row,0).toString());
            }
            TRole role = userSetupController.getRoleByRoleId(roleid);
            if(role!=null && row !=-1){
                if(!assignedpermissionlist.isSelectionEmpty()){
                    TPermission selectedpermission = (TPermission)assignedpermissionlist.getSelectedValue();
                    TRolePermission getrolepermission = userSetupController.getRolePermission(role,selectedpermission);
                            assignedpermissionmodel.removeElement(selectedpermission);
                            permissionmodel.addElement(selectedpermission);
                            userSetupController.deletePermissionFromRole(getrolepermission);
                }else{
                    JOptionPane.showMessageDialog(null, "Select permission from list to be removed");
                }
            }else{
                JOptionPane.showMessageDialog(null, "Select role first");
            }
        }catch(IllegalArgumentException e){
                JOptionPane.showMessageDialog(null, MessageProperties.getMessage("error.aleardydeleted",new Object[]{"Permission"}));
        }catch (ProcessingException ex) {
            Logger.getLogger(UserSecurityPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_removepermissionbuttonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField addnewroletextbox;
    private javax.swing.JButton addpermissionbutton;
    private javax.swing.JButton addrolebutton;
    private javax.swing.JList assignedpermissionlist;
    private javax.swing.JPanel assignedpermissionpanel;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JList permissionlist;
    private javax.swing.JTable permissiontable;
    private javax.swing.JButton removepermissionbutton;
    private javax.swing.JTextField rolenamesearchfield;
    private javax.swing.JTable roletable;
    private javax.swing.JButton searchbutton;
    // End of variables declaration//GEN-END:variables
    UserSetupController userSetupController;
    private Vector<Object> addObject;
    DefaultTableModel model;
    private List<TPermission> permissionList;
    private List<TRole> roleList;
    DefaultListModel permissionmodel;
    DefaultListModel assignedpermissionmodel;
    TRole newrole;
    TRolePermission newrolepermission;
        
    private void populate() {
        newrole = new TRole();
        newrolepermission = new TRolePermission();
        userSetupController = (UserSetupController)HealthcareLogin.context.getBean("userSetupController");
        permissionmodel = new DefaultListModel();
        
        try {
            //permissionList = userSetupController.getAllPermissions();
            roleList = userSetupController.getRoleList();
        } catch (ProcessingException ex) {
            Logger.getLogger(UserSecurityPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
        /*for(TPermission permission:permissionList){
            permissionmodel.addElement(permission);
        }*/
    }

    private void changecolumnlength() {
        roletable.getColumnModel().getColumn(0).setMinWidth(0);
        roletable.getColumnModel().getColumn(0).setPreferredWidth(0);
        roletable.getColumnModel().getColumn(0).setMaxWidth(0);
        roletable.getTableHeader().setFont(new Font("SansSerif", Font.BOLD, 12));
        roletable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    }

    private void updateRoleTable() {
        try {
            roleList = userSetupController.getRoleList();
            roletable.setModel(new javax.swing.table.DefaultTableModel(new Object [][] {},new String [] {"Role Id", "Role Name"}));
            changecolumnlength();
            model = (DefaultTableModel)roletable.getModel();
            for(TRole role:roleList){
               addObject = new Vector<Object>();
               addObject.add(role.getId());
               addObject.add(role.getRoleName());
               model.addRow(addObject);
            }
        } catch (ProcessingException ex) {
            Logger.getLogger(UserSecurityPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
         
    }

    private boolean validRole() {
        boolean valid = true;
         if(addnewroletextbox.getText()==null || addnewroletextbox.getText().trim().length()==0){
            JOptionPane.showMessageDialog(null, MessageProperties.getMessage("role.mantatory"));
            valid = false;
        }
        return valid;
    }
}

Commits for Aurocare_27_07_2018/AuroCareEMR/src/main/java/com/bestray/healthcareemr/Views/UserSecurityPanel.java

Diff revisions: vs.
Revision Author Commited Message
1 girijabapi picture girijabapi Fri 27 Jul, 2018 07:21:55 +0000