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.builder;
17  
18  import java.util.Collection;
19  import java.util.Map;
20  
21  import net.sf.jguiraffe.di.BeanContext;
22  import net.sf.jguiraffe.di.BeanCreationListener;
23  import net.sf.jguiraffe.di.BeanStore;
24  import net.sf.jguiraffe.di.InvocationHelper;
25  import net.sf.jguiraffe.gui.builder.action.ActionStore;
26  import net.sf.jguiraffe.gui.builder.utils.MessageOutput;
27  import net.sf.jguiraffe.gui.builder.window.Window;
28  import net.sf.jguiraffe.gui.cmd.CommandQueue;
29  import net.sf.jguiraffe.gui.forms.BindingStrategy;
30  import net.sf.jguiraffe.gui.forms.FormValidator;
31  import net.sf.jguiraffe.transform.TransformerContext;
32  
33  /**
34   * <p>
35   * Definition of an interface that describes the parameters of a builder
36   * operation.
37   * </p>
38   * <p>
39   * An implementation of this interface is used in calls of builder methods to
40   * pass all required parameters. There is a bunch of parameters supported by the
41   * builder, all of which must be defined so that the builder can work properly.
42   * </p>
43   * <p>
44   * In addition to the input parameters required by the builder, the builder will
45   * also store its results in this object. During the builder operation a
46   * {@link BeanStore} is created and populated, which can be
47   * queried for obtaining objects created by the builder. Some constants define
48   * reserved keys for typical objects involved in a builder operation. More of
49   * these keys allowing access to typical builder results are defined by the
50   * {@link net.sf.jguiraffe.gui.forms.components.ComponentBuilderData ComponentBuilderData}
51   * class.
52   * </p>
53   * <p>
54   * There will be implementations of this interface that provide default values
55   * for many of the settings defined here. So an application won't have to bother
56   * with all. If not marked otherwise in the description of a getter method, the
57   * corresponding property is expected to be set by the application invoking the
58   * builder.
59   * </p>
60   *
61   * @author Oliver Heger
62   * @version $Id: BuilderData.java 205 2012-01-29 18:29:57Z oheger $
63   */
64  public interface BuilderData
65  {
66      /** Constant for the key under which the result window is stored. */
67      String KEY_RESULT_WINDOW = "RESULT_WINDOW";
68  
69      /**
70       * Returns the default resource group. This property is used for i18n
71       * support. If builder scripts contain only resource IDs without a
72       * corresponding group definition, this default group will be used.
73       *
74       * @return the default resource group
75       */
76      Object getDefaultResourceGroup();
77  
78      /**
79       * Returns the transformer context to be used by the builder. This context
80       * contains some important data required for resolving resources and for
81       * validators and transformers.
82       *
83       * @return the transformer context
84       */
85      TransformerContext getTransformerContext();
86  
87      /**
88       * Returns a reference to the action store. Actions defined during the
89       * builder process will be stored here.
90       *
91       * @return the action store
92       */
93      ActionStore getActionStore();
94  
95      /**
96       * Returns a reference to the <code>MessageOutput</code> object to be used
97       * by the builder and dependent objects. Components that need to output
98       * messages to the user can make use of this object.
99       *
100      * @return the <code>MessageOutput</code> object
101      */
102     MessageOutput getMessageOutput();
103 
104     /**
105      * Returns a reference to the global <code>CommandQueue</code> object.
106      * This object can be used by the builder (or objects created by the
107      * builder) if commands have to be issued.
108      *
109      * @return the <code>CommandQueue</code>
110      */
111     CommandQueue getCommandQueue();
112 
113     /**
114      * Returns a name for the builder. The name returned by this method is
115      * evaluated by most of the tags defined by this library. It can be tested
116      * using the standard {@code ifName} and {@code unlessName} attributes. This
117      * is a very easy means for supporting conditional execution of builder
118      * scripts. Per default no builder name is set.
119      *
120      * @return a name for the builder
121      */
122     String getBuilderName();
123 
124     /**
125      * Returns the value of the menu icon flag. This is a hint for the builder
126      * that indicates whether menu items should have icons (if defined and
127      * supported by the platform).
128      *
129      * @return the menu icon flag
130      */
131     boolean isMenuIcon();
132 
133     /**
134      * Returns the value of the toolbar text flag. This is a hint for the
135      * builder that indicates whether toolbar buttons should have texts.
136      *
137      * @return the toolbar text flag
138      */
139     boolean isToolbarText();
140 
141     /**
142      * Returns the form bean. This is a data object that will be used to
143      * initialize the input components defined in the GUI and for later storing
144      * the current values.
145      *
146      * @return the form bean
147      */
148     Object getFormBean();
149 
150     /**
151      * Returns the {@code BindingStrategy} to be used by the form. The {@code
152      * BindingStrategy} must be compatible with the model object used as form
153      * bean, i.e. it determines the type of model objects that can be used.
154      *
155      * @return the {@code BindingStrategy} for the {@code Form}
156      * @see #getFormBean()
157      */
158     BindingStrategy getBindingStrategy();
159 
160     /**
161      * Returns the {@code FormValidator} for validating the {@code Form} object.
162      * This property is optional. If a {@code FormValidator} is defined, input
163      * validation on the form-level is performed before the data is stored in
164      * the model object.
165      *
166      * @return the {@code FormValidator}
167      */
168     FormValidator getFormValidator();
169 
170     /**
171      * Returns the parent window. This information is needed if a (child) window
172      * is to be created.
173      *
174      * @return the parent window
175      */
176     Window getParentWindow();
177 
178     /**
179      * Returns a reference to the parent bean context. This object - and
180      * especially the default {@link BeanStore} set for the context - provides
181      * access to the global bean definitions. These can be accessed during the
182      * builder operation.
183      *
184      * @return the parent bean context
185      */
186     BeanContext getParentContext();
187 
188     /**
189      * Returns a collection with objects to be registered as {@code
190      * BeanCreationListener} at the {@code BeanContext} created during the
191      * builder operation. The objects contained in this collection are added
192      * before the builder operation actually starts as listeners at the {@code
193      * BeanContext} that can be queried through the {@link #getBuilderContext()}
194      * method. These listeners are triggered immediately for newly created
195      * beans, even if beans are created during the builder operation. This is an
196      * optional property; an implementation can return <b>null</b> if there are
197      * no listeners to register.
198      *
199      * @return a collection with the {@code BeanCreationListener} objects to be
200      *         registered at the {@code BeanContext} created by the builder
201      */
202     Collection<BeanCreationListener> getBeanCreationListeners();
203 
204     /**
205      * Returns a map with properties that should be available during the builder
206      * operation. An application can use this map to pass in data objects that
207      * should be accessible by tags in builder scripts. While executing a
208      * builder script access to all beans in the parent {@code BeanStore} is
209      * possible. However, sometimes additional objects need to be passed to the
210      * builder, for instance model objects for lists, tables, or tree views.
211      * These additional objects can be passed through the map returned by this
212      * method. This is more convenient than adding objects to the parent {@code
213      * BeanStore} only for this purpose. The {@code Builder} implementation
214      * evaluates this map and ensures that its content is made available during
215      * the execution of the builder script. An implementation is allowed to
216      * return <b>null</b> if there are no additional properties.
217      *
218      * @return a map with additional properties for the builder operation
219      */
220     Map<String, Object> getProperties();
221 
222     /**
223      * Returns the bean context that is used by the builder and the created
224      * components. This property is initialized by the builder. From the context
225      * returned by this method access to all objects created during the builder
226      * operation is possible.
227      *
228      * @return the bean context of the current builder operation
229      */
230     BeanContext getBuilderContext();
231 
232     /**
233      * Sets the bean context used during the builder operation. This method is
234      * called by the builder.
235      *
236      * @param ctx the new bean context used during the builder operation
237      */
238     void setBuilderContext(BeanContext ctx);
239 
240     /**
241      * Returns the result of the bean builder. This object contains the
242      * <code>{@link BeanStore}</code> objects created during the build. From
243      * here access to the components created during the builder operation is
244      * possible. This property is initialized by the builder.
245      *
246      * @return the object with the results of the bean builder
247      */
248     BeanBuilderResult getBeanBuilderResult();
249 
250     /**
251      * Sets the result of the bean builder. This method is called by the builder
252      * for passing this result object to the caller.
253      *
254      * @param res the result object of the bean builder
255      */
256     void setBeanBuilderResult(BeanBuilderResult res);
257 
258     /**
259      * Returns the root store created during the builder operation. This is a
260      * convenience method for callers to directly access the populated bean
261      * store. (Access to this object is also possible through the
262      * {@link BeanBuilderResult} object.
263      *
264      * @return the root store of the builder operation
265      * @see #getBeanBuilderResult()
266      */
267     BeanStore getRootStore();
268 
269     /**
270      * Returns the {@code InvocationHelper} object to be used during this
271      * builder operation. This object is used for reflection operation and data
272      * type conversions. If no {@code InvocationHelper} is provided, a default
273      * one is used by the builder. In most cases the default invocation helper
274      * will be sufficient. It is initialized in a way that it can access
275      * converters defined for the parent bean stores. If there are specific
276      * requirements related to converters, a custom object can be returned here.
277      *
278      * @return the {@code InvocationHelper} to be used
279      */
280     InvocationHelper getInvocationHelper();
281 
282     /**
283      * Returns the <em>auto release</em> flag. If this flag is set to
284      * <b>true</b>, at the main window produced by the builder operation a
285      * specialized window listener will be registered. When the window is closed
286      * this listener ensures that the builder's
287      * {@link Builder#release(BuilderData)} method is invoked. This is a very
288      * convenient way to automatically free resources obtained during the
289      * builder operation and used by the UI. Note that this flag is only
290      * evaluated if a window is produced by the builder operation. If the flag
291      * is set to <b>false</b> or if no window is generated by the builder
292      * operation, the caller is responsible for releasing the results of the
293      * builder. This can be done by passing this object to the builder's {@code
294      * release()} method. (A reference to the builder is also stored in the
295      * {@code builder} property.)
296      *
297      * @return the <em>auto release</em> flag
298      */
299     boolean isAutoRelease();
300 
301     /**
302      * Returns a reference to the {@link Builder} object that generated the
303      * builder results. This property is set by the builder.
304      *
305      * @return a reference to the the {@code Builder} used
306      */
307     Builder getBuilder();
308 
309     /**
310      * Sets a reference to the {@code Builder} that performs this builder
311      * operation. This method is called by the builder at the beginning of a
312      * builder operation. Having a reference to the {@code Builder} in the
313      * {@code BuilderData} object can be convenient, especially when the object
314      * is to be released.
315      *
316      * @param bldr the {@code Builder} performing the builder operation
317      */
318     void setBuilder(Builder bldr);
319 }