/* * 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.Color; 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.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableModel; import org.fusesource.jansi.Ansi; 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 status){ int COL_RESULT = 4; int COL_SUCCESS = 5; int COL_ICON = 6; 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; } } } String iconSource = "/icons/button_help-16px.png"; switch(status){ case "Success": iconSource = "/icons/button_ok-16px.png"; break; case "Fail": iconSource = "/icons/button_delete-16px.png"; break; case "Running": iconSource = "/icons/button_play-16px.png"; break; } ImageIcon icon = new ImageIcon(getClass().getResource(iconSource)); jTable1.setValueAt(icon, rowD, COL_ICON); if(colT>0 && rowD>0){ jTable1.setValueAt(res, rowD, COL_RESULT); jTable1.setValueAt(status, rowD, COL_SUCCESS); jTable1.getCellEditor(rowD, COL_SUCCESS); } else{ //no test found in table. appen new one DefaultTableModel model = (DefaultTableModel) jTable1.getModel(); model.addRow(new Object[]{true, getNow(), deviceName, testName, res, status, icon }); } } // //GEN-BEGIN:initComponents private void initComponents() { jButton1 = new javax.swing.JButton(); jScrollPane2 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); setLayout(new java.awt.BorderLayout()); jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/button_play.png"))); // NOI18N jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); add(jButton1, java.awt.BorderLayout.CENTER); jTable1.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { }, new String [] { "Select", "Time", "Device", "Test", "Result", "Status", "" } ) { 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, javax.swing.Icon.class }; boolean[] canEdit = new boolean [] { true, true, true, true, true, true, false }; public Class getColumnClass(int columnIndex) { return types [columnIndex]; } public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit [columnIndex]; } }); jScrollPane2.setViewportView(jTable1); if (jTable1.getColumnModel().getColumnCount() > 0) { jTable1.getColumnModel().getColumn(0).setResizable(false); jTable1.getColumnModel().getColumn(0).setPreferredWidth(5); jTable1.getColumnModel().getColumn(6).setResizable(false); jTable1.getColumnModel().getColumn(6).setPreferredWidth(10); } add(jScrollPane2, java.awt.BorderLayout.PAGE_END); }// //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); showResult("RS", "Calibrate", "Test running", "Running"); //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 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(){ String sDate = getNow(); ImageIcon icon = new ImageIcon(getClass().getResource("/icons/button_pause-16px.png")); DefaultTableModel model = (DefaultTableModel) jTable1.getModel(); model.addRow(new Object[] {false, sDate, "LS", "Check Status", "No comm", "Pending", icon}); model.addRow(new Object[] {true, sDate, "RS", "Calibrate", "Calibration done", "Pending", icon}); model.addRow(new Object[] {false, sDate, "MWD", "Display Test", "Sequence terminated", "Pending", icon}); model.addRow(new Object[] {false, sDate, "FIXL", "Lamp Test", "Failure", "Pending", icon}); jTable1.setModel(model); } public String getNow(){ DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date date = new Date(); return dateFormat.format(date); } } }