r2953 - in trunk: . lima-callao lima-callao/src/main/xmi lima-swing/src/main/java/org/chorem/lima/ui/celleditor lima-swing/src/main/java/org/chorem/lima/ui/combobox lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction lima-swing/src/main/java/org/chorem/lima/util
Author: jpepin Date: 2010-06-29 16:04:36 +0200 (Tue, 29 Jun 2010) New Revision: 2953 Url: http://chorem.org/repositories/revision/lima/2953 Log: Ajout de l'autocompl?\195?\169tion dans la fonction de saisie d'?\195?\169criture. Added: trunk/lima-swing/src/main/java/org/chorem/lima/util/AccountToString.java trunk/lima-swing/src/main/java/org/chorem/lima/util/EntryBookToString.java Modified: trunk/lima-callao/pom.xml trunk/lima-callao/src/main/xmi/accounting.zargo trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellEditor.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryBookTableCellEditor.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/AccountComboBoxModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/EntryBookComboBoxModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java trunk/pom.xml Modified: trunk/lima-callao/pom.xml =================================================================== --- trunk/lima-callao/pom.xml 2010-06-28 15:47:17 UTC (rev 2952) +++ trunk/lima-callao/pom.xml 2010-06-29 14:04:36 UTC (rev 2953) @@ -65,7 +65,12 @@ <phase>generate-sources</phase> <configuration> <inputs>zargo</inputs> - <templates>org.nuiton.topia.generator.TopiaMetaTransformer, org.nuiton.eugene.java.JavaBeanTransformer</templates> + <templates>org.nuiton.topia.generator.TopiaMetaTransformer, org.nuiton.topia.generator.EntityTransformer, org.nuiton.eugene.java.JavaBeanTransformer, org.nuiton.topia.generator.QueryHelperTransformer</templates> + <excludeTemplates> + <excludeTemplate>org.nuiton.topia.generator.EntityAbstractTransformer</excludeTemplate> + <excludeTemplate>org.nuiton.topia.generator.EntityImplTransformer</excludeTemplate> + <excludeTemplate>org.nuiton.topia.generator.EntityInterfaceTransformer</excludeTemplate> + </excludeTemplates> <defaultPackage>org.chorem.lima.entity</defaultPackage> <fullPackagePath>org.chorem.lima</fullPackagePath> </configuration> Modified: trunk/lima-callao/src/main/xmi/accounting.zargo =================================================================== (Binary files differ) Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellEditor.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellEditor.java 2010-06-28 15:47:17 UTC (rev 2952) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellEditor.java 2010-06-29 14:04:36 UTC (rev 2953) @@ -20,19 +20,25 @@ package org.chorem.lima.ui.celleditor; import java.awt.Component; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.util.EventObject; import javax.swing.AbstractCellEditor; import javax.swing.JTable; +import javax.swing.SwingUtilities; import javax.swing.table.TableCellEditor; +import javax.swing.text.JTextComponent; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.entity.Account; import org.chorem.lima.ui.combobox.AccountRenderer; import org.chorem.lima.ui.combobox.SubAccountComboBoxModel; +import org.chorem.lima.util.AccountToString; import org.chorem.lima.widgets.JWideComboBox; +import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator; public class AccountTableCellEditor extends AbstractCellEditor implements TableCellEditor { @@ -40,6 +46,7 @@ private final JWideComboBox comboBox; private static final long serialVersionUID = 2580476608066111095L; private static AccountTableCellEditor editor; + private static boolean keyPressed = false; /** * constructor @@ -50,6 +57,34 @@ comboBox.setModel(accountComboBoxModel); AccountRenderer accountRenderer = new AccountRenderer(); comboBox.setRenderer(accountRenderer); + AutoCompleteDecorator.decorate(comboBox, AccountToString.getInstance()); + + + /** + * Ajout d'un listener pour la frappe au clavier seulement, permettant + * de déplacer la sélection (et le caret) du fait que la première touche + * n'est pas prise en compte. + */ + comboBox.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() { + + @Override + public void keyReleased(KeyEvent e) { + // Vérifie si c'est la première frappe au clavier + if ( keyPressed == false ) + { + // Récupère l'editor de la comboBox + JTextComponent edit = (JTextComponent) comboBox.getEditor().getEditorComponent(); + // Met en place le curseur et la selection après la première lettre + edit.select(1, edit.getText().length()); + keyPressed = true; + } + // Validate editing with enter key + if ( e.getKeyChar() == KeyEvent.VK_ENTER ) + { + stopCellEditing(); + } + } + }); } @Override @@ -66,9 +101,37 @@ return comboBox.getSelectedItem(); } + /** + * Vérifie si la cellule peut être éditable : + * seulement si il y a une frappe au clavier ou un double clic. + * @param evt + * @return + */ @Override public boolean isCellEditable(EventObject evt) { - return !(evt instanceof MouseEvent) || ((MouseEvent) evt).getClickCount() == 2; + // Si il y a une frappe au clavier + if (evt instanceof KeyEvent) { + final KeyEvent keyEvent = (KeyEvent) evt; + // Empèche la touche echap + if ( keyEvent.getKeyChar() != KeyEvent.VK_ESCAPE ) + { + // Permet de placer le focus sur l'editor de la comboBox + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + comboBox.getEditor().getEditorComponent().requestFocus(); + JTextComponent edit = (JTextComponent) comboBox.getEditor().getEditorComponent(); + if (!Character.isIdentifierIgnorable(keyEvent.getKeyChar())) + { + edit.setText(Character.toString(keyEvent.getKeyChar())); + } + } + }); + } + } + // Remet à faux pour la premiere lettre tapée au clavier + keyPressed = false; + return ( !(evt instanceof MouseEvent) || ((MouseEvent) evt).getClickCount() == 2 ); } public static AccountTableCellEditor getInstance() { Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryBookTableCellEditor.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryBookTableCellEditor.java 2010-06-28 15:47:17 UTC (rev 2952) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryBookTableCellEditor.java 2010-06-29 14:04:36 UTC (rev 2953) @@ -20,19 +20,23 @@ package org.chorem.lima.ui.celleditor; import java.awt.Component; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.util.EventObject; - import javax.swing.AbstractCellEditor; import javax.swing.JTable; +import javax.swing.SwingUtilities; import javax.swing.table.TableCellEditor; - +import javax.swing.text.JTextComponent; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.ui.combobox.EntryBookComboBoxModel; import org.chorem.lima.ui.combobox.EntryBookRenderer; +import org.chorem.lima.util.EntryBookToString; import org.chorem.lima.widgets.JWideComboBox; +import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator; public class EntryBookTableCellEditor extends AbstractCellEditor implements TableCellEditor { @@ -40,6 +44,7 @@ private final JWideComboBox comboBox; private static final long serialVersionUID = 2580476608066111095L; private static EntryBookTableCellEditor editor; + private static boolean keyPressed = false; /** * constructor @@ -53,16 +58,44 @@ /*// Property Change Listener LimaContext.getContext().getDataManager().getJournalModel().addPropertyChangeListener(comboBoxModel); - comboBox.setModel(comboBoxModel); + comboBox.setModel(comboBoxModel);*/ + //LimaContext.getContext().addPropertyChangeListener(entryBookComboBoxModel); + // AutoCompletion - AutoCompleteDecorator.decorate(comboBox, JournalToStringConverter.getInstance());*/ + AutoCompleteDecorator.decorate(comboBox, EntryBookToString.getInstance()); + + /** + * Ajout d'un listener pour la frappe au clavier seulement, permettant + * de déplacer la sélection (et le caret) du fait que la première touche + * n'est pas prise en compte. + */ + comboBox.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() { + + @Override + public void keyReleased(KeyEvent e) { + // Vérifie si c'est la première frappe au clavier + if ( keyPressed == false ) + { + // Récupère l'editor de la comboBox + JTextComponent edit = (JTextComponent) comboBox.getEditor().getEditorComponent(); + // Met en place le curseur et la selection après la première lettre + edit.select(1, edit.getText().length()); + keyPressed = true; + } + // Validate editing with enter key + if ( e.getKeyChar() == KeyEvent.VK_ENTER ) + { + stopCellEditing(); + } + } + }); + } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { if (value instanceof EntryBook){ - comboBox.setSelectedItem((EntryBook) value); - + comboBox.setSelectedItem((EntryBook) value); } return comboBox; } @@ -72,9 +105,38 @@ return comboBox.getSelectedItem(); } + + /** + * Vérifie si la cellule peut être éditable : + * seulement si il y a une frappe au clavier ou un double clic. + * @param evt + * @return + */ @Override public boolean isCellEditable(EventObject evt) { - return !(evt instanceof MouseEvent) || ((MouseEvent) evt).getClickCount() == 2; + // Si il y a une frappe au clavier + if (evt instanceof KeyEvent) { + final KeyEvent keyEvent = (KeyEvent) evt; + // Empèche la touche echap + if ( keyEvent.getKeyChar() != KeyEvent.VK_ESCAPE ) + { + // Permet de placer le focus sur l'editor de la comboBox + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + comboBox.getEditor().getEditorComponent().requestFocus(); + JTextComponent edit = (JTextComponent) comboBox.getEditor().getEditorComponent(); + if (!Character.isIdentifierIgnorable(keyEvent.getKeyChar())) + { + edit.setText(Character.toString(keyEvent.getKeyChar())); + } + } + }); + } + } + // Remet à faux pour la premiere lettre tapée au clavier + keyPressed = false; + return ( !(evt instanceof MouseEvent) || ((MouseEvent) evt).getClickCount() == 2 ); } public static EntryBookTableCellEditor getInstance() { Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/AccountComboBoxModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/AccountComboBoxModel.java 2010-06-28 15:47:17 UTC (rev 2952) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/AccountComboBoxModel.java 2010-06-29 14:04:36 UTC (rev 2953) @@ -19,7 +19,6 @@ package org.chorem.lima.ui.combobox; import java.util.List; - import javax.swing.AbstractListModel; import javax.swing.ComboBoxModel; import org.apache.commons.logging.Log; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/EntryBookComboBoxModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/EntryBookComboBoxModel.java 2010-06-28 15:47:17 UTC (rev 2952) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/EntryBookComboBoxModel.java 2010-06-29 14:04:36 UTC (rev 2953) @@ -17,11 +17,9 @@ * ##%*/ package org.chorem.lima.ui.combobox; -import java.util.List; -import javax.swing.AbstractListModel; -import javax.swing.ComboBoxModel; -import javax.swing.event.ListDataListener; +import java.util.List; +import javax.swing.DefaultComboBoxModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.EntryBookService; @@ -39,7 +37,7 @@ * Last update : $Date$ * By : $Author$ */ -public class EntryBookComboBoxModel extends AbstractListModel implements ComboBoxModel { +public class EntryBookComboBoxModel extends DefaultComboBoxModel { private static final Log log = LogFactory.getLog(FinancialPeriodTableModel.class); @@ -94,5 +92,4 @@ cacheDatas = getDataList(); fireContentsChanged(this, 0, cacheDatas.size()); } - } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx 2010-06-28 15:47:17 UTC (rev 2952) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx 2010-06-29 14:04:36 UTC (rev 2953) @@ -22,7 +22,6 @@ <org.chorem.lima.ui.combobox.FiscalPeriodComboBoxModel id="modelFiscalPeriod"/> <script> <![CDATA[ - import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.FinancialPeriod; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java 2010-06-28 15:47:17 UTC (rev 2952) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java 2010-06-29 14:04:36 UTC (rev 2953) @@ -171,8 +171,7 @@ public void refresh(){ tableModel = view.getFinancialTransactionTableModel(); - tableModel.refresh(); - + tableModel.refresh(); fiscalPeriodComboBoxModel = view.getModelFiscalPeriod(); fiscalPeriodComboBoxModel.refresh(); Added: trunk/lima-swing/src/main/java/org/chorem/lima/util/AccountToString.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/util/AccountToString.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/util/AccountToString.java 2010-06-29 14:04:36 UTC (rev 2953) @@ -0,0 +1,29 @@ +package org.chorem.lima.util; + +import org.chorem.lima.entity.Account; +import org.jdesktop.swingx.autocomplete.ObjectToStringConverter; + +public class AccountToString extends ObjectToStringConverter { + + private static AccountToString converter; + + @Override + public String getPreferredStringForItem(Object item) { + String result = null; + if (item != null){ + if (item instanceof Account){ + Account account = (Account) item; + result = account.getAccountNumber()+" - "+account.getLabel(); + } + } + return result; + } + + public static AccountToString getInstance() { + if (converter == null) { + converter = new AccountToString(); + } + return converter; + } + +} Added: trunk/lima-swing/src/main/java/org/chorem/lima/util/EntryBookToString.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/util/EntryBookToString.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/util/EntryBookToString.java 2010-06-29 14:04:36 UTC (rev 2953) @@ -0,0 +1,47 @@ +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin + * + * 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.chorem.lima.util; + +import org.chorem.lima.entity.EntryBook; +import org.jdesktop.swingx.autocomplete.ObjectToStringConverter; + +public class EntryBookToString extends ObjectToStringConverter{ + + private static EntryBookToString converter; + + @Override + public String getPreferredStringForItem(Object item) { + String result = null; + if (item != null){ + if (item instanceof EntryBook){ + EntryBook entryBook = (EntryBook) item; + result = entryBook.getCode()+" - "+entryBook.getLabel(); + } + } + return result; + } + + + public static EntryBookToString getInstance() { + if (converter == null) { + converter = new EntryBookToString(); + } + return converter; + } +} Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-06-28 15:47:17 UTC (rev 2952) +++ trunk/pom.xml 2010-06-29 14:04:36 UTC (rev 2953) @@ -241,8 +241,8 @@ <!-- customized libs version --> <nuiton-utils.version>1.2.2</nuiton-utils.version> - <eugene.version>2.0.2-SNAPSHOT</eugene.version> - <topia.version>2.3.4</topia.version> + <eugene.version>2.0.3-SNAPSHOT</eugene.version> + <topia.version>2.3.5-SNAPSHOT</topia.version> <jaxx.version>2.0.2</jaxx.version> <i18n.version>1.2.2</i18n.version>
participants (1)
-
jpepin@users.chorem.org