IndexTable.java

00001 /*
00002  * IndexTable.java
00003  *
00004  *
00005  */
00006 
00007 package DisplayGUI;
00008 
00009 import javax.swing.JTable;
00010 import javax.swing.event.*;
00011 import javax.swing.ListSelectionModel;
00012 import javax.swing.table.TableModel;
00013 import javax.swing.event.ListSelectionListener;
00014 import javax.swing.event.ListSelectionEvent;
00015 import java.util.Vector;
00016 import java.util.Hashtable;
00017 import java.util.Collections;
00018 import Sct_CalibrationController.TestData;
00019 import GuiComponents.*;
00024 public class IndexTable extends GuiTable implements TableModelListener,ListSelectionListener {
00025 
00026 private TestSelection testSelection;
00027 private IVTestSelection ivTestSelection;
00028 
00029 
00030 public IndexTable(gui parent) {
00031         super(parent);
00032         guiControl=parent;
00033       table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
00034         table.addMouseListener(new tablesMouseAdapter());
00035       rowSM.addListSelectionListener(this);
00036       testSelection=null;
00037       ivTestSelection=null;
00038         }
00039 
00040 public TestSelection getTestSelection() {
00041       return testSelection;
00042       }
00043 public IVTestSelection getIVTestSelection() {
00044         return ivTestSelection;
00045       }
00046 public void setNullTestSelection() {
00047         testSelection=null;
00048         ivTestSelection=null;
00049         }
00050 public int getSelectedTest() {
00051         return rowSM.getMinSelectionIndex();
00052       }
00053 public Vector getTestControlObjectNames() {
00054       return objectNames;
00055       }
00056 public String getTestControlObjectName() {
00057       int selectedRow = rowSM.getMinSelectionIndex();
00058       if(selectedRow==-1) return null;
00059       if(objectNames==null) return null;
00060       if(selectedRow>=objectNames.size()) return null;
00061       return (String)objectNames.elementAt(selectedRow);
00062       }
00063 
00065 public void valueChanged(ListSelectionEvent e) {
00066         if(!selectionListenerIsActive) {
00067 //        selectionListenerIsActive=true;
00068           return;
00069           }
00070 
00071         if (e.getValueIsAdjusting()) return;
00072 
00073         ListSelectionModel lsm = (ListSelectionModel)e.getSource();
00074 
00075       if (lsm.isSelectionEmpty()) {
00076                  //no rows are selected
00077                 testSelection=null;
00078                 ivTestSelection=null;
00079                 guiControl.displayPane.setDisplayColors();
00080                 guiControl.displayPane.refreshDisplay();
00081                 guiControl.selectorPane.initParamList();
00082                 return;
00083                 }
00084 
00085         int minRow=lsm.getMinSelectionIndex();
00086       int maxRow=lsm.getMaxSelectionIndex();
00087       int nselected = maxRow-minRow+1;
00088 
00089       int displayStatus=guiControl.displayStatus.getStatus();
00090       switch(displayStatus) {
00091                 case DisplayStatus.MODULE_GROUP_SELECTION:
00092                    if(nselected>0) lsm.setSelectionInterval(minRow,minRow);
00093                    guiControl.selectorPane.setMouseClickIndex(minRow);
00094                    guiControl.displayPane.setDisplayColors();
00095                    guiControl.displayPane.refreshDisplay();
00096                    break;
00097             case DisplayStatus.IS_MONITOR:
00098 // if more than one row is selected, assume they want to delete them
00099                    if(objectNames!=null && objectNames.size()>0) testSelection = new TestSelection((String)objectNames.elementAt(minRow),guiControl.isInterface.getLocation());
00100 
00101                    String runScanRegex = testSelection.getRunScanRegex();
00102                    if(runScanRegex!=null) guiControl.isInterface.setISCounter(runScanRegex);
00103 
00104                    guiControl.selectorPane.initParamList(); // maybe require change of parameter menu
00105 
00106                    if(testSelection.isRetrievedData()) guiControl.tablesDisplayPane.checkForRetrievedObjects();
00107 
00108                    guiControl.colorScalePane.setColorScale();
00109                    guiControl.displayPane.setDisplayColors();
00110                    ModuleCell lastClickedCell;
00111                    if((lastClickedCell=guiControl.displayPane.getLastClickedCell())!=null) guiControl.tablesDisplayPane.listISObjects(lastClickedCell);
00112                    guiControl.displayPane.refreshDisplay();
00113                    break;
00114                 case DisplayStatus.TEST_DATA:
00115                    if(objectNames!=null && objectNames.size()>0) testSelection = new TestSelection((String)objectNames.elementAt(minRow),guiControl.isInterface.getLocation());
00116                    guiControl.selectorPane.initParamList(); // maybe require change of parameter menu
00117 
00118                    if(testSelection.isRetrievedData()) guiControl.tablesDisplayPane.checkForRetrievedObjects(2);   // publish test data object, if not already done
00119 
00120                    guiControl.colorScalePane.setColorScale();
00121                    guiControl.displayPane.setDisplayColors();
00122                    guiControl.displayPane.refreshDisplay();
00123                    guiControl.tablesDisplayPane.listTestResults();
00124                    break;
00125             case DisplayStatus.SCTDB_DATA:
00126                    if(objectNames!=null && objectNames.size()>0) testSelection = new TestSelection((String)objectNames.elementAt(minRow),guiControl.isInterface.getLocation());
00127                    guiControl.selectorPane.initParamList(); // maybe require change of parameter menu
00128                    guiControl.colorScalePane.setColorScale();
00129                    guiControl.displayPane.setDisplayColors();
00130                    guiControl.displayPane.refreshDisplay();
00131                    guiControl.tablesDisplayPane.listTestResults();
00132                    break;
00133             case DisplayStatus.SCTDB_RODDAQ_DATA:
00134                    if(objectNames!=null && objectNames.size()>0) {
00135                         String objectName = (String)objectNames.elementAt(minRow);
00136                                 java.util.regex.Matcher matcher = ISInterface.SctRodDaqRefPattern.matcher(objectName);
00137                                 String locn = matcher.matches() ? objectName.substring(matcher.start(ISInterface.LOCATION),matcher.end(ISInterface.LOCATION)) : "Unknown";
00138                                 testSelection = new TestSelection(objectName,locn);
00139                                 }
00140                    guiControl.selectorPane.initParamList(); // maybe require change of parameter menu
00141                    guiControl.colorScalePane.setColorScale();
00142                    guiControl.displayPane.setDisplayColors();
00143                    guiControl.displayPane.refreshDisplay();
00144                    guiControl.tablesDisplayPane.listTestResults();
00145                    break;
00146             case DisplayStatus.IV_DATA:
00147                   if(objectNames!=null && objectNames.size()>0) ivTestSelection = new IVTestSelection((String)objectNames.elementAt(minRow));
00148                   guiControl.selectorPane.initParamList(); // maybe require change of parameter menu
00149                   guiControl.colorScalePane.setColorScale();
00150                         guiControl.displayPane.setDisplayColors();
00151                   guiControl.displayPane.refreshDisplay();
00152                   guiControl.tablesDisplayPane.listTestResults();
00153                   break;
00154                 default:
00155             }
00156    }
00157 
00158    public Vector getTestTableList() {
00159 // generate the test table list ordered by run numer and scan number
00160        Vector theLine = new Vector();        // each line of the table
00161        Vector tableContent = new Vector();   // vector of table lines
00162        Vector orderVector = new Vector();      // vector for re-ordering based on runno and scanno
00163        Hashtable orderHash = new Hashtable();// hashtable to map order runno/scanno to table lines
00164        Hashtable objectOrderHash = new Hashtable();
00165 
00166        boolean isSCTDBSctRodDaqData = (guiControl.displayStatus.getStatus()==DisplayStatus.SCTDB_RODDAQ_DATA);
00167 
00168        theLine.addElement("Test");
00169        theLine.addElement(isSCTDBSctRodDaqData ? "Locn" : "Status");
00170        theLine.addElement("Run");
00171        theLine.addElement("Scan");
00172        theLine.addElement("#Scans");
00173        theLine.addElement("Source");
00174        tableContent.addElement(theLine);
00175        int exceptionCount=0;
00176        for(int i=0;i<objectNames.size();i++) {
00177            String thisObject = (String)objectNames.elementAt(i);
00178            TestData testData = new TestData();
00179            try {
00180            GuiComponents.System.ISInterface.getInstance().getRepository().getValue(thisObject, testData);
00181            theLine=new Vector();
00182            if(testData.testName.equals("NPtGainTest") && testData.nScans==3) testData.testName = "3PtGainTest";
00183            theLine.addElement(testData.testName);
00184            if(!isSCTDBSctRodDaqData) {
00185               switch(testData.status) {
00186                  case 0:
00187                    theLine.addElement("Executing");
00188                    break;
00189                case 1:
00190                  theLine.addElement("Completed");
00191                  break;
00192                case 2:
00193                  theLine.addElement("Aborted");
00194                  break;
00195                default:
00196                  theLine.addElement("Unknown");
00197                }
00198            }
00199            else {
00200               java.util.regex.Matcher matcher = ISInterface.SctRodDaqRefPattern.matcher(thisObject);
00201               theLine.addElement(matcher.matches() ? thisObject.substring(matcher.start(ISInterface.LOCATION),matcher.end(ISInterface.LOCATION)) : "Unknown");
00202               }
00203 
00204            theLine.addElement(new Integer(testData.runNumber));
00205            theLine.addElement(new Integer(testData.startScanNumber));
00206            theLine.addElement(new Integer(testData.nScans));
00207 
00208            int offsetCount = (thisObject.matches("RetrievedData.*")) ? 0 : 100000000;
00209            Integer runScanNumber = new Integer(testData.runNumber*10000 + testData.startScanNumber +offsetCount);
00210 
00211            if(thisObject.matches("RetrievedData.*")) theLine.addElement("Archive");
00212            else if(thisObject.matches("SCTDBData.*")) theLine.addElement("SCTDB");
00213            else theLine.addElement("New");
00214 
00215            orderVector.addElement(runScanNumber);
00216            orderHash.put(runScanNumber,theLine);
00217            objectOrderHash.put(runScanNumber,thisObject);
00218            }catch(Exception e){exceptionCount++;}
00219 
00220            }
00221 
00222        Collections.sort(orderVector);
00223        objectNames=new Vector();
00224        for(int i=0;i<orderVector.size();i++) {
00225             Integer runscan= (Integer)orderVector.elementAt(i);
00226             objectNames.addElement((String)objectOrderHash.get(orderVector.elementAt(i)));          // re-order object names appropriately
00227             tableContent.addElement((Vector)orderHash.get(orderVector.elementAt(i))); // and the same for the table entries
00228             }
00229        if(exceptionCount>0) System.err.println("SctGUI::TablesDisplayPane - exception reading retrieving IS data.");
00230        return tableContent;
00231     }
00232 
00233   public Vector getIVScanList() {
00234 // generate the test table list ordered by run numer and scan number
00235        Vector theLine = new Vector();        // each line of the table
00236        Vector tableContent = new Vector();   // vector of table lines
00237        Vector orderVector = new Vector();      // vector for re-ordering based on runno and scanno
00238        Hashtable orderHash = new Hashtable();// hashtable to map order runno/scanno to table lines
00239        Hashtable objectOrderHash = new Hashtable();
00240 
00241        theLine.addElement("Run");
00242        theLine.addElement("Scan");
00243        theLine.addElement("Date");
00244        theLine.addElement("Time");
00245        theLine.addElement("#Modules");
00246        theLine.addElement("Source");
00247        tableContent.addElement(theLine);
00248        for(int i=0;i<objectNames.size();i++) {
00249            String thisObject = (String)objectNames.elementAt(i);
00250            IVScanControl iv = new IVScanControl();
00251            GuiComponents.System.ISInterface.getInstance().getRepository().getValue(thisObject, iv);
00252            theLine=new Vector();
00253            theLine.addElement(new Integer(iv.runNo));
00254            theLine.addElement(new Integer(iv.scanNo));
00255            theLine.addElement(iv.scanDate);
00256            theLine.addElement(iv.scanTime);
00257            theLine.addElement(new Integer(iv.modules.length));
00258 
00259            int offsetCount = (thisObject.matches("RetrievedData.*")) ? 0 : 100000000;
00260            Integer runScanNumber = new Integer(iv.runNo*10000 + iv.scanNo +offsetCount); 
00261 
00262            if(thisObject.matches("SCTDBData.*")) theLine.addElement("SCTDB");
00263            else theLine.addElement("DCS");
00264 
00265            orderVector.addElement(runScanNumber);
00266            orderHash.put(runScanNumber,theLine);
00267            objectOrderHash.put(runScanNumber,thisObject);
00268 
00269            }
00270 
00271        Collections.sort(orderVector);
00272        objectNames=new Vector();
00273        for(int i=0;i<orderVector.size();i++) {
00274             Integer runscan= (Integer)orderVector.elementAt(i);
00275             objectNames.addElement((String)objectOrderHash.get(orderVector.elementAt(i)));          // re-order object names appropriately
00276             tableContent.addElement((Vector)orderHash.get(orderVector.elementAt(i))); // and the same for the table entries
00277             }
00278        return tableContent;
00279     }
00280 
00281     public void updateTest(String testObjectName) {
00282            if(objectNames==null) return;
00283            if(!objectNames.contains(testObjectName)) return;
00284            int rowNumber=objectNames.indexOf(testObjectName);
00285            try {
00286            TestData testData = new TestData();
00287            Sct.IS.SctNames.getISRepository().getValue(testObjectName, testData);
00288            switch(testData.status) {
00289                case 0:
00290                  resultTable.setValueAt("Executing",rowNumber,1);
00291                  break;
00292                case 1:
00293                  resultTable.setValueAt("Completed",rowNumber,1);
00294                  break;
00295                case 2:
00296                  resultTable.setValueAt("Aborted",rowNumber,1);
00297                  break;
00298                default:
00299                  resultTable.setValueAt("Unknown",rowNumber,1);
00300                }
00301              resultTable.fireTableCellUpdated(rowNumber,1);
00302             }catch(Exception updateE){System.err.println("***ERROR updating test status in table list : "+updateE.toString());}
00303 
00304          }
00305 
00306     public void updateTestTable(String testObjectName, int rowNumber) {
00307            if(rowNumber==-1) return;
00308            try {
00309            TestData testData = new TestData();
00310            Sct.IS.SctNames.getISRepository().getValue(testObjectName, testData);
00311            switch(testData.status) {
00312                case 0:
00313                  resultTable.setValueAt("Executing",rowNumber,1);
00314                  break;
00315                case 1:
00316                  resultTable.setValueAt("Completed",rowNumber,1);
00317                  break;
00318                case 2:
00319                  resultTable.setValueAt("Aborted",rowNumber,1);
00320                  break;
00321                default:
00322                  resultTable.setValueAt("Unknown",rowNumber,1);
00323                }
00324              resultTable.fireTableCellUpdated(rowNumber,1);
00325             }catch(Exception updateE){System.err.println("***ERROR updating test status in table list : "+updateE.toString());}
00326          }
00327 
00328 
00329 
00330     class tablesMouseAdapter extends java.awt.event.MouseAdapter {
00331             public void mouseClicked(java.awt.event.MouseEvent e) {
00332                switch(e.getModifiers()) {
00333                  case java.awt.event.InputEvent.BUTTON2_MASK:
00334                  case java.awt.event.InputEvent.BUTTON3_MASK:
00335                        int rowSelect = table.rowAtPoint(new java.awt.Point(e.getX(),e.getY()));
00336                        rowSM.setSelectionInterval(rowSelect,rowSelect);
00337                        guiControl.menuActions.showTablesPopupMenu(0,e);
00338                        break;
00339                  default:
00340                  }
00341             }
00342     }
00343 
00344 }

Generated on Mon Feb 6 14:12:13 2006 for SCT DAQ/DCS Software - Java by  doxygen 1.4.6