00001
00002
00003
00004
00005
00006
00007 package DisplayGUI;
00008 import javax.swing.ListSelectionModel;
00009 import javax.swing.event.ListSelectionListener;
00010 import javax.swing.ListSelectionModel;
00011 import javax.swing.event.ListSelectionEvent;
00012 import java.util.*;
00013 import ProdDatabase.*;
00014
00015 import is.*;
00016
00021 public class ConfigFileLister extends javax.swing.JFrame implements displayParams, SCTDBInfo, TestDataInfo, ListSelectionListener {
00022
00023 DataList dataList;
00024 Map testMap;
00025 ListSelectionModel rowSM;
00026
00027 private javax.swing.JButton jButton1;
00028 private javax.swing.JTable jTable;
00029 private javax.swing.JButton jButton2;
00030 private javax.swing.JButton jButton3;
00031 private javax.swing.JButton jButton4;
00032 private javax.swing.JTextField jtextField;
00033 private javax.swing.JLabel jLabel1,jLabel2;
00034 private javax.swing.JScrollPane jScrollPane1;
00035
00036 String masterConfigFileName=null;
00037
00038 private sctConf.Configuration config;
00039
00040
00042 public ConfigFileLister(sctConf.Configuration config) {
00043 super("Add new module");
00044 this.config=config;
00045 initComponents();
00046 try {
00047 String ISObject = "ConfigurationServer.Filename";
00048 if(Sct.IS.SctNames.getISRepository().contains(ISObject)) {
00049 is.AnyInfo theValue = new is.AnyInfo();
00050 Sct.IS.SctNames.getISRepository().getValue(ISObject, theValue);
00051 masterConfigFileName = (String)theValue.getAttribute(0);
00052 System.out.println("Filename="+masterConfigFileName);
00053 }
00054 }catch(Exception e) {}
00055
00056 }
00057
00063 private void initComponents() {
00064
00065 java.awt.GridBagConstraints gridBagConstraints;
00066
00067 jButton2 = new javax.swing.JButton();
00068 jButton2.setFont(displayTextFont);
00069 jButton4 = new javax.swing.JButton();
00070 jButton4.setFont(displayTextFont);
00071
00072 jtextField = new javax.swing.JTextField(14);
00073 jtextField.setFont(displayTextFont);
00074 jtextField.setBackground(backgroundColor);
00075
00076 jLabel1 = new javax.swing.JLabel();
00077 jLabel2 = new javax.swing.JLabel();
00078 dataList = new DataList();
00079 jTable = new javax.swing.JTable(dataList);
00080 jTable.setFont(tableFont);
00081 jTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
00082 rowSM = jTable.getSelectionModel();
00083 rowSM.addListSelectionListener(this);
00084 jScrollPane1 = new javax.swing.JScrollPane(jTable);
00085 jScrollPane1.setBackground(new java.awt.Color(255, 255, 255));
00086 jScrollPane1.setBorder(new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.LOWERED));
00087 jScrollPane1.setMinimumSize(new java.awt.Dimension(300, 150));
00088 jScrollPane1.setPreferredSize(new java.awt.Dimension(300, 200));
00089 jButton1 = new javax.swing.JButton();
00090 jButton1.setFont(displayTextFont);
00091 jButton3 = new javax.swing.JButton();
00092 jButton3.setFont(displayTextFont);
00093
00094 getContentPane().setLayout(new java.awt.GridBagLayout());
00095
00096 addWindowListener(new java.awt.event.WindowAdapter() {
00097 public void windowClosing(java.awt.event.WindowEvent evt) {
00098 exitForm(evt);
00099 }
00100 });
00101
00102 jButton2.setText("Use Selected Config File");
00103 gridBagConstraints = new java.awt.GridBagConstraints();
00104 gridBagConstraints.gridx = 0;
00105 gridBagConstraints.gridy = 3;
00106 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00107 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
00108 getContentPane().add(jButton2, gridBagConstraints);
00109 jButton2.addActionListener(new java.awt.event.ActionListener() {
00110 public void actionPerformed(java.awt.event.ActionEvent evt) {
00111 int selectedRow = rowSM.getMinSelectionIndex();
00112 String parent = (masterConfigFileName!=null) ? (new java.io.File(masterConfigFileName)).getParent() : null;
00113 String child = "module"+dataList.getValueAt(selectedRow,0)+".xml";
00114 java.io.File outputFile = (parent!=null) ? new java.io.File(parent,child) : new java.io.File(child);
00115 try {
00116 Vector theData = GeneralUtilities.getRawData((String)GeneralUtilities.testNumberList.elementAt(selectedRow));
00117 if(theData.size()<2) {
00118 System.err.println("No config file available!!!");
00119 return;
00120 }
00121 java.io.BufferedWriter out = new java.io.BufferedWriter(new java.io.FileWriter(outputFile));
00122 out.write((String)theData.elementAt(1));
00123 out.close();
00124
00125 config.configureModuleFromFile(outputFile.toString());
00126
00127 javax.swing.JOptionPane.showMessageDialog(null,"Added "+dataList.getValueAt(selectedRow,0));
00128
00129 }catch(Exception e) {
00130 javax.swing.JOptionPane.showMessageDialog(null,"Failed to download configuration file:\n"+e.toString());
00131 }
00132
00133 }
00134 });
00135 jButton2.setEnabled(false);
00136
00137 jButton4.setText("View Selected Config File");
00138 gridBagConstraints = new java.awt.GridBagConstraints();
00139 gridBagConstraints.gridx = 1;
00140 gridBagConstraints.gridy = 3;
00141 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00142 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
00143 getContentPane().add(jButton4, gridBagConstraints);
00144 jButton4.addActionListener(new java.awt.event.ActionListener() {
00145 public void actionPerformed(java.awt.event.ActionEvent evt) {
00146 int selectedRow = rowSM.getMinSelectionIndex();
00147 try {
00148 Vector theData = GeneralUtilities.getRawData((String)GeneralUtilities.testNumberList.elementAt(selectedRow));
00149 if(theData.size()>=2) guiUtilities.RawDataViewer.getInstance().showNewData(theData,"Module Condiguration Data");
00150 }catch(Exception e4) {System.err.println("ERROR: Exception downloading raw data: "+e4.toString());};
00151
00152
00153 }
00154 });
00155 jButton4.setEnabled(false);
00156
00157
00158 gridBagConstraints = new java.awt.GridBagConstraints();
00159 gridBagConstraints.gridx = 1;
00160 gridBagConstraints.gridy = 0;
00161 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00162 gridBagConstraints.weightx = 0.5;
00163 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
00164 getContentPane().add(jtextField, gridBagConstraints);
00165
00166 jLabel1.setText("Module Serial No:");
00167 jLabel1.setFont(displayTextFont);
00168 gridBagConstraints = new java.awt.GridBagConstraints();
00169 gridBagConstraints.gridx = 0;
00170 gridBagConstraints.gridy = 0;
00171 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00172 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
00173 gridBagConstraints.weightx = 0.2;
00174 getContentPane().add(jLabel1, gridBagConstraints);
00175
00176 jLabel2.setText("No Data listed...");
00177 jLabel2.setFont(displayScaleFont);
00178 gridBagConstraints = new java.awt.GridBagConstraints();
00179 gridBagConstraints.gridx = 0;
00180 gridBagConstraints.gridy = 1;
00181 gridBagConstraints.gridwidth = 3;
00182 gridBagConstraints.insets = new java.awt.Insets(2, 5, 0, 5);
00183 gridBagConstraints.weighty = 0.1;
00184 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
00185
00186 getContentPane().add(jLabel2, gridBagConstraints);
00187
00188 gridBagConstraints = new java.awt.GridBagConstraints();
00189 gridBagConstraints.gridx = 0;
00190 gridBagConstraints.gridy = 2;
00191 gridBagConstraints.gridwidth = 3;
00192 gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
00193 gridBagConstraints.weighty = 0.6;
00194 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
00195 getContentPane().add(jScrollPane1, gridBagConstraints);
00196
00197 jButton1.setText("List Available Config Files");
00198 gridBagConstraints = new java.awt.GridBagConstraints();
00199 gridBagConstraints.gridx = 2;
00200 gridBagConstraints.gridy = 0;
00201 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00202 gridBagConstraints.weightx = 0.3;
00203 gridBagConstraints.weighty = 0.2;
00204 getContentPane().add(jButton1, gridBagConstraints);
00205 jButton1.addActionListener(new java.awt.event.ActionListener() {
00206 public void actionPerformed(java.awt.event.ActionEvent evt) {
00207
00208 String sn = jtextField.getText();
00209 if(sn.length()!=14) {
00210 javax.swing.JOptionPane.showMessageDialog(null,"Invalid serial number (not 14 digits)");
00211 return;
00212 }
00213 try {
00214 Long l = Long.valueOf(sn);
00215 }catch(Exception ee) {
00216 javax.swing.JOptionPane.showMessageDialog(null,"Invalid serial number (not 14 digits)");
00217 return;
00218 }
00219
00220 try {
00221 dataList.reTable(GeneralUtilities.getRodList(sn));
00222 jLabel2.setText(dataList.getRowCount()+" configurations are available.");
00223 }catch(Exception e){javax.swing.JOptionPane.showMessageDialog(null,"Failed to retrieve config files - "+e.toString());}
00224 }
00225 });
00226
00227
00228
00229
00230 jButton3.setText("Close");
00231 gridBagConstraints = new java.awt.GridBagConstraints();
00232 gridBagConstraints.gridx = 2;
00233 gridBagConstraints.gridy = 3;
00234 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00235 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
00236 gridBagConstraints.weighty = 0.1;
00237 getContentPane().add(jButton3, gridBagConstraints);
00238 jButton3.addActionListener(new java.awt.event.ActionListener() {
00239 public void actionPerformed(java.awt.event.ActionEvent evt) {
00240 exitForm(null);
00241 }
00242 });
00243 getContentPane().setBackground(new java.awt.Color(255, 255, 255));
00244
00245 pack();
00246 java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
00247 java.awt.Dimension WSize = getSize();
00248 setLocation((screenSize.width-(int)WSize.getWidth())/2,(screenSize.height-(int)WSize.getHeight())/2);
00249 }
00250
00252 public void valueChanged(ListSelectionEvent e) {
00253
00254 if (e.getValueIsAdjusting()) return;
00255
00256 ListSelectionModel lsm = (ListSelectionModel)e.getSource();
00257
00258
00259 if (lsm.isSelectionEmpty()) {
00260 jButton2.setEnabled(false);
00261 jButton4.setEnabled(false);
00262 return;
00263 }
00264
00265 jButton2.setEnabled(true);
00266 jButton4.setEnabled(true);
00267 }
00268
00270 private void exitForm(java.awt.event.WindowEvent evt) {
00271 setVisible(false);
00272 }
00273
00274
00275
00276
00277 public class DataList extends javax.swing.table.AbstractTableModel {
00278 private String[] columnNames = {"SerialNo","Location","Date","Temperature"};
00279 List rows;
00280
00281 public DataList() {
00282 rows=new ArrayList();
00283 }
00284
00285
00286 public void reTable(List rows) {
00287 this.rows=rows;
00288 fireTableChanged(null);
00289 return ;
00290 }
00291
00292
00293
00294
00295
00296 public String getColumnName(int column) {
00297 if (columnNames[column] != null) {
00298 return columnNames[column];
00299 } else {
00300 return "";
00301 }
00302 }
00303
00304 public Class getColumnClass(int column) {
00305 return getValueAt(0, column).getClass();
00306
00307 }
00308
00309 public boolean isCellEditable(int row, int column) {
00310 return false;
00311 }
00312
00313 public int getColumnCount() {
00314 return columnNames.length;
00315 }
00316
00317 public int getRowCount() {
00318 return rows.size();
00319 }
00320
00321 public Object getValueAt(int aRow, int column) {
00322
00323 List theRow = (ArrayList)rows.get(aRow);
00324 return theRow.get(column);
00325 }
00326
00327
00328 public void setValueAt(Object value, int row, int column) {
00329 List dataRow = (List)rows.get(row);
00330 dataRow.set(column, value);
00331 }
00332
00333
00334
00335 }
00336
00337
00338
00339
00340
00341 }