1 /*
2 * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3 * the spring framework, http://el4j.sf.net
4 * Copyright (C) 2005 by ELCA Informatique SA, Av. de la Harpe 22-24,
5 * 1000 Lausanne, Switzerland, http://www.elca.ch
6 *
7 * EL4J is published under the GNU Lesser General Public License (LGPL)
8 * Version 2.1. See http://www.gnu.org/licenses/
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * For alternative licensing, please contact info@elca.ch
16 */
17 package com.silvermindsoftware.hitch;
18
19 import java.awt.Container;
20
21 import javax.swing.JComponent;
22
23 import org.jdesktop.beansbinding.AutoBinding;
24 import org.jdesktop.beansbinding.BindingGroup;
25 import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy;
26
27 import com.silvermindsoftware.hitch.binding.BindingCreator;
28 import com.silvermindsoftware.hitch.validation.response.ValidationResponder;
29
30 /**
31 * Interface for convenience beans binding support between model and GUI.
32 *
33 * @svnLink $Revision: 3873 $;$Date: 2009-08-04 13:59:45 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/swing/src/main/java/com/silvermindsoftware/hitch/Binder.java $
34 *
35 * @author Stefan Wismer (SWI)
36 */
37 public interface Binder {
38 /**
39 * Add all bindings that can be derived from the binding annotations. The name of the annotated fields must match
40 * a property of the model (field prefix "m_" is removed if applicable).
41 *
42 * @param container the GUI component container to bind to
43 * @param modelId the optional model identifiers
44 * (to select models to bind)
45 * @return the added binding group
46 */
47 public BindingGroup addAutoBinding(Container container, String... modelId);
48
49 /**
50 * @param container the GUI component container to bind to
51 * @param performValidate validate user input
52 * @param modelId the optional model identifiers
53 * (to select models to bind)
54 * @return the added binding group
55 */
56 public BindingGroup addAutoBinding(Container container,
57 boolean performValidate, String... modelId);
58
59 /**
60 * Bind a component to a model using a specific binding creator.
61 *
62 * @param container the GUI component container to bind to
63 * @param component the form component to bind to
64 * @param creator the specific binding creator
65 * @param performValidate determines if a validation should be performed
66 * @return the created binding
67 */
68 @SuppressWarnings("unchecked")
69 public AutoBinding addAutoBinding(Container container,
70 JComponent component, BindingCreator creator, boolean performValidate);
71
72 /**
73 * Bind a component to a model using the standard binding creator.
74 *
75 * @param model the model to bind
76 * @param property the property of the model to bind
77 * @param component the form component to bind
78 * @param performValidate determines if a validation should be performed
79 * @return the created binding
80 */
81 @SuppressWarnings("unchecked")
82 public AutoBinding addManualBinding(UpdateStrategy strategy, Object model,
83 String property, JComponent component, boolean performValidate);
84
85 /**
86 * Bind a component to a model using a specific binding creator.
87 *
88 * @param model the model to bind
89 * @param property the property of the model to bind
90 * @param component the form component to bind to
91 * @param creator the specific binding creator
92 * @param performValidate determines if a validation should be performed
93 * @return the created binding
94 */
95 @SuppressWarnings("unchecked")
96 public AutoBinding addManualBinding(Object model, String property,
97 JComponent component, BindingCreator creator, boolean performValidate);
98
99 /**
100 * Bind a component to a model completely manually.
101 *
102 * @param binding the binding to add
103 * @return the added binding
104 */
105 @SuppressWarnings("unchecked")
106 public AutoBinding addManualBinding(AutoBinding binding);
107
108 /**
109 * Bind a component to a model completely manually.
110 *
111 * @param binding the binding to add
112 * @param performValidate determines if a validation should be performed
113 * @return the added binding
114 */
115 @SuppressWarnings("unchecked")
116 public AutoBinding addManualBinding(AutoBinding binding,
117 boolean performValidate);
118
119 /**
120 * Remove a binding group.
121 *
122 * @param group the binding group to remove
123 */
124 public void remove(BindingGroup group);
125
126 /**
127 * Remove a binding.
128 *
129 * @param binding the binding to remove
130 */
131 @SuppressWarnings("unchecked")
132 public void remove(AutoBinding binding);
133
134
135 /**
136 * Remove all bindings.
137 */
138 public void removeAll();
139
140 /**
141 * Find a specific binding. Parameters being <code>null</code>
142 * mean "don't care".
143 *
144 * @param model the model to bind
145 * @param property the property of the model to bind to
146 * @param component the form component to bind to
147 * @return the found bindings or <code>null</code> if none
148 */
149 public BindingGroup find(Object model, String property,
150 JComponent component);
151
152 /**
153 * Add a custom validation responder to a binding.
154 *
155 * @param binding the binding
156 * @param responder the validation responder
157 */
158 @SuppressWarnings("unchecked")
159 public void addValidationResponder(AutoBinding binding,
160 ValidationResponder responder);
161
162 /**
163 * Add a custom validation responder to a binding group.
164 *
165 * @param group the binding group
166 * @param responder the validation responder
167 */
168 public void addValidationResponder(BindingGroup group,
169 ValidationResponder responder);
170
171
172 /**
173 * Bind all managed bindings.
174 */
175 public void bindAll();
176
177 /**
178 * Unbind all managed bindings.
179 */
180 public void unbindAll();
181 }