1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.swing;
17
18 import javax.swing.JTable;
19
20 import org.apache.commons.jelly.JellyTagException;
21 import org.apache.commons.jelly.tags.core.UseBeanTag;
22 import org.apache.commons.jelly.tags.swing.model.ExpressionTableModel;
23
24 /***
25 * Creates a default TableModel using nested tableColumn tags.
26 *
27 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
28 * @version $Revision: 155420 $
29 */
30 public class TableModelTag extends UseBeanTag {
31
32 public ExpressionTableModel getTableModel() {
33 return (ExpressionTableModel) getBean();
34 }
35
36
37
38
39 protected void processBean(String var, Object bean) throws JellyTagException {
40 super.processBean(var, bean);
41
42 ComponentTag tag = (ComponentTag) findAncestorWithClass( ComponentTag.class );
43 if ( tag == null ) {
44 throw new JellyTagException( "This tag must be nested within a JellySwing <table> tag" );
45 }
46 ExpressionTableModel model = getTableModel();
47 model.setContext(context);
48
49 Object component = tag.getComponent();
50 if (component instanceof JTable) {
51 JTable table = (JTable) component;
52 table.setModel(model);
53 }
54 else {
55 throw new JellyTagException( "This tag must be nested within a JellySwing <table> tag" );
56 }
57 }
58
59 protected Class getDefaultClass() {
60 return ExpressionTableModel.class;
61 }
62 }
63