r1659 - isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor
Author: sletellier Date: 2008-12-11 15:35:31 +0000 (Thu, 11 Dec 2008) New Revision: 1659 Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/ParameterColumnEditor.java Log: StopEditing work Modified: 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 2008-12-10 16:49:59 UTC (rev 1658) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/ParameterColumnEditor.java 2008-12-11 15:35:31 UTC (rev 1659) @@ -33,6 +33,8 @@ 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; @@ -60,6 +62,8 @@ 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; /** * @author poussin @@ -156,7 +160,9 @@ type = (Class)p.getValue(); JComboBox c; //if (!table.hasFocus()) return null; - + + + TypeClassMapping mapping = TypeClassMapping.getMapping(type); switch (mapping) { case Topia: @@ -201,11 +207,48 @@ 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()); + } + } + } 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; @@ -297,6 +340,7 @@ * @see javax.swing.CellEditor#cancelCellEditing() */ public void cancelCellEditing() { + log.debug("cancelCellEditing"); ChangeEvent e = new ChangeEvent(this); for (CellEditorListener listener : listeners) { listener.editingCanceled(e); @@ -337,6 +381,7 @@ */ public boolean stopCellEditing() { // to prevent concurent modification exception + log.debug("stopCellEditing"); CellEditorListener[] list = listeners .toArray(new CellEditorListener[listeners.size()]); @@ -365,6 +410,13 @@ this.add(this.year); } + public JComboBox getYearCombo(){ + return year; + } + public JComboBox getMounthCombo(){ + return mounth; + } + public int getSelectedMounth() { return mounth.getSelectedIndex(); }
participants (1)
-
sletellier@users.labs.libre-entreprise.org