Startup
This commit is contained in:
74
plugins/FilterTable.java
Normal file
74
plugins/FilterTable.java
Normal file
@@ -0,0 +1,74 @@
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.regex.*;
|
||||
|
||||
public class FilterTable {
|
||||
public static void main(String args[]) {
|
||||
Runnable runner = new Runnable() {
|
||||
public void run() {
|
||||
JFrame frame = new JFrame("Sorting JTable");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
Object rows[][] = {
|
||||
{"AMZN", "Amazon", 41.28},
|
||||
{"EBAY", "eBay", 41.57},
|
||||
{"GOOG", "Google", 388.33},
|
||||
{"MSFT", "Microsoft", 26.56},
|
||||
{"NOK", "Nokia Corp", 17.13},
|
||||
{"ORCL", "Oracle Corp.", 12.52},
|
||||
{"SUNW", "Sun Microsystems", 3.86},
|
||||
{"TWX", "Time Warner", 17.66},
|
||||
{"VOD", "Vodafone Group", 26.02},
|
||||
{"YHOO", "Yahoo!", 37.69}
|
||||
};
|
||||
Object columns[] = {"Symbol", "Name", "Price"};
|
||||
TableModel model =
|
||||
new DefaultTableModel(rows, columns) {
|
||||
public Class getColumnClass(int column) {
|
||||
Class returnValue;
|
||||
if ((column >= 0) && (column < getColumnCount())) {
|
||||
returnValue = getValueAt(0, column).getClass();
|
||||
} else {
|
||||
returnValue = Object.class;
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
};
|
||||
JTable table = new JTable(model);
|
||||
final TableRowSorter<TableModel> sorter =
|
||||
new TableRowSorter<TableModel>(model);
|
||||
table.setRowSorter(sorter);
|
||||
JScrollPane pane = new JScrollPane(table);
|
||||
frame.add(pane, BorderLayout.CENTER);
|
||||
JPanel panel = new JPanel(new BorderLayout());
|
||||
JLabel label = new JLabel("Filter");
|
||||
panel.add(label, BorderLayout.WEST);
|
||||
final JTextField filterText =
|
||||
new JTextField("SUN");
|
||||
panel.add(filterText, BorderLayout.CENTER);
|
||||
frame.add(panel, BorderLayout.NORTH);
|
||||
JButton button = new JButton("Filter");
|
||||
button.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String text = filterText.getText();
|
||||
if (text.length() == 0) {
|
||||
sorter.setRowFilter(null);
|
||||
} else {
|
||||
try {
|
||||
sorter.setRowFilter(
|
||||
RowFilter.regexFilter(text));
|
||||
} catch (PatternSyntaxException pse) {
|
||||
System.err.println("Bad regex pattern");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
frame.add(button, BorderLayout.SOUTH);
|
||||
frame.setSize(300, 250);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
};
|
||||
EventQueue.invokeLater(runner);
|
||||
}
|
||||
}
|
||||
336
plugins/NewTest - Copy.java
Normal file
336
plugins/NewTest - Copy.java
Normal file
@@ -0,0 +1,336 @@
|
||||
/*
|
||||
* 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.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
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;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
import javax.swing.event.HyperlinkListener;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author boccioli_m
|
||||
*/
|
||||
public class NewTest extends javax.swing.JPanel {
|
||||
|
||||
/**
|
||||
* Creates new form TestingListDetails
|
||||
*/
|
||||
public NewTest() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
public NewTest(String hDetails) {
|
||||
initComponents();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
|
||||
jLabel4 = new javax.swing.JLabel();
|
||||
txtTestSuite = new javax.swing.JTextField();
|
||||
jLabel5 = new javax.swing.JLabel();
|
||||
txtTestName = new javax.swing.JTextField();
|
||||
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();
|
||||
jLabel8 = new javax.swing.JLabel();
|
||||
jScrollPane3 = new javax.swing.JScrollPane();
|
||||
txtTestDescription = new javax.swing.JTextArea();
|
||||
jScrollPane4 = new javax.swing.JScrollPane();
|
||||
jEditorPaneHelp = new javax.swing.JEditorPane();
|
||||
|
||||
jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
jLabel4.setText("Test Case/Suite");
|
||||
|
||||
txtTestSuite.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
|
||||
jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
jLabel5.setText("Test Name");
|
||||
|
||||
txtTestName.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
|
||||
jTableParams.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
jTableParams.setModel(new javax.swing.table.DefaultTableModel(
|
||||
new Object [][] {
|
||||
|
||||
},
|
||||
new String [] {
|
||||
"Parameter", "Value", "Description"
|
||||
}
|
||||
) {
|
||||
boolean[] canEdit = new boolean [] {
|
||||
false, true, false
|
||||
};
|
||||
|
||||
public boolean isCellEditable(int rowIndex, int columnIndex) {
|
||||
return canEdit [columnIndex];
|
||||
}
|
||||
});
|
||||
jTableParams.setDragEnabled(true);
|
||||
jTableParams.setRowHeight(20);
|
||||
jScrollPane1.setViewportView(jTableParams);
|
||||
if (jTableParams.getColumnModel().getColumnCount() > 0) {
|
||||
jTableParams.getColumnModel().getColumn(0).setMinWidth(150);
|
||||
jTableParams.getColumnModel().getColumn(0).setPreferredWidth(150);
|
||||
jTableParams.getColumnModel().getColumn(0).setMaxWidth(150);
|
||||
jTableParams.getColumnModel().getColumn(1).setPreferredWidth(80);
|
||||
jTableParams.getColumnModel().getColumn(1).setMaxWidth(100);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
jLabel8.setText("Test Description");
|
||||
|
||||
jScrollPane3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
|
||||
txtTestDescription.setColumns(20);
|
||||
txtTestDescription.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
txtTestDescription.setLineWrap(true);
|
||||
txtTestDescription.setRows(5);
|
||||
jScrollPane3.setViewportView(txtTestDescription);
|
||||
|
||||
jEditorPaneHelp.setContentType("text/html"); // NOI18N
|
||||
jEditorPaneHelp.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
jEditorPaneHelp.setDropMode(javax.swing.DropMode.INSERT);
|
||||
jScrollPane4.setViewportView(jEditorPaneHelp);
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(jLabel4)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(txtTestSuite, javax.swing.GroupLayout.PREFERRED_SIZE, 513, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(jLabel5)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(txtTestName, javax.swing.GroupLayout.PREFERRED_SIZE, 513, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jLabel7)
|
||||
.addComponent(jLabel8))
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(331, 331, 331)
|
||||
.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))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 513, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 513, javax.swing.GroupLayout.PREFERRED_SIZE)))))
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
|
||||
.addContainerGap())
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(jLabel5)
|
||||
.addComponent(txtTestName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(jLabel4)
|
||||
.addComponent(txtTestSuite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(jLabel8))
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(jLabel7)
|
||||
.addGap(0, 0, Short.MAX_VALUE)))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(cmCancel)
|
||||
.addComponent(cmOk)))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(jScrollPane4)
|
||||
.addContainerGap())))
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
|
||||
public static Path TESTS_DEVICES_DEFAULT_DIR = Paths.get(".", "home", "script", "tests", "devices");
|
||||
public static Path TESTS_TESTS_DEFAULT_DIR = Paths.get(".", "home", "script", "tests", "tests");
|
||||
public static Path TESTS_CONFIG_DEFAULT_DIR = Paths.get(".", "home", "script", "tests", "config");
|
||||
public static String TESTS_CONFIG_FILENAME = ".config";
|
||||
public static String TESTS_HELP_FILENAME = "help.html";
|
||||
public static Path TEMPLATES_HELP_FILEPATH = Paths.get(".", "home", "script", "tests","templates","helpTemplate.html");
|
||||
public static Path TEMPLATES_TEST_FILEPATH = Paths.get(".", "home", "script", "tests","templates","testTemplate.html");
|
||||
public static Path TEMPLATES_CONFIG_FILEPATH = Paths.get(".", "home", "script", "tests","templates","configTemplate.html");
|
||||
|
||||
private void fillComponents(HashMap hDetails) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void generateTestFiles(){
|
||||
HashMap hmTestParams = new HashMap();
|
||||
generateTestFiles(this.txtTestName.getText(),
|
||||
this.txtTestDescription.getText(),
|
||||
this.txtTestSuite.getText(),
|
||||
hmTestParams);
|
||||
}
|
||||
|
||||
public void generateTestFiles(String sTestName,
|
||||
String sTestDescription,
|
||||
String sTestSuite,
|
||||
HashMap hmTestParams){
|
||||
if (!TESTS_TESTS_DEFAULT_DIR.toFile().isDirectory()) {
|
||||
//check that the tests suite dir exists. If not, create it
|
||||
Path testSuiteDir = Paths.get(TESTS_TESTS_DEFAULT_DIR.toString(),sTestSuite);
|
||||
if( !testSuiteDir.toFile().isDirectory()){
|
||||
boolean success = testSuiteDir.toFile().mkdirs();
|
||||
if (!success) {
|
||||
// Directory creation failed
|
||||
SwingUtils.showMessage(this, "saveSettings()", "Cannot create directory " + testSuiteDir.toString());
|
||||
}else{
|
||||
//new test directory inside tests suite dir
|
||||
Path testDir = Paths.get(testSuiteDir.toString(),sTestName);
|
||||
success = testDir.toFile().mkdirs();
|
||||
if (!success) {
|
||||
// Directory creation failed
|
||||
SwingUtils.showMessage(this, "saveSettings()", "Cannot create directory " + testDir.toString());
|
||||
} else{
|
||||
//generate test files inside test dir
|
||||
generateTestConfig(testDir,
|
||||
sTestName,
|
||||
sTestDescription,
|
||||
sTestSuite,
|
||||
hmTestParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void generateTestScript(String sTestName,
|
||||
String sTestDescription,
|
||||
String sTestSuite,
|
||||
HashMap hmTestParams){
|
||||
|
||||
}
|
||||
|
||||
public void generateTestConfig(Path testDir,
|
||||
String sTestName,
|
||||
String sTestDescription,
|
||||
String sTestSuite,
|
||||
HashMap hmTestParams){
|
||||
//generate test config file from template
|
||||
try {
|
||||
Path path = Paths.get(testDir + FilenameUtils.separatorsToSystem("/"+TESTS_CONFIG_FILENAME));
|
||||
Files.copy(TEMPLATES_CONFIG_FILEPATH, path);
|
||||
File configFile = path.toFile();
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("name", sTestName);
|
||||
properties.setProperty("description", sTestDescription);
|
||||
OutputStream is = new FileOutputStream(configFile);
|
||||
properties.store(is, "Test config");
|
||||
is.close();
|
||||
} catch (FileNotFoundException ex) {
|
||||
Logger.getLogger(NewTest.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(NewTest.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void generateTestHelp(Path testDir,
|
||||
String sTestName,
|
||||
String sTestDescription,
|
||||
String sTestSuite,
|
||||
HashMap hmTestParams){
|
||||
//generate test config file from template
|
||||
Path path = Paths.get(testDir + FilenameUtils.separatorsToSystem("/"+TESTS_HELP_FILENAME));
|
||||
try {
|
||||
Files.copy(TEMPLATES_HELP_FILEPATH, path);
|
||||
File configFile = path.toFile();
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(NewTest.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void cmCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmCancelActionPerformed
|
||||
|
||||
}//GEN-LAST:event_cmCancelActionPerformed
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton cmCancel;
|
||||
private javax.swing.JButton cmOk;
|
||||
private javax.swing.JEditorPane jEditorPaneHelp;
|
||||
private javax.swing.JLabel jLabel4;
|
||||
private javax.swing.JLabel jLabel5;
|
||||
private javax.swing.JLabel jLabel7;
|
||||
private javax.swing.JLabel jLabel8;
|
||||
private javax.swing.JScrollPane jScrollPane1;
|
||||
private javax.swing.JScrollPane jScrollPane3;
|
||||
private javax.swing.JScrollPane jScrollPane4;
|
||||
private javax.swing.JTable jTableParams;
|
||||
private javax.swing.JTextArea txtTestDescription;
|
||||
private javax.swing.JTextField txtTestName;
|
||||
private javax.swing.JTextField txtTestSuite;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
240
plugins/NewTest.form
Normal file
240
plugins/NewTest.form
Normal file
@@ -0,0 +1,240 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
||||
<NonVisualComponents>
|
||||
<Container class="javax.swing.JPopupMenu" name="jPopupMenuTable">
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
|
||||
<Property name="useNullLayout" type="boolean" value="true"/>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="jMenuItemAddRow">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Add Row"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuItemAddRowActionPerformed"/>
|
||||
</Events>
|
||||
</MenuItem>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="jMenuItemReleteRow">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Delete Row"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuItemReleteRowActionPerformed"/>
|
||||
</Events>
|
||||
</MenuItem>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</NonVisualComponents>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" max="-2" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="jLabel4" max="-2" attributes="0"/>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<Component id="txtTestSuite" min="-2" pref="513" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="jLabel5" max="-2" attributes="0"/>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<Component id="txtTestName" min="-2" pref="513" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="jLabel7" alignment="0" max="-2" attributes="0"/>
|
||||
<Component id="jLabel8" alignment="0" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace min="-2" pref="19" max="-2" attributes="0"/>
|
||||
<Component id="jScrollPane3" min="-2" pref="513" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Component id="jScrollPane1" min="-2" pref="513" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
<Component id="jButtonGenerate" alignment="1" min="-2" pref="188" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="jLabel5" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="txtTestName" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="jLabel4" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="txtTestSuite" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="jScrollPane3" min="-2" pref="81" max="-2" attributes="0"/>
|
||||
<Component id="jLabel8" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="jLabel7" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jScrollPane1" min="-2" pref="180" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<Component id="jButtonGenerate" min="-2" pref="33" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JLabel" name="jLabel4">
|
||||
<Properties>
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||
<Font name="Tahoma" size="14" style="0"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="Test Case/Suite *"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtTestSuite">
|
||||
<Properties>
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||
<Font name="Tahoma" size="14" style="0"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="jLabel5">
|
||||
<Properties>
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||
<Font name="Tahoma" size="14" style="0"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="Test Name *"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtTestName">
|
||||
<Properties>
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||
<Font name="Tahoma" size="14" style="0"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
|
||||
<AuxValues>
|
||||
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JTable" name="jTableParams">
|
||||
<Properties>
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||
<Font name="Tahoma" size="14" style="0"/>
|
||||
</Property>
|
||||
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
|
||||
<Table columnCount="3" rowCount="0">
|
||||
<Column editable="true" title="Parameter" type="java.lang.Object"/>
|
||||
<Column editable="true" title="Value" type="java.lang.Object"/>
|
||||
<Column editable="true" title="Description" type="java.lang.Object"/>
|
||||
</Table>
|
||||
</Property>
|
||||
<Property name="columnModel" type="javax.swing.table.TableColumnModel" editor="org.netbeans.modules.form.editors2.TableColumnModelEditor">
|
||||
<TableColumnModel selectionModel="0">
|
||||
<Column maxWidth="150" minWidth="150" prefWidth="150" resizable="true">
|
||||
<Title/>
|
||||
<Editor/>
|
||||
<Renderer/>
|
||||
</Column>
|
||||
<Column maxWidth="100" minWidth="-1" prefWidth="80" resizable="true">
|
||||
<Title/>
|
||||
<Editor/>
|
||||
<Renderer/>
|
||||
</Column>
|
||||
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
|
||||
<Title/>
|
||||
<Editor/>
|
||||
<Renderer/>
|
||||
</Column>
|
||||
</TableColumnModel>
|
||||
</Property>
|
||||
<Property name="dragEnabled" type="boolean" value="true"/>
|
||||
<Property name="rowHeight" type="int" value="20"/>
|
||||
<Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor">
|
||||
<TableHeader reorderingAllowed="true" resizingAllowed="true"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="jTableParamsMouseClicked"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Component class="javax.swing.JLabel" name="jLabel7">
|
||||
<Properties>
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||
<Font name="Tahoma" size="14" style="0"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="Test Parameters"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="jLabel8">
|
||||
<Properties>
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||
<Font name="Tahoma" size="14" style="0"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="Test Description *"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Container class="javax.swing.JScrollPane" name="jScrollPane3">
|
||||
<Properties>
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||
<Font name="Tahoma" size="14" style="0"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JTextArea" name="txtTestDescription">
|
||||
<Properties>
|
||||
<Property name="columns" type="int" value="20"/>
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||
<Font name="Tahoma" size="14" style="0"/>
|
||||
</Property>
|
||||
<Property name="lineWrap" type="boolean" value="true"/>
|
||||
<Property name="rows" type="int" value="5"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Component class="javax.swing.JButton" name="jButtonGenerate">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Generate"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButtonGenerateActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
607
plugins/NewTest.java
Normal file
607
plugins/NewTest.java
Normal file
@@ -0,0 +1,607 @@
|
||||
/*
|
||||
* Copyright (c) 2015 Paul Scherrer Institute. All rights reserved.
|
||||
*/
|
||||
|
||||
import ch.psi.utils.swing.SwingUtils;
|
||||
import ch.psi.utils.swing.SwingUtils.OptionResult;
|
||||
import ch.psi.utils.swing.SwingUtils.OptionType;
|
||||
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.InputStream;
|
||||
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;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
import javax.swing.event.HyperlinkListener;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author boccioli_m
|
||||
*/
|
||||
public class NewTest extends javax.swing.JPanel {
|
||||
|
||||
/**
|
||||
* Creates new form TestingListDetails
|
||||
*/
|
||||
public NewTest() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
public NewTest(String hDetails) {
|
||||
initComponents();
|
||||
fillComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
|
||||
jPopupMenuTable = new javax.swing.JPopupMenu();
|
||||
jMenuItemAddRow = new javax.swing.JMenuItem();
|
||||
jMenuItemReleteRow = new javax.swing.JMenuItem();
|
||||
jLabel4 = new javax.swing.JLabel();
|
||||
txtTestSuite = new javax.swing.JTextField();
|
||||
jLabel5 = new javax.swing.JLabel();
|
||||
txtTestName = new javax.swing.JTextField();
|
||||
jScrollPane1 = new javax.swing.JScrollPane();
|
||||
jTableParams = new javax.swing.JTable();
|
||||
jLabel7 = new javax.swing.JLabel();
|
||||
jLabel8 = new javax.swing.JLabel();
|
||||
jScrollPane3 = new javax.swing.JScrollPane();
|
||||
txtTestDescription = new javax.swing.JTextArea();
|
||||
jButtonGenerate = new javax.swing.JButton();
|
||||
|
||||
jMenuItemAddRow.setText("Add Row");
|
||||
jMenuItemAddRow.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jMenuItemAddRowActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jPopupMenuTable.add(jMenuItemAddRow);
|
||||
|
||||
jMenuItemReleteRow.setText("Delete Row");
|
||||
jMenuItemReleteRow.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jMenuItemReleteRowActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jPopupMenuTable.add(jMenuItemReleteRow);
|
||||
|
||||
jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
jLabel4.setText("Test Case/Suite *");
|
||||
|
||||
txtTestSuite.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
|
||||
jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
jLabel5.setText("Test Name *");
|
||||
|
||||
txtTestName.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
|
||||
jTableParams.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
jTableParams.setModel(new javax.swing.table.DefaultTableModel(
|
||||
new Object [][] {
|
||||
|
||||
},
|
||||
new String [] {
|
||||
"Parameter", "Value", "Description"
|
||||
}
|
||||
));
|
||||
jTableParams.setDragEnabled(true);
|
||||
jTableParams.setRowHeight(20);
|
||||
jTableParams.addMouseListener(new java.awt.event.MouseAdapter() {
|
||||
public void mouseClicked(java.awt.event.MouseEvent evt) {
|
||||
jTableParamsMouseClicked(evt);
|
||||
}
|
||||
});
|
||||
jScrollPane1.setViewportView(jTableParams);
|
||||
if (jTableParams.getColumnModel().getColumnCount() > 0) {
|
||||
jTableParams.getColumnModel().getColumn(0).setMinWidth(150);
|
||||
jTableParams.getColumnModel().getColumn(0).setPreferredWidth(150);
|
||||
jTableParams.getColumnModel().getColumn(0).setMaxWidth(150);
|
||||
jTableParams.getColumnModel().getColumn(1).setPreferredWidth(80);
|
||||
jTableParams.getColumnModel().getColumn(1).setMaxWidth(100);
|
||||
}
|
||||
|
||||
jLabel7.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
jLabel7.setText("Test Parameters");
|
||||
|
||||
jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
jLabel8.setText("Test Description *");
|
||||
|
||||
jScrollPane3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
|
||||
txtTestDescription.setColumns(20);
|
||||
txtTestDescription.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
txtTestDescription.setLineWrap(true);
|
||||
txtTestDescription.setRows(5);
|
||||
jScrollPane3.setViewportView(txtTestDescription);
|
||||
|
||||
jButtonGenerate.setText("Generate");
|
||||
jButtonGenerate.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButtonGenerateActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(jLabel4)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(txtTestSuite, javax.swing.GroupLayout.PREFERRED_SIZE, 513, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(jLabel5)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(txtTestName, javax.swing.GroupLayout.PREFERRED_SIZE, 513, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jLabel7)
|
||||
.addComponent(jLabel8))
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addGap(19, 19, 19)
|
||||
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 513, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 513, javax.swing.GroupLayout.PREFERRED_SIZE))))
|
||||
.addComponent(jButtonGenerate, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, 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(jLabel5)
|
||||
.addComponent(txtTestName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(jLabel4)
|
||||
.addComponent(txtTestSuite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(jLabel8))
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jLabel7)
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(jButtonGenerate, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap())
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void jButtonGenerateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGenerateActionPerformed
|
||||
// TODO add your handling code here:
|
||||
if(checkDataFields())
|
||||
{
|
||||
generateTestFiles();
|
||||
}
|
||||
}//GEN-LAST:event_jButtonGenerateActionPerformed
|
||||
|
||||
private void jTableParamsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableParamsMouseClicked
|
||||
// TODO add your handling code here:
|
||||
if(evt.getButton() == java.awt.event.MouseEvent.BUTTON3){
|
||||
jPopupMenuTable.show(jTableParams, evt.getX(), evt.getY());
|
||||
}
|
||||
}//GEN-LAST:event_jTableParamsMouseClicked
|
||||
|
||||
private void jMenuItemAddRowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemAddRowActionPerformed
|
||||
// TODO add your handling code here:
|
||||
DefaultTableModel model = (DefaultTableModel) jTableParams.getModel();
|
||||
model.addRow(new Object[]{"", "", ""});
|
||||
jTableParams.setModel(model);
|
||||
}//GEN-LAST:event_jMenuItemAddRowActionPerformed
|
||||
|
||||
private void jMenuItemReleteRowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemReleteRowActionPerformed
|
||||
// TODO add your handling code here:
|
||||
int row = jTableParams.getSelectedRow();
|
||||
if(row>=0 && row<jTableParams.getRowCount()){
|
||||
DefaultTableModel model = (DefaultTableModel) jTableParams.getModel();
|
||||
model.removeRow(row);
|
||||
}
|
||||
}//GEN-LAST:event_jMenuItemReleteRowActionPerformed
|
||||
|
||||
|
||||
public static Path TESTS_DEVICES_DEFAULT_DIR = Paths.get(".", "home", "script", "tests", "devices");
|
||||
public static Path TESTS_TESTS_DEFAULT_DIR = Paths.get(".", "home", "script", "tests", "tests");
|
||||
public static Path TESTS_CONFIG_DEFAULT_DIR = Paths.get(".", "home", "script", "tests", "config");
|
||||
public static String TESTS_CONFIG_FILENAME = ".config";
|
||||
public static String TESTS_HELP_FILENAME = "help.html";
|
||||
public static Path TEMPLATES_HELP_FILEPATH = Paths.get(".", "home", "script", "tests","templates","helpTemplate.html");
|
||||
public static Path TEMPLATES_TESTSCRIPT_FILEPATH = Paths.get(".", "home", "script", "tests","templates","testTemplate.py");
|
||||
public static Path TEMPLATES_CONFIG_FILEPATH = Paths.get(".", "home", "script", "tests","templates","template.config");
|
||||
public static String ALLOWED_CHARS = "[a-zA-Z0-9._\\-\\]\\[(){} ]*";
|
||||
|
||||
/**
|
||||
* fill table with example parameters
|
||||
*/
|
||||
private void fillComponents() {
|
||||
InputStream ist = null;
|
||||
try {
|
||||
Properties propTest = new Properties();
|
||||
File configFile = TEMPLATES_CONFIG_FILEPATH.toFile();
|
||||
ist = new FileInputStream(configFile);
|
||||
propTest.load(ist);
|
||||
String testParams = propTest.getProperty("parameters");
|
||||
if (testParams == null) {
|
||||
testParams = "";
|
||||
}
|
||||
ist.close();
|
||||
HashMap hParams = (HashMap) buildParametersMap(testParams);
|
||||
String name="", value="", description="";
|
||||
DefaultTableModel model = (DefaultTableModel) jTableParams.getModel();
|
||||
for(Object entry : hParams.keySet()){
|
||||
Object param = entry;
|
||||
if(param instanceof String){
|
||||
name = (String) param;
|
||||
HashMap attributes = (HashMap) hParams.get(param);
|
||||
value = (String) attributes.get("value");
|
||||
description = (String) attributes.get("description");
|
||||
model.addRow(new Object[]{name, value, description});
|
||||
}
|
||||
jTableParams.setModel(model);
|
||||
}
|
||||
} catch (FileNotFoundException ex) {
|
||||
SwingUtils.showMessage(this, "fillComponents()", "Cannot find file " + TEMPLATES_CONFIG_FILEPATH.toString());
|
||||
Logger.getLogger(NewTest.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (IOException ex) {
|
||||
SwingUtils.showMessage(this, "fillComponents()", "Cannot read file " + TEMPLATES_CONFIG_FILEPATH.toString());
|
||||
Logger.getLogger(NewTest.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} finally {
|
||||
try {
|
||||
ist.close();
|
||||
} catch (IOException ex) {
|
||||
SwingUtils.showMessage(this, "fillComponents()", "Cannot close file " + TEMPLATES_CONFIG_FILEPATH.toString());
|
||||
Logger.getLogger(NewTest.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 checkDataFields(){
|
||||
//check compulsory data fields
|
||||
if(this.txtTestName.getText().isEmpty() ||
|
||||
this.txtTestDescription.getText().isEmpty() ||
|
||||
this.txtTestSuite.getText().isEmpty()){
|
||||
SwingUtils.showMessage(this, "checkDataFields()",
|
||||
"Please fill-in all compulsory fields (marked with *)");
|
||||
return false;
|
||||
}
|
||||
if(!(txtTestName.getText().matches(ALLOWED_CHARS) &&
|
||||
txtTestDescription.getText().matches(ALLOWED_CHARS) &&
|
||||
txtTestSuite.getText().matches(ALLOWED_CHARS)
|
||||
)){
|
||||
SwingUtils.showMessage(this, "checkDataFields()",
|
||||
"Please remove forbidden chars: only letters, numbers, parenthesis are allowed");
|
||||
return false;
|
||||
}
|
||||
//check parameters table
|
||||
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();
|
||||
if(sParam.isEmpty() || sVal.isEmpty() || sDescr.isEmpty()){
|
||||
SwingUtils.showMessage(this, "checkDataFields()", "You must fill-in all the values in the parameters table");
|
||||
return false;
|
||||
}
|
||||
if(!(sParam.matches(ALLOWED_CHARS) &&
|
||||
sVal.matches(ALLOWED_CHARS) &&
|
||||
sDescr.matches(ALLOWED_CHARS))
|
||||
){
|
||||
SwingUtils.showMessage(this, "checkDataFields()",
|
||||
"Please remove forbidden chars from parameters table: only letters, numbers, parenthesis are allowed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void generateTestFiles(){
|
||||
HashMap hmTestParams = (HashMap) getParametersFromTable();
|
||||
generateTestFiles(this.txtTestName.getText(),
|
||||
this.txtTestDescription.getText(),
|
||||
this.txtTestSuite.getText(),
|
||||
hmTestParams);
|
||||
}
|
||||
|
||||
public void generateTestFiles(String sTestName,
|
||||
String sTestDescription,
|
||||
String sTestSuite,
|
||||
HashMap hmTestParams){
|
||||
if (TESTS_TESTS_DEFAULT_DIR.toFile().isDirectory()) {
|
||||
//check that the tests suite dir exists. If not, create it
|
||||
Path testSuiteDir = Paths.get(TESTS_TESTS_DEFAULT_DIR.toString(),sTestSuite);
|
||||
if( !testSuiteDir.toFile().isDirectory()){
|
||||
boolean success = testSuiteDir.toFile().mkdirs();
|
||||
if (!success) {
|
||||
// Directory creation failed
|
||||
SwingUtils.showMessage(this, "generateTestFiles()", "Cannot create directory " + testSuiteDir.toString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
//new test directory inside tests suite dir
|
||||
Path testDir = Paths.get(testSuiteDir.toString(),sTestName);
|
||||
if( testDir.toFile().isDirectory()){
|
||||
//test already exists: ask to overwrite
|
||||
OptionResult res = SwingUtils.showOption(this, "Overwrite Test?", "Test already exists. Overwrite with this new one?", OptionType.YesNo);
|
||||
if (res == OptionResult.No){
|
||||
return;
|
||||
}
|
||||
}else{
|
||||
boolean success = testDir.toFile().mkdirs();
|
||||
if (!success) {
|
||||
// Directory creation failed
|
||||
SwingUtils.showMessage(this, "generateTestFiles()", "Cannot create directory " + testDir.toString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
//generate test files inside test dir
|
||||
|
||||
if (!generateTestConfig(testDir,
|
||||
sTestName,
|
||||
sTestDescription,
|
||||
sTestSuite,
|
||||
hmTestParams)) return;
|
||||
if (!generateTestHelp(testDir,
|
||||
sTestName,
|
||||
sTestDescription,
|
||||
sTestSuite,
|
||||
hmTestParams)) return;
|
||||
if (!generateTestScript(testDir,
|
||||
sTestName,
|
||||
sTestDescription,
|
||||
sTestSuite,
|
||||
hmTestParams)) return;
|
||||
SwingUtils.showMessage(this, "Test generated", "Test "+sTestName+" successfully generated in \n"+testDir.toString());
|
||||
|
||||
}else{
|
||||
SwingUtils.showMessage(this, "generateTestFiles()", "Cannot find tests default directory " + TESTS_TESTS_DEFAULT_DIR.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean generateTestScript(Path testDir,
|
||||
String sTestName,
|
||||
String sTestDescription,
|
||||
String sTestSuite,
|
||||
HashMap hmTestParams){
|
||||
boolean success = false;
|
||||
Path path = Paths.get(testDir + FilenameUtils.separatorsToSystem("/"+sTestName+".py"));
|
||||
try {
|
||||
if(Files.exists(path)){
|
||||
Files.delete(path);
|
||||
}
|
||||
Files.copy(TEMPLATES_TESTSCRIPT_FILEPATH, path);
|
||||
//add test parameters
|
||||
String name="", value="", description="";
|
||||
DefaultTableModel model = (DefaultTableModel) jTableParams.getModel();
|
||||
String sSyntaxGetTestParameters = "";
|
||||
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
|
||||
sSyntaxGetTestParameters = sSyntaxGetTestParameters + name + " = float(params[\""+name+"\"][\"value\"]) ; ";
|
||||
}
|
||||
}
|
||||
replaceParameters(path,
|
||||
new String[]{"$testName","$testDescription","#$testParameters"},
|
||||
new String[]{sTestName,sTestDescription,sSyntaxGetTestParameters});
|
||||
success = true;
|
||||
} catch (IOException ex) {
|
||||
SwingUtils.showMessage(this, "generateTestScript()", "Cannot copy file " + ex.toString());
|
||||
Logger.getLogger(NewTest.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
public boolean generateTestConfig(Path testDir,
|
||||
String sTestName,
|
||||
String sTestDescription,
|
||||
String sTestSuite,
|
||||
HashMap hmTestParams){
|
||||
//generate test config file from template
|
||||
boolean success = false;
|
||||
try {
|
||||
Path path = Paths.get(testDir + FilenameUtils.separatorsToSystem("/"+TESTS_CONFIG_FILENAME));
|
||||
if(Files.exists(path)){
|
||||
Files.delete(path);
|
||||
}
|
||||
Files.copy(TEMPLATES_CONFIG_FILEPATH, path);
|
||||
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 + ";" ;
|
||||
}
|
||||
}
|
||||
String content = "#Test configuration\n";
|
||||
content +=("\nname=" + sTestName);
|
||||
content +=("\ndescription=" + sTestDescription);
|
||||
content +=("\nparameters=" + sTestParameters);
|
||||
OutputStream is = new FileOutputStream(configFile);
|
||||
Charset charset = StandardCharsets.UTF_8;
|
||||
Files.write(path, content.getBytes(charset));
|
||||
is.write(content.getBytes());
|
||||
is.close();
|
||||
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;
|
||||
}
|
||||
|
||||
public boolean generateTestHelp(Path testDir,
|
||||
String sTestName,
|
||||
String sTestDescription,
|
||||
String sTestSuite,
|
||||
HashMap hmTestParams){
|
||||
//generate test config file from template
|
||||
Path path = Paths.get(testDir + FilenameUtils.separatorsToSystem("/"+TESTS_HELP_FILENAME));
|
||||
boolean success = false;
|
||||
try {
|
||||
if(Files.exists(path)){
|
||||
Files.delete(path);
|
||||
}
|
||||
Files.copy(TEMPLATES_HELP_FILEPATH, path);
|
||||
//Loop among the test parameters and generate parameter help
|
||||
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 + "<code>" + name + " </code>" + description + "<br/>\n" ;
|
||||
}
|
||||
}
|
||||
success = replaceParameters(path,
|
||||
new String[]{"$testName","$testDescription","$testParameters"},
|
||||
new String[]{sTestName,sTestDescription,sTestParameters});
|
||||
|
||||
} catch (IOException ex) {
|
||||
SwingUtils.showMessage(this, "generateTestHelp()", "Cannot create directory " + ex.toString());
|
||||
Logger.getLogger(NewTest.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
public boolean replaceParameters(Path path,
|
||||
String parameterNames[],
|
||||
String parameterValues[]){
|
||||
boolean success = false;
|
||||
try {
|
||||
//replace parameters in template
|
||||
String content = new String(Files.readAllBytes(path));
|
||||
for(int i=0 ; i<parameterNames.length ; i++ ){
|
||||
content = content.replace(parameterNames[i], parameterValues[i]);
|
||||
}
|
||||
//System.out.print(content);
|
||||
Charset charset = StandardCharsets.UTF_8;
|
||||
Files.write(path, content.getBytes(charset));
|
||||
OutputStream is = new FileOutputStream(path.toFile());
|
||||
is.write(content.getBytes());
|
||||
is.close();
|
||||
success = true;
|
||||
} catch (IOException ex) {
|
||||
SwingUtils.showMessage(this, "replaceParameters()", "Cannot access file " + path + ". "+ ex.toString());
|
||||
Logger.getLogger(NewTest.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton jButtonGenerate;
|
||||
private javax.swing.JLabel jLabel4;
|
||||
private javax.swing.JLabel jLabel5;
|
||||
private javax.swing.JLabel jLabel7;
|
||||
private javax.swing.JLabel jLabel8;
|
||||
private javax.swing.JMenuItem jMenuItemAddRow;
|
||||
private javax.swing.JMenuItem jMenuItemReleteRow;
|
||||
private javax.swing.JPopupMenu jPopupMenuTable;
|
||||
private javax.swing.JScrollPane jScrollPane1;
|
||||
private javax.swing.JScrollPane jScrollPane3;
|
||||
private javax.swing.JTable jTableParams;
|
||||
private javax.swing.JTextArea txtTestDescription;
|
||||
private javax.swing.JTextField txtTestName;
|
||||
private javax.swing.JTextField txtTestSuite;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
465
plugins/TestingListDetails - Copy.java
Normal file
465
plugins/TestingListDetails - Copy.java
Normal file
@@ -0,0 +1,465 @@
|
||||
/*
|
||||
* 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;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
import javax.swing.event.HyperlinkListener;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author boccioli_m
|
||||
*/
|
||||
public class TestingListDetails extends javax.swing.JPanel {
|
||||
|
||||
/**
|
||||
* Creates new form TestingListDetails
|
||||
*/
|
||||
public TestingListDetails() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
public TestingListDetails(HashMap hDetails) {
|
||||
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.
|
||||
* 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();
|
||||
txtDeviceName = new javax.swing.JTextField();
|
||||
jLabel2 = new javax.swing.JLabel();
|
||||
txtDeviceDescription = new javax.swing.JTextField();
|
||||
jLabel4 = new javax.swing.JLabel();
|
||||
txtTestSuite = new javax.swing.JTextField();
|
||||
jLabel5 = new javax.swing.JLabel();
|
||||
txtTestName = new javax.swing.JTextField();
|
||||
jLabel6 = new javax.swing.JLabel();
|
||||
jScrollPane1 = new javax.swing.JScrollPane();
|
||||
jTableParams = new javax.swing.JTable();
|
||||
jLabel7 = new javax.swing.JLabel();
|
||||
jScrollPane2 = new javax.swing.JScrollPane();
|
||||
txtTestResult = new javax.swing.JTextArea();
|
||||
jLabel8 = new javax.swing.JLabel();
|
||||
jScrollPane3 = new javax.swing.JScrollPane();
|
||||
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");
|
||||
|
||||
txtDeviceName.setEditable(false);
|
||||
txtDeviceName.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
txtDeviceName.setText("jTextField1");
|
||||
|
||||
jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
jLabel2.setText("Device Description");
|
||||
|
||||
txtDeviceDescription.setEditable(false);
|
||||
txtDeviceDescription.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
txtDeviceDescription.setText("jTextField2");
|
||||
|
||||
jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
jLabel4.setText("Test Case/Suite");
|
||||
|
||||
txtTestSuite.setEditable(false);
|
||||
txtTestSuite.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
txtTestSuite.setText("jTextField2");
|
||||
|
||||
jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
jLabel5.setText("Test Name");
|
||||
|
||||
txtTestName.setEditable(false);
|
||||
txtTestName.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
txtTestName.setText("jTextField2");
|
||||
|
||||
jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
jLabel6.setText("Last Test Result");
|
||||
|
||||
jTableParams.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
jTableParams.setModel(new javax.swing.table.DefaultTableModel(
|
||||
new Object [][] {
|
||||
|
||||
},
|
||||
new String [] {
|
||||
"Parameter", "Value", "Description"
|
||||
}
|
||||
) {
|
||||
boolean[] canEdit = new boolean [] {
|
||||
false, true, false
|
||||
};
|
||||
|
||||
public boolean isCellEditable(int rowIndex, int columnIndex) {
|
||||
return canEdit [columnIndex];
|
||||
}
|
||||
});
|
||||
jTableParams.setDragEnabled(true);
|
||||
jTableParams.setRowHeight(20);
|
||||
jScrollPane1.setViewportView(jTableParams);
|
||||
if (jTableParams.getColumnModel().getColumnCount() > 0) {
|
||||
jTableParams.getColumnModel().getColumn(0).setMinWidth(150);
|
||||
jTableParams.getColumnModel().getColumn(0).setPreferredWidth(150);
|
||||
jTableParams.getColumnModel().getColumn(0).setMaxWidth(150);
|
||||
jTableParams.getColumnModel().getColumn(1).setPreferredWidth(80);
|
||||
jTableParams.getColumnModel().getColumn(1).setMaxWidth(100);
|
||||
}
|
||||
|
||||
jLabel7.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
jLabel7.setText("Test Parameters");
|
||||
|
||||
jScrollPane2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
|
||||
txtTestResult.setEditable(false);
|
||||
txtTestResult.setColumns(20);
|
||||
txtTestResult.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
txtTestResult.setLineWrap(true);
|
||||
txtTestResult.setRows(5);
|
||||
jScrollPane2.setViewportView(txtTestResult);
|
||||
|
||||
jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
jLabel8.setText("Test Description");
|
||||
|
||||
jScrollPane3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
|
||||
txtTestDescription.setEditable(false);
|
||||
txtTestDescription.setColumns(20);
|
||||
txtTestDescription.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
txtTestDescription.setLineWrap(true);
|
||||
txtTestDescription.setRows(5);
|
||||
jScrollPane3.setViewportView(txtTestDescription);
|
||||
|
||||
jEditorPaneHelp.setContentType("text/html"); // NOI18N
|
||||
jEditorPaneHelp.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
|
||||
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(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jLabel4)
|
||||
.addComponent(jLabel5)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jLabel1)
|
||||
.addComponent(jLabel2)
|
||||
.addComponent(jLabel7)
|
||||
.addComponent(jLabel6)
|
||||
.addComponent(jLabel8))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addComponent(txtDeviceName)
|
||||
.addComponent(txtDeviceDescription)
|
||||
.addComponent(txtTestSuite)
|
||||
.addComponent(txtTestName)
|
||||
.addComponent(jScrollPane3)
|
||||
.addComponent(jScrollPane2)
|
||||
.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())
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(jLabel1)
|
||||
.addComponent(txtDeviceName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(jLabel2)
|
||||
.addComponent(txtDeviceDescription, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(jLabel4)
|
||||
.addComponent(txtTestSuite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(jLabel5)
|
||||
.addComponent(txtTestName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jLabel8)
|
||||
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(jLabel6))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(jLabel7)
|
||||
.addGap(0, 192, Short.MAX_VALUE))
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
|
||||
.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())))
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void fillComponents(HashMap hDetails) {
|
||||
//add values to each text box
|
||||
this.txtDeviceName.setText(hDetails.get("deviceName").toString());
|
||||
this.txtDeviceDescription.setText(hDetails.get("deviceDescription").toString());
|
||||
this.txtTestDescription.setText(hDetails.get("testDescription").toString());
|
||||
this.txtTestSuite.setText(hDetails.get("testSuite").toString());
|
||||
this.txtTestName.setText(hDetails.get("testName").toString());
|
||||
this.txtTestResult.setText(hDetails.get("time").toString() + "\n" + hDetails.get("testResult").toString());
|
||||
//help text
|
||||
showHelp(String.valueOf(hDetails.get("testPath")), String.valueOf(hDetails.get("testHelp")));
|
||||
//parameters table
|
||||
HashMap hParams = (HashMap) hDetails.get("parameters");
|
||||
String name="", value="", description="";
|
||||
DefaultTableModel model = (DefaultTableModel) jTableParams.getModel();
|
||||
|
||||
for(Object entry : hParams.keySet()){
|
||||
Object param = entry;
|
||||
if(param instanceof String){
|
||||
name = (String) param;
|
||||
HashMap attributes = (HashMap) hParams.get(param);
|
||||
value = (String) attributes.get("value");
|
||||
description = (String) attributes.get("description");
|
||||
model.addRow(new Object[]{name, value, description});
|
||||
}
|
||||
jTableParams.setModel(model);
|
||||
}
|
||||
}
|
||||
|
||||
//load and show help
|
||||
private void showHelp(String sTestPath, String sHelpText){
|
||||
this.jEditorPaneHelp.addHyperlinkListener(new HyperlinkListener() {
|
||||
@Override
|
||||
public void hyperlinkUpdate(HyperlinkEvent hle) {
|
||||
if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) {
|
||||
System.out.println(hle.getURL());
|
||||
Desktop desktop = Desktop.getDesktop();
|
||||
try {
|
||||
desktop.browse(hle.getURL().toURI());
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
this.jEditorPaneHelp.setEditable(false);
|
||||
//if there is no input, exit
|
||||
if(sTestPath == "" && sHelpText == ""){
|
||||
return;
|
||||
}
|
||||
File fTest = new File(sTestPath);
|
||||
String sParentPath = fTest.getParent().toString();
|
||||
File fHelp = new File(FilenameUtils.separatorsToSystem(sParentPath + "/help.html"));
|
||||
|
||||
if(fHelp.isFile()){//if local help file existis:
|
||||
try {
|
||||
this.jEditorPaneHelp.setPage(fHelp.toURI().toURL());
|
||||
} catch (IOException ex) {
|
||||
this.jEditorPaneHelp.setText(String.valueOf(ex));
|
||||
}
|
||||
} else { //help.html file is present. see if a plain text has been given from .config file
|
||||
if(sHelpText.isEmpty() || sHelpText == "null"){
|
||||
this.jEditorPaneHelp.setText("[No help available]");
|
||||
//this.jEditorPaneHelp.setVisible(false);
|
||||
}else {
|
||||
this.jEditorPaneHelp.setText(sHelpText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
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 jButtonOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOkActionPerformed
|
||||
// TODO add your handling code here:
|
||||
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 jButtonCancel;
|
||||
private javax.swing.JButton jButtonOk;
|
||||
private javax.swing.JEditorPane jEditorPaneHelp;
|
||||
private javax.swing.JLabel jLabel1;
|
||||
private javax.swing.JLabel jLabel2;
|
||||
private javax.swing.JLabel jLabel4;
|
||||
private javax.swing.JLabel jLabel5;
|
||||
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;
|
||||
private javax.swing.JScrollPane jScrollPane4;
|
||||
private javax.swing.JTable jTableParams;
|
||||
private javax.swing.JTextField txtDeviceDescription;
|
||||
private javax.swing.JTextField txtDeviceName;
|
||||
private javax.swing.JTextArea txtTestDescription;
|
||||
private javax.swing.JTextField txtTestName;
|
||||
private javax.swing.JTextArea txtTestResult;
|
||||
private javax.swing.JTextField txtTestSuite;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
BIN
plugins/icons/settings-128px.png
Normal file
BIN
plugins/icons/settings-128px.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
BIN
plugins/icons/settings-32px.png
Normal file
BIN
plugins/icons/settings-32px.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 791 B |
BIN
plugins/icons/settings2-128px.png
Normal file
BIN
plugins/icons/settings2-128px.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
Reference in New Issue
Block a user