Files
ncs/plugins/TestingList.java
boccioli_m a3fb000b77 Closedown
2015-06-08 10:19:34 +02:00

226 lines
8.6 KiB
Java

/*
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
import ch.psi.pshell.dev.Motor;
import ch.psi.pshell.plot.LinePlotBase;
import ch.psi.pshell.plot.LinePlotJFree;
import ch.psi.pshell.plot.LinePlotSeries;
import ch.psi.pshell.plot.Plot;
import ch.psi.pshell.swing.MotorPanel;
import ch.psi.pshell.ui.App;
import ch.psi.utils.swing.MonitoredPanel;
import ch.psi.pshell.ui.Panel;
import ch.psi.utils.swing.SwingUtils;
import ch.psi.wsaf.ApplicationStateException;
import ch.psi.wsaf.Task;
import ch.psi.wsaf.TaskRunMode;
import ch.psi.wsaf.TaskRunningException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.table.DefaultTableModel;
public class TestingList extends Panel {
NetbeansPluginPanel testingList;
Task task = new Task() {
@Override
protected Object execute() throws Exception {
return true;
}
};
@Override
protected JPanel create() {
testingList = new NetbeansPluginPanel();
return testingList;
}
//listen to script end of execution and get return value
@Override
protected void onExecutedFile(String fileName) {
try {
switch(fileName){
case "power-supply":
Object ret = eval("ret");
boolean success = (boolean) eval("success");
Object deviceName = eval("deviceName");
Object testName = eval("testName");
String sSuccess = (success == true) ? "Success": "Fail";
if (ret != null) {
//SwingUtils.showMessage(getComponent(), "", ret.toString() + " - " + ret.getClass().getName());
testingList.showResult(deviceName.toString(), testName.toString(), ret.toString(), sSuccess);
}
break;
}
}
catch (Exception ex) {
SwingUtils.showException(getComponent(), ex);
}
}
public class NetbeansPluginPanel extends MonitoredPanel {
public NetbeansPluginPanel() {
initComponents();
buildTable();
}
@SuppressWarnings("unchecked")
public void showResult(String deviceName, String testName, String res, String success){
int COL_RESULT = 3;
int COL_SUCCESS = 4;
int rowD=-1, colT=-1;
//search for device name in table
for (int row = 0; row <= jTable1.getRowCount() - 1; row++) {
for (int col = 0; col <= jTable1.getColumnCount() - 1; col++) {
if (deviceName.equals(jTable1.getValueAt(row, col))) {
rowD = row;
break;
}
}
}
if (rowD>0){
//search for test name in table
for (int col = 0; col <= jTable1.getColumnCount() - 1; col++) {
if (testName.equals(jTable1.getValueAt(rowD, col))) {
colT = col;
break;
}
}
}
if(colT>0 && rowD>0){
jTable1.setValueAt(res, rowD, COL_RESULT);
jTable1.setValueAt(success, rowD, COL_SUCCESS);
}
}
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jButton1 = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
deviceStatePanel1 = new ch.psi.pshell.swing.DeviceStatePanel();
jButton1.setText("Test PS");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane2.setViewportView(jTable1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(244, 244, 244)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(213, 213, 213)
.addComponent(deviceStatePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jButton1)))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 783, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(25, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(42, 42, 42)
.addComponent(jButton1)
.addGap(28, 28, 28)
.addComponent(deviceStatePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(90, 90, 90)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(18, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
try {
boolean var1 = true;
int var2 = 2;// (Integer)spinner.getValue();
int result;
HashMap args = new HashMap();
args.put("relative", var1);
args.put("steps", var2);
run("power-supply", args);
for(int i=0 ; i<1000000 ; i++){}
//evalAsync("run('args', locals = {'relative':" + (var1 ? "True" :"False") + ", 'steps':" + var2 + "})");
} catch (Exception ex) {
SwingUtils.showException(this, ex);
}
}//GEN-LAST:event_jButton1ActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private ch.psi.pshell.swing.DeviceStatePanel deviceStatePanel1;
private javax.swing.JButton jButton1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTable jTable1;
// End of variables declaration//GEN-END:variables
//table with checkboxes
public void buildTable(){
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
String sDate = dateFormat.format(date);
Object[] columnNames = {"Time", "Device", "Test", "Result", "Status"};
Object[][] data = {
{sDate, "LS", "Check Status", "No comm", "Pending"},
{sDate, "RS", "Calibrate", "Calibration done", "Pending"},
{sDate, "MWD", "Display Test", "Sequence terminated", "Pending"},
{sDate, "FIXL", "Lamp Test", "Failure", "Pending"}
};
DefaultTableModel model = new DefaultTableModel(data, columnNames);
jTable1.setModel(model);
}
}
}