/*
* 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.Techoverview;
import edu.bellevue.its.migration.entities.User;
import edu.bellevue.its.migration.global.AppGlobals;
import edu.bellevue.its.migration.global.AppHelper;
import edu.bellevue.its.migration.gui.MainApp;
import edu.bellevue.its.migration.gui.dialogs.FormattedTextDialog;
import edu.bellevue.its.migration.gui.frames.UpdateableFrame;
import edu.bellevue.its.migration.gui.frames.UpdateableFrame;
import java.awt.Point;
import java.util.Set;
import javax.swing.DefaultListModel;
import javax.swing.JInternalFrame;
/**
*
* @author tslater
*/
public class EditTechnicalOverviewFrame extends javax.swing.JInternalFrame implements UpdateableFrame {
/**
* Creates new form EditTechnicalOverviewFrame
*/
private Techoverview tech;
private UpdateableFrame owner;
public EditTechnicalOverviewFrame(UpdateableFrame frame, Techoverview tech) {
initComponents();
owner = frame;
AppHelper.placeRightOfParent(this,((JInternalFrame)owner));
this.tech = tech;
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();
jLabel3 = new javax.swing.JLabel();
btnEditConfig = new javax.swing.JButton();
btnViewConfigs = new javax.swing.JButton();
btnEditCode = new javax.swing.JButton();
btnViewCode = new javax.swing.JButton();
btnEditDepends = new javax.swing.JButton();
btnViewDepends = 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();
jLabel6 = new javax.swing.JLabel();
chkTechApproved = new javax.swing.JCheckBox();
txtTechApprover = new javax.swing.JTextField();
btnMarkApproved = new javax.swing.JButton();
setIconifiable(true);
setResizable(true);
jLabel1.setText("Configurations: ");
jLabel2.setText("Code Summary: ");
jLabel3.setText("Dependencies: ");
btnEditConfig.setText("Edit...");
btnEditConfig.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnEditConfigActionPerformed(evt);
}
});
btnViewConfigs.setText("View...");
btnViewConfigs.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnViewConfigsActionPerformed(evt);
}
});
btnEditCode.setText("Edit...");
btnEditCode.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnEditCodeActionPerformed(evt);
}
});
btnViewCode.setText("View...");
btnViewCode.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnViewCodeActionPerformed(evt);
}
});
btnEditDepends.setText("Edit...");
btnEditDepends.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnEditDependsActionPerformed(evt);
}
});
btnViewDepends.setText("View...");
btnViewDepends.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnViewDependsActionPerformed(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);
}
});
jLabel6.setText("Tech Approver:");
chkTechApproved.setText("Tech Approved");
chkTechApproved.setEnabled(false);
txtTechApprover.setEditable(false);
btnMarkApproved.setText("Mark Approved");
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(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel3)
.addGap(37, 37, 37))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel4))
.addGap(31, 31, 31)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(btnEditConfig)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnViewConfigs))
.addGroup(layout.createSequentialGroup()
.addComponent(btnEditCode)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnViewCode))
.addGroup(layout.createSequentialGroup()
.addComponent(btnEditDepends)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnViewDepends)))
.addGroup(layout.createSequentialGroup()
.addComponent(btnAddFile)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnRemoveFile))))
.addGroup(layout.createSequentialGroup()
.addGap(110, 110, 110)
.addComponent(btnDone))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel6)
.addComponent(chkTechApproved, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(1, 1, 1)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(btnMarkApproved, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(txtTechApprover))))
.addContainerGap(21, 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(btnEditConfig)
.addComponent(btnViewConfigs))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(btnEditCode)
.addComponent(btnViewCode))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(btnEditDepends)
.addComponent(btnViewDepends))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnAddFile)
.addComponent(btnRemoveFile)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(chkTechApproved)
.addComponent(btnMarkApproved, javax.swing.GroupLayout.Alignment.TRAILING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(txtTechApprover, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnDone)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void btnEditConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditConfigActionPerformed
// TODO add your handling code here:
FormattedTextDialog ftd = new FormattedTextDialog(null, true);
if (tech.getConfigurations() != null)
{
ftd.setContent(AppHelper.decodeHTML(tech.getConfigurations()));
}
ftd.setVisible(true);
String s = ftd.getResult();
try
{
tech.setConfigurations(AppHelper.encodeHTML(s));
} catch(Exception e){}
}//GEN-LAST:event_btnEditConfigActionPerformed
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 btnViewConfigsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnViewConfigsActionPerformed
// TODO add your handling code here:
FormattedTextDialog ftd = new FormattedTextDialog(null, true);
if (tech.getConfigurations() != null)
{
ftd.setContent(AppHelper.decodeHTML(tech.getConfigurations()));
}
ftd.setReadOnly(true);
ftd.setVisible(true);
}//GEN-LAST:event_btnViewConfigsActionPerformed
private void btnEditCodeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditCodeActionPerformed
// TODO add your handling code here:
FormattedTextDialog ftd = new FormattedTextDialog(null, true);
if (tech.getCodeSummary() != null)
{
ftd.setContent(AppHelper.decodeHTML(tech.getCodeSummary()));
}
ftd.setVisible(true);
String s = ftd.getResult();
try
{
tech.setCodeSummary(AppHelper.encodeHTML(s));
} catch(Exception e){}
}//GEN-LAST:event_btnEditCodeActionPerformed
private void btnEditDependsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditDependsActionPerformed
// TODO add your handling code here:
FormattedTextDialog ftd = new FormattedTextDialog(null, true);
if (tech.getDependencies() != null)
{
ftd.setContent(AppHelper.decodeHTML(tech.getDependencies()));
}
ftd.setVisible(true);
String s = ftd.getResult();
try
{
tech.setDependencies(AppHelper.encodeHTML(s));
} catch(Exception e){}
}//GEN-LAST:event_btnEditDependsActionPerformed
private void btnViewCodeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnViewCodeActionPerformed
// TODO add your handling code here:
FormattedTextDialog ftd = new FormattedTextDialog(null, true);
if (tech.getCodeSummary() != null)
{
ftd.setContent(AppHelper.decodeHTML(tech.getCodeSummary()));
}
ftd.setReadOnly(true);
ftd.setVisible(true);
}//GEN-LAST:event_btnViewCodeActionPerformed
private void btnViewDependsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnViewDependsActionPerformed
// TODO add your handling code here:
FormattedTextDialog ftd = new FormattedTextDialog(null, true);
if (tech.getDependencies() != null)
{
ftd.setContent(AppHelper.decodeHTML(tech.getDependencies()));
}
ftd.setReadOnly(true);
ftd.setVisible(true);
}//GEN-LAST:event_btnViewDependsActionPerformed
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);
tech.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: " + tech.getFileattachments().size());
tech.getFileattachments().remove(value);
System.out.println("File count: " + tech.getFileattachments().size());
}
}//GEN-LAST:event_btnRemoveFileActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnAddFile;
private javax.swing.JButton btnDone;
private javax.swing.JButton btnEditCode;
private javax.swing.JButton btnEditConfig;
private javax.swing.JButton btnEditDepends;
private javax.swing.JButton btnMarkApproved;
private javax.swing.JButton btnRemoveFile;
private javax.swing.JButton btnViewCode;
private javax.swing.JButton btnViewConfigs;
private javax.swing.JButton btnViewDepends;
private javax.swing.JCheckBox chkTechApproved;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel6;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JList lstFiles;
private javax.swing.JTextField txtTechApprover;
// End of variables declaration//GEN-END:variables
@Override
public final void updateView() {
Role techReviewRole = AppHelper.getRoleByName("TechReview");
boolean isTechReviewer = AppGlobals.getInstance().loggedInUser.getRoles().contains(techReviewRole);
btnMarkApproved.setEnabled(isTechReviewer);
String techId = "[ NEW ]";
if (this.tech.getIdTechOverview() != null )
{
techId = "# " + this.tech.getIdTechOverview().toString();
}
this.title = "Edit Tech Overview: " + techId;
if (this.tech.getTechApproved() != null)
{
chkTechApproved.setSelected(tech.getTechApproved().equals("Y"));
if (chkTechApproved.isSelected())
{
int approverId = tech.getTechApprover();
User approver = AppHelper.getUserById(approverId);
txtTechApprover.setText(AppHelper.getUserDisplayName(approver));
}
}
if (this.tech.getFileattachments() != null)
{
Set<Fileattachment> files = this.tech.getFileattachments();
((DefaultListModel)lstFiles.getModel()).clear();
for (Fileattachment fa : files.toArray(new Fileattachment[0]))
{
((DefaultListModel)lstFiles.getModel()).addElement(fa);
}
}
}
}