Startup
This commit is contained in:
351
plugins/EditTestingListNew.java
Normal file
351
plugins/EditTestingListNew.java
Normal file
@@ -0,0 +1,351 @@
|
||||
/*
|
||||
* Copyright (c) 2015 Paul Scherrer Institute. All rights reserved.
|
||||
*/
|
||||
|
||||
import ch.psi.utils.swing.SwingUtils;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
import java.util.Vector;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import javax.swing.table.TableModel;
|
||||
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 EditTestingListNew extends javax.swing.JPanel {
|
||||
|
||||
/**
|
||||
* Creates new form TestingListDetails
|
||||
*/
|
||||
public EditTestingListNew() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
public EditTestingListNew(TableModel hDetails) {
|
||||
initComponents();
|
||||
//fillComponents(hDetails);
|
||||
loadTests();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
|
||||
jPanel1 = new javax.swing.JPanel();
|
||||
jScrollPane2 = new javax.swing.JScrollPane();
|
||||
jList2 = new javax.swing.JList();
|
||||
jScrollPane5 = new javax.swing.JScrollPane();
|
||||
jTable1 = new javax.swing.JTable();
|
||||
jPanel2 = new javax.swing.JPanel();
|
||||
cmDefault = new javax.swing.JButton();
|
||||
cmCancel = new javax.swing.JButton();
|
||||
cmOk = new javax.swing.JButton();
|
||||
|
||||
setPreferredSize(new java.awt.Dimension(963, 556));
|
||||
setLayout(new java.awt.BorderLayout());
|
||||
|
||||
jPanel1.setPreferredSize(new java.awt.Dimension(963, 556));
|
||||
jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1, javax.swing.BoxLayout.LINE_AXIS));
|
||||
|
||||
jScrollPane2.setMaximumSize(new java.awt.Dimension(4000, 32767));
|
||||
jScrollPane2.setMinimumSize(new java.awt.Dimension(100, 27));
|
||||
jScrollPane2.setPreferredSize(new java.awt.Dimension(100, 146));
|
||||
|
||||
jList2.setModel(new javax.swing.AbstractListModel() {
|
||||
String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
|
||||
public int getSize() { return strings.length; }
|
||||
public Object getElementAt(int i) { return strings[i]; }
|
||||
});
|
||||
jList2.setMaximumSize(new java.awt.Dimension(0, 0));
|
||||
jList2.setMinimumSize(new java.awt.Dimension(0, 0));
|
||||
jScrollPane2.setViewportView(jList2);
|
||||
|
||||
jPanel1.add(jScrollPane2);
|
||||
|
||||
jScrollPane5.setMinimumSize(new java.awt.Dimension(300, 300));
|
||||
|
||||
jTable1.setFont(new java.awt.Font("Tahoma", 0, 15)); // NOI18N
|
||||
jTable1.setModel(new javax.swing.table.DefaultTableModel(
|
||||
new Object [][] {
|
||||
|
||||
},
|
||||
new String [] {
|
||||
"Select", "Start", "Device Name", "Device Description", "Test Suite", "Test Name", "Test Peth", "Test Description",
|
||||
}
|
||||
) {
|
||||
Class[] types = new Class [] {
|
||||
java.lang.Boolean.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class
|
||||
};
|
||||
boolean[] canEdit = new boolean [] {
|
||||
true, true, false, false, false, false, false, false
|
||||
};
|
||||
|
||||
public Class getColumnClass(int columnIndex) {
|
||||
return types [columnIndex];
|
||||
}
|
||||
|
||||
public boolean isCellEditable(int rowIndex, int columnIndex) {
|
||||
return canEdit [columnIndex];
|
||||
}
|
||||
});
|
||||
jTable1.setColumnSelectionAllowed(true);
|
||||
jTable1.setDragEnabled(true);
|
||||
jTable1.setDropMode(javax.swing.DropMode.INSERT);
|
||||
jTable1.setRowHeight(22);
|
||||
jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
|
||||
public void mouseClicked(java.awt.event.MouseEvent evt) {
|
||||
jTable1MouseClicked(evt);
|
||||
}
|
||||
});
|
||||
jTable1.addKeyListener(new java.awt.event.KeyAdapter() {
|
||||
public void keyReleased(java.awt.event.KeyEvent evt) {
|
||||
jTable1KeyReleased(evt);
|
||||
}
|
||||
});
|
||||
jScrollPane5.setViewportView(jTable1);
|
||||
jTable1.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
|
||||
|
||||
jPanel1.add(jScrollPane5);
|
||||
|
||||
add(jPanel1, java.awt.BorderLayout.CENTER);
|
||||
|
||||
jPanel2.setPreferredSize(new java.awt.Dimension(263, 50));
|
||||
|
||||
cmDefault.setText("Save as Default");
|
||||
this.cmCancel.setVisible(false);
|
||||
this.cmOk.setVisible(false);
|
||||
this.cmDefault.setVisible(false);
|
||||
cmDefault.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
cmDefaultActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
|
||||
jPanel2.setLayout(jPanel2Layout);
|
||||
jPanel2Layout.setHorizontalGroup(
|
||||
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel2Layout.createSequentialGroup()
|
||||
.addComponent(cmDefault, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 223, Short.MAX_VALUE)
|
||||
.addComponent(cmOk, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(32, 32, 32)
|
||||
.addComponent(cmCancel))
|
||||
);
|
||||
jPanel2Layout.setVerticalGroup(
|
||||
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel2Layout.createSequentialGroup()
|
||||
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(cmCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(cmOk, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(cmDefault, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(25, 25, 25))
|
||||
);
|
||||
|
||||
add(jPanel2, java.awt.BorderLayout.SOUTH);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void fillComponents(TableModel hDetails) {
|
||||
jTable1.setModel(hDetails);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Load test list from file
|
||||
*
|
||||
* @param file file containing the settings
|
||||
*/
|
||||
private void loadSettings(String sFileName) {
|
||||
final JFileChooser fc = new JFileChooser();
|
||||
File file = new File(sFileName);
|
||||
if (file.isFile()){
|
||||
DefaultTableModel tableModel = (DefaultTableModel) jTable1.getModel();
|
||||
try {
|
||||
ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
|
||||
Vector rowData = (Vector) in.readObject();
|
||||
Iterator itr = rowData.iterator();
|
||||
//clear table
|
||||
tableModel.getDataVector().removeAllElements();
|
||||
tableModel.fireTableDataChanged();
|
||||
//rewrite table
|
||||
while (itr.hasNext()) {
|
||||
tableModel.addRow((Vector) itr.next());
|
||||
}
|
||||
in.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
SwingUtils.showMessage(this, "loadSettings()", ex.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* scan tests directory, scan devices directory, search for their test cases
|
||||
* and scan for tests.
|
||||
*
|
||||
* @throws FileNotFoundException
|
||||
* @throws IOException
|
||||
*/
|
||||
public void loadTests() {
|
||||
try {
|
||||
Properties propDevice = new Properties();
|
||||
Properties propTest = new Properties();
|
||||
//String fileName = TESTS_DEVICES_DEFAULT_DIR;
|
||||
//File folder = new File(fileName);
|
||||
TestingList testingList = new TestingList();
|
||||
|
||||
File testsFolder = null;
|
||||
String sTestName;
|
||||
int iCounter = 0;
|
||||
//search devices and their tests
|
||||
//Scan the list of devices
|
||||
File[] listOfFiles = (testingList.TESTS_DEVICES_DEFAULT_DIR.toFile()).listFiles();
|
||||
for (File listOfFile : listOfFiles) {
|
||||
propDevice.clear();
|
||||
if (listOfFile.isFile()) {
|
||||
} else if (listOfFile.isDirectory()) {
|
||||
File configFile = new File(listOfFile.getPath() + FilenameUtils.separatorsToSystem("/.config"));
|
||||
if (configFile.exists() && !configFile.isDirectory()) {
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = new FileInputStream(configFile);
|
||||
} catch (FileNotFoundException ex) {
|
||||
Logger.getLogger(EditTestingList.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
if(is != null){
|
||||
try {
|
||||
propDevice.load(is);
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(EditTestingList.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
//config of device was loaded. now load the config of each test belonging to the device
|
||||
//sTestName = TESTS_TESTS_DEFAULT_DIR + propDevice.getProperty("tests");
|
||||
//testsFolder = new File(sTestName);
|
||||
testsFolder = Paths.get(testingList.TESTS_TESTS_DEFAULT_DIR.toString(), propDevice.getProperty("tests")).toFile();
|
||||
if (testsFolder.exists() && testsFolder.isDirectory()) {
|
||||
File[] listOfTests = testsFolder.listFiles();
|
||||
for (File listOfTest : listOfTests) {
|
||||
propTest.clear();
|
||||
if (listOfTest.isDirectory()) {
|
||||
configFile = new File(listOfTest.getPath() + FilenameUtils.separatorsToSystem("/.config"));
|
||||
if (configFile.exists() && !configFile.isDirectory()) {
|
||||
InputStream ist = null;
|
||||
try {
|
||||
ist = new FileInputStream(configFile);
|
||||
} catch (FileNotFoundException ex) {
|
||||
Logger.getLogger(EditTestingList.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
try {
|
||||
propTest.load(ist);
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(EditTestingList.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
addToTable("",
|
||||
propDevice.getProperty("name"),
|
||||
propDevice.getProperty("description"),
|
||||
propDevice.getProperty("tests"),
|
||||
"path",
|
||||
propTest.getProperty("name"),
|
||||
propTest.getProperty("parameters"));
|
||||
iCounter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
SwingUtils.showMessage(this, "loadTests()", "Could not find any test");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(EditTestingList.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
|
||||
if (this.jTable1.isEnabled()) {
|
||||
try {
|
||||
switch (evt.getClickCount()) {
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
SwingUtils.showException(this, ex);
|
||||
}
|
||||
}
|
||||
}//GEN-LAST:event_jTable1MouseClicked
|
||||
|
||||
private void jTable1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyReleased
|
||||
|
||||
}//GEN-LAST:event_jTable1KeyReleased
|
||||
|
||||
private void cmCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmCancelActionPerformed
|
||||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_cmCancelActionPerformed
|
||||
|
||||
private void cmDefaultActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmDefaultActionPerformed
|
||||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_cmDefaultActionPerformed
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton cmCancel;
|
||||
private javax.swing.JButton cmDefault;
|
||||
private javax.swing.JButton cmOk;
|
||||
private javax.swing.JList jList2;
|
||||
private javax.swing.JPanel jPanel1;
|
||||
private javax.swing.JPanel jPanel2;
|
||||
private javax.swing.JScrollPane jScrollPane2;
|
||||
private javax.swing.JScrollPane jScrollPane5;
|
||||
private javax.swing.JTable jTable1;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
private void addToTable(String property, String property0, String property1, String property2, String property3, String property4, String property5) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user