KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > person > search > PersonStructFieldSearchItemEditorManager


1 /*
2  * Created on Dec 17, 2004
3  * by alex
4  *
5  */

6 package com.nightlabs.ipanema.person.search;
7
8 import org.eclipse.swt.widgets.Composite;
9 import org.eclipse.swt.widgets.Control;
10
11 import com.nightlabs.ipanema.person.AbstractPersonStructField;
12 import com.nightlabs.jdo.search.SearchFilterItem;
13
14 /**
15  * A concrete PersonStructFieldSearchItemEditorHelper that
16  * serves as a manager for other PersonStructFieldSearchItemEditorHelper.
17  * It searches for PersonStructFieldSearchItemEditorHelper in
18  * the PersonSearchFilterItemEditorHelperRegistry liked to
19  * a class of PersonStructFields.
20  *
21  * @author Alexander Bieber <alex[AT]nightlabs[DOT]de>
22  */

23 public class PersonStructFieldSearchItemEditorManager extends
24         PersonStructFieldSearchItemEditorHelper {
25
26     /**
27      *
28      */

29     public PersonStructFieldSearchItemEditorManager() {
30         super();
31     }
32
33     /**
34      * @param personStructField
35      */

36     public PersonStructFieldSearchItemEditorManager(
37             AbstractPersonStructField personStructField) {
38         super(personStructField);
39     }
40
41     
42     private PersonSearchFilterItemEditorHelper helper;
43     private Control helperControl;
44     
45     /**
46      * This searches for the right helper,
47      * gets and remembers a new instance of it
48      * and the Control it returned.
49      *
50      * @see com.nightlabs.ipanema.person.search.PersonSearchFilterItemEditorHelper#getControl(org.eclipse.swt.widgets.Composite)
51      */

52     public Control getControl(Composite parent) {
53         if (helper != null)
54             if (helperControl != null)
55                 return helperControl;
56             
57         PersonSearchFilterItemEditorHelperRegistry registry = PersonSearchFilterItemEditorHelperRegistry.getSharedInstance();
58         if (personStructField == null)
59             throw new IllegalStateException JavaDoc("Member personStructField is null. init(personStructField) might not have been called.");
60         
61         try {
62             helper = registry.getEditorHelper(personStructField.getClass());
63         } catch (PersonSearchFilterItemEditorHelperNotFoundException e) {
64             IllegalStateException JavaDoc ill = new IllegalStateException JavaDoc("No helper found for class "+personStructField.getClass().getName());
65             ill.initCause(e);
66             throw ill;
67         }
68         helper = helper.newInstance();
69         if (helper instanceof PersonStructFieldSearchItemEditorHelper)
70             ((PersonStructFieldSearchItemEditorHelper)helper).init(this.personStructField);
71 // helper.
72
helperControl = helper.getControl(parent);
73         return helperControl;
74     }
75
76     /**
77      * Delegates to the helper from the registry.
78      * @see #getControl(Composite)
79      * @see com.nightlabs.ipanema.person.search.PersonSearchFilterItemEditorHelper#getSearchFilterItem()
80      */

81     public SearchFilterItem getSearchFilterItem() {
82         if (helper == null)
83             throw new IllegalStateException JavaDoc("SearchItemEditorHelper is null and can not be asked for the SearchFilterItem");
84         
85         return helper.getSearchFilterItem();
86     }
87
88     /**
89      * @see com.nightlabs.ipanema.person.search.PersonSearchFilterItemEditorHelper#close()
90      */

91     public void close() {
92     }
93
94 }
95
Popular Tags