< prev index next >

src/com/sun/javatest/exec/NewReportDialog.java

Print this page
rev 145 : 7902237: Fixing raw use of parameterized class
Reviewed-by: jjg


 124         // upgrade to use resource bundle+key as message
 125         // the given error occurred, and the user was informed
 126         public void errorWriting(String problem);
 127     }
 128 
 129     NewReportDialog(Component parent, UIFactory uif, FilterConfig f,
 130                     ReportBrowser reportBrowser, ExecModel model) {
 131         super(parent, uif, "nrd");
 132 
 133         this.model = model;
 134         filterHandler = f.createFilterSelectionHandler();
 135         this.reportBrowser = reportBrowser;
 136     }
 137 
 138     public void setInterviewParameters(InterviewParameters p) {
 139          interviewParams = p;
 140     }
 141 
 142     // ---------------------------------------------------------------------------
 143 
 144     void setLastState(Map h) {
 145         String rd = (String) (h.get(REPORT_DIR));
 146         String filter = (String) (h.get(FILTER));
 147 
 148         if (dirField == null)
 149             initGUI();
 150 
 151         dirField.setText(rd);
 152 
 153         if (filter != null && filter.length() > 0)
 154            filterHandler.setFilter(filter);
 155 
 156         updateHtmlCheckboxStates();
 157         updateCofCheckboxStates();
 158     }
 159 
 160     Map<String, String> getLastState() {
 161         String rd = dirField.getText();
 162         String filter = filterHandler.getActiveFilter().getName();
 163         Map<String, String> lastState = new HashMap<>();
 164 
 165         if (rd != null && rd.length() > 0)
 166            lastState.put(REPORT_DIR, rd);


 884             Report r = new Report();
 885 
 886             // if no work directory selected, throw exception.
 887             if (interviewParams.getWorkDirectory() == null) {
 888                 throw new IOException(uif.getI18NString("nrd.noWorkDir.err"));
 889             }
 890             r.addStartGenListener(new ReportGenListener());
 891             settings.setCustomReports(getActiveCustomReports());
 892             r.writeReports(settings, reportDir );
 893 
 894         }
 895         else {
 896             throw new IOException(uif.getI18NString("nrd.nullParams.err"));
 897         }
 898     }
 899 
 900     private ArrayList<CustomReport> getActiveCustomReports() {
 901 
 902         ArrayList<CustomReport> customReps = new ArrayList<>();
 903         if (customBoxes != null && customBoxes.size() > 0) {
 904             Iterator it = customBoxes.keySet().iterator();
 905             while (it.hasNext()) {
 906                 JCheckBox box = (JCheckBox)(it.next());
 907                 if (box.isSelected()) {
 908                     customReps.add(customBoxes.get(box));
 909                 }
 910             }
 911         }
 912         return customReps;
 913     }
 914 
 915     private boolean isEmptyDirectory(File f) {
 916         return (f.isDirectory() && f.list().length == 0);
 917     }
 918 
 919     private void updateHtmlCheckboxStates() {
 920         // config buttons done before html buttons to ensure that
 921         // config gets disabled if HTML reporting is off
 922 
 923         if (!cbHtml.isSelected()) {
 924             for (int i = 0; i < htmlGroup.size(); i++)
 925                 htmlGroup.get(i).setEnabled(false);
 926         }


1079                 }
1080             }
1081             else if (src == okBtn) {
1082                 String s = dirField.getText();
1083 
1084                 // check null input
1085                 if (s == null || s.length() == 0) {
1086                     uif.showError("nrd.emptyInput");
1087                     return;
1088                 }
1089 
1090                 // check for empty input
1091                 if (cbBak.isSelected() && numBak.getText().equals("")) {
1092                     uif.showError("nrd.emptyBak");
1093                     // select the last tab (assumes this has the backup settings)
1094                     tabs.setSelectedIndex(tabs.getTabCount()-1);
1095                     return;
1096                 }
1097 
1098                 // validate custom reports
1099                 Iterator it = getActiveCustomReports().iterator();
1100                 while (it.hasNext()) {
1101                     CustomReport cr = (CustomReport) it.next();
1102                     String error = cr.validateOptions();
1103                     if (error != null) {
1104                         for (int i = 0; i < listModel.getSize(); i++ ) {
1105                             JCheckBox cb = listModel.elementAt(i);
1106                             if (cb.getName().equals(cr.getReportId())) {
1107                                 list.setSelectedIndex(i);
1108                             }
1109                         }
1110                         uif.showError("nrd.optionsErr", new Object[] {error} );
1111                         return;
1112                     }
1113                 }
1114 
1115                 reportDir = new File(s);
1116 
1117                 try {
1118                     // check if dir needs to be created.
1119                     if (!reportDir.isDirectory()) {
1120                         reportDir.mkdirs();
1121                     }


1350                 if("nrd.wait".equals(cmp[i].getName())) {
1351                     if (cmp[i] instanceof JTextComponent) {
1352                         ((JTextComponent)cmp[i]).setText(status);
1353                     }
1354                     break;
1355                 }
1356             }
1357         }
1358     }
1359 
1360     /**
1361      * This listener changes options state against checkboxes
1362      */
1363     private class SelectListener extends MouseInputAdapter implements KeyListener, ListSelectionListener {
1364 
1365         /**
1366          * @param lst JList of checkboxes
1367          * @param p parent Panel
1368          * @param cardLayout The CardLayout for options
1369          */
1370         SelectListener(JList lst, JPanel p, CardLayout cardLayout ) {
1371             list = lst;
1372             listModel = list.getModel();
1373             lastSelected = listModel.getElementAt(0);
1374             panel = p;
1375             cards = cardLayout;
1376         }
1377 
1378         public void keyTyped(KeyEvent e) {
1379             if (e.getKeyChar() == ' ') {
1380                 process(list.getSelectedIndex());
1381             }
1382         }
1383 
1384         @Override
1385         public void mouseClicked(MouseEvent e) {
1386             if (e.getPoint().getX() <= emptyCBW) {
1387                 process(list.locationToIndex(e.getPoint()));
1388             }
1389         }
1390 


1460             lastSelected = box;
1461         }
1462 
1463         public void keyReleased(KeyEvent e) {
1464         }
1465 
1466         public void keyPressed(KeyEvent e) {
1467         }
1468 
1469         /**
1470          * Sets the button to change enable/disable state. If none of
1471          * check boxes is selected, the button will be disabled until a check
1472          * box is selected.
1473          * @param okBtn - button
1474          */
1475         private void setOkBtn(JButton okBtn) {
1476             this.okBtn = okBtn;
1477         }
1478 
1479         Object lastSelected;
1480         JList list;
1481         ListModel listModel;
1482         JPanel panel;
1483         CardLayout cards;
1484         JButton okBtn = null; // should be disable iff all check boxes are off
1485         double emptyCBW = new JCheckBox("").getPreferredSize().getWidth() + 2;
1486     }
1487 
1488     /*
1489      * PropertyChangeListener for enabling/disabling container's content
1490      */
1491     private class PanelEnableListener implements PropertyChangeListener {
1492         /**
1493          * @param container Container for controlling
1494          */
1495         PanelEnableListener(Container container) {
1496             theContainer = container;
1497         }
1498         /**
1499          * Catches changes of "enabled" property
1500          * and changes enabled status for all child components
1501          */




 124         // upgrade to use resource bundle+key as message
 125         // the given error occurred, and the user was informed
 126         public void errorWriting(String problem);
 127     }
 128 
 129     NewReportDialog(Component parent, UIFactory uif, FilterConfig f,
 130                     ReportBrowser reportBrowser, ExecModel model) {
 131         super(parent, uif, "nrd");
 132 
 133         this.model = model;
 134         filterHandler = f.createFilterSelectionHandler();
 135         this.reportBrowser = reportBrowser;
 136     }
 137 
 138     public void setInterviewParameters(InterviewParameters p) {
 139          interviewParams = p;
 140     }
 141 
 142     // ---------------------------------------------------------------------------
 143 
 144     void setLastState(Map<String, String> h) {
 145         String rd = (h.get(REPORT_DIR));
 146         String filter = (h.get(FILTER));
 147 
 148         if (dirField == null)
 149             initGUI();
 150 
 151         dirField.setText(rd);
 152 
 153         if (filter != null && filter.length() > 0)
 154            filterHandler.setFilter(filter);
 155 
 156         updateHtmlCheckboxStates();
 157         updateCofCheckboxStates();
 158     }
 159 
 160     Map<String, String> getLastState() {
 161         String rd = dirField.getText();
 162         String filter = filterHandler.getActiveFilter().getName();
 163         Map<String, String> lastState = new HashMap<>();
 164 
 165         if (rd != null && rd.length() > 0)
 166            lastState.put(REPORT_DIR, rd);


 884             Report r = new Report();
 885 
 886             // if no work directory selected, throw exception.
 887             if (interviewParams.getWorkDirectory() == null) {
 888                 throw new IOException(uif.getI18NString("nrd.noWorkDir.err"));
 889             }
 890             r.addStartGenListener(new ReportGenListener());
 891             settings.setCustomReports(getActiveCustomReports());
 892             r.writeReports(settings, reportDir );
 893 
 894         }
 895         else {
 896             throw new IOException(uif.getI18NString("nrd.nullParams.err"));
 897         }
 898     }
 899 
 900     private ArrayList<CustomReport> getActiveCustomReports() {
 901 
 902         ArrayList<CustomReport> customReps = new ArrayList<>();
 903         if (customBoxes != null && customBoxes.size() > 0) {
 904             Iterator<JCheckBox> it = customBoxes.keySet().iterator();
 905             while (it.hasNext()) {
 906                 JCheckBox box = (it.next());
 907                 if (box.isSelected()) {
 908                     customReps.add(customBoxes.get(box));
 909                 }
 910             }
 911         }
 912         return customReps;
 913     }
 914 
 915     private boolean isEmptyDirectory(File f) {
 916         return (f.isDirectory() && f.list().length == 0);
 917     }
 918 
 919     private void updateHtmlCheckboxStates() {
 920         // config buttons done before html buttons to ensure that
 921         // config gets disabled if HTML reporting is off
 922 
 923         if (!cbHtml.isSelected()) {
 924             for (int i = 0; i < htmlGroup.size(); i++)
 925                 htmlGroup.get(i).setEnabled(false);
 926         }


1079                 }
1080             }
1081             else if (src == okBtn) {
1082                 String s = dirField.getText();
1083 
1084                 // check null input
1085                 if (s == null || s.length() == 0) {
1086                     uif.showError("nrd.emptyInput");
1087                     return;
1088                 }
1089 
1090                 // check for empty input
1091                 if (cbBak.isSelected() && numBak.getText().equals("")) {
1092                     uif.showError("nrd.emptyBak");
1093                     // select the last tab (assumes this has the backup settings)
1094                     tabs.setSelectedIndex(tabs.getTabCount()-1);
1095                     return;
1096                 }
1097 
1098                 // validate custom reports
1099                 Iterator<CustomReport> it = getActiveCustomReports().iterator();
1100                 while (it.hasNext()) {
1101                     CustomReport cr = it.next();
1102                     String error = cr.validateOptions();
1103                     if (error != null) {
1104                         for (int i = 0; i < listModel.getSize(); i++ ) {
1105                             JCheckBox cb = listModel.elementAt(i);
1106                             if (cb.getName().equals(cr.getReportId())) {
1107                                 list.setSelectedIndex(i);
1108                             }
1109                         }
1110                         uif.showError("nrd.optionsErr", new Object[] {error} );
1111                         return;
1112                     }
1113                 }
1114 
1115                 reportDir = new File(s);
1116 
1117                 try {
1118                     // check if dir needs to be created.
1119                     if (!reportDir.isDirectory()) {
1120                         reportDir.mkdirs();
1121                     }


1350                 if("nrd.wait".equals(cmp[i].getName())) {
1351                     if (cmp[i] instanceof JTextComponent) {
1352                         ((JTextComponent)cmp[i]).setText(status);
1353                     }
1354                     break;
1355                 }
1356             }
1357         }
1358     }
1359 
1360     /**
1361      * This listener changes options state against checkboxes
1362      */
1363     private class SelectListener extends MouseInputAdapter implements KeyListener, ListSelectionListener {
1364 
1365         /**
1366          * @param lst JList of checkboxes
1367          * @param p parent Panel
1368          * @param cardLayout The CardLayout for options
1369          */
1370         SelectListener(JList<?> lst, JPanel p, CardLayout cardLayout ) {
1371             list = lst;
1372             listModel = list.getModel();
1373             lastSelected = listModel.getElementAt(0);
1374             panel = p;
1375             cards = cardLayout;
1376         }
1377 
1378         public void keyTyped(KeyEvent e) {
1379             if (e.getKeyChar() == ' ') {
1380                 process(list.getSelectedIndex());
1381             }
1382         }
1383 
1384         @Override
1385         public void mouseClicked(MouseEvent e) {
1386             if (e.getPoint().getX() <= emptyCBW) {
1387                 process(list.locationToIndex(e.getPoint()));
1388             }
1389         }
1390 


1460             lastSelected = box;
1461         }
1462 
1463         public void keyReleased(KeyEvent e) {
1464         }
1465 
1466         public void keyPressed(KeyEvent e) {
1467         }
1468 
1469         /**
1470          * Sets the button to change enable/disable state. If none of
1471          * check boxes is selected, the button will be disabled until a check
1472          * box is selected.
1473          * @param okBtn - button
1474          */
1475         private void setOkBtn(JButton okBtn) {
1476             this.okBtn = okBtn;
1477         }
1478 
1479         Object lastSelected;
1480         JList<?> list;
1481         ListModel<?> listModel;
1482         JPanel panel;
1483         CardLayout cards;
1484         JButton okBtn = null; // should be disable iff all check boxes are off
1485         double emptyCBW = new JCheckBox("").getPreferredSize().getWidth() + 2;
1486     }
1487 
1488     /*
1489      * PropertyChangeListener for enabling/disabling container's content
1490      */
1491     private class PanelEnableListener implements PropertyChangeListener {
1492         /**
1493          * @param container Container for controlling
1494          */
1495         PanelEnableListener(Container container) {
1496             theContainer = container;
1497         }
1498         /**
1499          * Catches changes of "enabled" property
1500          * and changes enabled status for all child components
1501          */


< prev index next >