01: package net.xoetrope.swing;
02:
03: import java.awt.Component;
04: import javax.swing.JTree;
05:
06: import net.xoetrope.swing.tree.XTreeBinding;
07: import net.xoetrope.swing.tree.XTreeModelAdapter;
08: import net.xoetrope.xui.data.XDataBinding;
09: import net.xoetrope.xui.data.XDataBindingFactory;
10: import net.xoetrope.xui.data.XModel;
11: import net.xoetrope.xui.data.XModelAdapter;
12: import net.xoetrope.builder.XuiBuilder;
13: import net.xoetrope.xml.XmlElement;
14:
15: /**
16: * A data binding factory for the additional swing bindings
17: * <p>Copyright: Copyright (c) Xoetrope Ltd., 2001-2004</p>
18: * <p>$Revision: 1.5 $ </p>
19: * License see license.txt
20: */
21: public class SwingDataBindingFactory implements XDataBindingFactory {
22: private static SwingDataBindingFactory instance = null;
23:
24: private SwingDataBindingFactory() {
25: }
26:
27: /**
28: * Registe an instance of this binding factory.
29: */
30: public static void register() {
31: if (instance == null)
32: XuiBuilder
33: .registerBindingFactory(instance = new SwingDataBindingFactory());
34: }
35:
36: /**
37: * Try to get a binding factory to construct the binding
38: * @param comp the target component
39: * @param model the source data model
40: * @param bindingNode the XML element defining the binding
41: * @return the new binding if one could be constructed
42: */
43: public XDataBinding getBinding(Component comp, XModel model,
44: XmlElement bindingNode) {
45: XDataBinding binding = null;
46: if (comp instanceof XTree) {
47: XModelAdapter adapter = new XTreeModelAdapter(model);
48: binding = new XTreeBinding((JTree) comp, adapter);
49: }
50:
51: if (binding != null) {
52: binding.setSourcePath(bindingNode.getAttribute("source"));
53: binding.setOutputPath(XModel.prefixOutputPath(bindingNode
54: .getAttribute("output")));
55: }
56:
57: return binding;
58: }
59: }
|