aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/plugin/chatconfig/replacement/ReplacementConfigurationTableModel.java
blob: b9057f1fde50bde0c1b383e9fd06bb9caabf0b3d (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
/*
 * SIP Communicator, 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.chatconfig.replacement;

import java.util.*;

import javax.swing.table.*;

import net.java.sip.communicator.plugin.chatconfig.*;
import net.java.sip.communicator.service.configuration.*;
import net.java.sip.communicator.service.replacement.*;

/**
 * Table model for the table in <tt>ReplacementConfigPanel</tt> listing all
 * available replacement sources
 * 
 * @author Purvesh Sahoo
 */
public class ReplacementConfigurationTableModel
    extends AbstractTableModel
{
    /**
     * The source list of all the available replacement sources
     */
    private ArrayList<String> sourceList;

    /**
     * The configuration service
     */
    private static ConfigurationService configService =
        ChatConfigActivator.getConfigurationService();

    /**
     * Creates an instance of <tt>ReplacementConfigurationTableModel</tt> by
     * specifying the source list.
     *
     * @param source the source list to initialize the table model with
     */
    public ReplacementConfigurationTableModel(ArrayList<String> source)
    {
        this.sourceList = source;
    }

    /**
     * @param columnIndex
     * @return the Class of the column. <tt>Boolean</tt> for the first column.
     */
    public Class<?> getColumnClass(int columnIndex)
    {
        return (columnIndex == 0) ? Boolean.class : super
            .getColumnClass(columnIndex);
    }

    /**
     * {@inheritDoc }
     */
    public int getColumnCount()
    {
        return 2;
    }

    /**
     * {@inheritDoc }
     */
    public int getRowCount()
    {
        return sourceList.size();
    }

    /**
     * @param rowIndex the row index.
     * @param columnIndex the column index
     * 
     * @return the value specified rowIndex and columnIndex. boolean in case of
     *         the first column, String replacement source label in case of the
     *         second column; null otherwise
     */
    public Object getValueAt(int rowIndex, int columnIndex)
    {
        String source = sourceList.get(rowIndex);
        switch (columnIndex)
        {
        case 0:
            boolean e =
                configService.getBoolean(ReplacementProperty
                    .getPropertyName(source), true);
            return e;
        case 1:
            return ChatConfigActivator.getResources().getI18NString(
                "plugin.chatconfig.replacement.sources." + source);
        default:
            return null;
        }

    }

    /**
     * @param rowIndex the row index
     * @param columnIndex the column index
     * 
     * @return boolean; true for first column false otherwise
     */
    public boolean isCellEditable(int rowIndex, int columnIndex)
    {
        return (columnIndex == 0);
    }

    /**
     * Set the value at rowIndex and columnIndex. Sets the replacement source
     * property enabled/disabled based on whether the first column is true or
     * false.
     * 
     * @param value The object to set at rowIndex and columnIndex
     * @param rowIndex
     * @param columnIndex
     */
    public void setValueAt(Object value, int rowIndex, int columnIndex)
    {
        if ((columnIndex == 0) && (value instanceof Boolean))
        {
            String source = sourceList.get(rowIndex);
            boolean e = (Boolean) value;
            configService.setProperty(ReplacementProperty
                .getPropertyName(source), e);
            configService.setProperty(ReplacementProperty.REPLACEMENT_ENABLE,
                Boolean.toString(e));
            fireTableCellUpdated(rowIndex, columnIndex);

        }
    }

}