View Javadoc

1   /*
2    * Copyright 2006-2016 The JGUIraffe Team.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License")
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.jguiraffe.gui.forms;
17  
18  import java.util.Set;
19  
20  /**
21   * <p>
22   * Definition of an interface for objects that are able to manage entities
23   * related to a <code>Form</code> object.
24   * </p>
25   * <p>Objects implementing this interface are able to store
26   * <code>{@link FieldHandler}</code>s, <code>{@link ComponentHandler}</code>s,
27   * and simple components. All these entities can also be accessed by name.
28   * </p>
29   * <p>This interface is especially useful when a <code>Form</code> object is
30   * constructed. If this is done by a <em>builder</em>, all components created
31   * during the builder operation must be collected. It is even possible that
32   * multiple component stores are involved, e.g. if there are complex components,
33   * which create their own sub forms. In such cases having multiple - even
34   * different - implementations of the <code>ComponentStore</code> interface can
35   * be helpful.
36   * </p>
37   *
38   * @author Oliver Heger
39   * @version $Id: ComponentStore.java 205 2012-01-29 18:29:57Z oheger $
40   */
41  public interface ComponentStore
42  {
43      /**
44       * Adds the specified component to this component store under the given
45       * name.
46       *
47       * @param name the name of the component
48       * @param component the component itself
49       */
50      void add(String name, Object component);
51  
52      /**
53       * Adds the specified component handler to this component store under the
54       * given name.
55       *
56       * @param name the name of the component
57       * @param handler the component handler
58       */
59      void addComponentHandler(String name, ComponentHandler<?> handler);
60  
61      /**
62       * Adds the specified field handler to this component store. The caller is
63       * responsible for adding the associated <code>ComponentHandler</code>
64       * manually.
65       *
66       * @param name the name of the component
67       * @param fldHandler the field handler to be added
68       */
69      void addFieldHandler(String name, FieldHandler fldHandler);
70  
71      /**
72       * Returns the component with the given name. If no such component can be
73       * found, <b>null</b> is returned.
74       *
75       * @param name the name of the desired component
76       * @return the component
77       */
78      Object findComponent(String name);
79  
80      /**
81       * Returns the component handler with the given name. This handler must have
82       * been added before using
83       * <code>{@link #addComponentHandler(String, ComponentHandler)}</code>.
84       * If no such component handler can be found, <b>null</b> is returned.
85       *
86       * @param name the name of the desired component handler
87       * @return the corresponding handler
88       */
89      ComponentHandler<?> findComponentHandler(String name);
90  
91      /**
92       * Returns the field handler with the given name. This handler must have
93       * been added before using
94       * <code>{@link #addFieldHandler(String, FieldHandler)}</code>. If no
95       * such field handler can be found, <b>null</b> is returned.
96       *
97       * @param name the name of the desired field handler
98       * @return the corresponding handler
99       */
100     FieldHandler findFieldHandler(String name);
101 
102     /**
103      * Returns a set with the names of all components that are contained in this
104      * store.
105      *
106      * @return a set with the names of the components in this store
107      */
108     Set<String> getComponentNames();
109 
110     /**
111      * Returns a set with the names of all component handlers that are contained
112      * in this store.
113      *
114      * @return a set with the names of the component handlers in this store
115      */
116     Set<String> getComponentHandlerNames();
117 
118     /**
119      * Returns a set with the names of all field handlers that are contained in
120      * this store.
121      *
122      * @return a set with the names of the field handlers in this store
123      */
124     Set<String> getFieldHandlerNames();
125 }