blob: cc0e4036d7af2280c08086c0aabcb861103b1821 (
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
128
129
130
131
132
133
134
135
136
137
138
139
|
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.plugin.propertieseditor;
import java.beans.*;
import javax.swing.event.*;
import javax.swing.table.*;
import org.jitsi.service.configuration.*;
/**
* @author Marin Dzhigarov
* @author Pawel Domas
*
*/
public class PropsTableModel
implements TableModel,
PropertyChangeListener
{
/**
* The configuration service.
*/
private ConfigurationService confService = PropertiesEditorActivator.getConfigurationService();
/**
* Creates an instance of <tt>PropsTableModel</tt>.
*/
PropsTableModel() {}
public void Register()
{
confService.addPropertyChangeListener(this);
}
public void Unregister()
{
confService.removePropertyChangeListener(this);
}
public void propertyChange(PropertyChangeEvent evt)
{
for (TableModelListener l : listeners.getListeners(TableModelListener.class))
{
l.tableChanged(new TableModelEvent(this));
}
}
public int getRowCount()
{
return confService.getAllPropertyNames().size();
}
/**
* Returns the count of table columns.
* @return int the count of table columns
*/
public int getColumnCount()
{
return 2;
}
/**
* Returns the column name given column index.
* @param columnIndex The column index.
* @return The column name.
*/
public String getColumnName(int columnIndex)
{
if(columnIndex == 0)
{
return "Property";
} else
{
return "Value";
}
}
/**
* Returns the class of the column given a column index
*/
public Class<?> getColumnClass(int columnIndex)
{
return String.class;
}
/**
* Returns true if the given cell is edittable.
* Edittable cells in this model are cells with column index 1.
* @param rowIndex The row index.
* @param columnIndex The column index.
* @return True if the column index is 1
*/
public boolean isCellEditable(int rowIndex, int columnIndex)
{
return columnIndex == 1;
}
/**
* Returns the value in the cell given by row and column.
*/
public Object getValueAt(int rowIndex, int columnIndex)
{
if (columnIndex == 0)
{
return confService.getAllPropertyNames().get(rowIndex);
} else
{
return confService.getProperty(confService.getAllPropertyNames().get(rowIndex));
}
}
/**
* Sets aValue at a cell with coordinates [rowIndex, columnIndex]
* @param aValue The given value.
* @param rowIndex The row index that the value will be set to.
* @param columnIndex The column index that the value will be set to.
*/
public void setValueAt(Object aValue, int rowIndex, int columnIndex)
{
String property = confService.getAllPropertyNames().get(rowIndex);
confService.setProperty(property, aValue);
}
private EventListenerList listeners = new EventListenerList();
public void addTableModelListener(TableModelListener l)
{
listeners.add(TableModelListener.class, l);
}
public void removeTableModelListener(TableModelListener l)
{
listeners.remove(TableModelListener.class, l);
}
}
|