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.List;
021:
022: import javax.swing.table.AbstractTableModel;
023:
024: import de.finix.contelligent.client.base.ContelligentComponent;
025: import de.finix.contelligent.client.i18n.Resources;
026: import de.finix.contelligent.client.security.Principal;
027:
028: class OwnerTableModel extends AbstractTableModel {
029:
030: private Object[][] data = new Object[0][1];
031:
032: private String[] columnNames = { Resources
033: .getLocalString("principal") };
034:
035: private ContelligentComponent component;
036:
037: public OwnerTableModel(ContelligentComponent component) {
038: this .component = component;
039: updateData();
040: }
041:
042: public void updateData() {
043: List owners = component.getOwners();
044: if (owners.size() == 0) {
045: data = new Object[1][1];
046: data[0][0] = Resources.getLocalString("no_owner_specified");
047: } else {
048: data = new Object[owners.size()][1];
049: for (int i = 0; i < owners.size(); i++) {
050: data[i][0] = (Principal) owners.get(i);
051: }
052: }
053: fireTableDataChanged();
054: }
055:
056: public int getColumnCount() {
057: return columnNames.length;
058: }
059:
060: public int getRowCount() {
061: return data.length;
062: }
063:
064: public String getColumnName(int col) {
065: return columnNames[col];
066: }
067:
068: public Object getValueAt(int row, int col) {
069: return data[row][col];
070: }
071:
072: public Class getColumnClass(int c) {
073: return getValueAt(0, c).getClass();
074: }
075:
076: public boolean isCellEditable(int row, int col) {
077: return false;
078: }
079:
080: public void setValueAt(Object value, int row, int col) {
081: fireTableCellUpdated(row, col);
082: }
083:
084: public void addOwner(Principal principal) {
085: component.addOwner(principal);
086: updateData();
087: }
088:
089: public void removeOwner(Principal principal) {
090: if (hasOwner()) {
091: component.removeOwner(principal);
092: updateData();
093: }
094: }
095:
096: public boolean hasOwner() {
097: if (component.getOwners().size() == 0) {
098: return false;
099: }
100: return true;
101: }
102:
103: public boolean hasOwner(Principal principal) {
104: for (int i = 0; i < component.getOwners().size(); i++) {
105: return false;
106: }
107: return true;
108: }
109: }
|