diff --git a/plugins/NewTest.form b/plugins/NewTest.form index 53da18f..53d2ed6 100644 --- a/plugins/NewTest.form +++ b/plugins/NewTest.form @@ -42,8 +42,8 @@ - - + + @@ -51,28 +51,35 @@ - - - - - - - - - - - - - - - + + + + + + + + + + - - + + + + + + + + + + + + + + @@ -92,13 +99,21 @@ - + - + - - + + + + + + + + + + @@ -114,6 +129,7 @@ + @@ -140,11 +156,26 @@ + + + + + + + + + + + + + + + @@ -155,6 +186,7 @@ + @@ -183,10 +215,19 @@ + + + + + + + + + diff --git a/plugins/NewTest.java b/plugins/NewTest.java index f6143b9..19cae87 100644 --- a/plugins/NewTest.java +++ b/plugins/NewTest.java @@ -5,6 +5,8 @@ import ch.psi.utils.swing.SwingUtils; import ch.psi.utils.swing.SwingUtils.OptionResult; import ch.psi.utils.swing.SwingUtils.OptionType; +import java.awt.Color; +import java.awt.Component; import java.awt.Desktop; import java.awt.Point; import java.awt.event.MouseAdapter; @@ -38,7 +40,24 @@ import org.apache.commons.io.FilenameUtils; * @author boccioli_m */ public class NewTest extends javax.swing.JPanel { - + /** + * constants declarations + */ + 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 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_TESTCONFIG_FILEPATH = Paths.get(".", "home", "script", "tests","templates","testTemplate.config"); + public static Path TEMPLATES_DEVICECONFIG_FILEPATH = Paths.get(".", "home", "script", "tests","templates","deviceTemplate.config"); + public static String TESTS_CONFIG_FILENAME = ".config"; + public static String TESTS_HELP_FILENAME = "help.html"; + public static String ALLOWED_CHARSET1 = "[a-z A-Z 0-9 . _ \\- \\[\\] () : , < > =]*"; //les restricted set of chars + public static String ALLOWED_CHARSET2 = "[a-z A-Z 0-9 . _ \\- \\[\\] ()]*"; //more restricted set of chars + public static String ALLOWED_CHARSET3 = "[a-zA-Z0-9._\\-]*"; //even more restricted set of chars + public static String NEW_TYPE_DEVICE = "Device"; + public static String NEW_TYPE_TEST = "Test"; + /** * Creates new form TestingListDetails */ @@ -69,10 +88,12 @@ public class NewTest extends javax.swing.JPanel { lblSuite = new javax.swing.JLabel(); lblParams = new javax.swing.JLabel(); lblDescr = new javax.swing.JLabel(); + lblContact = new javax.swing.JLabel(); txtTestName = new javax.swing.JTextField(); jComboBoxTestSuites = new javax.swing.JComboBox(); jScrollPane3 = new javax.swing.JScrollPane(); txtTestDescription = new javax.swing.JTextArea(); + txtContactName = new javax.swing.JTextField(); jScrollPane1 = new javax.swing.JScrollPane(); jTableParams = new javax.swing.JTable(); jPanel1 = new javax.swing.JPanel(); @@ -96,6 +117,7 @@ public class NewTest extends javax.swing.JPanel { lblName.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N lblName.setText("Name *"); + lblName.setToolTipText("Test Name"); lblSuite.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N lblSuite.setText("Test Case/Suite *"); @@ -106,9 +128,16 @@ public class NewTest extends javax.swing.JPanel { lblDescr.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N lblDescr.setText("Description *"); + lblContact.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N + lblContact.setText("Contact person *"); + txtTestName.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N + txtTestName.setToolTipText(""); + txtTestName.setMinimumSize(new java.awt.Dimension(30, 23)); + txtTestName.setPreferredSize(new java.awt.Dimension(60, 23)); jComboBoxTestSuites.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N + jComboBoxTestSuites.setToolTipText("Select a Test Suite or add a new one"); jComboBoxTestSuites.setMinimumSize(new java.awt.Dimension(31, 26)); jComboBoxTestSuites.setPreferredSize(new java.awt.Dimension(31, 26)); @@ -118,8 +147,12 @@ public class NewTest extends javax.swing.JPanel { txtTestDescription.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N txtTestDescription.setLineWrap(true); txtTestDescription.setRows(5); + txtTestDescription.setToolTipText("Add here a detailed description"); jScrollPane3.setViewportView(txtTestDescription); + txtContactName.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N + txtContactName.setToolTipText("Write a user name"); + jTableParams.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N jTableParams.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { @@ -184,22 +217,27 @@ public class NewTest extends javax.swing.JPanel { .addGap(1, 1, 1)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(lblParams) - .addComponent(lblDescr)) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGap(19, 19, 19) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 513, Short.MAX_VALUE) - .addComponent(txtTestName, javax.swing.GroupLayout.DEFAULT_SIZE, 513, Short.MAX_VALUE) - .addComponent(jComboBoxTestSuites, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addGroup(layout.createSequentialGroup() + .addComponent(lblParams) .addGap(18, 18, 18) - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 513, Short.MAX_VALUE) - .addGap(1, 1, 1))) + .addComponent(jScrollPane1)) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(lblName) + .addComponent(lblSuite)) + .addGap(0, 0, Short.MAX_VALUE))) .addGap(12, 12, 12)) - .addComponent(lblName) - .addComponent(lblSuite))) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(lblDescr) + .addComponent(lblContact)) + .addGap(10, 10, 10) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(txtTestName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jComboBoxTestSuites, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(txtContactName)) + .addGap(12, 12, 12)))) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -214,12 +252,18 @@ public class NewTest extends javax.swing.JPanel { .addComponent(jComboBoxTestSuites, 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(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE) .addComponent(lblDescr)) - .addGap(18, 18, 18) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(lblParams) - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)) + .addComponent(txtContactName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(lblContact)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(lblParams) + .addGap(0, 132, Short.MAX_VALUE)) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) @@ -258,29 +302,13 @@ public class NewTest extends javax.swing.JPanel { model.removeRow(row); } }//GEN-LAST:event_jMenuItemDeleteRowActionPerformed - - /** - * constants declarations - */ - 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_TESTCONFIG_FILEPATH = Paths.get(".", "home", "script", "tests","templates","testTemplate.config"); - public static Path TEMPLATES_DEVICECONFIG_FILEPATH = Paths.get(".", "home", "script", "tests","templates","deviceTemplate.config"); - public static String ALLOWED_CHARS = "[a-zA-Z0-9._\\-\\]\\[(){} ]*"; - public static String NEW_TYPE_DEVICE = "Device"; - public static String NEW_TYPE_TEST = "Test"; - + /** * fill table with example parameters * @param newType the new can be NEW_TYPE_DEVICE or NEW_TYPE_TEST. */ private void fillComponents(String newType) { - + // listener for mouse-click also on table header jTableParams.getTableHeader().addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { @@ -294,9 +322,13 @@ public class NewTest extends javax.swing.JPanel { if(newType == NEW_TYPE_DEVICE){ this.lblDescr.setText(newType + " "+ this.lblDescr.getText()); this.lblName.setText( newType + " "+ this.lblName.getText()); + this.lblName.setToolTipText(newType + " name. Can be a PV name."); + this.txtTestName.setToolTipText(newType + " name. Can be a PV name."); lblParams.setVisible(false); jTableParams.setVisible(false); jScrollPane1.setVisible(false); + lblContact.setVisible(false); + txtContactName.setVisible(false); } //fill test suites combo box @@ -354,7 +386,7 @@ public class NewTest extends javax.swing.JPanel { Logger.getLogger(NewTest.class.getName()).log(Level.SEVERE, null, ex); } } - + } /** @@ -419,12 +451,27 @@ public class NewTest extends javax.swing.JPanel { "Please fill-in all compulsory fields (marked with *)"); return false; } - if(!(txtTestName.getText().matches(ALLOWED_CHARS) && - txtTestDescription.getText().matches(ALLOWED_CHARS) && - jComboBoxTestSuites.getSelectedItem().toString().matches(ALLOWED_CHARS) + if(sType.equals(NEW_TYPE_TEST) && this.txtContactName.getText().isEmpty()){ + SwingUtils.showMessage(this, "checkDataFields()", + "Please write a user name in the field Contact person"); + return false; + } + String allowedChars = ALLOWED_CHARSET2; + if (sType.equals(NEW_TYPE_DEVICE)){ + allowedChars = ALLOWED_CHARSET1; + } + if(!(txtTestName.getText().matches(allowedChars) && + txtTestDescription.getText().matches(ALLOWED_CHARSET1) && + jComboBoxTestSuites.getSelectedItem().toString().matches(allowedChars) )){ SwingUtils.showMessage(this, "checkDataFields()", - "Please remove forbidden chars: only letters, numbers, parenthesis are allowed"); + "Please remove forbidden chars; allowed are: "+ allowedChars.replace("\\", "").replace("*", "")); + return false; + } + if(!(txtContactName.getText().matches(ALLOWED_CHARSET3) + )){ + SwingUtils.showMessage(this, "checkDataFields()", + "Please provide a valid user name"); return false; } //check parameters table @@ -436,12 +483,12 @@ public class NewTest extends javax.swing.JPanel { 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)) + if(!(sParam.matches(ALLOWED_CHARSET2) && + sVal.matches(ALLOWED_CHARSET2) && + sDescr.matches(ALLOWED_CHARSET2)) ){ SwingUtils.showMessage(this, "checkDataFields()", - "Please remove forbidden chars from parameters table: only letters, numbers, parenthesis are allowed"); + "Please remove forbidden chars from parameters table; allowed are: "+ ALLOWED_CHARSET2.replace("\\", "").replace("*", "")); return false; } } @@ -462,6 +509,7 @@ public class NewTest extends javax.swing.JPanel { }else{ generateTestFiles(this.txtTestName.getText(), this.txtTestDescription.getText(), + this.txtContactName.getText(), this.jComboBoxTestSuites.getSelectedItem().toString(), hmTestParams); } @@ -477,11 +525,12 @@ public class NewTest extends javax.swing.JPanel { */ public void generateTestFiles(String sTestName, String sTestDescription, + String sContactName, 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); + Path testSuiteDir = Paths.get(TESTS_TESTS_DEFAULT_DIR.toString(),cleanFileName(sTestSuite)); if( !testSuiteDir.toFile().isDirectory()){ boolean success = testSuiteDir.toFile().mkdirs(); if (!success) { @@ -491,7 +540,7 @@ public class NewTest extends javax.swing.JPanel { } } //new test directory inside tests suite dir - Path testDir = Paths.get(testSuiteDir.toString(),sTestName); + Path testDir = Paths.get(testSuiteDir.toString(),cleanFileName(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); @@ -517,6 +566,7 @@ public class NewTest extends javax.swing.JPanel { if (!generateTestHelp(testDir, sTestName, sTestDescription, + sContactName, sTestSuite, hmTestParams)) return; if (!generateTestScript(testDir, @@ -546,7 +596,7 @@ public class NewTest extends javax.swing.JPanel { HashMap hmTestParams){ if (TESTS_DEVICES_DEFAULT_DIR.toFile().isDirectory()) { //new device directory inside tests suite dir - Path testDir = Paths.get(TESTS_DEVICES_DEFAULT_DIR.toString(),sTestName); + Path testDir = Paths.get(TESTS_DEVICES_DEFAULT_DIR.toString(),cleanFileName(sTestName)); if( testDir.toFile().isDirectory()){ //device already exists: ask to overwrite OptionResult res = SwingUtils.showOption(this, "Overwrite Device?", "Device already exists. Overwrite with this new one?", OptionType.YesNo); @@ -592,7 +642,7 @@ public class NewTest extends javax.swing.JPanel { String sTestSuite, HashMap hmTestParams){ boolean success = false; - Path path = Paths.get(testDir + FilenameUtils.separatorsToSystem("/"+sTestName+".py")); + Path path = Paths.get(testDir.toString(), cleanFileName(sTestName+".py")); try { if(Files.exists(path)){ Files.delete(path); @@ -645,7 +695,7 @@ public class NewTest extends javax.swing.JPanel { //generate test config file from template boolean success = false; try { - Path path = Paths.get(testDir + FilenameUtils.separatorsToSystem("/"+TESTS_CONFIG_FILENAME)); + Path path = Paths.get(testDir.toString(),TESTS_CONFIG_FILENAME); if(Files.exists(path)){ Files.delete(path); } @@ -674,12 +724,13 @@ public class NewTest extends javax.swing.JPanel { //creation of device config props.setProperty("name", sTestName); props.setProperty("description", sTestDescription); - props.setProperty("parameters", sTestParameters); + props.setProperty("tests", sTestSuite); }else{ //creation of test config props.setProperty("name", sTestName); props.setProperty("description", sTestDescription); - props.setProperty("tests", sTestSuite); + props.setProperty("parameters", sTestParameters); + } props.store(out, null); out.close(); @@ -708,10 +759,11 @@ public class NewTest extends javax.swing.JPanel { public boolean generateTestHelp(Path testDir, String sTestName, String sTestDescription, + String sContactName, String sTestSuite, HashMap hmTestParams){ //generate test config file from template - Path path = Paths.get(testDir + FilenameUtils.separatorsToSystem("/"+TESTS_HELP_FILENAME)); + Path path = Paths.get(testDir.toString(),TESTS_HELP_FILENAME); boolean success = false; try { if(Files.exists(path)){ @@ -733,8 +785,8 @@ public class NewTest extends javax.swing.JPanel { } } success = replaceParameters(path, - new String[]{"$testName","$testDescription","$testParameters"}, - new String[]{sTestName,sTestDescription,sTestParameters}); + new String[]{"$testName","$testDescription","$testParameters","$contactName"}, + new String[]{sTestName,sTestDescription,sTestParameters,sContactName}); } catch (IOException ex) { SwingUtils.showMessage(this, "generateTestHelp()", "Cannot create directory " + ex.toString()); @@ -777,6 +829,16 @@ public class NewTest extends javax.swing.JPanel { } return success; } + + /** + * remove forbidden file system characters from file name, replace them with "-" + * + * @param sName text to be cleaned + * @return cleaned text + */ + private String cleanFileName(String sName){ + return sName.replace(":", "-"); + } @@ -790,10 +852,12 @@ public class NewTest extends javax.swing.JPanel { private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JTable jTableParams; + private javax.swing.JLabel lblContact; private javax.swing.JLabel lblDescr; private javax.swing.JLabel lblName; private javax.swing.JLabel lblParams; private javax.swing.JLabel lblSuite; + private javax.swing.JTextField txtContactName; private javax.swing.JTextArea txtTestDescription; private javax.swing.JTextField txtTestName; // End of variables declaration//GEN-END:variables diff --git a/plugins/TestingList.java b/plugins/TestingList.java index 015f6f0..adf480d 100644 --- a/plugins/TestingList.java +++ b/plugins/TestingList.java @@ -920,7 +920,7 @@ public class TestingList extends Panel { */ public void openNewTestEditor(String type){ try { - JDialog dlg = new JDialog(getView(), "New Test", true); + JDialog dlg = new JDialog(getView(), "New "+ type, true); //create a class to visualise the details panel Class testingListDetailsClass = getController().getClassByName("NewTest"); JPanel detailsPanel = (JPanel) testingListDetailsClass.getConstructor(new Class[]{String.class}).newInstance(new Object[]{type}); @@ -991,12 +991,17 @@ public class TestingList extends Panel { private void moveUp() { DefaultTableModel model = (DefaultTableModel) jTable1.getModel(); int[] rows = jTable1.getSelectedRows(); - if (rows[0] - 1 >= 0) { - jTable1.setAutoCreateRowSorter(false); - model.moveRow(rows[0], rows[rows.length - 1], rows[0] - 1); - jTable1.setAutoCreateRowSorter(true); - jTable1.setRowSelectionInterval(rows[0] - 1, rows[rows.length - 1] - 1); + try{ + if (rows[0] - 1 >= 0) { + jTable1.setAutoCreateRowSorter(false); + model.moveRow(rows[0], rows[rows.length - 1], rows[0] - 1); + jTable1.setAutoCreateRowSorter(true); + jTable1.setRowSelectionInterval(rows[0] - 1, rows[rows.length - 1] - 1); + } } + catch(Exception ex){ + //fail silently + } } /** @@ -1005,11 +1010,16 @@ public class TestingList extends Panel { private void moveDown() { DefaultTableModel model = (DefaultTableModel) jTable1.getModel(); int[] rows = jTable1.getSelectedRows(); - if (rows[rows.length - 1] < jTable1.getRowCount()) { - jTable1.setAutoCreateRowSorter(false); - model.moveRow(rows[0], rows[rows.length - 1], rows[0] + 1); - jTable1.setAutoCreateRowSorter(true); - jTable1.setRowSelectionInterval(rows[0] + 1, rows[rows.length - 1] + 1); + try{ + if (rows[rows.length - 1] < jTable1.getRowCount()) { + jTable1.setAutoCreateRowSorter(false); + model.moveRow(rows[0], rows[rows.length - 1], rows[0] + 1); + jTable1.setAutoCreateRowSorter(true); + jTable1.setRowSelectionInterval(rows[0] + 1, rows[rows.length - 1] + 1); + } + } + catch(Exception ex){ + //fail silently } } diff --git a/script/tests/config/testConfig2 b/script/tests/config/testConfig2 deleted file mode 100644 index 83ceec3..0000000 Binary files a/script/tests/config/testConfig2 and /dev/null differ diff --git a/script/tests/templates/helpTemplate.html b/script/tests/templates/helpTemplate.html index 16eaee5..527a061 100644 --- a/script/tests/templates/helpTemplate.html +++ b/script/tests/templates/helpTemplate.html @@ -7,7 +7,7 @@ Add here the detailed description of the test, with reference to the parameters

Parameters

$testParameters

Contact

-Contact Person +$contactName