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
87 // preferences for custom plugin tools, for now it is hardcoded
88
89 if (fConfig != null)
90 return fConfig;
91
92 fConfig = new FilterConfig(model, parentComponent, uif);
93
94 fHandler = fConfig.createFilterSelectionHandler();
95
96 // add observer here so that the menu gets the additions
97 // also watches for user selection of new filter
229 }
230 }
231 else {
232 // filter is the same
233 }
234 }
235
236 public JMenu getMenu() {
237 loadFilters();
238 return null;
239 //return fHandler.getFilterMenu();
240 }
241
242 public FilterConfig getFilterConfig() {
243 return fConfig;
244 }
245
246 /**
247 * Save internal state.
248 */
249 public void save(Map m) {
250 // -------- saved to given map (desktop) -------
251 Preferences prefs = Preferences.access();
252 TestFilter aFilter = fHandler.getActiveFilter();
253 m.put(ExecTool.ACTIVE_FILTER, aFilter.getClass().getName());
254
255 // -------- saved to global prefs -------
256 TestSuite ts = model.getTestSuite();
257 String tsId = null;
258 String tsName = null;
259 if (ts != null) {
260 tsId = ts.getID();
261 tsName = ts.getName();
262 }
263
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 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() {
307 lastTs = model.getTestSuite();
308 String tsId = null;
309 String tsName = null;
310
311 // may be null, meaning that the exec tool has no TS
312 if (lastTs != null) {
313 tsId = lastTs.getID();
314 tsName = lastTs.getName();
315 }
316
317 Preferences prefs = Preferences.access();
318 int prefIndex = getPreferenceIndexForRead(prefs, tsId);
319
320 // using META_ prefix for info not written by the filter itself
321 // XXX could check value of c in the future
322 //String c = prefs.getPreference(FILTER_PREFIX + "." + prefIndex + META_CLASS);
323
324 if (prefIndex >= 0) {
325 // load previous settings
326 ConstrainedPreferenceMap cpm = new ConstrainedPreferenceMap(prefs);
327 PrefixMap pm = new PrefixMap(cpm, FILTER_PREFIX + prefIndex);
328
329 if (bctf == null) { // init
330 bctf = new BasicCustomTestFilter(pm, model, uif);
331 allFilters.add(bctf);
332 fConfig.add(bctf);
333 }
334 else { // tell filter load settings
335 bctf.load(pm);
336 fHandler.updateFilterMetaInfo(bctf);
337 }
338 }
339 else if (bctf == null) {
340 // no previous settings to use
341 bctf = new BasicCustomTestFilter(model, uif);
342 allFilters.add(bctf);
343 fConfig.add(bctf);
344 }
345
346 }
347
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 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) {
465 if (ev instanceof BasicSession.E_NewConfig) {
466 paramFilter.update(((BasicSession.E_NewConfig)ev).ip);
467 }
468 updateFilters();
469 }
470
471 /**
472 * This class is completely private and only implements what we
473 * want to use here.
474 */
475 private static class ConstrainedPreferenceMap implements Map {
476 ConstrainedPreferenceMap(Preferences p) {
477 prefs = p;
478 }
479
480 public void clear() {
481 throw new UnsupportedOperationException();
482 }
483
484 public boolean containsKey(Object o) {
485 throw new UnsupportedOperationException();
486 }
487
488 public boolean containsValue(Object v) {
489 throw new UnsupportedOperationException();
490 }
491
492 public Set entrySet() {
493 throw new UnsupportedOperationException();
494 }
495
496 public Object 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 keySet() {
508 throw new UnsupportedOperationException();
509 }
510
511 public Object put(Object key, Object value) {
512 if (!(key instanceof String) ||
513 !(value instanceof String))
514 throw new IllegalArgumentException("both args must be strings");
515
516 prefs.setPreference((String)key, (String)value);
517
518 return null;
519 }
520
521 public void putAll(Map t) {
522 throw new UnsupportedOperationException();
523 }
524
525 public Object remove(Object key) {
526 throw new UnsupportedOperationException();
527 }
528
529 public int size() {
530 throw new UnsupportedOperationException();
531 }
532
533 public Collection values() {
534 throw new UnsupportedOperationException();
535 }
536
537 // custom methods
538 public void put(String key, String value) {
539 prefs.setPreference(key, value);
540 }
541
542 public String get(String key) {
543 return (String)(prefs.getPreference(key));
544 }
545
546 private Preferences prefs;
547 }
548
549 private class FilterWatcher implements FilterSelectionHandler.Observer {
550 // NOTE: disconnected in loadFilters()
551 // ---------- FilterConfig.Observer ----------
552 public void filterUpdated(TestFilter f) {
553 // ignore here
554 }
555
556 public void filterSelected(TestFilter f) {
557 // change menu selection
558 /* XXX not implemented yet
559 int index = items.getValueIndex(f);
560
561 if (index != -1) {
|
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
87 // preferences for custom plugin tools, for now it is hardcoded
88
89 if (fConfig != null)
90 return fConfig;
91
92 fConfig = new FilterConfig(model, parentComponent, uif);
93
94 fHandler = fConfig.createFilterSelectionHandler();
95
96 // add observer here so that the menu gets the additions
97 // also watches for user selection of new filter
229 }
230 }
231 else {
232 // filter is the same
233 }
234 }
235
236 public JMenu getMenu() {
237 loadFilters();
238 return null;
239 //return fHandler.getFilterMenu();
240 }
241
242 public FilterConfig getFilterConfig() {
243 return fConfig;
244 }
245
246 /**
247 * Save internal state.
248 */
249 public void save(Map<String, String> m) {
250 // -------- saved to given map (desktop) -------
251 Preferences prefs = Preferences.access();
252 TestFilter aFilter = fHandler.getActiveFilter();
253 m.put(ExecTool.ACTIVE_FILTER, aFilter.getClass().getName());
254
255 // -------- saved to global prefs -------
256 TestSuite ts = model.getTestSuite();
257 String tsId = null;
258 String tsName = null;
259 if (ts != null) {
260 tsId = ts.getID();
261 tsName = ts.getName();
262 }
263
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() {
307 lastTs = model.getTestSuite();
308 String tsId = null;
309 String tsName = null;
310
311 // may be null, meaning that the exec tool has no TS
312 if (lastTs != null) {
313 tsId = lastTs.getID();
314 tsName = lastTs.getName();
315 }
316
317 Preferences prefs = Preferences.access();
318 int prefIndex = getPreferenceIndexForRead(prefs, tsId);
319
320 // using META_ prefix for info not written by the filter itself
321 // XXX could check value of c in the future
322 //String c = prefs.getPreference(FILTER_PREFIX + "." + prefIndex + META_CLASS);
323
324 if (prefIndex >= 0) {
325 // load previous settings
326 ConstrainedPreferenceMap cpm = new ConstrainedPreferenceMap(prefs);
327 PrefixMap<String> pm = new PrefixMap<>(cpm, FILTER_PREFIX + prefIndex);
328
329 if (bctf == null) { // init
330 bctf = new BasicCustomTestFilter(pm, model, uif);
331 allFilters.add(bctf);
332 fConfig.add(bctf);
333 }
334 else { // tell filter load settings
335 bctf.load(pm);
336 fHandler.updateFilterMetaInfo(bctf);
337 }
338 }
339 else if (bctf == null) {
340 // no previous settings to use
341 bctf = new BasicCustomTestFilter(model, uif);
342 allFilters.add(bctf);
343 fConfig.add(bctf);
344 }
345
346 }
347
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) {
465 if (ev instanceof BasicSession.E_NewConfig) {
466 paramFilter.update(((BasicSession.E_NewConfig)ev).ip);
467 }
468 updateFilters();
469 }
470
471 /**
472 * This class is completely private and only implements what we
473 * want to use here.
474 */
475 private static class ConstrainedPreferenceMap implements Map<String, String> {
476 ConstrainedPreferenceMap(Preferences p) {
477 prefs = p;
478 }
479
480 public void clear() {
481 throw new UnsupportedOperationException();
482 }
483
484 public boolean containsKey(Object o) {
485 throw new UnsupportedOperationException();
486 }
487
488 public boolean containsValue(Object v) {
489 throw new UnsupportedOperationException();
490 }
491
492 public Set<Map.Entry<String, String>> entrySet() {
493 throw new UnsupportedOperationException();
494 }
495
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 if (!(key instanceof String) ||
513 !(value instanceof String))
514 throw new IllegalArgumentException("both args must be strings");
515
516 prefs.setPreference(key, value);
517
518 return null;
519 }
520
521 public void putAll(Map t) {
522 throw new UnsupportedOperationException();
523 }
524
525 public String remove(Object key) {
526 throw new UnsupportedOperationException();
527 }
528
529 public int size() {
530 throw new UnsupportedOperationException();
531 }
532
533 public Collection<String> values() {
534 throw new UnsupportedOperationException();
535 }
536
537 public String get(String key) {
538 return (String)(prefs.getPreference(key));
539 }
540
541 private Preferences prefs;
542 }
543
544 private class FilterWatcher implements FilterSelectionHandler.Observer {
545 // NOTE: disconnected in loadFilters()
546 // ---------- FilterConfig.Observer ----------
547 public void filterUpdated(TestFilter f) {
548 // ignore here
549 }
550
551 public void filterSelected(TestFilter f) {
552 // change menu selection
553 /* XXX not implemented yet
554 int index = items.getValueIndex(f);
555
556 if (index != -1) {
|