/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.bellevue.its.migration.gui.frames.developer;
import edu.bellevue.its.migration.entities.Fileattachment;
import edu.bellevue.its.migration.entities.Role;
import edu.bellevue.its.migration.entities.Securityoverview;
import edu.bellevue.its.migration.global.AppGlobals;
import edu.bellevue.its.migration.global.AppHelper;
import edu.bellevue.its.migration.global.HibernateUtil;
import edu.bellevue.its.migration.gui.MainApp;
import edu.bellevue.its.migration.gui.dialogs.FormattedTextDialog;
import edu.bellevue.its.migration.gui.frames.UpdateableFrame;
import java.util.Set;
import javax.swing.DefaultListModel;
import javax.swing.JInternalFrame;
/**
*
* @author tslater
*/
public class EditSecurityOverviewFrame extends javax.swing.JInternalFrame implements UpdateableFrame {
/**
* Creates new form EditTechnicalOverviewFrame
*/
private Securityoverview security;
private UpdateableFrame owner;
private boolean readOnly;
public EditSecurityOverviewFrame(UpdateableFrame frame, Securityoverview security, boolean readonly) {
initComponents();
readOnly = readonly;
owner = frame;
this.security = security;
AppHelper.placeRightOfParent(this,((JInternalFrame)owner));
this.updateView();
}
/**
* 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() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
btnEditNeeds = new javax.swing.JButton();
btnViewNeeds = new javax.swing.JButton();
btnEditUsers = new javax.swing.JButton();
btnViewUsers = new javax.swing.JButton();
btnDone = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
lstFiles = new javax.swing.JList();
btnAddFile = new javax.swing.JButton();
btnRemoveFile = new javax.swing.JButton();
chkApproved = new javax.swing.JCheckBox();
btnMarkApproved = new javax.swing.JButton();
setClosable(true);
setIconifiable(true);
setResizable(true);
jLabel1.setText("Security Needs: ");
jLabel2.setText("Navigation / Users: ");
btnEditNeeds.setText("Edit...");
btnEditNeeds.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnEditNeedsActionPerformed(evt);
}
});
btnViewNeeds.setText("View...");
btnViewNeeds.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnViewNeedsActionPerformed(evt);
}
});
btnEditUsers.setText("Edit...");
btnEditUsers.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnEditUsersActionPerformed(evt);
}
});
btnViewUsers.setText("View...");
btnViewUsers.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnViewUsersActionPerformed(evt);
}
});
btnDone.setText("Done");
btnDone.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnDoneActionPerformed(evt);
}
});
jLabel4.setText("File Attachments");
lstFiles.setModel(new DefaultListModel());
jScrollPane1.setViewportView(lstFiles);
btnAddFile.setText("+");
btnAddFile.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAddFileActionPerformed(evt);
}
});
btnRemoveFile.setText("-");
btnRemoveFile.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnRemoveFileActionPerformed(evt);
}
});
chkApproved.setText("Approved");
chkApproved.setEnabled(false);
btnMarkApproved.setText("Mark Approved");
btnMarkApproved.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnMarkApprovedActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(chkApproved, javax.swing.GroupLayout.Alignment.TRAILING))
.addComponent(jLabel4))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(31, 31, 31)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(btnAddFile)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnRemoveFile))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(btnEditNeeds)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnViewNeeds))
.addGroup(layout.createSequentialGroup()
.addComponent(btnEditUsers)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnViewUsers))))
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnMarkApproved, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(layout.createSequentialGroup()
.addGap(110, 110, 110)
.addComponent(btnDone))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(btnEditNeeds)
.addComponent(btnViewNeeds))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(btnEditUsers)
.addComponent(btnViewUsers))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(chkApproved)
.addComponent(btnMarkApproved))
.addGap(24, 24, 24)
.addComponent(jLabel4))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnRemoveFile)
.addComponent(btnAddFile)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnDone)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void btnEditNeedsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditNeedsActionPerformed
// TODO add your handling code here:
FormattedTextDialog ftd = new FormattedTextDialog(null, true);
if (security.getSecurityNeeds() != null)
{
ftd.setContent(AppHelper.decodeHTML(security.getSecurityNeeds()));
}
ftd.setVisible(true);
String s = ftd.getResult();
try
{
security.setSecurityNeeds(AppHelper.encodeHTML(s));
} catch(Exception e){}
}//GEN-LAST:event_btnEditNeedsActionPerformed
private void btnDoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDoneActionPerformed
// TODO add your handling code here:
this.setVisible(false);
owner.updateView();
}//GEN-LAST:event_btnDoneActionPerformed
private void btnViewNeedsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnViewNeedsActionPerformed
// TODO add your handling code here:
FormattedTextDialog ftd = new FormattedTextDialog(null, true);
if (security.getSecurityNeeds() != null)
{
ftd.setContent(AppHelper.decodeHTML(security.getSecurityNeeds()));
}
ftd.setReadOnly(true);
ftd.setVisible(true);
}//GEN-LAST:event_btnViewNeedsActionPerformed
private void btnEditUsersActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditUsersActionPerformed
// TODO add your handling code here:
FormattedTextDialog ftd = new FormattedTextDialog(null, true);
if (security.getNavUsers() != null)
{
ftd.setContent(AppHelper.decodeHTML(security.getNavUsers()));
}
ftd.setVisible(true);
String s = ftd.getResult();
try
{
security.setNavUsers(AppHelper.encodeHTML(s));
} catch(Exception e){}
}//GEN-LAST:event_btnEditUsersActionPerformed
private void btnViewUsersActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnViewUsersActionPerformed
// TODO add your handling code here:
FormattedTextDialog ftd = new FormattedTextDialog(null, true);
if (security.getNavUsers() != null)
{
ftd.setContent(AppHelper.decodeHTML(security.getNavUsers()));
}
ftd.setReadOnly(true);
ftd.setVisible(true);
}//GEN-LAST:event_btnViewUsersActionPerformed
private void btnAddFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddFileActionPerformed
// TODO add your handling code here:
Fileattachment file = new Fileattachment();
EditFileAttachmentFrame efaf = new EditFileAttachmentFrame(file, this);
security.getFileattachments().add(file);
MainApp.getDesktop().add(efaf);
efaf.setVisible(true);
}//GEN-LAST:event_btnAddFileActionPerformed
private void btnRemoveFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveFileActionPerformed
// TODO add your handling code here:
Fileattachment value = (Fileattachment) lstFiles.getSelectedValue();
if (value != null)
{
((DefaultListModel)lstFiles.getModel()).removeElement(value);
System.out.println("File count: " + security.getFileattachments().size());
security.getFileattachments().remove(value);
System.out.println("File count: " + security.getFileattachments().size());
}
}//GEN-LAST:event_btnRemoveFileActionPerformed
private void btnMarkApprovedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMarkApprovedActionPerformed
// TODO add your handling code here:
security.setSecurityApprover(AppGlobals.getInstance().loggedInUser.getIdUser());
HibernateUtil.saveOrUpdateItem(security);
btnMarkApproved.setEnabled(false);
}//GEN-LAST:event_btnMarkApprovedActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnAddFile;
private javax.swing.JButton btnDone;
private javax.swing.JButton btnEditNeeds;
private javax.swing.JButton btnEditUsers;
private javax.swing.JButton btnMarkApproved;
private javax.swing.JButton btnRemoveFile;
private javax.swing.JButton btnViewNeeds;
private javax.swing.JButton btnViewUsers;
private javax.swing.JCheckBox chkApproved;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel4;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JList lstFiles;
// End of variables declaration//GEN-END:variables
@Override
public void updateView() {
Role securityRole = AppHelper.getRoleByName("Security");
boolean isSecurityApprover = AppGlobals.getInstance().loggedInUser.getRoles().contains(securityRole);
btnMarkApproved.setEnabled(isSecurityApprover);
String techId = "[ NEW ]";
if (this.security.getIdSecurityOverview() != null )
{
techId = "# " + this.security.getIdSecurityOverview().toString();
}
this.title = "Edit Security Overview: " + techId;
if (this.security.getFileattachments() != null)
{
Set<Fileattachment> files = this.security.getFileattachments();
((DefaultListModel)lstFiles.getModel()).clear();
for (Fileattachment fa : files.toArray(new Fileattachment[0]))
{
((DefaultListModel)lstFiles.getModel()).addElement(fa);
}
}
chkApproved.setSelected(security.getSecurityApprover() == 0 ? false : true);
if (AppGlobals.getInstance().loggedInUser.getRoles().contains(AppHelper.getRoleByName("Admin")))
{
btnMarkApproved.setEnabled(!chkApproved.isSelected());
}
if (readOnly)
{
btnAddFile.setEnabled(false);
btnRemoveFile.setEnabled(false);
btnEditNeeds.setEnabled(false);
btnEditUsers.setEnabled(false);
}
}
}