KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > swing > binding > DirectListBinding


1 /*
2  * $Id: DirectListBinding.java,v 1.1 2005/02/28 17:40:17 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.swing.binding;
9
10 import javax.swing.JComponent JavaDoc;
11 import javax.swing.JList JavaDoc;
12
13 import org.jdesktop.swing.data.DataModelToListModelAdapter;
14 import org.jdesktop.swing.data.SelectionModel;
15 import org.jdesktop.swing.data.TabularDataModel;
16
17 /**
18  * This "Binding" happens to the given DataModel as a whole (as
19  * opposed to a single field of the model).
20  *
21  * @author Richard Bair
22  */

23 public class DirectListBinding extends AbstractBinding {
24     
25     private JList JavaDoc list;
26
27
28     public DirectListBinding(JList JavaDoc list, TabularDataModel model, String JavaDoc displayFieldName, SelectionModel sm) {
29         super(list, model, displayFieldName, AbstractBinding.AUTO_VALIDATE_NONE);
30         //create a selection binding
31
new ListSelectionBinding(sm, list.getSelectionModel());
32         //create a custom ListModel bound to the entire TabularDataModel
33
list.setModel(new DataModelToListModelAdapter(model, displayFieldName));
34     }
35     
36     public boolean isModified() {
37         return false;
38     }
39
40     public boolean isValid() {
41         return true;
42     }
43
44     public JComponent JavaDoc getComponent() {
45         return list;
46     }
47
48     protected void setComponent(JComponent JavaDoc component) {
49         list = (JList JavaDoc)component;
50     }
51
52     protected Object JavaDoc getComponentValue(){
53         return null;
54     }
55
56     protected void setComponentValue(Object JavaDoc value) {
57     }
58 }
59
60
Popular Tags