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
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bestray.healthcareemr.Views;

import com.bestray.healthcarecommonutil.exception.HealthCareException;
import com.bestray.healthcarecommonutil.exception.ProcessingException;
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.util.ArrayList;
import java.util.List;
import java.util.Vector;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException;

// TODO: Auto-generated Javadoc
/**
 * The Class RolePanel.
 *
 * @author user3
 */
public class RolePanel extends javax.swing.JPanel {

    /**
     * Creates new form RolePanel.
     */
    public RolePanel() {
        populate();
        initComponents();
    }

    /**
     * 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() {

        permission_combobox = new javax.swing.JComboBox();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        roleid_textfield = new javax.swing.JTextField();
        roleid_label = new javax.swing.JLabel();
        rolename_label = new javax.swing.JLabel();
        rolename_textfield = new javax.swing.JTextField();
        permission_label = new javax.swing.JLabel();
        role_save_button = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        sourcelist = new javax.swing.JList();
        add_button = new javax.swing.JButton();
        remove_button = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        destinationlist = new javax.swing.JList();

        permission_combobox.setModel(new javax.swing.DefaultComboBoxModel(permissionList));

        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 Role");

        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))
        );

        roleid_label.setFont(new java.awt.Font("SansSerif", 0, 13)); // NOI18N
        roleid_label.setText("Role Id :");

        rolename_label.setFont(new java.awt.Font("SansSerif", 0, 13)); // NOI18N
        rolename_label.setText("Role Name :");

        permission_label.setFont(new java.awt.Font("SansSerif", 0, 13)); // NOI18N
        permission_label.setText("Permission :");

        role_save_button.setFont(new java.awt.Font("SansSerif", 1, 12)); // NOI18N
        role_save_button.setText("Save");
        role_save_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                role_save_buttonActionPerformed(evt);
            }
        });

        sourcelist.setModel(sourcemodel);
        jScrollPane1.setViewportView(sourcelist);

        add_button.setFont(new java.awt.Font("SansSerif", 0, 11)); // NOI18N
        add_button.setText("ADD >>");
        add_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                add_buttonActionPerformed(evt);
            }
        });

        remove_button.setFont(new java.awt.Font("SansSerif", 0, 11)); // NOI18N
        remove_button.setText("<< REMOVE");
        remove_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                remove_buttonActionPerformed(evt);
            }
        });

        destinationlist.setModel(destmodel);
        jScrollPane2.setViewportView(destinationlist);

        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)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(roleid_label)
                            .addComponent(rolename_label)
                            .addComponent(permission_label))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(rolename_textfield, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(roleid_textfield, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 152, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(remove_button, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(add_button, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 813, Short.MAX_VALUE)
                        .addComponent(role_save_button)))
                .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.BASELINE)
                    .addComponent(roleid_label)
                    .addComponent(roleid_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rolename_label)
                    .addComponent(rolename_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(permission_label)
                            .addComponent(jScrollPane1)
                            .addComponent(jScrollPane2)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addComponent(add_button)
                        .addGap(18, 18, 18)
                        .addComponent(remove_button)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 107, Short.MAX_VALUE)
                .addComponent(role_save_button)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Role_save_button action performed.
     *
     * @param evt the evt
     */
    private void role_save_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_role_save_buttonActionPerformed
        try{
            role.setRoleName(rolename_textfield.getText().toUpperCase());
            //rolePermission.setPermissionId((TPermission)permission_combobox.getSelectedItem());
            userSetupController.saveRoleWithPermission(role,destlist);
            JOptionPane.showMessageDialog(null, MessageProperties.getMessage("success.save",new Object[]{"Role"}));
        }catch(HibernateOptimisticLockingFailureException e){
                JOptionPane.showMessageDialog(null, MessageProperties.getMessage("error.update",new Object[]{"Role"}));
        }catch(IllegalArgumentException e){
                JOptionPane.showMessageDialog(null, MessageProperties.getMessage("error.aleardydeleted",new Object[]{"Role"}));
        }catch(ProcessingException e){
                JOptionPane.showMessageDialog(null, MessageProperties.getMessage("error.save",new Object[]{"Role"}));
                throw new HealthCareException(MessageProperties.getMessage("error.dao"));
        }catch(Exception e){
                JOptionPane.showMessageDialog(null, MessageProperties.getMessage("error.save",new Object[]{"Role"}));
        }
    }//GEN-LAST:event_role_save_buttonActionPerformed

    /**
     * Add_button action performed.
     *
     * @param evt the evt
     */
    private void add_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_add_buttonActionPerformed
        if(!sourcelist.isSelectionEmpty()){
            List<TPermission> selected = sourcelist.getSelectedValuesList();
            for(TPermission  p:selected){
                destlist.add(p);
                destmodel.addElement(p);
                sourcemodel.removeElement(p);
            }
            sourcelist.getSelectionModel().clearSelection();
        }
    }//GEN-LAST:event_add_buttonActionPerformed

    /**
     * Remove_button action performed.
     *
     * @param evt the evt
     */
    private void remove_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_remove_buttonActionPerformed
        if(!destinationlist.isSelectionEmpty()){
            List<TPermission> selected= destinationlist.getSelectedValuesList();
            for(TPermission p:selected){
                destlist.remove(p);
                sourcemodel.addElement(p);
                destmodel.removeElement(p);
            }
            destinationlist.getSelectionModel().clearSelection();
        }
    }//GEN-LAST:event_remove_buttonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    /** The add_button. */
    private javax.swing.JButton add_button;
    
    /** The destinationlist. */
    private javax.swing.JList destinationlist;
    
    /** The j label1. */
    private javax.swing.JLabel jLabel1;
    
    /** The j panel1. */
    private javax.swing.JPanel jPanel1;
    
    /** The j scroll pane1. */
    private javax.swing.JScrollPane jScrollPane1;
    
    /** The j scroll pane2. */
    private javax.swing.JScrollPane jScrollPane2;
    
    /** The permission_combobox. */
    private javax.swing.JComboBox permission_combobox;
    
    /** The permission_label. */
    private javax.swing.JLabel permission_label;
    
    /** The remove_button. */
    private javax.swing.JButton remove_button;
    
    /** The role_save_button. */
    private javax.swing.JButton role_save_button;
    
    /** The roleid_label. */
    private javax.swing.JLabel roleid_label;
    
    /** The roleid_textfield. */
    private javax.swing.JTextField roleid_textfield;
    
    /** The rolename_label. */
    private javax.swing.JLabel rolename_label;
    
    /** The rolename_textfield. */
    private javax.swing.JTextField rolename_textfield;
    
    /** The sourcelist. */
    private javax.swing.JList sourcelist;
    // End of variables declaration//GEN-END:variables
    /** The permission list. */
    private Vector<TPermission> permissionList = new Vector<TPermission>();
    
    /** The role. */
    private TRole role;
    
    /** The role permission. */
    private TRolePermission rolePermission;
    
    /** The permission. */
    private TPermission permission;
    
    /** The user setup controller. */
    private UserSetupController userSetupController;
    
    /** The sourcemodel. */
    final DefaultListModel sourcemodel = new DefaultListModel();
    
    /** The destmodel. */
    final DefaultListModel destmodel = new DefaultListModel();
    
    /** The destlist. */
    List<TPermission> destlist=new ArrayList<TPermission>();
    
    /**
     * Populate.
     */
    private void populate(){
        userSetupController = (UserSetupController)HealthcareLogin.context.getBean("userSetupController");
        role=new TRole();
        rolePermission = new TRolePermission();
        permission = new TPermission();
        //permission.setPermissionName("---None---");
        try{
        permissionList = userSetupController.getPermissionList();
        }catch(ProcessingException e){
            JOptionPane.showMessageDialog(null,MessageProperties.getMessage("error.fetch",new Object[]{"permission"}));
            throw new HealthCareException(MessageProperties.getMessage("error.dao"));
        }catch(Exception e){
            JOptionPane.showMessageDialog(null,MessageProperties.getMessage("error.fetch",new Object[]{"permission"}));
        }
        //permissionList.add(0, permission);
        for(TPermission permission:permissionList){
            sourcemodel.addElement(permission);
        }
        
    }
}

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

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