Closedown

This commit is contained in:
boccioli_m
2015-08-27 15:31:57 +02:00
parent 400c94aeda
commit e37ebd9000
8 changed files with 731 additions and 392 deletions

View File

@@ -2,10 +2,21 @@
* Copyright (c) 2015 Paul Scherrer Institute. All rights reserved.
*/
import ch.psi.utils.swing.SwingUtils;
import java.awt.Desktop;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
@@ -39,6 +50,9 @@ public class TestingListDetails extends javax.swing.JPanel {
initComponents();
fillComponents(hDetails);
}
public static String TESTS_CONFIG_FILENAME = ".config";
public static Path TESTS_TESTS_DEFAULT_DIR = Paths.get(".", "home", "script", "tests", "tests");
/**
* This method is called from within the constructor to initialize the form.
@@ -61,9 +75,6 @@ public class TestingListDetails extends javax.swing.JPanel {
jScrollPane1 = new javax.swing.JScrollPane();
jTableParams = new javax.swing.JTable();
jLabel7 = new javax.swing.JLabel();
cmCancel = new javax.swing.JButton();
cmOk = new javax.swing.JButton();
cmDefault = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
txtTestResult = new javax.swing.JTextArea();
jLabel8 = new javax.swing.JLabel();
@@ -71,6 +82,9 @@ public class TestingListDetails extends javax.swing.JPanel {
txtTestDescription = new javax.swing.JTextArea();
jScrollPane4 = new javax.swing.JScrollPane();
jEditorPaneHelp = new javax.swing.JEditorPane();
jPanel1 = new javax.swing.JPanel();
jButtonCancel = new javax.swing.JButton();
jButtonOk = new javax.swing.JButton();
jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
jLabel1.setText("Device name");
@@ -134,29 +148,6 @@ public class TestingListDetails extends javax.swing.JPanel {
jLabel7.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
jLabel7.setText("Test Parameters");
cmCancel.setText("Cancel");
this.cmCancel.setVisible(false);
this.cmOk.setVisible(false);
cmCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmCancelActionPerformed(evt);
}
});
cmOk.setText("Ok");
this.cmCancel.setVisible(false);
this.cmOk.setVisible(false);
cmDefault.setText("Save as Default");
this.cmCancel.setVisible(false);
this.cmOk.setVisible(false);
this.cmDefault.setVisible(false);
cmDefault.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmDefaultActionPerformed(evt);
}
});
jScrollPane2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
txtTestResult.setEditable(false);
@@ -183,6 +174,35 @@ public class TestingListDetails extends javax.swing.JPanel {
jEditorPaneHelp.setDropMode(javax.swing.DropMode.INSERT);
jScrollPane4.setViewportView(jEditorPaneHelp);
jButtonCancel.setText("Cancel");
jButtonOk.setText("Ok");
jButtonOk.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonOkActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButtonOk, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jButtonCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButtonCancel)
.addComponent(jButtonOk))
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
@@ -207,13 +227,8 @@ public class TestingListDetails extends javax.swing.JPanel {
.addComponent(txtTestName)
.addComponent(jScrollPane3)
.addComponent(jScrollPane2)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 513, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(cmDefault, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cmOk, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 513, Short.MAX_VALUE)))
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
.addContainerGap())
@@ -251,13 +266,10 @@ public class TestingListDetails extends javax.swing.JPanel {
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel7)
.addGap(0, 229, Short.MAX_VALUE))
.addGap(0, 192, Short.MAX_VALUE))
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmCancel)
.addComponent(cmOk)
.addComponent(cmDefault)))
.addGap(18, 18, 18)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane4)
.addContainerGap())))
@@ -332,20 +344,103 @@ public class TestingListDetails extends javax.swing.JPanel {
}
}
}
/**
* Build a map with optional parameters to be passed to the testing script.
* The map is like this: parameters \_ name | \_ value | \_ description \_
* name | \_ value | \_ description ... the name 'name' is the mapping key.
* 'value' and 'description' are constant mapping keys of a nested map.
*
* @param parametersString string containing the parameters. Syntax:
* name:value:description[;name:value:description;...]
*/
private HashMap buildParametersMap(String parametersString) {
HashMap mParameters = new HashMap(); // contains name and attributes
HashMap mParameterAttributes = new HashMap(); //contians value and description
String[] dsParameterAttributes = null;
String[] dsParameters = parametersString.split(";");
for (String sParameter : dsParameters) {
dsParameterAttributes = sParameter.split(":");
if (dsParameterAttributes.length > 2) {
mParameterAttributes = new HashMap();
mParameterAttributes.put("value", (Object) dsParameterAttributes[1]);
mParameterAttributes.put("description", dsParameterAttributes[2]);
//add parameter name and attributes (value + description)
mParameters.put(dsParameterAttributes[0], mParameterAttributes);
}
}
return mParameters;
}
private HashMap getParametersFromTable(){
HashMap mParameters = new HashMap(); // contains name and attributes
HashMap mParameterAttributes = new HashMap(); //contians value and description
for(int row=0 ; row<jTableParams.getRowCount() ; row++){
String sParam = jTableParams.getValueAt(row, 0).toString();
String sVal = jTableParams.getValueAt(row, 1).toString();
String sDescr = jTableParams.getValueAt(row, 2).toString();
mParameterAttributes = new HashMap();
mParameterAttributes.put("value", (Object) sVal);
mParameterAttributes.put("description", sDescr);
//add parameter name and attributes (value + description)
mParameters.put(sParam, mParameterAttributes);
}
return mParameters;
}
public boolean updateTestConfig(Path testDir,
String sTestName,
String sTestSuite,
HashMap hmTestParams){
//generate test config file from template
boolean success = false;
try {
Path path = Paths.get(testDir + FilenameUtils.separatorsToSystem("/"+TESTS_CONFIG_FILENAME));
File configFile = path.toFile();
//Loop among the test parameters and generate variable assignement syntax for python
String sTestParameters = "";
String name="", value="", description="";
for(Object entry : hmTestParams.keySet()){
Object param = entry;
if(param instanceof String){
name = (String) param;
HashMap attributes = (HashMap) hmTestParams.get(param);
value = (String) attributes.get("value");
description = (String) attributes.get("description");
//build the python code for getting the test parameter
sTestParameters = sTestParameters + name + ":" + value + ":" + description + ";" ;
}
}
FileOutputStream out = new FileOutputStream(path.toFile());
FileInputStream in = new FileInputStream(path.toFile());
Properties props = new Properties();
props.load(in);
in.close();
props.setProperty("parameters", "sTestParameters");
props.store(out, null);
out.close();
private void cmCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmCancelActionPerformed
}//GEN-LAST:event_cmCancelActionPerformed
success = true;
} catch (FileNotFoundException ex) {
SwingUtils.showMessage(this, "generateTestConfig()", "Cannot find file: " + ex.toString());
Logger.getLogger(NewTest.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
SwingUtils.showMessage(this, "generateTestConfig()", "Problem with file aaccess: " + ex.toString());
Logger.getLogger(NewTest.class.getName()).log(Level.SEVERE, null, ex);
}
return success;
}
private void cmDefaultActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmDefaultActionPerformed
private void jButtonOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOkActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_cmDefaultActionPerformed
Path testPath = Paths.get(TESTS_TESTS_DEFAULT_DIR.toString(), this.txtTestSuite.getText(), this.txtTestName.getText());
updateTestConfig(testPath, this.txtTestName.getText(), this.txtTestSuite.getText(),getParametersFromTable());
}//GEN-LAST:event_jButtonOkActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cmCancel;
private javax.swing.JButton cmDefault;
private javax.swing.JButton cmOk;
private javax.swing.JButton jButtonCancel;
private javax.swing.JButton jButtonOk;
private javax.swing.JEditorPane jEditorPaneHelp;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
@@ -354,6 +449,7 @@ public class TestingListDetails extends javax.swing.JPanel {
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;