KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > jdnc > markup > attr > FormAttributes


1 /*
2  * $Id: FormAttributes.java,v 1.4 2005/01/27 14:40:30 kleopatra Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.jdnc.markup.attr;
9
10 import org.jdesktop.swing.data.DataModel;
11 import org.jdesktop.swing.data.DefaultTableModelExt;
12 import org.jdesktop.swing.data.TableModelExtAdapter;
13
14 import org.jdesktop.swing.binding.Binding;
15 import org.jdesktop.swing.binding.BindException;
16
17 import org.jdesktop.swing.JXTable;
18 import org.jdesktop.swing.decorator.FilterPipeline;
19 import org.jdesktop.swing.form.JForm;
20 import org.jdesktop.swing.form.RowSelector;
21
22 import org.jdesktop.jdnc.JNForm;
23 import org.jdesktop.jdnc.JNTable;
24
25 import org.jdesktop.jdnc.markup.elem.FormElement;
26
27 import javax.swing.JTable JavaDoc;
28 import javax.swing.event.TableModelEvent JavaDoc;
29 import javax.swing.event.TableModelListener JavaDoc;
30
31 import net.openmarkup.ApplierException;
32 import net.openmarkup.AttributeApplier;
33 import net.openmarkup.Realizable;
34
35
36 /**
37  * @author Amy Fowler
38  */

39 public class FormAttributes {
40
41     public static final AttributeApplier dataApplier = new AttributeApplier() {
42         public void apply(Realizable target, String JavaDoc namespaceURI,
43                           String JavaDoc attributeName, String JavaDoc attributeValue)
44             throws ApplierException {
45             Object JavaDoc dataModel = BaseAttribute.getReferencedObject(target, attributeValue);
46             JNForm form = (JNForm) target.getObject();
47             ((FormElement)target).handleBinding(form, dataModel);
48         }
49     };
50
51     /**@todo aim: this is a total hack until we can work out an elegant way
52      * to track selection.
53      */

54     public static final AttributeApplier tracksApplier = new AttributeApplier() {
55         public void apply(Realizable target, String JavaDoc namespaceURI,
56                           String JavaDoc attributeName, String JavaDoc attributeValue)
57             throws ApplierException {
58             Object JavaDoc selectionComponent = BaseAttribute.getReferencedObject(target,
59                 attributeValue);
60             JNForm form = (JNForm) target.getObject();
61             if (selectionComponent instanceof JNTable) {
62                 Binding bindings[] = form.getForm().getBindings();
63                 DataModel model = null;
64                 if (bindings.length > 0) {
65                     model = bindings[0].getDataModel();
66                 }
67                 final JTable JavaDoc table = ((JNTable)selectionComponent).getTable();
68                 new org.jdesktop.swing.form.RowSelector(table, model);
69                 /*
70                 if (model.getRecordCount() == 0) {
71                     // no data yet, so we watch for data to set initial selection
72                     // to ensure that DataModel has a non -1 current index
73                     table.getModel().addTableModelListener(new TableModelListener() {
74                         public void tableChanged(TableModelEvent e) {
75                             if (e.getType() == TableModelEvent.INSERT) {
76                                 // Hack to patch Amy's hack!
77                                 if (table instanceof JXTable) {
78                                     FilterPipeline fp = ((JXTable) table).getFilters();
79                                     if (fp != null) {
80                                         fp.flush();
81                                     }
82                                 }
83
84                                 table.getSelectionModel().setLeadSelectionIndex(0);
85                                 table.getSelectionModel().setAnchorSelectionIndex(0);
86                                 table.getModel().removeTableModelListener(this);
87                             }
88                         }
89                     });
90                 }
91                 */

92             }
93         }
94     };
95     // ...
96
}
97
Popular Tags