View Javadoc

1   /***
2    * Copyright (C) 2006 Philipp Mpalampanis
3    *
4    * License: MPL 1.1/GPL 2.0/LGPL 2.1
5    *
6    * The contents of this file are subject to the Mozilla Public License Version
7    * 1.1 (the "License"); you may not use this file except in compliance with
8    * the License. You may obtain a copy of the License at
9    * http://www.mozilla.org/MPL/
10   *
11   * Software distributed under the License is distributed on an "AS IS" basis,
12   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13   * for the specific language governing rights and limitations under the
14   * License.
15   *
16   * Alternatively, the contents of this file may be used under the terms of
17   * either the GNU General Public License Version 2 or later (the "GPL"), or
18   * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
19   * in which case the provisions of the GPL or the LGPL are applicable instead
20   * of those above. If you wish to allow use of your version of this file only
21   * under the terms of either the GPL or the LGPL, and not to allow others to
22   * use your version of this file under the terms of the MPL, indicate your
23   * decision by deleting the provisions above and replace them with the notice
24   * and other provisions required by the GPL or the LGPL. If you do not delete
25   * the provisions above, a recipient may use your version of this file under
26   * the terms of any one of the MPL, the GPL or the LGPL.
27   */
28  
29  package net.sf.echobinding.table;
30  
31  import java.util.*;
32  
33  import net.sf.echobinding.binding.BindingContext;
34  
35  /***
36   * 
37   * A data bound table with selectable rows. On selection, the abstract method
38   * showEditForm() is called, which provides a <code>BindingContext</code> for
39   * the selected row. Use this binding context to arrange your data bound widgets
40   * within a form. Changes made through this form will be reflected by the table.
41   * 
42   * @see BoundTable
43   */
44  public abstract class SelectableBoundTable<T> extends SelectableTable<T> {
45  
46  	public static final String ACTION_SHOW_DETAIL = "showDetail";
47  	
48  	private static final long serialVersionUID = 5397923394009444655L;
49  
50  //	private Column _detailColumn;
51  	
52  	/***
53  	 * Creates a new <code>SelectableBoundTable</code> from a list and a binding
54  	 * context.
55  	 * 
56  	 * @param list
57  	 * @param ctx
58  	 */
59  	public SelectableBoundTable(List<T> list, BindingContext ctx) {
60  		super(list, ctx);
61  	}
62  
63  	/***
64  	 * Creates a new <code>SelectableBoundTable</code> using a bounded list and a
65  	 * binding context.
66  	 * 
67  	 * @param listBindingId
68  	 * @param ctx
69  	 */
70  	public SelectableBoundTable(String listBindingId, BindingContext ctx) {
71  		super(listBindingId, ctx);
72  
73  	}
74  
75  	/***
76  	 * Defines what will happen on row selection..
77  	 * @param ctx
78  	 */
79  	public abstract void onSelect(BindingContext ctx);
80  
81  	@Override
82  	public void rowIndexChanged(int rowIndex) {
83  		super.rowIndexChanged(rowIndex);
84  		onSelect(getBindingContext(rowIndex));
85  	}
86  
87  	/* (non-Javadoc)
88  	 * @see echobinding.table.SelectableTable#initialize()
89  	 */
90  	@Override
91  	protected void initialize() {
92  		super.initialize();
93  		
94  		setDefaultRenderer(HashSet.class, new BoundTableCollectionCellRenderer());
95  		setDefaultRenderer(Collection.class, new BoundTableCollectionCellRenderer());
96  		setDefaultRenderer(List.class, new BoundTableCollectionCellRenderer());
97  		// setDefaultRenderer(PersistentSet.class, new BoundTableCollectionCellRenderer());
98  	}
99  
100 //	/***
101 //	 * @param set
102 //	 */
103 //	@SuppressWarnings("unchecked")
104 //	public void showDetails(int col, Set set) {
105 //
106 //		if (_detailColumn != null) {
107 //
108 //			if (set == null || set.size() == 0) {
109 //				_detailColumn.removeAll();
110 //				_detailColumn.add(new Label("No data to display!"));
111 //				return;
112 //			}
113 //
114 //			List list = new ArrayList(set);
115 //			PropertyAdapter binding = getColumnAdapters().get(col);
116 //
117 //			if (binding.getSubContext() != null) {
118 //				_detailColumn.removeAll();
119 //				BoundTable detailTable = new BoundTable(list, binding
120 //						.getSubContext());
121 //				detailTable.init();
122 //				_detailColumn.add(detailTable);
123 //			}
124 //
125 //		}
126 //
127 //	}
128 
129 //	public void setDetailColumn(Column detailColumn) {
130 //		_detailColumn = detailColumn;
131 //	}
132 
133 	
134 }