/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package org.ourgrid.peer.ui.async.gui; import java.io.File; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import org.ourgrid.common.util.IssuedCertificateGenerator; import org.ourgrid.peer.PeerConfiguration; /** * * @author Abmar */ public class IssueCertificateDialog extends javax.swing.JDialog { /** * */ private static final long serialVersionUID = 1L; /** * Creates new form SignCertificateDialog */ public IssueCertificateDialog(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); setTitle("Issue certificate"); } /** * 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. */ // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { workerCerticateTxt = new javax.swing.JTextField(); jLabel1 = new javax.swing.JLabel(); browseSourceBtn = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); outputCertificateTxt = new javax.swing.JTextField(); browseOutputBtn = new javax.swing.JButton(); issueBtn = new javax.swing.JButton(); closeBtn = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); jLabel1.setText("Worker certificate"); browseSourceBtn.setText("Browse"); browseSourceBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { browseSourceBtnActionPerformed(evt); } }); jLabel2.setText("Output certificate"); browseOutputBtn.setText("Browse"); browseOutputBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { browseOutputBtnActionPerformed(evt); } }); issueBtn.setText("Issue"); issueBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { issueBtnActionPerformed(evt); } }); closeBtn.setText("Close"); closeBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { closeBtnActionPerformed(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() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) .addComponent(jLabel2) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addGap(0, 159, Short.MAX_VALUE) .addComponent(issueBtn) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(closeBtn)) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(workerCerticateTxt) .addComponent(outputCertificateTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(browseSourceBtn) .addComponent(browseOutputBtn))))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(8, 8, 8) .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(workerCerticateTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(browseSourceBtn)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(outputCertificateTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(browseOutputBtn)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(closeBtn) .addComponent(issueBtn)) .addContainerGap()) ); pack(); }// </editor-fold> private void browseSourceBtnActionPerformed(java.awt.event.ActionEvent evt) { final JFileChooser fc = new JFileChooser(); fc.setFileFilter(createFileFilter()); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); workerCerticateTxt.setText(file.getAbsolutePath()); } } private FileNameExtensionFilter createFileFilter() { return new FileNameExtensionFilter("Certificate file (*.cer)", "cer"); } private void browseOutputBtnActionPerformed(java.awt.event.ActionEvent evt) { final JFileChooser fc = new JFileChooser(); fc.setFileFilter(createFileFilter()); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { String file = fc.getSelectedFile().getAbsolutePath(); if (!file.endsWith(".cer")) { file += ".cer"; } outputCertificateTxt.setText(file); } } private void issueBtnActionPerformed(java.awt.event.ActionEvent evt) { String certificatePath = workerCerticateTxt.getText(); if (certificatePath == null || certificatePath.isEmpty()) { JOptionPane.showMessageDialog(this, "An input certificate file must be selected.", "Issue certificate", JOptionPane.ERROR_MESSAGE); return; } String outPutCertificatePath = outputCertificateTxt.getText(); if (outPutCertificatePath == null || outPutCertificatePath.isEmpty()) { JOptionPane.showMessageDialog(this, "An output certificate file must be selected.", "Issue certificate", JOptionPane.ERROR_MESSAGE); return; } try { IssuedCertificateGenerator.issueCertificate(certificatePath, PeerConfiguration.PROPERTIES_FILENAME, outPutCertificatePath); JOptionPane.showMessageDialog(this, "Worker certificate was successfully issued.", "Issue certificate", JOptionPane.INFORMATION_MESSAGE); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Worker certificate could not be issued. Error: " + e.getMessage(), "Issue certificate", JOptionPane.ERROR_MESSAGE); } } private void closeBtnActionPerformed(java.awt.event.ActionEvent evt) { this.setVisible(false); } // Variables declaration - do not modify private javax.swing.JButton browseOutputBtn; private javax.swing.JButton browseSourceBtn; private javax.swing.JButton closeBtn; private javax.swing.JButton issueBtn; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JTextField outputCertificateTxt; private javax.swing.JTextField workerCerticateTxt; // End of variables declaration }