KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > client > acl > AclTableModel


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2005 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.client.acl;
20
21 import org.lucane.common.acl.AclInfo;
22 import org.lucane.client.util.Translation;
23 import org.lucane.client.Plugin;
24
25 import javax.swing.table.AbstractTableModel JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28
29 public class AclTableModel extends AbstractTableModel JavaDoc
30 {
31     private static final String JavaDoc[] columns = {"acl.lbl.permission", "acl.lbl.allow", "acl.lbl.deny"};
32
33     private Plugin plugin;
34     private AclEditor editor;
35     private ArrayList JavaDoc acls;
36     private String JavaDoc[] accesses;
37
38     public AclTableModel(Plugin plugin, AclEditor editor, String JavaDoc[] accesses, ArrayList JavaDoc acls)
39     {
40         this.plugin = plugin;
41         this.editor = editor;
42         this.accesses = accesses;
43         this.acls = acls;
44     }
45
46     public String JavaDoc getColumnName(int column) {
47         return Translation.tr(columns[column]);
48     }
49
50     public int getColumnCount() {
51         return columns.length;
52     }
53
54     public int getRowCount() {
55         return this.accesses.length;
56     }
57
58     public boolean isCellEditable(int row, int col) {
59         return col != 0;
60     }
61
62     public Object JavaDoc getValueAt(int rowIndex, int columnIndex) {
63         String JavaDoc access = (String JavaDoc)this.accesses[rowIndex];
64         if(columnIndex == 0)
65             return plugin.tr("acl." + access);
66
67         Iterator JavaDoc infos = this.acls.iterator();
68         while(infos.hasNext())
69         {
70             AclInfo info = (AclInfo)infos.next();
71             if(info.getAccess().equals(access))
72             {
73                 if(columnIndex == 1)
74                     return Boolean.valueOf(info.isAllow());
75                 else if(columnIndex == 2)
76                     return Boolean.valueOf(info.isDeny());
77             }
78         }
79
80         return Boolean.FALSE;
81     }
82
83      public Class JavaDoc getColumnClass(int columnIndex) {
84         if(columnIndex == 0)
85             return String JavaDoc.class;
86
87         return Boolean JavaDoc.class;
88     }
89
90     public void setValueAt(Object JavaDoc aValue, int row, int column)
91     {
92         String JavaDoc access = (String JavaDoc)accesses[row];
93         boolean value = aValue.equals(Boolean.TRUE);
94         boolean allow = (column == 1);
95
96         if(value && allow)
97             editor.allowAccess(access);
98         else if(value)
99             editor.denyAccess(access);
100         else
101             editor.removeAccess(access);
102     }
103 }
Popular Tags