< prev index next >

## src/com/sun/javatest/audit/OptionsDialog.java

Print this page

     175
     176     private void updateFieldChoices() {
     177         updateTestSuiteChoices();
     178         updateWorkDirectoryChoices();
     179         updateConfigFileChoices();
     180     }
     181
     182     private void chooseTestSuite() {
     183         if (testSuiteChooser == null)
     184             testSuiteChooser = new TestSuiteChooser();
     185         int action = testSuiteChooser.showDialog(tool);
     186         if (action != JFileChooser.APPROVE_OPTION)
     187             return;
     188         TestSuite ts = testSuiteChooser.getSelectedTestSuite();
     189         tsField.setSelectedItem(ts.getPath());
     190     }
     191
     192     private void updateTestSuiteChoices() {
     193         // get the paths of currently loaded test suites
     194         // could move this to TestSuite, and use the dirMap cache
     195         SortedSet s = new TreeSet();
     196         Desktop d = tool.getDesktop();
     197         Tool[] tools = d.getTools();
     198         if (tools != null) {
     199             for (int i = 0; i < tools.length; i++) {
     200                 Tool t = tools[i];
     201                 TestSuite[] tss = t.getLoadedTestSuites();
     202                 if (tss != null) {
     203                     for (int j = 0; j < tss.length; j++)
     204                         s.add(tss[j].getPath());
     205                 }
     206             }
     207         }
     208
     209         setItems(tsField, s);
     210         updateWorkDirectoryChoices();
     211     }
     212
     213     private void chooseWorkDirectory() {
     214         if (workDirChooser == null) {
     215             workDirChooser = new WorkDirChooser(true);
     220             return;
     221         WorkDirectory wd = workDirChooser.getSelectedWorkDirectory();
     222         wdField.setSelectedItem(wd.getPath());
     223     }
     224
     225     private void updateWorkDirectoryChoices() {
     226         String tsID = null;
     227         try {
     228             String tsp = (String) (tsField.getSelectedItem());
     229             if (tsp != null && tsp.length() > 0) {
     230                 TestSuite ts = TestSuite.open(new File(tsp));
     231                 tsID = ts.getID();
     232             }
     233         }
     234         catch (Exception e) {
     235             // ignore
     236         }
     237
     238         // get the paths of currently loaded work directories
     239         // could move this to WorkDirectory and use the dirMap cache
     240         SortedSet s = new TreeSet();
     241         Desktop d = tool.getDesktop();
     242         Tool[] tools = d.getTools();
     243         if (tools != null) {
     244             for (int i = 0; i < tools.length; i++) {
     245                 Tool t = tools[i];
     246                 WorkDirectory[] wds = t.getLoadedWorkDirectories();
     247                 if (wds != null) {
     248                     for (int j = 0; j < wds.length; j++) {
     249                         WorkDirectory wd = wds[j];
     250                         if (tsID == null || tsID.equals(wd.getTestSuite().getID()))
     251                             s.add(wd.getPath());
     252                     }
     253                 }
     254             }
     255         }
     256
     257         setItems(wdField, s);
     258     }
     259
     260     private void chooseConfigFile() {
     274                 });
     275         }
     276
     277         int action = configFileChooser.showOpenDialog(tool);
     278         if (action != JFileChooser.APPROVE_OPTION)
     279             return;
     280
     281         File cf = configFileChooser.getSelectedFile();
     282         String cfp;
     283         if (cf == null)
     284             cfp = "";
     285         else {
     286             cfp = cf.getPath();
     287             if (!cfp.endsWith(".jti"))
     288                 cfp += ".jti";
     289         }
     290         cfField.setSelectedItem(cfp);
     291     }
     292
     293     private void updateConfigFileChoices() {
     294         SortedSet s = new TreeSet();
     295         String wdp = (String) (wdField.getSelectedItem());
     296         try {
     297             WorkDirectory wd = WorkDirectory.open(new File(wdp));
     298             FileHistory history = FileHistory.getFileHistory(wd, "configHistory.jtl");
     299             File[] entries = history.getRecentEntries(10);
     300             for (int i = 0; i < entries.length; i++)
     301                 s.add(entries[i].getPath());
     302         }
     303         catch (Exception e) {
     304             // ignore
     305         }
     306         setItems(cfField, s);
     307     }
     308
     309     private void setItems(JComboBox field, SortedSet s) {
     310         // first, remove unwanted entries from field
     311         for (int i = field.getItemCount() - 1; i >= 0; i-- ) {
     312             String item = (String) (field.getItemAt(i));
     313             if (s.contains(item)) {
     314                 // this item is required, so remove it from the
     315                 // set to be added later
     316                 s.remove(item);
     317             }
     318             else if (item.length() > 0 && !item.equals(field.getSelectedItem()))
     319                 // this item is not required, remove it
     320                 field.removeItemAt(i);
     321         }
     322
     323         // those items remaining in s need to be added to the field
     324         for (Iterator iter = s.iterator(); iter.hasNext(); )
     325             field.addItem(iter.next());
     326     }
     327
     328     private Tool tool;
     329     private ActionListener okListener;
     330     private JPanel body;
     331
     332     private JComboBox tsField;
     333     private JButton tsBtn;
     334     private TestSuiteChooser testSuiteChooser;
     335
     336     private JComboBox wdField;
     337     private JButton wdBtn;
     338     private WorkDirChooser workDirChooser;
     339
     340     private JComboBox cfField;
     341     private JButton cfBtn;
     342     private JFileChooser configFileChooser;
     343
     344     private Listener listener;
     345
     346     static final String OK = "OK";
     347
     348     private class Listener
     349         extends ComponentAdapter
     350         implements ActionListener
     351     {
     352         // ComponentListener
     353         public void componentShown(ComponentEvent e) {
     354             updateFieldChoices();
     355         }
     356
     357         // ActionListener
     358         public void actionPerformed(ActionEvent e) {
     359             Object src = e.getSource();
     360             if (src == tsField)
     175
     176     private void updateFieldChoices() {
     177         updateTestSuiteChoices();
     178         updateWorkDirectoryChoices();
     179         updateConfigFileChoices();
     180     }
     181
     182     private void chooseTestSuite() {
     183         if (testSuiteChooser == null)
     184             testSuiteChooser = new TestSuiteChooser();
     185         int action = testSuiteChooser.showDialog(tool);
     186         if (action != JFileChooser.APPROVE_OPTION)
     187             return;
     188         TestSuite ts = testSuiteChooser.getSelectedTestSuite();
     189         tsField.setSelectedItem(ts.getPath());
     190     }
     191
     192     private void updateTestSuiteChoices() {
     193         // get the paths of currently loaded test suites
     194         // could move this to TestSuite, and use the dirMap cache
     195         SortedSet<String> s = new TreeSet<>();
     196         Desktop d = tool.getDesktop();
     197         Tool[] tools = d.getTools();
     198         if (tools != null) {
     199             for (int i = 0; i < tools.length; i++) {
     200                 Tool t = tools[i];
     201                 TestSuite[] tss = t.getLoadedTestSuites();
     202                 if (tss != null) {
     203                     for (int j = 0; j < tss.length; j++)
     204                         s.add(tss[j].getPath());
     205                 }
     206             }
     207         }
     208
     209         setItems(tsField, s);
     210         updateWorkDirectoryChoices();
     211     }
     212
     213     private void chooseWorkDirectory() {
     214         if (workDirChooser == null) {
     215             workDirChooser = new WorkDirChooser(true);
     220             return;
     221         WorkDirectory wd = workDirChooser.getSelectedWorkDirectory();
     222         wdField.setSelectedItem(wd.getPath());
     223     }
     224
     225     private void updateWorkDirectoryChoices() {
     226         String tsID = null;
     227         try {
     228             String tsp = (String) (tsField.getSelectedItem());
     229             if (tsp != null && tsp.length() > 0) {
     230                 TestSuite ts = TestSuite.open(new File(tsp));
     231                 tsID = ts.getID();
     232             }
     233         }
     234         catch (Exception e) {
     235             // ignore
     236         }
     237
     238         // get the paths of currently loaded work directories
     239         // could move this to WorkDirectory and use the dirMap cache
     240         SortedSet<String> s = new TreeSet<>();
     241         Desktop d = tool.getDesktop();
     242         Tool[] tools = d.getTools();
     243         if (tools != null) {
     244             for (int i = 0; i < tools.length; i++) {
     245                 Tool t = tools[i];
     246                 WorkDirectory[] wds = t.getLoadedWorkDirectories();
     247                 if (wds != null) {
     248                     for (int j = 0; j < wds.length; j++) {
     249                         WorkDirectory wd = wds[j];
     250                         if (tsID == null || tsID.equals(wd.getTestSuite().getID()))
     251                             s.add(wd.getPath());
     252                     }
     253                 }
     254             }
     255         }
     256
     257         setItems(wdField, s);
     258     }
     259
     260     private void chooseConfigFile() {
     274                 });
     275         }
     276
     277         int action = configFileChooser.showOpenDialog(tool);
     278         if (action != JFileChooser.APPROVE_OPTION)
     279             return;
     280
     281         File cf = configFileChooser.getSelectedFile();
     282         String cfp;
     283         if (cf == null)
     284             cfp = "";
     285         else {
     286             cfp = cf.getPath();
     287             if (!cfp.endsWith(".jti"))
     288                 cfp += ".jti";
     289         }
     290         cfField.setSelectedItem(cfp);
     291     }
     292
     293     private void updateConfigFileChoices() {
     294         SortedSet<String> s = new TreeSet<>();
     295         String wdp = (String) (wdField.getSelectedItem());
     296         try {
     297             WorkDirectory wd = WorkDirectory.open(new File(wdp));
     298             FileHistory history = FileHistory.getFileHistory(wd, "configHistory.jtl");
     299             File[] entries = history.getRecentEntries(10);
     300             for (int i = 0; i < entries.length; i++)
     301                 s.add(entries[i].getPath());
     302         }
     303         catch (Exception e) {
     304             // ignore
     305         }
     306         setItems(cfField, s);
     307     }
     308
     309     private void setItems(JComboBox<String> field, SortedSet<String> s) {
     310         // first, remove unwanted entries from field
     311         for (int i = field.getItemCount() - 1; i >= 0; i-- ) {
     312             String item =  field.getItemAt(i);
     313             if (s.contains(item)) {
     314                 // this item is required, so remove it from the
     315                 // set to be added later
     316                 s.remove(item);
     317             }
     318             else if (item.length() > 0 && !item.equals(field.getSelectedItem()))
     319                 // this item is not required, remove it
     320                 field.removeItemAt(i);
     321         }
     322
     323         // those items remaining in s need to be added to the field
     324         for (Iterator<String> iter = s.iterator(); iter.hasNext(); )
     325             field.addItem(iter.next());
     326     }
     327
     328     private Tool tool;
     329     private ActionListener okListener;
     330     private JPanel body;
     331
     332     private JComboBox<String> tsField;
     333     private JButton tsBtn;
     334     private TestSuiteChooser testSuiteChooser;
     335
     336     private JComboBox<String> wdField;
     337     private JButton wdBtn;
     338     private WorkDirChooser workDirChooser;
     339
     340     private JComboBox<String> cfField;
     341     private JButton cfBtn;
     342     private JFileChooser configFileChooser;
     343
     344     private Listener listener;
     345
     346     static final String OK = "OK";
     347
     348     private class Listener
     349         extends ComponentAdapter
     350         implements ActionListener
     351     {
     352         // ComponentListener
     353         public void componentShown(ComponentEvent e) {
     354             updateFieldChoices();
     355         }
     356
     357         // ActionListener
     358         public void actionPerformed(ActionEvent e) {
     359             Object src = e.getSource();
     360             if (src == tsField)

< prev index next >