Index: lutinutil/src/java/org/codelutin/option/ui/ConfigTableEditor.java diff -u /dev/null lutinutil/src/java/org/codelutin/option/ui/ConfigTableEditor.java:1.1 --- /dev/null Tue Jan 8 23:50:49 2008 +++ lutinutil/src/java/org/codelutin/option/ui/ConfigTableEditor.java Tue Jan 8 23:50:43 2008 @@ -0,0 +1,100 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, +* Tony Chemit +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package org.codelutin.option.ui; + +import org.codelutin.option.ConfigPropertyKey; +import org.codelutin.util.EnumEditor; + +import javax.swing.JTable; +import javax.swing.DefaultCellEditor; +import javax.swing.event.CellEditorListener; +import javax.swing.table.TableCellEditor; +import java.awt.Component; +import java.util.EventObject; + +/** + * L'éditeur des valeurs des propriétés d'une configuration + * + * @author chemit + */ +public class ConfigTableEditor implements TableCellEditor { + + protected TableCellEditor delegate; + protected ConfigTableModel model; + + public ConfigTableEditor(ConfigTableModel model) { + this.model = model; + } + + public Object getCellEditorValue() { + return delegate == null ? null : delegate.getCellEditorValue(); + } + + public boolean isCellEditable(EventObject anEvent) { + return delegate == null || delegate.isCellEditable(anEvent); + } + + public boolean shouldSelectCell(EventObject anEvent) { + return delegate != null && delegate.shouldSelectCell(anEvent); + } + + public boolean stopCellEditing() { + return delegate == null || delegate.stopCellEditing(); + } + + public void cancelCellEditing() { + if (delegate != null) { + delegate.cancelCellEditing(); + } + } + + public void addCellEditorListener(CellEditorListener l) { + if (delegate != null) { + delegate.addCellEditorListener(l); + } + } + + public void removeCellEditorListener(CellEditorListener l) { + if (delegate != null) { + delegate.removeCellEditorListener(l); + } + } + + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + if (column == 0) { + return null; + } + ConfigPropertyKey key = model.getKey(row); + Class type = key.getType(); + delegate = table.getDefaultEditor(type); + TableCellEditor defaultEditor = table.getDefaultEditor(Object.class); + if (delegate == defaultEditor) { + if (type.isEnum()) { + // add a EnumEditor to table + delegate = new DefaultCellEditor(EnumEditor.newEditor(type)); + table.setDefaultEditor(type,delegate); + } else { + delegate = table.getDefaultEditor(String.class); + } + } + Component comp; + comp = delegate.getTableCellEditorComponent(table, value, isSelected, row, column); + return comp; + } +}