< prev index next >

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

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


  46 import javax.swing.JTextArea;
  47 
  48 import com.sun.javatest.AllTestsFilter;
  49 import com.sun.javatest.Harness;
  50 import com.sun.javatest.InterviewParameters;
  51 import com.sun.javatest.LastRunFilter;
  52 import com.sun.javatest.ParameterFilter;
  53 import com.sun.javatest.Parameters;
  54 import com.sun.javatest.TestFilter;
  55 import com.sun.javatest.TestResult;
  56 import com.sun.javatest.TestSuite;
  57 import com.sun.javatest.tool.Preferences;
  58 import com.sun.javatest.tool.UIFactory;
  59 import com.sun.javatest.util.PrefixMap;
  60 
  61 /**
  62  * This class handles all the special filter juggling that exec tool needs to do.
  63  */
  64 public class ET_FilterHandler implements ET_FilterControl, Session.Observer {
  65     ET_FilterHandler(JComponent parent, ExecModel model, Harness h, UIFactory uif,
  66                      Map map) {
  67         this(parent, model, uif);
  68         setHarness(h);
  69         restore(map);
  70     }
  71 
  72     protected ET_FilterHandler(JComponent parent, ExecModel model, UIFactory uif) {
  73         this.uif = uif;
  74         this.model = model;
  75         this.parentComponent = parent;
  76 
  77         allFilters = new Vector<>();
  78 
  79     }
  80 
  81     public void setHarness(Harness h) {
  82         h.addObserver(new Watcher());
  83     }
  84 
  85     FilterConfig loadFilters() {
  86         // this method may eventually do fancy things to scan the classpath or


 143 
 144     /**
 145      * Subclasses may override this method to insert filters
 146      * like TemplateFilter
 147      *
 148      * @return list of filters defined for the User's TestSuite, or null
 149      */
 150     protected List<TestFilter> getUsersFilters() {
 151         return null;
 152     }
 153 
 154     public JMenu getFilterMenu() {
 155         return getFilterSelectionHandler().getFilterMenu();
 156     }
 157 
 158     FilterSelectionHandler getFilterSelectionHandler() {
 159         loadFilters();
 160         return fHandler;
 161     }
 162 
 163     private TestFilter getDefaultFilter(Map map) {
 164         if (map != null) {
 165             String pref = (String)(map.get(ExecTool.ACTIVE_FILTER));
 166 
 167             // try to use filter indicated in preference
 168             for (int i = 0; i < allFilters.size(); i++) {
 169                 if (allFilters.elementAt(i).getClass().getName().equals(pref))
 170                     return allFilters.elementAt(i);
 171             }   // for
 172         }
 173 
 174         // default filter
 175         return allFilter;
 176     }
 177 
 178     protected void updateFilters() {
 179         loadFilters();
 180 
 181         // special code for custom filter loading
 182         updateCustomFilter();
 183 
 184         // update Last Test Run filtered if needed
 185         if (!ltrFilter.isWorkDirectorySet())


 264         int prefIndex = getPreferenceIndexForWrite(prefs, tsId);
 265 
 266         ConstrainedPreferenceMap cpm = new ConstrainedPreferenceMap(prefs);
 267         // using meta_ prefix for info not written by the filter itself
 268         PrefixMap<String> pm = new PrefixMap<>(cpm, FILTER_PREFIX + prefIndex);
 269 
 270         // it's really a special case to have a pref. entry which does not
 271         // have a tsId associated
 272         // it should really only be used (if at all) if a default set of
 273         // settings is being saved
 274         if (tsId != null) {
 275             pm.put(META_ID, tsId);
 276             pm.put(META_NAME, tsName);
 277         }
 278 
 279         pm.put(META_CLASS, bctf.getClass().getName());
 280         bctf.save(pm);
 281 
 282         prefs.save();
 283     }
 284     public void restore(Map m) {
 285         this.map = m;
 286         fHandler.setFilter(getDefaultFilter(m));
 287     }
 288     public void updateGUI() {
 289         // do nothing
 290     }
 291 
 292     public List<Action> getToolBarActionList() {
 293         return null;
 294     }
 295 
 296     public void dispose() {
 297         // do nothing
 298     }
 299 
 300 
 301     private void updateCustomFilter() {
 302         // we only go thru here once per init.
 303         if (lastTs != null)
 304             return;


 424         else
 425             return index;
 426     }
 427 
 428     /**
 429      * How many indexes are we using for filters right now.
 430      * @return -1 for none.
 431      */
 432     private int getPreferenceCount(Preferences p) {
 433         int numFilters = Integer.parseInt(
 434                             p.getPreference(FILTER_PREFIX + ".count", "0"));
 435 
 436         return numFilters;
 437     }
 438 
 439     private FilterConfig fConfig;
 440     private FilterSelectionHandler fHandler;
 441     private ExecModel model;
 442     private UIFactory uif;
 443     private JComponent parentComponent;
 444     private Map map;        // saved desktop map to restore from
 445 
 446     // filters
 447     private LastRunFilter ltrFilter;        // last test run
 448     private ParameterFilter paramFilter;    // current param filter
 449     private BasicCustomTestFilter bctf;     // "custom" filter
 450     private AllTestsFilter allFilter;
 451     private TestFilter certFilter;          // "certification" filter
 452     protected Vector<TestFilter> allFilters;
 453 
 454     // custom filter info
 455     private TestSuite lastTs;
 456 
 457     // preferences constants
 458     private static final String FILTER_PREFIX = "exec.vfilters";
 459     private static final String BTF_PREFIX = FILTER_PREFIX + ".btf";
 460     private static final String META_ID = "meta_tsid";
 461     private static final String META_NAME = "meta_tsn";
 462     private static final String META_CLASS = "meta_class";
 463 
 464     public void updated(Event ev) {


 496         public String get(Object key) {
 497             if (!(key instanceof String))
 498                 throw new IllegalArgumentException("key must be a string");
 499 
 500             return prefs.getPreference((String)key);
 501         }
 502 
 503         public boolean isEmpty() {
 504             throw new UnsupportedOperationException();
 505         }
 506 
 507         public Set<String> keySet() {
 508             throw new UnsupportedOperationException();
 509         }
 510 
 511         public String put(String key, String value) {
 512             prefs.setPreference(key, value);
 513             return null;
 514         }
 515 
 516         public void putAll(Map t) {
 517             throw new UnsupportedOperationException();
 518         }
 519 
 520         public String remove(Object key) {
 521             throw new UnsupportedOperationException();
 522         }
 523 
 524         public int size() {
 525             throw new UnsupportedOperationException();
 526         }
 527 
 528         public Collection<String> values() {
 529             throw new UnsupportedOperationException();
 530         }
 531 
 532         public String get(String key) {
 533             return prefs.getPreference(key);
 534         }
 535 
 536         private Preferences prefs;




  46 import javax.swing.JTextArea;
  47 
  48 import com.sun.javatest.AllTestsFilter;
  49 import com.sun.javatest.Harness;
  50 import com.sun.javatest.InterviewParameters;
  51 import com.sun.javatest.LastRunFilter;
  52 import com.sun.javatest.ParameterFilter;
  53 import com.sun.javatest.Parameters;
  54 import com.sun.javatest.TestFilter;
  55 import com.sun.javatest.TestResult;
  56 import com.sun.javatest.TestSuite;
  57 import com.sun.javatest.tool.Preferences;
  58 import com.sun.javatest.tool.UIFactory;
  59 import com.sun.javatest.util.PrefixMap;
  60 
  61 /**
  62  * This class handles all the special filter juggling that exec tool needs to do.
  63  */
  64 public class ET_FilterHandler implements ET_FilterControl, Session.Observer {
  65     ET_FilterHandler(JComponent parent, ExecModel model, Harness h, UIFactory uif,
  66                      Map<String, String> map) {
  67         this(parent, model, uif);
  68         setHarness(h);
  69         restore(map);
  70     }
  71 
  72     protected ET_FilterHandler(JComponent parent, ExecModel model, UIFactory uif) {
  73         this.uif = uif;
  74         this.model = model;
  75         this.parentComponent = parent;
  76 
  77         allFilters = new Vector<>();
  78 
  79     }
  80 
  81     public void setHarness(Harness h) {
  82         h.addObserver(new Watcher());
  83     }
  84 
  85     FilterConfig loadFilters() {
  86         // this method may eventually do fancy things to scan the classpath or


 143 
 144     /**
 145      * Subclasses may override this method to insert filters
 146      * like TemplateFilter
 147      *
 148      * @return list of filters defined for the User's TestSuite, or null
 149      */
 150     protected List<TestFilter> getUsersFilters() {
 151         return null;
 152     }
 153 
 154     public JMenu getFilterMenu() {
 155         return getFilterSelectionHandler().getFilterMenu();
 156     }
 157 
 158     FilterSelectionHandler getFilterSelectionHandler() {
 159         loadFilters();
 160         return fHandler;
 161     }
 162 
 163     private TestFilter getDefaultFilter(Map<String, String> map) {
 164         if (map != null) {
 165             String pref = (map.get(ExecTool.ACTIVE_FILTER));
 166 
 167             // try to use filter indicated in preference
 168             for (int i = 0; i < allFilters.size(); i++) {
 169                 if (allFilters.elementAt(i).getClass().getName().equals(pref))
 170                     return allFilters.elementAt(i);
 171             }   // for
 172         }
 173 
 174         // default filter
 175         return allFilter;
 176     }
 177 
 178     protected void updateFilters() {
 179         loadFilters();
 180 
 181         // special code for custom filter loading
 182         updateCustomFilter();
 183 
 184         // update Last Test Run filtered if needed
 185         if (!ltrFilter.isWorkDirectorySet())


 264         int prefIndex = getPreferenceIndexForWrite(prefs, tsId);
 265 
 266         ConstrainedPreferenceMap cpm = new ConstrainedPreferenceMap(prefs);
 267         // using meta_ prefix for info not written by the filter itself
 268         PrefixMap<String> pm = new PrefixMap<>(cpm, FILTER_PREFIX + prefIndex);
 269 
 270         // it's really a special case to have a pref. entry which does not
 271         // have a tsId associated
 272         // it should really only be used (if at all) if a default set of
 273         // settings is being saved
 274         if (tsId != null) {
 275             pm.put(META_ID, tsId);
 276             pm.put(META_NAME, tsName);
 277         }
 278 
 279         pm.put(META_CLASS, bctf.getClass().getName());
 280         bctf.save(pm);
 281 
 282         prefs.save();
 283     }
 284     public void restore(Map<String, String> m) {
 285         this.map = m;
 286         fHandler.setFilter(getDefaultFilter(m));
 287     }
 288     public void updateGUI() {
 289         // do nothing
 290     }
 291 
 292     public List<Action> getToolBarActionList() {
 293         return null;
 294     }
 295 
 296     public void dispose() {
 297         // do nothing
 298     }
 299 
 300 
 301     private void updateCustomFilter() {
 302         // we only go thru here once per init.
 303         if (lastTs != null)
 304             return;


 424         else
 425             return index;
 426     }
 427 
 428     /**
 429      * How many indexes are we using for filters right now.
 430      * @return -1 for none.
 431      */
 432     private int getPreferenceCount(Preferences p) {
 433         int numFilters = Integer.parseInt(
 434                             p.getPreference(FILTER_PREFIX + ".count", "0"));
 435 
 436         return numFilters;
 437     }
 438 
 439     private FilterConfig fConfig;
 440     private FilterSelectionHandler fHandler;
 441     private ExecModel model;
 442     private UIFactory uif;
 443     private JComponent parentComponent;
 444     private Map<String, String> map;        // saved desktop map to restore from
 445 
 446     // filters
 447     private LastRunFilter ltrFilter;        // last test run
 448     private ParameterFilter paramFilter;    // current param filter
 449     private BasicCustomTestFilter bctf;     // "custom" filter
 450     private AllTestsFilter allFilter;
 451     private TestFilter certFilter;          // "certification" filter
 452     protected Vector<TestFilter> allFilters;
 453 
 454     // custom filter info
 455     private TestSuite lastTs;
 456 
 457     // preferences constants
 458     private static final String FILTER_PREFIX = "exec.vfilters";
 459     private static final String BTF_PREFIX = FILTER_PREFIX + ".btf";
 460     private static final String META_ID = "meta_tsid";
 461     private static final String META_NAME = "meta_tsn";
 462     private static final String META_CLASS = "meta_class";
 463 
 464     public void updated(Event ev) {


 496         public String get(Object key) {
 497             if (!(key instanceof String))
 498                 throw new IllegalArgumentException("key must be a string");
 499 
 500             return prefs.getPreference((String)key);
 501         }
 502 
 503         public boolean isEmpty() {
 504             throw new UnsupportedOperationException();
 505         }
 506 
 507         public Set<String> keySet() {
 508             throw new UnsupportedOperationException();
 509         }
 510 
 511         public String put(String key, String value) {
 512             prefs.setPreference(key, value);
 513             return null;
 514         }
 515 
 516         public void putAll(Map<? extends String, ? extends String> t) {
 517             throw new UnsupportedOperationException();
 518         }
 519 
 520         public String remove(Object key) {
 521             throw new UnsupportedOperationException();
 522         }
 523 
 524         public int size() {
 525             throw new UnsupportedOperationException();
 526         }
 527 
 528         public Collection<String> values() {
 529             throw new UnsupportedOperationException();
 530         }
 531 
 532         public String get(String key) {
 533             return prefs.getPreference(key);
 534         }
 535 
 536         private Preferences prefs;


< prev index next >