summaryrefslogtreecommitdiff
path: root/org/freedesktop/dbus/viewer/DBusTableModel.java
blob: cd23f4b391d15e1c674c208aa09489ab0a196ae2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
   D-Bus Java Viewer
   Copyright (c) 2006 Peter Cox

   This program is free software; you can redistribute it and/or modify it
   under the terms of either the GNU General Public License Version 2 or the
   Academic Free Licence Version 2.1.

   Full licence texts are included in the COPYING file with this program.
*/
package org.freedesktop.dbus.viewer;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

@SuppressWarnings("serial")
class DBusTableModel extends AbstractTableModel
{
	private static final String INTROSPECTABLE = "introspectable?";

	private static final String OWNER = "owner";

	private static final String USER = "user";

	private static final String NAME = "name";
	
	private static final String PATH = "path";

	final String[] columns = { NAME, PATH, USER, OWNER, INTROSPECTABLE };

	private List<DBusEntry> entries = new ArrayList<DBusEntry>();

	/** {@inheritDoc} */
	public int getRowCount()
	{
		return entries.size();
	}
	/** Add a row to the table model
	 * 
	 * @param entry The dbus entry to add
	 */
	public void add(DBusEntry entry)
	{
		entries.add(entry);
	}

	/** {@inheritDoc} */
	public int getColumnCount()
	{
		return columns.length;
	}

	/** {@inheritDoc} */
	@Override
	public String getColumnName(int column)
	{
		return columns[column];
	}
	
	/** Get a row of the table
	 * @param row The row index
	 * @return The table row
	 */
	public DBusEntry getEntry(int row)
	{
		return entries.get(row);
	}
	
	/** {@inheritDoc} */
	@Override
	public Class<?> getColumnClass(int columnIndex)
	{
		String columnName = getColumnName(columnIndex);
		if (columnName.equals(NAME))
		{
			return String.class;
		}
		if (columnName.equals(PATH))
		{
			return String.class;
		}
		else if (columnName.equals(USER))
		{
			return Object.class;
		}
		else if (columnName.equals(OWNER))
		{
			return String.class;
		}
		else if (columnName.equals(INTROSPECTABLE))
		{
			return Boolean.class;
		}
		return super.getColumnClass(columnIndex);
	}

	/** {@inheritDoc} */
	public Object getValueAt(int rowIndex, int columnIndex)
	{
		DBusEntry entry = getEntry(rowIndex);
		String columnName = getColumnName(columnIndex);
		if (columnName.equals(NAME))
		{
			return entry.getName();
		}
		if (columnName.equals(PATH))
		{
			return entry.getPath();
		}
		else if (columnName.equals(USER))
		{
			return entry.getUser();
		}
		else if (columnName.equals(OWNER))
		{
			return entry.getOwner();
		}
		else if (columnName.equals(INTROSPECTABLE))
		{
			return entry.getIntrospectable() != null;
		}
		return null;
	}

}