001: /*
002: * Lucane - a collaborative platform
003: * Copyright (C) 2005 Vincent Fiack <vfiack@mail15.com>
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019: package org.lucane.client.acl;
020:
021: import org.lucane.common.acl.AclInfo;
022: import org.lucane.client.util.Translation;
023: import org.lucane.client.Plugin;
024:
025: import javax.swing.table.AbstractTableModel;
026: import java.util.ArrayList;
027: import java.util.Iterator;
028:
029: public class AclTableModel extends AbstractTableModel {
030: private static final String[] columns = { "acl.lbl.permission",
031: "acl.lbl.allow", "acl.lbl.deny" };
032:
033: private Plugin plugin;
034: private AclEditor editor;
035: private ArrayList acls;
036: private String[] accesses;
037:
038: public AclTableModel(Plugin plugin, AclEditor editor,
039: String[] accesses, ArrayList acls) {
040: this .plugin = plugin;
041: this .editor = editor;
042: this .accesses = accesses;
043: this .acls = acls;
044: }
045:
046: public String getColumnName(int column) {
047: return Translation.tr(columns[column]);
048: }
049:
050: public int getColumnCount() {
051: return columns.length;
052: }
053:
054: public int getRowCount() {
055: return this .accesses.length;
056: }
057:
058: public boolean isCellEditable(int row, int col) {
059: return col != 0;
060: }
061:
062: public Object getValueAt(int rowIndex, int columnIndex) {
063: String access = (String) this .accesses[rowIndex];
064: if (columnIndex == 0)
065: return plugin.tr("acl." + access);
066:
067: Iterator infos = this .acls.iterator();
068: while (infos.hasNext()) {
069: AclInfo info = (AclInfo) infos.next();
070: if (info.getAccess().equals(access)) {
071: if (columnIndex == 1)
072: return Boolean.valueOf(info.isAllow());
073: else if (columnIndex == 2)
074: return Boolean.valueOf(info.isDeny());
075: }
076: }
077:
078: return Boolean.FALSE;
079: }
080:
081: public Class getColumnClass(int columnIndex) {
082: if (columnIndex == 0)
083: return String.class;
084:
085: return Boolean.class;
086: }
087:
088: public void setValueAt(Object aValue, int row, int column) {
089: String access = (String) accesses[row];
090: boolean value = aValue.equals(Boolean.TRUE);
091: boolean allow = (column == 1);
092:
093: if (value && allow)
094: editor.allowAccess(access);
095: else if (value)
096: editor.denyAccess(access);
097: else
098: editor.removeAccess(access);
099: }
100: }
|