package rms.view.item;

import java.awt.Desktop;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import rms.model.item.FileItem;

/**
 *
 * @author Timothy
 */
public class FileItemPanel extends BaseItemPanel {

    private static final Logger LOG = Logger.getLogger(FileItemPanel.class.getName());

    /**
     * Creates new form FileItemPanel
     *
     * @param item
     * @param startCollapsed
     */
    public FileItemPanel(FileItem item, boolean startCollapsed) {
        super(item, startCollapsed);
        initComponents();
        reflectItemChangesInUI_Additional();
    }

    private FileItem getFileItem() {
        return (FileItem) displayedItem;
    }

    @Override
    protected void reflectItemChangesInUI_Additional() {
        jButtonFileLink.setText(getFileItem().getFile().getName());
    }

    @Override
    protected void deleteButtonAction_WithApproval() {
        getFileItem().getFile().delete();
    }

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

        jButtonFileLink = new javax.swing.JButton();

        jButtonFileLink.setForeground(new java.awt.Color(0, 0, 255));
        jButtonFileLink.setText("Open File");
        jButtonFileLink.setBorderPainted(false);
        jButtonFileLink.setContentAreaFilled(false);
        jButtonFileLink.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButtonFileLink.setFocusPainted(false);
        jButtonFileLink.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jButtonFileLink.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonFileLinkActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getInnerContentPanel());
        getInnerContentPanel().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jButtonFileLink)
                .addGap(0, 318, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jButtonFileLink)
                .addGap(0, 13, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonFileLinkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonFileLinkActionPerformed
        try {
            Desktop.getDesktop().open(getFileItem().getFile());
        } catch (IllegalArgumentException | IOException ex) {
            LOG.log(Level.SEVERE, "Unable to open file.", ex);
        }
    }//GEN-LAST:event_jButtonFileLinkActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonFileLink;
    // End of variables declaration//GEN-END:variables
}

@@ -2951,14 +2951,141 @@
     
-try %7B%0A
+java.awt.EventQueue.invokeLater(new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                try %7B%0A        
     
@@ -3152,16 +3152,24 @@
         
+      
+  
 %7D catch 
@@ -3226,16 +3226,24 @@
         
+        
 LOG.log(
@@ -3289,25 +3289,59 @@
 x);%0A        
+ 
-%7D
+       %7D%0A            %7D%0A        %7D);
 %0A    %7D//GEN-

Move Desktop.open call off Event Dispatch Thread