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.directory;
019:
020: import java.util.Iterator;
021: import java.util.logging.Level;
022: import java.util.logging.Logger;
023:
024: import javax.swing.table.DefaultTableModel;
025:
026: import de.finix.contelligent.client.base.ComponentFactory;
027: import de.finix.contelligent.client.base.ComponentNotFoundException;
028: import de.finix.contelligent.client.base.ContelligentComponent;
029: import de.finix.contelligent.client.gui.View;
030: import de.finix.contelligent.client.i18n.Resources;
031:
032: public class FolderTableModel extends DefaultTableModel {
033:
034: private static Logger logger = Logger
035: .getLogger(FolderTableModel.class.getName());
036:
037: private ContelligentComponent component;
038:
039: private boolean editable = false;
040:
041: private View view;
042:
043: public FolderTableModel(ContelligentComponent component, View view) {
044: this .component = component;
045: this .view = view;
046: setColumnCount(3);
047: setColumnIdentifiers(new String[] {
048: Resources.getLocalString("name"),
049: Resources.getLocalString("type"),
050: Resources.getLocalString("date") });
051: updateModel();
052: }
053:
054: View getView() {
055: return view;
056: }
057:
058: public void updateModel() {
059: String subcomponentName = null;
060: ContelligentComponent subcomponent = null;
061: setRowCount(0);
062: for (Iterator j = component.getSubcomponents().iterator(); j
063: .hasNext();) {
064: subcomponentName = (String) j.next();
065: try {
066: subcomponent = ComponentFactory.getInstance()
067: .getComponent(
068: component.getPath() + "/"
069: + subcomponentName);
070: addRow(new Object[] { subcomponent, subcomponent,
071: subcomponent });
072: } catch (ComponentNotFoundException cnfe) {
073: logger.log(Level.SEVERE,
074: "Could not update subcomponent!", cnfe);
075: }
076: }
077: }
078:
079: public int getComponentRow(ContelligentComponent searched) {
080: int result = -1;
081: for (int i = 0; i < getRowCount(); i++) {
082: ContelligentComponent found = (ContelligentComponent) getValueAt(
083: i, 0);
084: if (searched.equals(found)) {
085: result = i;
086: }
087: }
088: return result;
089: }
090:
091: public Class getColumnClass(int columnIndex) {
092: return ContelligentComponent.class;
093: }
094:
095: public boolean isCellEditable(int row, int col) {
096: // Note that the data/cell address is constant,
097: // no matter where the cell appears onscreen.
098: if (col == 1) {
099: return editable;
100: }
101: return false;
102: }
103:
104: public void setEditable(boolean editable) {
105: this .editable = editable;
106: }
107:
108: public boolean isEditable() {
109: return editable;
110: }
111:
112: /**
113: * Sets the component.
114: *
115: * @param component
116: * The component to set
117: */
118: public void setComponent(ContelligentComponent component) {
119: this.component = component;
120: }
121:
122: }
|