Closedown
This commit is contained in:
@@ -35,12 +35,16 @@ import java.util.Vector;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.FileHandler;
|
||||
import java.util.logging.SimpleFormatter;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
import javax.swing.DefaultCellEditor;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.RowFilter;
|
||||
import javax.swing.filechooser.FileSystemView;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
import javax.swing.table.TableModel;
|
||||
import javax.swing.table.TableRowSorter;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.python.core.PyList;
|
||||
import static org.python.bouncycastle.util.Arrays.append;
|
||||
@@ -52,8 +56,6 @@ import static org.python.bouncycastle.util.Arrays.append;
|
||||
*/
|
||||
public class TestingList extends Panel {
|
||||
|
||||
TableModel fullTable; //all tests are in this table model
|
||||
TableModel partialTable; //only tests selected are in this table model
|
||||
Task task = new Task() {
|
||||
@Override
|
||||
protected Object execute() throws Exception {
|
||||
@@ -243,7 +245,8 @@ public class TestingList extends Panel {
|
||||
//these paths are converted to unix or win path according to host OS
|
||||
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 final Path TESTS_LOG_DEFAULT_DIR = Paths.get(".","home", "script", "tests", "log", "TestsLog"+ getnow() + ".txt");
|
||||
public static Path TESTS_CONFIG_DEFAULT_DIR = Paths.get(".","home", "script", "tests", "comfig");
|
||||
public final Path TESTS_LOG_DEFAULT_DIR = Paths.get(".","home", "script", "tests", "log", "TestsLog"+ getnow() + ".txt");
|
||||
|
||||
|
||||
private void log(Object text){
|
||||
@@ -279,22 +282,41 @@ public class TestingList extends Panel {
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
jPopupMenuOptions = new javax.swing.JPopupMenu();
|
||||
jCheckBoxMenuShowSelectedTests = new javax.swing.JCheckBoxMenuItem();
|
||||
jMenuItemOpenLog = new javax.swing.JMenuItem();
|
||||
jScrollPane2 = new javax.swing.JScrollPane();
|
||||
jTable1 = new javax.swing.JTable();
|
||||
jPanel1 = new javax.swing.JPanel();
|
||||
jButtonRun = new javax.swing.JButton();
|
||||
jPanel3 = new javax.swing.JPanel();
|
||||
jButtonOpenLog = new javax.swing.JButton();
|
||||
jButtonOpen = new javax.swing.JButton();
|
||||
jButtonShowCheckedOnly = new javax.swing.JButton();
|
||||
jButtonSave = new javax.swing.JButton();
|
||||
jButton1 = new javax.swing.JButton();
|
||||
jButtonOpen = new javax.swing.JButton();
|
||||
jPanel2 = new javax.swing.JPanel();
|
||||
jCheckBox1 = new javax.swing.JCheckBox();
|
||||
jButtonMoveDown = new javax.swing.JButton();
|
||||
jButtonMoveUp = new javax.swing.JButton();
|
||||
|
||||
jCheckBoxMenuShowSelectedTests.setText("Show selected tests only");
|
||||
jCheckBoxMenuShowSelectedTests.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jCheckBoxMenuShowSelectedTestsActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jPopupMenuOptions.add(jCheckBoxMenuShowSelectedTests);
|
||||
|
||||
jMenuItemOpenLog.setText("Open Log");
|
||||
jMenuItemOpenLog.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jMenuItemOpenLogActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jPopupMenuOptions.add(jMenuItemOpenLog);
|
||||
|
||||
setLayout(new java.awt.BorderLayout());
|
||||
|
||||
jTable1.setAutoCreateRowSorter(true);
|
||||
jTable1.setFont(new java.awt.Font("Tahoma", 0, 15)); // NOI18N
|
||||
jTable1.setModel(new javax.swing.table.DefaultTableModel(
|
||||
new Object [][] {
|
||||
@@ -355,26 +377,13 @@ public class TestingList extends Panel {
|
||||
|
||||
jPanel3.setLayout(new java.awt.BorderLayout());
|
||||
|
||||
jButtonOpenLog.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/logbook-64px.png"))); // NOI18N
|
||||
jButtonOpenLog.setToolTipText("Open current sessions Log");
|
||||
jButtonOpenLog.setMaximumSize(new java.awt.Dimension(80, 39));
|
||||
jButtonOpenLog.setMinimumSize(new java.awt.Dimension(90, 90));
|
||||
jButtonOpenLog.setPreferredSize(new java.awt.Dimension(90, 70));
|
||||
jButtonOpenLog.addActionListener(new java.awt.event.ActionListener() {
|
||||
jButtonShowCheckedOnly.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/settings-32px.png"))); // NOI18N
|
||||
jButtonShowCheckedOnly.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButtonOpenLogActionPerformed(evt);
|
||||
jButtonShowCheckedOnlyActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jPanel3.add(jButtonOpenLog, java.awt.BorderLayout.SOUTH);
|
||||
|
||||
jButtonOpen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/folder-open-24-000000.png"))); // NOI18N
|
||||
jButtonOpen.setToolTipText("Open configuration");
|
||||
jButtonOpen.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButtonOpenActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jPanel3.add(jButtonOpen, java.awt.BorderLayout.CENTER);
|
||||
jPanel3.add(jButtonShowCheckedOnly, java.awt.BorderLayout.LINE_START);
|
||||
|
||||
jButtonSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/android-save-24-000000.png"))); // NOI18N
|
||||
jButtonSave.setToolTipText("Save current configuration");
|
||||
@@ -385,13 +394,15 @@ public class TestingList extends Panel {
|
||||
});
|
||||
jPanel3.add(jButtonSave, java.awt.BorderLayout.LINE_END);
|
||||
|
||||
jButton1.setText("+");
|
||||
jButton1.addActionListener(new java.awt.event.ActionListener() {
|
||||
jButtonOpen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/folder-open-24-000000.png"))); // NOI18N
|
||||
jButtonOpen.setToolTipText("Open configuration");
|
||||
jButtonOpen.setPreferredSize(new java.awt.Dimension(33, 50));
|
||||
jButtonOpen.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton1ActionPerformed(evt);
|
||||
jButtonOpenActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jPanel3.add(jButton1, java.awt.BorderLayout.LINE_START);
|
||||
jPanel3.add(jButtonOpen, java.awt.BorderLayout.PAGE_END);
|
||||
|
||||
jPanel1.add(jPanel3, java.awt.BorderLayout.EAST);
|
||||
|
||||
@@ -497,23 +508,6 @@ public class TestingList extends Panel {
|
||||
}
|
||||
}//GEN-LAST:event_jTable1MouseClicked
|
||||
|
||||
//oopen the log file using one of th default OS text reades
|
||||
private void jButtonOpenLogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOpenLogActionPerformed
|
||||
String cmd;
|
||||
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
|
||||
cmd = "notepad.exe " + TESTS_LOG_DEFAULT_DIR;
|
||||
} else {
|
||||
cmd = "nedit " + TESTS_LOG_DEFAULT_DIR;
|
||||
}
|
||||
try {
|
||||
Runtime.getRuntime().exec(cmd);
|
||||
} catch (IOException ex) {
|
||||
SwingUtils.showMessage(this, "jButtonOpenLogActionPerformed()", "jButtonOpenLogActionPerformed() " + ex.toString()
|
||||
+ " \nPlease open the file manually. \nFile dir: " + TESTS_LOG_DEFAULT_DIR);
|
||||
Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}//GEN-LAST:event_jButtonOpenLogActionPerformed
|
||||
|
||||
private void jTable1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyReleased
|
||||
updateStatus();
|
||||
}//GEN-LAST:event_jTable1KeyReleased
|
||||
@@ -549,60 +543,98 @@ public class TestingList extends Panel {
|
||||
saveSettings();
|
||||
}//GEN-LAST:event_jButtonSaveActionPerformed
|
||||
|
||||
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
|
||||
try {
|
||||
//openListEditor();
|
||||
if(jButton1.getText() == "+"){
|
||||
showDeselectedTests(true);
|
||||
jButton1.setText("-");
|
||||
}
|
||||
else{
|
||||
showDeselectedTests(false);
|
||||
jButton1.setText("+");
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
SwingUtils.showException(null, ex);
|
||||
private void jButtonShowCheckedOnlyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonShowCheckedOnlyActionPerformed
|
||||
jPopupMenuOptions.show(jButtonShowCheckedOnly,0,jButtonShowCheckedOnly.getHeight());
|
||||
}//GEN-LAST:event_jButtonShowCheckedOnlyActionPerformed
|
||||
|
||||
private void jCheckBoxMenuShowSelectedTestsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxMenuShowSelectedTestsActionPerformed
|
||||
// TODO add your handling code here:
|
||||
showSelectedTestsOnly(jCheckBoxMenuShowSelectedTests.getState());
|
||||
}//GEN-LAST:event_jCheckBoxMenuShowSelectedTestsActionPerformed
|
||||
|
||||
private void jMenuItemOpenLogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemOpenLogActionPerformed
|
||||
// TODO add your handling code here:
|
||||
String cmd;
|
||||
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
|
||||
cmd = "notepad.exe " + TESTS_LOG_DEFAULT_DIR;
|
||||
} else {
|
||||
cmd = "nedit " + TESTS_LOG_DEFAULT_DIR;
|
||||
}
|
||||
}//GEN-LAST:event_jButton1ActionPerformed
|
||||
try {
|
||||
Runtime.getRuntime().exec(cmd);
|
||||
} catch (IOException ex) {
|
||||
SwingUtils.showMessage(this, "jButtonOpenLogActionPerformed()", "jButtonOpenLogActionPerformed() " + ex.toString()
|
||||
+ " \nPlease open the file manually. \nFile dir: " + TESTS_LOG_DEFAULT_DIR);
|
||||
Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}//GEN-LAST:event_jMenuItemOpenLogActionPerformed
|
||||
|
||||
//<editor-fold defaultstate="collapsed" desc="Witget Variables declaration">
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton jButton1;
|
||||
private javax.swing.JButton jButtonMoveDown;
|
||||
private javax.swing.JButton jButtonMoveUp;
|
||||
private javax.swing.JButton jButtonOpen;
|
||||
private javax.swing.JButton jButtonOpenLog;
|
||||
private javax.swing.JButton jButtonRun;
|
||||
private javax.swing.JButton jButtonSave;
|
||||
private javax.swing.JButton jButtonShowCheckedOnly;
|
||||
private javax.swing.JCheckBox jCheckBox1;
|
||||
private javax.swing.JCheckBoxMenuItem jCheckBoxMenuShowSelectedTests;
|
||||
private javax.swing.JMenuItem jMenuItemOpenLog;
|
||||
private javax.swing.JPanel jPanel1;
|
||||
private javax.swing.JPanel jPanel2;
|
||||
private javax.swing.JPanel jPanel3;
|
||||
private javax.swing.JPopupMenu jPopupMenuOptions;
|
||||
private javax.swing.JScrollPane jScrollPane2;
|
||||
private javax.swing.JTable jTable1;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
//</editor-fold>
|
||||
|
||||
private void showDeselectedTests(boolean show){
|
||||
|
||||
|
||||
jTable1.removeAll();
|
||||
|
||||
/**
|
||||
* filter table: show only rows selected (checkbox checked) for running.
|
||||
* @param show if false, show all tests. If true, show only selected tests.
|
||||
*/
|
||||
private void showSelectedTestsOnly(boolean show){
|
||||
if(show){
|
||||
buildTable();
|
||||
filterTests("true");
|
||||
}
|
||||
else{
|
||||
DefaultTableModel modelAll = (DefaultTableModel) jTable1.getModel();
|
||||
DefaultTableModel modelOnlySelected = modelAll;
|
||||
int rows = modelOnlySelected.getRowCount();
|
||||
for(int row=0 ; row<rows ; row++) {
|
||||
if(modelOnlySelected.getValueAt(row, COL.CHECK.ordinal()).toString()=="false"){
|
||||
modelOnlySelected.removeRow(row);
|
||||
rows--;
|
||||
}
|
||||
}
|
||||
filterTests("");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* filter table: show only rows containing the specified text.
|
||||
* @param filterText text for filtering; can be a regex pattern.
|
||||
*/
|
||||
private void filterTests(String filterText){
|
||||
TableModel model = new DefaultTableModel() {
|
||||
public Class getColumnClass(int column) {
|
||||
Class returnValue;
|
||||
if ((column >= 0) && (column < getColumnCount())) {
|
||||
returnValue = getValueAt(0, column).getClass();
|
||||
} else {
|
||||
returnValue = Object.class;
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
};
|
||||
model = jTable1.getModel();
|
||||
|
||||
final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
|
||||
jTable1.setRowSorter(sorter);
|
||||
if (filterText.length() == 0) {
|
||||
sorter.setRowFilter(null);
|
||||
} else {
|
||||
try {
|
||||
sorter.setRowFilter(RowFilter.regexFilter(filterText));
|
||||
} catch (PatternSyntaxException pse) {
|
||||
System.err.println("Bad regex pattern");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* returns whether or not the tests can run (Run launched by the user)
|
||||
*
|
||||
@@ -652,7 +684,7 @@ public class TestingList extends Panel {
|
||||
String sTestName = jTable1.getValueAt(row, COL.TESTNAME.ordinal()).toString();
|
||||
String sTestPath = String.valueOf(jTable1.getValueAt(row, COL.TESTPATH.ordinal()));
|
||||
String sTestCaseName = jTable1.getValueAt(row, COL.TESTSUITE.ordinal()).toString();
|
||||
String sTestDescription = jTable1.getValueAt(row, COL.TESTDESCR.ordinal()).toString();
|
||||
String sTestDescription = getTestDescription(sTestPath);
|
||||
String sDeviceDescription = jTable1.getValueAt(row, COL.DEVICEDESCR.ordinal()).toString();
|
||||
String sLastResult = jTable1.getValueAt(row, COL.RESULT.ordinal()).toString();
|
||||
String sResultTime = jTable1.getValueAt(row, COL.TIME.ordinal()).toString();
|
||||
@@ -1230,12 +1262,19 @@ public class TestingList extends Panel {
|
||||
if (testName.equals("") || deviceName.equals("")) {
|
||||
return;
|
||||
}
|
||||
ImageIcon icon = null;// new ImageIcon(getClass().getResource("/icons/button_pause-16px.png"));
|
||||
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
|
||||
//String testPath = FilenameUtils.separatorsToSystem(TESTS_TESTS_DEFAULT_DIR + testSuite + "/" + testName + "/" + testName + ".py");
|
||||
String testPath = Paths.get(TESTS_TESTS_DEFAULT_DIR.toString(), testSuite, testName, testName + ".py").toString();
|
||||
model.addRow(new Object[]{false, "", sDate, deviceName, deviceDescription, testSuite, testName, testPath, testParams, testDescription, testHelp, "", "Pending", icon});
|
||||
jTable1.setModel(model);
|
||||
try{
|
||||
ImageIcon icon = null;// new ImageIcon(getClass().getResource("/icons/button_pause-16px.png"));
|
||||
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
|
||||
//String testPath = FilenameUtils.separatorsToSystem(TESTS_TESTS_DEFAULT_DIR + testSuite + "/" + testName + "/" + testName + ".py");
|
||||
String testPath = Paths.get(TESTS_TESTS_DEFAULT_DIR.toString(), testSuite, testName, testName + ".py").toString();
|
||||
Object rowData[] = new Object[]{false, "", sDate, deviceName, deviceDescription, testSuite, testName, testPath, testParams, testDescription, testHelp, "", "Pending", icon};
|
||||
|
||||
model.addRow(rowData);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
SwingUtils.showMessage(this, "loadSettings()", ex.toString());
|
||||
}
|
||||
updateStatus();
|
||||
}
|
||||
|
||||
@@ -1304,8 +1343,8 @@ public class TestingList extends Panel {
|
||||
propDevice.getProperty("description"),
|
||||
propDevice.getProperty("tests"),
|
||||
propTest.getProperty("name"),
|
||||
propTest.getProperty("parameters"),
|
||||
propTest.getProperty("description"),
|
||||
"", //test parameters
|
||||
"", //test description
|
||||
propTest.getProperty("help"));
|
||||
iCounter++;
|
||||
}
|
||||
@@ -1346,6 +1385,15 @@ public class TestingList extends Panel {
|
||||
}
|
||||
|
||||
private HashMap getTestParameters(String sTestPath){
|
||||
String testParams = getConfigItem("parameters", sTestPath);
|
||||
return buildParametersMap(testParams);
|
||||
}
|
||||
|
||||
private String getTestDescription(String sTestPath){
|
||||
return getConfigItem("description", sTestPath);
|
||||
}
|
||||
|
||||
private String getConfigItem(String sParameterName, String sTestPath){
|
||||
Properties propTest = new Properties();
|
||||
File fileTest = new File(sTestPath);
|
||||
File dirTest = fileTest.getParentFile();
|
||||
@@ -1356,13 +1404,13 @@ public class TestingList extends Panel {
|
||||
try {
|
||||
InputStream ist = new FileInputStream(configFile);
|
||||
propTest.load(ist);
|
||||
testParams = propTest.getProperty("parameters");
|
||||
testParams = propTest.getProperty(sParameterName);
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
return buildParametersMap(testParams);
|
||||
return testParams;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1370,7 +1418,8 @@ public class TestingList extends Panel {
|
||||
* saved.
|
||||
*/
|
||||
public void saveSettings() {
|
||||
final JFileChooser fc = new JFileChooser();
|
||||
final FileSystemView fsv = new DirectoryRestrictedFileSystemView(TESTS_CONFIG_DEFAULT_DIR.toFile());
|
||||
JFileChooser fc = new JFileChooser(fsv.getHomeDirectory(),fsv);
|
||||
int returnVal = fc.showSaveDialog(this);
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
File file = fc.getSelectedFile();
|
||||
@@ -1406,6 +1455,8 @@ public class TestingList extends Panel {
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
File file = fc.getSelectedFile();
|
||||
loadSettings(file);
|
||||
jCheckBoxMenuShowSelectedTests.setSelected(true);
|
||||
this.showSelectedTestsOnly(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1435,5 +1486,53 @@ public class TestingList extends Panel {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* override FileSystemView in order to create a file system view restricted directory
|
||||
* so that user can only load/save settings on a specific directory
|
||||
*
|
||||
*/
|
||||
public class DirectoryRestrictedFileSystemView extends FileSystemView
|
||||
{
|
||||
private final File[] rootDirectories;
|
||||
|
||||
public DirectoryRestrictedFileSystemView(File rootDirectory)
|
||||
{
|
||||
this.rootDirectories = new File[] {rootDirectory};
|
||||
}
|
||||
|
||||
public DirectoryRestrictedFileSystemView(File[] rootDirectories)
|
||||
{
|
||||
this.rootDirectories = rootDirectories;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File createNewFolder(File containingDir) throws IOException
|
||||
{
|
||||
throw new UnsupportedOperationException("Unable to create directory");
|
||||
}
|
||||
|
||||
@Override
|
||||
public File[] getRoots()
|
||||
{
|
||||
return rootDirectories;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRoot(File file)
|
||||
{
|
||||
for (File root : rootDirectories) {
|
||||
if (root.equals(file)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getHomeDirectory()
|
||||
{
|
||||
return rootDirectories[0];
|
||||
}
|
||||
}
|
||||
//end of class
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user