/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package com.ptc.tifworkbench.ui; import com.ptc.tifworkbench.model.TifEnvironment; import java.io.File; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JOptionPane; import org.apache.commons.configuration.ConfigurationException; /** * * @author pbowden */ public class EnvironmentFrame extends javax.swing.JInternalFrame { private File buildProps = null; private TifEnvironment env = null; /** * Creates new form EnvironmentFrame */ public EnvironmentFrame(File buildProps) { initComponents(); this.buildProps = buildProps; this.setTitle("Environment: " + buildProps.getAbsolutePath()); try { env = new TifEnvironment(buildProps); this.nameLabel.setText(env.getName()); this.prefixLabel.setText(env.getPrefix()); this.dirLabel.setText(env.getEnvDir().getAbsolutePath()); } catch (ConfigurationException ex) { JOptionPane.showMessageDialog(null, "Could not read environment" + env.getPropertiesFile().getAbsolutePath() + "\n" + ex.getMessage(), "Environment error", JOptionPane.ERROR_MESSAGE); this.nameLabel.setText("Error reading environment."); this.dirLabel.setText(buildProps.getParentFile().getAbsolutePath()); } } /** * 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() { detailsPanel = new javax.swing.JPanel(); editBtn = new javax.swing.JButton(); nameLabel = new javax.swing.JLabel(); prefixLabel = new javax.swing.JLabel(); dirLabel = new javax.swing.JLabel(); targetPanel = new javax.swing.JPanel(); targetCombo = new javax.swing.JComboBox(); runBtn = new javax.swing.JButton(); setClosable(true); setIconifiable(true); setTitle("Environment"); setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/com/ptc/tifworkbench/ui/environment.png"))); // NOI18N detailsPanel.setName("Environment"); // NOI18N editBtn.setText("Edit..."); editBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { editBtnActionPerformed(evt); } }); nameLabel.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N nameLabel.setText("Name: TIF environment"); prefixLabel.setText("Prefix: TIF_"); dirLabel.setText("Path"); javax.swing.GroupLayout detailsPanelLayout = new javax.swing.GroupLayout(detailsPanel); detailsPanel.setLayout(detailsPanelLayout); detailsPanelLayout.setHorizontalGroup( detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(detailsPanelLayout.createSequentialGroup() .addContainerGap() .addGroup(detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(dirLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(detailsPanelLayout.createSequentialGroup() .addComponent(nameLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(editBtn)) .addGroup(detailsPanelLayout.createSequentialGroup() .addComponent(prefixLabel) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) ); detailsPanelLayout.setVerticalGroup( detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(detailsPanelLayout.createSequentialGroup() .addContainerGap() .addGroup(detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(nameLabel) .addComponent(editBtn)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(prefixLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(dirLabel) .addContainerGap(19, Short.MAX_VALUE)) ); targetPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Run")); targetCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "scripts", "deploy", "reset", "get-templates", "put-templates", "docs-html", "tif-manifest" })); runBtn.setText("Run"); runBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { runBtnActionPerformed(evt); } }); javax.swing.GroupLayout targetPanelLayout = new javax.swing.GroupLayout(targetPanel); targetPanel.setLayout(targetPanelLayout); targetPanelLayout.setHorizontalGroup( targetPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(targetPanelLayout.createSequentialGroup() .addContainerGap() .addComponent(targetCombo, 0, 303, Short.MAX_VALUE) .addGap(18, 18, 18) .addComponent(runBtn)) ); targetPanelLayout.setVerticalGroup( targetPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(targetPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(targetCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(runBtn)) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(targetPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(detailsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(detailsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(targetPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(15, Short.MAX_VALUE)) ); pack(); }// </editor-fold>//GEN-END:initComponents private void editBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editBtnActionPerformed EnvironmentDialog dlg = new EnvironmentDialog(null, true, true); dlg.setEnvironment(env); boolean result = dlg.showDialog(); if(result) { try { env.writeEnvironment(); this.nameLabel.setText(env.getName()); this.prefixLabel.setText(env.getPrefix()); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Could not save environment" + env.getPropertiesFile().getAbsolutePath() + "\n" + ex.getMessage(), "Environment error", JOptionPane.ERROR_MESSAGE); } } }//GEN-LAST:event_editBtnActionPerformed private void runBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_runBtnActionPerformed try { File cwd = env.getEnvDir(); String targetName = targetCombo.getSelectedItem().toString(); Runtime.getRuntime().exec("cmd /c start ant.bat " + targetName, null, cwd); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Error launching external command window" + ex.getMessage(), "Ant error", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_runBtnActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel detailsPanel; private javax.swing.JLabel dirLabel; private javax.swing.JButton editBtn; private javax.swing.JLabel nameLabel; private javax.swing.JLabel prefixLabel; private javax.swing.JButton runBtn; private javax.swing.JComboBox targetCombo; private javax.swing.JPanel targetPanel; // End of variables declaration//GEN-END:variables }