CollectionVisualizer.java

biz/hammurapi/swing/CollectionVisualizer.java

Violations

Inspector Message Severity Location
Java Inspector 048 Copyrights information should be present in each file. 1
Java Inspector 089 Type is not documented 2 41:1
Java Inspector 089 Undocumented method 2 43:9
Java Inspector 089 Undocumented method 2 46:25
Java Inspector 089 Undocumented method 2 49:41
Java Inspector 089 Undocumented method 2 68:41
Java Inspector 025 Avoid hardwired numeric literals. Allowed literals: [1, -1, 0] 3 69:92
Java Inspector 025 Avoid hardwired numeric literals. Allowed literals: [1, -1, 0] 3 69:94
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 56:73
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 59:93
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 70:87
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 70:99
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 71:63
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 73:63

Source code

1/*
2 * hgcommons 9
3 * Hammurapi Group Common Library
4 * Copyright (C) 2003 Hammurapi Group
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * URL: http://www.hammurapi.biz/hammurapi-biz/ef/xmenu/hammurapi-group/products/products/hgcommons/index.html
21 * e-Mail: support@hammurapi.biz
22 */
23package biz.hammurapi.swing;
24
25import java.util.ArrayList;
26import java.util.Collection;
27import java.util.Iterator;
28import java.util.List;
29
30import javax.swing.table.DefaultTableModel;
31import javax.swing.table.TableModel;
32import javax.swing.tree.TreeNode;
33
34import biz.hammurapi.convert.Converter;
35
36/**
37 * @author Pavel Vlasov
38 *
39 * @version $Revision: 1.1 $
40 */
41public class CollectionVisualizer {
42
43 public Visualizable convert(final Collection col, final Converter master) {
44 return new Visualizable() {
45
46 public TreeNode toTreeNode(TreeNode parent, String title) {
47 return new LazyTreeNodeTableVisualizable(parent, title) {
48
49 protected List loadChildren() {
50 ArrayList ret = new ArrayList();
51 Iterator it = col.iterator();
52 for (int i=0; it.hasNext(); ++i) {
53 Object next = it.next();
54 String cName;
55 if (next==null) {
56 cName = "(null)";
57 } else {
58 String nName = next.getClass().getName();
59 int idx = nName.lastIndexOf(".");
60 cName = idx==-1 ? nName : nName.substring(idx+1);
61 }
62 Visualizable vs = (Visualizable) master.convert(next, Visualizable.class, null);
63 ret.add(vs.toTreeNode(this, cName));
64 }
65 return ret;
66 }
67
68 public TableModel toTable() {
69 DefaultTableModel tm=new DefaultTableModel(2,2);
70 tm.setColumnIdentifiers(new String[] {"Property", "Value"});
71 tm.setValueAt("type", 0, 0);
72 tm.setValueAt(col.getClass().getName(), 0, 1);
73 tm.setValueAt("size", 1, 0);
74 tm.setValueAt(String.valueOf(col.size()), 1, 1);
75
76 return tm;
77 }
78
79 };
80 }
81
82 };
83 }
84}
85