r2730 - isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor
Author: chatellier Date: 2009-11-02 16:28:34 +0000 (Mon, 02 Nov 2009) New Revision: 2730 Removed: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/GenericCell.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/ParameterColumnEditor.java Log: Replaced by model style implementation Deleted: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/GenericCell.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/GenericCell.java 2009-11-02 16:27:43 UTC (rev 2729) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/GenericCell.java 2009-11-02 16:28:34 UTC (rev 2730) @@ -1,60 +0,0 @@ -/* *##% - * Copyright (C) 2002 - 2009 Code Lutin - * - * 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 fr.ifremer.isisfish.ui.widget.editor; - -/** - * GenericCell. - * - * @author letellier - * Copyright Code Lutin - * @version $Revision: 1628 $ - * - * Mise a jour: $Date: 2008-11-28 10:25:59 +0100 (ven 28 nov 2008) $ - * par : $Author: chatellier $ - * - * @deprecated since 3.2.0.5, Use specific model instead - */ -public class GenericCell { - private String name; - private Object value; - private Class<?> type; - - public GenericCell(String n, Object c, Class<?> t) { - name = n; - value = c; - type = t; - } - - @Override - public String toString() { - return name; - } - - public Object getValue() { - return value; - } - - public String getName() { - return name; - } - - public Class<?> getType() { - return type; - } -} Deleted: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/ParameterColumnEditor.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/ParameterColumnEditor.java 2009-11-02 16:27:43 UTC (rev 2729) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/ParameterColumnEditor.java 2009-11-02 16:28:34 UTC (rev 2730) @@ -1,500 +0,0 @@ -/* *##% - * Copyright (C) 2006 - 2009 - * Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin - * - * 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 fr.ifremer.isisfish.ui.widget.editor; - -import java.awt.Component; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.FocusEvent; -import java.util.ArrayList; -import java.util.EventObject; -import java.util.HashSet; -import java.util.List; - -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JPanel; -import javax.swing.JTable; -import javax.swing.JTextField; -import javax.swing.event.CellEditorListener; -import javax.swing.event.ChangeEvent; -import javax.swing.table.TableCellEditor; - -import org.apache.commons.beanutils.ConvertUtilsBean; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.util.MonthEnum; -import org.nuiton.util.EnumEditor; - -import fr.ifremer.isisfish.datastore.RegionStorage; -import fr.ifremer.isisfish.types.Date; -import fr.ifremer.isisfish.types.Month; -import fr.ifremer.isisfish.util.ConverterUtil; -import java.awt.event.ActionListener; -import java.awt.event.FocusListener; - -/** - * ParameterColumnEditor. - * - * Created: 25 sept. 06 12:35:21 - * - * @author poussin - * @author chemit - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - * - * @deprecated since 3.2.0.5, Use specific model instead - */ -public class ParameterColumnEditor extends JComponent implements - TableCellEditor { - - /** Class logger. */ - private static Log log = LogFactory.getLog(ParameterColumnEditor.class); - - private enum TypeClassMapping { - /** - * for simple int - */ - Int(int.class), - /** - * for a topia entity - */ - Topia(TopiaEntity.class), - /** - * for a mounth - */ - Mounth(Month.class), - /** - * for a simple date - */ - Date(Date.class), - /** - * for a simple boolean - */ - Double(double.class), - /** - * for a simple boolean - */ - Boolean(boolean.class), - /** - * for a file location - */ - File(java.io.File.class), - /** - * for a simple String - * - */ - String(java.lang.String.class); - - final Class<?> klazz; - - TypeClassMapping(Class<?> klazz) { - this.klazz = klazz; - } - - protected static TypeClassMapping getMapping(Class<?> klazz) { - for (TypeClassMapping t : TypeClassMapping.values()) - if (t.klazz.isAssignableFrom(klazz)) - return t; - throw new RuntimeException( - "could not found a TypeClassMapping for this class " - + klazz); - } - } - - private static final long serialVersionUID = 6860330126841984303L; - - protected HashSet<CellEditorListener> listeners = new HashSet<CellEditorListener>(); - - protected RegionStorage region = null; - - protected Component editor = null; - - protected Class type = null; - - /** - * @return Returns the topiaContext. - */ - public RegionStorage getRegion() { - return this.region; - } - - /** - * @param region - * The topiaContext to set. - */ - public void setRegion(RegionStorage region) { - this.region = region; - } - - @SuppressWarnings( { "unchecked" }) - public Component getTableCellEditorComponent(JTable table, Object value, - boolean isSelected, int row, int column) { - // Map.Entry<String, Class> p = (Map.Entry<String, Class>) table.getValueAt(row, 0); - // type = p.getValue(); - // log.debug(p.getKey() + " P.type:" + type); - GenericCell p = (GenericCell) table.getValueAt(row, 0); - type = (Class) p.getValue(); - JComboBox c; - //if (!table.hasFocus()) return null; - - TypeClassMapping mapping = TypeClassMapping.getMapping(type); - switch (mapping) { - case Topia: - // on a un bean comme parametre - try { - if (region == null) { - return null; - } - TopiaContext context = region.getStorage().beginTransaction(); - if (context != null) { - List list = context.find("from " + type.getName()); - c = new JComboBox(list.toArray()); - c.setSelectedItem(value); - editor = c; - context.closeContext(); - } - - } catch (Exception eee) { - if (log.isWarnEnabled()) { - log.warn("Can't get entity object for combobox", eee); - } - } - break; - case Boolean: - List<Boolean> listB = new ArrayList<Boolean>(); - listB.add(Boolean.TRUE); - listB.add(Boolean.FALSE); - c = new JComboBox(listB.toArray()); - listB.clear(); - // TODO See how to convert - c.setSelectedItem(value); - editor = c; - break; - case Date: - Date date = (Date) value; - if (date == null) - date = new Date(0); - int mou = date.getMonth().getMonthNumber(); - int yea = date.getYear(); - editor = new DateComponent(mou, yea, region == null ? null : region - .getStorage()); - //editor = new JTextField(String.valueOf(date.getDate())); - break; - case Mounth: - editor = DateComponent.createMounthCombo(((Month) value) - .getMonthNumber(), region == null ? null : region - .getStorage()); - break; - case File: - // break; - default: - editor = new JTextField(value.toString()); - } - if (editor != null) { - if (JComboBox.class.isInstance(editor)) { - ((JComboBox) editor).addActionListener(getComboListener()); - } else if (JTextField.class.isInstance(editor)) { - ((JTextField) editor).addFocusListener(new FocusListener() { - - @Override - public void focusGained(FocusEvent e) { - - } - - @Override - public void focusLost(FocusEvent e) { - stopCellEditing(); - } - }); - } else if (DateComponent.class.isInstance(editor)) { - DateComponent date = ((DateComponent) editor); - if (date.getMounthCombo() != null) { - date.getMounthCombo().addActionListener(getComboListener()); - } - if (date.getYearCombo() != null) { - date.getYearCombo().addActionListener(getComboListener()); - } - } - } - if (log.isInfoEnabled()) { - log.info("getCellEditorValue [" + type + "] [mapping:" + mapping + "=" - + editor); - } - //+ editor==null?null:editor.getClass().getSimpleName()); - return editor; - } - - protected ActionListener getComboListener() { - return new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - stopCellEditing(); - } - }; - } - - public Object getCellEditorValue() { - - Object result = null; - TopiaContext context = null; - if (editor == null) - return ""; - TypeClassMapping mapping = TypeClassMapping.getMapping(type); - switch (mapping) { - case Topia: - result = getComboBoxValue(editor); - break; - case Boolean: - result = getComboBoxValue(editor); - // TODO test - break; - case Mounth: - result = getComboBoxIndex(editor) + ""; - break; - case Date: - result = ((DateComponent) editor).getSelectedValue() + ""; - break; - case File: - //TODO - // result = getTextFieldValue(editor);break; - default: - if (editor instanceof JTextField) { - result = ((JTextField) editor).getText(); - } else if (editor instanceof JComboBox) { - result = ((JComboBox) editor).getSelectedItem(); - } - } - - if (result instanceof String && !String.class.equals(type)) { - if (region != null) - context = region.getStorage(); - ConvertUtilsBean cub = ConverterUtil.getConverter(context); - result = cub.convert((String) result, type); - } - - if (log.isInfoEnabled()) { - log.info("getCellEditorValue [" + type + "] [mapping:" + mapping - + "]= " + result); - } - - return result; - } - - protected Object getTextFieldValue(Component editor) { - return ((JTextField) editor).getText(); - } - - protected Object getComboBoxValue(Component editor) { - return ((JComboBox) editor).getSelectedItem(); - } - - protected int getComboBoxIndex(Component editor) { - return (((JComboBox) editor)).getSelectedIndex(); - } - - public Object getCellEditorValueOld() { - - Object result = null; - if (editor instanceof JTextField) { - result = ((JTextField) editor).getText(); - } else if (editor instanceof JComboBox) { - result = ((JComboBox) editor).getSelectedItem(); - } - - if (result instanceof String && !String.class.equals(type)) { - TopiaContext context = null; - if (region != null) { - context = region.getStorage(); - } - ConvertUtilsBean cub = ConverterUtil.getConverter(context); - result = cub.convert((String) result, type); - } - - return result; - } - - /* - * (non-Javadoc) - * - * @see javax.swing.CellEditor#addCellEditorListener(javax.swing.event.CellEditorListener) - */ - public void addCellEditorListener(CellEditorListener l) { - listeners.add(l); - } - - /* - * @see javax.swing.CellEditor#cancelCellEditing() - */ - public void cancelCellEditing() { - if (log.isDebugEnabled()) { - log.debug("cancelCellEditing"); - } - ChangeEvent e = new ChangeEvent(this); - for (CellEditorListener listener : listeners) { - listener.editingCanceled(e); - } - } - - /* - * @see javax.swing.CellEditor#isCellEditable(java.util.EventObject) - */ - public boolean isCellEditable(EventObject anEvent) { - return true; - } - - /* - * @see javax.swing.CellEditor#removeCellEditorListener(javax.swing.event.CellEditorListener) - */ - public void removeCellEditorListener(CellEditorListener l) { - listeners.remove(l); - } - - /* - * @see javax.swing.CellEditor#shouldSelectCell(java.util.EventObject) - */ - public boolean shouldSelectCell(EventObject anEvent) { - return true; - } - - /* - * @see javax.swing.CellEditor#stopCellEditing() - */ - public boolean stopCellEditing() { - // to prevent concurent modification exception - if (log.isDebugEnabled()) { - log.debug("stopCellEditing"); - } - CellEditorListener[] list = listeners - .toArray(new CellEditorListener[listeners.size()]); - - ChangeEvent e = new ChangeEvent(this); - for (CellEditorListener l : list) { - l.editingStopped(e); - } - return true; - } - - public static class DateComponent extends JPanel { - - private static final long serialVersionUID = -6694461572642939712L; - - protected JComboBox mounth; - - protected JComboBox year; - - public DateComponent(int mounth, int year, TopiaContext context) { - super(new GridLayout(0, 2)); - - this.mounth = createMounthCombo(mounth, context); - this.year = createYearCombo(200, year); - - this.add(this.mounth); - this.add(this.year); - } - - public JComboBox getYearCombo() { - return year; - } - - public JComboBox getMounthCombo() { - return mounth; - } - - public int getSelectedMounth() { - return mounth.getSelectedIndex(); - } - - public int getSelectedYear() { - return year.getSelectedIndex(); - } - - public void setSelectedValue(int year, int mounth) { - this.mounth.setSelectedIndex(mounth); - this.year.setSelectedIndex(year); - } - - public int getSelectedValue() { - int selectedYear = getSelectedYear(); - int selectedMounth = getSelectedMounth(); - if (log.isInfoEnabled()) { - log.info("selected mounth " + selectedMounth); - log.info("selected year " + selectedYear); - } - return selectedMounth + selectedYear * 12; - } - - public static JComboBox createMounthCombo(int mounth, - TopiaContext context) { - JComboBox combo = EnumEditor.newEditor(MonthEnum.class); - combo.setSelectedIndex(mounth); - return combo; - } - - /*public static JComboBox createMounthCombo(int mounth, TopiaContext context) { - JComboBox combo = createMounthCombo0(context); - combo.setSelectedIndex(mounth); - return combo; - }*/ - /*public static JComboBox createMounthCombo(Object mounth, TopiaContext context) { - JComboBox combo = createMounthCombo0(context); - combo.setSelectedItem(mounth); - return combo; - }*/ - - /*private static JComboBox createMounthCombo0(TopiaContext context) { - - List<String> listM = new ArrayList<String>(); - // TODO Should use database ? data instead of thoses awfull hardcore - // code... - listM.add("janvier"); - listM.add("fevrier"); - listM.add("mars"); - listM.add("avril"); - listM.add("mai"); - listM.add("juin"); - listM.add("juillet"); - listM.add("aout"); - listM.add("septembre"); - listM.add("octobre"); - listM.add("novembre"); - listM.add("decembre"); - JComboBox combo = new JComboBox(listM.toArray()); - listM.clear(); - return combo; - }*/ - - public static JComboBox createYearCombo(int nb, int yearS) { - - List<Integer> listI = new ArrayList<Integer>(); - for (int i = 0; i < nb; i++) - listI.add(i); - JComboBox year = new JComboBox(listI.toArray()); - listI.clear(); - year.setSelectedIndex(yearS); - return year; - } - } -}
participants (1)
-
chatellier@users.labs.libre-entreprise.org