001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.gui.access;
019:
020: import java.util.Iterator;
021: import java.util.List;
022: import java.util.TreeMap;
023:
024: import javax.swing.table.AbstractTableModel;
025:
026: import de.finix.contelligent.client.base.ContelligentComponent;
027: import de.finix.contelligent.client.i18n.Resources;
028: import de.finix.contelligent.client.security.ComponentAccess;
029:
030: class AccessTableModel extends AbstractTableModel {
031:
032: private Object[][] data = new Object[0][4];
033:
034: private String[] columnNames = {
035: Resources.getLocalString("principal"),
036: Resources.getLocalString("permission"),
037: Resources.getLocalString("mode"),
038: Resources.getLocalString("acl_time_header") };
039:
040: private boolean editable;
041:
042: private ContelligentComponent component;
043:
044: public AccessTableModel(ContelligentComponent component) {
045: this .component = component;
046: updateData();
047: }
048:
049: public void updateData() {
050: List acl = component.getACL();
051: data = new Object[acl.size()][4];
052: TreeMap<String, ComponentAccess> sorter = new TreeMap<String, ComponentAccess>();
053: for (int i = 0; i < acl.size(); i++) {
054: ComponentAccess aclEntry = (ComponentAccess) acl.get(i);
055: String baseKey = aclEntry.getPrincipal().getGroupId() + ":"
056: + aclEntry.getPrincipal().getId();
057: int j = 0;
058: do {
059: j++;
060: } while (sorter.get(baseKey + new Integer(j).toString()) != null);
061: sorter.put(baseKey + new Integer(j).toString(), aclEntry);
062: }
063: Iterator it = sorter.values().iterator();
064: for (int i = 0; it.hasNext(); i++) {
065: ComponentAccess aclEntry = (ComponentAccess) it.next();
066: data[i][0] = aclEntry;
067: data[i][1] = aclEntry;
068: data[i][2] = aclEntry;
069: data[i][3] = aclEntry;
070: }
071: fireTableDataChanged();
072: }
073:
074: public int getColumnCount() {
075: return columnNames.length;
076: }
077:
078: public int getRowCount() {
079: return data.length;
080: }
081:
082: public String getColumnName(int col) {
083: return columnNames[col];
084: }
085:
086: public Object getValueAt(int row, int col) {
087: return data[row][col];
088: }
089:
090: public Class getColumnClass(int c) {
091: return getValueAt(0, c).getClass();
092: }
093:
094: public boolean isCellEditable(int row, int col) {
095: // Note that the data/cell address is constant,
096: // no matter where the cell appears onscreen.
097: if ((col == 2) || (col == 3)) {
098: return editable;
099: }
100: return false;
101: }
102:
103: public void setEditable(boolean editable) {
104: this .editable = editable;
105: }
106:
107: public void setValueAt(Object value, int row, int col) {
108: if (value != null) {
109: data[row][col] = value;
110: addAclEntry((ComponentAccess) value);
111: fireTableCellUpdated(row, col);
112: }
113: }
114:
115: public ContelligentComponent getComponent() {
116: return component;
117: }
118:
119: public void addAclEntry(ComponentAccess entry) {
120: component.addAclEntry(entry);
121: updateData();
122: }
123:
124: public void removeAclEntry(ComponentAccess entry) {
125: component.removeAclEntry(entry);
126: updateData();
127: }
128: }
|