Author: kmorin Date: 2014-12-11 14:13:27 +0000 (Thu, 11 Dec 2014) New Revision: 726 Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/726 Log: fixes #6284 Garder le filtre du tableau tout au long de l'application Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/DecoratorServiceImpl.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/FaxToMailUIContext.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListTableFilter.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUIHandler.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/DemandeTableModel.java trunk/pom.xml Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/DecoratorServiceImpl.java =================================================================== --- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/DecoratorServiceImpl.java 2014-12-09 11:19:50 UTC (rev 725) +++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/DecoratorServiceImpl.java 2014-12-11 14:13:27 UTC (rev 726) @@ -138,7 +138,7 @@ } }); registerMultiJXPathDecorator(Reply.class, "${sentDate}$s#${subject}$s", SEPARATOR, " - "); - registerMultiJXPathDecorator(FaxToMailUser.class, "${trigraph}$s#${firstName}$s#${lastName}$s", SEPARATOR, " "); + registerMultiJXPathDecorator(FaxToMailUser.class, "${lastName}$s#${firstName}$s#${trigraph}$s", SEPARATOR, " "); } }; } Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/FaxToMailUIContext.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/FaxToMailUIContext.java 2014-12-09 11:19:50 UTC (rev 725) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/FaxToMailUIContext.java 2014-12-11 14:13:27 UTC (rev 726) @@ -41,7 +41,9 @@ import javax.swing.JOptionPane; import com.franciaflex.faxtomail.persistence.entities.Email; +import com.franciaflex.faxtomail.persistence.entities.EmailFilter; import com.franciaflex.faxtomail.services.service.ldap.Contact; +import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeListTableFilter; import jaxx.runtime.swing.editor.bean.BeanDoubleList; import jaxx.runtime.swing.editor.bean.BeanFilterableComboBox; import jaxx.runtime.swing.session.BeanDoubleListState; @@ -49,6 +51,7 @@ import jaxx.runtime.swing.session.State; import jaxx.runtime.swing.session.SwingSession; +import jaxx.runtime.swing.table.filter.TableFilter; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; @@ -56,6 +59,7 @@ import org.jdesktop.beans.AbstractBean; import org.jdesktop.swingx.JXLoginPane; import org.jdesktop.swingx.JXLoginPane.Status; +import org.jdesktop.swingx.JXTable; import org.jdesktop.swingx.auth.LoginService; import org.jdesktop.swingx.error.ErrorInfo; import org.nuiton.i18n.I18n; @@ -225,6 +229,8 @@ /** */ protected List<Contact> contactCache; + protected EmailFilter emailFilter = new EmailFilter(); + public static FaxToMailUIContext newContext(FaxToMailConfiguration config) { Preconditions.checkNotNull(config); Preconditions.checkState(applicationContext == null, @@ -394,6 +400,7 @@ // init action UI //--------------------------------------------------------------------// setActionUI(new ApplicationActionUI(null, this)); + } /** @@ -861,4 +868,12 @@ this.paginationResult = paginationResult; } } + + public EmailFilter getEmailFilter() { + return emailFilter; + } + + public void setEmailFilter(EmailFilter emailFilter) { + this.emailFilter = emailFilter; + } } Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListTableFilter.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListTableFilter.java 2014-12-09 11:19:50 UTC (rev 725) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListTableFilter.java 2014-12-11 14:13:27 UTC (rev 726) @@ -285,7 +285,7 @@ executeFilter(); } - protected void executeFilter() { + public void executeFilter() { FaxToMailUIContext context = handler.getContext(); // reset pagination when folder change Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUIHandler.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUIHandler.java 2014-12-09 11:19:50 UTC (rev 725) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUIHandler.java 2014-12-11 14:13:27 UTC (rev 726) @@ -30,12 +30,17 @@ import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseEvent; +import java.beans.IntrospectionException; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.beans.PropertyDescriptor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.Enumeration; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -51,17 +56,24 @@ import javax.swing.tree.TreePath; import com.franciaflex.faxtomail.persistence.entities.Configuration; +import com.franciaflex.faxtomail.persistence.entities.DemandType; import com.franciaflex.faxtomail.persistence.entities.EmailFilter; import com.franciaflex.faxtomail.persistence.entities.MailAction; +import com.franciaflex.faxtomail.persistence.entities.Priority; +import com.franciaflex.faxtomail.persistence.entities.Range; +import com.franciaflex.faxtomail.persistence.entities.WaitingState; import com.franciaflex.faxtomail.services.service.EmailService; import com.franciaflex.faxtomail.ui.swing.FaxToMailUIContext; import com.franciaflex.faxtomail.ui.swing.actions.OpenMailFolderChooserFromListAction; import com.franciaflex.faxtomail.ui.swing.util.DemandeTableModel; +import com.google.common.collect.Lists; import jaxx.runtime.JAXXUtil; +import jaxx.runtime.swing.table.filter.FilterChangeListener; import jaxx.runtime.swing.table.filter.TableFilter; import jaxx.runtime.swing.table.filter.TableRowFilterSupport; import jaxx.runtime.validator.swing.SwingValidator; +import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -97,6 +109,10 @@ import com.franciaflex.faxtomail.ui.swing.util.PaginationComboModel; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; +import org.nuiton.util.ObjectUtil; +import org.nuiton.util.beans.BeanUtil; +import org.nuiton.util.beans.Binder; +import org.nuiton.util.beans.BinderFactory; import org.nuiton.util.pagination.PaginationParameter; /** @@ -113,16 +129,26 @@ protected Configuration config; - protected TableFilter<JXTable> tableFilter; + protected DemandeListTableFilter tableFilter; + protected final Binder<EmailFilter, EmailFilter> binder = BinderFactory.newBinder(EmailFilter.class); + public TableFilter<JXTable> getTableFilter() { return tableFilter; } - public final PropertyChangeListener selectedDemandeChangeListener = new PropertyChangeListener() { + protected final PropertyChangeListener emailFilterPropertyChangeListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { + EmailFilter emailFilter = (EmailFilter) evt.getSource(); + binder.copy(emailFilter, getContext().getEmailFilter(), evt.getPropertyName()); + } + }; + protected final PropertyChangeListener selectedDemandeChangeListener = new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + String propertyName = evt.getPropertyName(); if (Email.PROPERTY_PRIORITY.equals(propertyName)) { if (evt.getNewValue() != null || evt.getOldValue() != null) { @@ -304,6 +330,12 @@ } public void initTableFilter() { + + EmailFilter emailFilter = getModel().getEmailFilter(); + emailFilter.removePropertyChangeListener(emailFilterPropertyChangeListener); + filtersFromContextToModel(); + emailFilter.addPropertyChangeListener(emailFilterPropertyChangeListener); + Decorator<Object> decorator = new Decorator<Object>(Object.class) { @Override public String toString(Object bean) { @@ -320,14 +352,156 @@ return s; } }; - TableRowFilterSupport.forFilter(tableFilter) - .searchable(true) - .searchDecorator(decorator) - .useTableRenderers(true) - .setPopupDefaultSize(new Dimension(250, 290)) - .apply(); + + JTable table = TableRowFilterSupport.forFilter(tableFilter) + .searchable(true) + .searchDecorator(decorator) + .useTableRenderers(true) + .setPopupDefaultSize(new Dimension(250, 290)) + .apply(); + + tableFilter.modelChanged(table.getModel()); } + protected void filtersFromContextToModel() { + EmailFilter contextEmailFilter = getContext().getEmailFilter(); + EmailFilter currentEmailFilter = getModel().getEmailFilter(); + + currentEmailFilter.clear(); + + List<MailField> fields = getColumns(); + if (CollectionUtils.isEmpty(fields)) { + fields = Lists.newArrayList(MailField.getTableFields()); + } + + List<String> propertiesToBind = new ArrayList<>(); + + for (int i = 0; i < fields.size(); i++) { + String property = null; + + MailField field = fields.get(i); + switch (field) { + case DEMAND_STATUS: + property = EmailFilter.PROPERTY_DEMAND_STATUS; + break; + + case RECEPTION_DATE: + property = EmailFilter.PROPERTY_RECEPTION_DATES; + break; + + case RECIPIENT: + property = EmailFilter.PROPERTY_RECIPIENTS; + break; + + case SENDER: + property = EmailFilter.PROPERTY_SENDERS; + break; + + case OBJECT: + property = EmailFilter.PROPERTY_DEMAND_OBJECTS; + break; + + case CLIENT_CODE: + property = EmailFilter.PROPERTY_CLIENT_CODES; + break; + + case CLIENT_BRAND: + property = EmailFilter.PROPERTY_CLIENT_BRANDS; + break; + + case DEMAND_TYPE: + property = EmailFilter.PROPERTY_DEMAND_TYPES; + break; + + case EDI_RETURN: + property = EmailFilter.PROPERTY_EDI_CODE_NUMBERS; + break; + + case WAITING_STATE: + property = EmailFilter.PROPERTY_WAITING_STATES; + break; + + case TAKEN_BY: + property = EmailFilter.PROPERTY_TAKEN_BYS; + break; + + case PRIORITY: + property = EmailFilter.PROPERTY_PRIORITIES; + break; + + case PROJECT_REFERENCE: + property = EmailFilter.PROPERTY_PROJECT_REFERENCES; + break; + + case COMPANY_REFERENCE: + property = EmailFilter.PROPERTY_LOCAL_REFERENCES; + break; + + case REFERENCE: + property = EmailFilter.PROPERTY_REFERENCES; + break; + + case RANGE_ROW: + property = EmailFilter.PROPERTY_RANGES; + break; + + case PF_NB: + property = EmailFilter.PROPERTY_PRODUCT_QUANTITIES; + break; + + case SAV_NB: + property = EmailFilter.PROPERTY_SAV_QUANTITIES; + break; + + case QUOTATION_NB: + property = EmailFilter.PROPERTY_QUOTATION_QUANTITIES; + break; + + case LAST_ATTACHMENT_OPENING_IN_THIS_FOLDER_USER: + property = EmailFilter.PROPERTY_LAST_ATTACHMENT_OPENERS; + break; + + case COMMENT: + property = EmailFilter.PROPERTY_COMMENTS; + break; + } + + if (log.isDebugEnabled()) { + log.debug(i + "property to copy to model's emailfilter : " + property); + } + if (property != null) { + try { + Method getter = new PropertyDescriptor(property, EmailFilter.class).getReadMethod(); + Collection value = (Collection) getter.invoke(contextEmailFilter); + tableFilter.setFilterState(i, value); + + } catch (IntrospectionException e) { + if (log.isErrorEnabled()) { + log.error("error while introspecting emailfilter for property " + property, e); + } + } catch (InvocationTargetException e) { + if (log.isErrorEnabled()) { + log.error("error while calling getter for property " + property, e); + } + } catch (IllegalAccessException e) { + if (log.isErrorEnabled()) { + log.error("error while calling getter for property " + property, e); + } + } + propertiesToBind.add(property); + + } else { + tableFilter.setFilterState(i, null); + } + } + + binder.copy(contextEmailFilter, currentEmailFilter, propertiesToBind.toArray(new String[propertiesToBind.size()])); + } + + public String populateColumnModel(JXTable table, boolean sortable) { + return super.populateColumnModel(table, sortable); + } + protected void loadFolderDemands(MailFolder folder, Map<MailFolder, FolderTreeNode> nodesByFolder) { if (folder != null) { FolderTreeNode folderNode = nodesByFolder.get(folder); @@ -343,7 +517,7 @@ model.setNewDemandEnabled(readable && folder != null && Boolean.TRUE.equals(folder.getAllowCreateDemandIntoFolder())); } - tableFilter.clear(); + tableFilter.executeFilter(); } public void goToNextPage() { @@ -443,6 +617,8 @@ log.debug("closing: " + ui); } + getModel().getEmailFilter().removePropertyChangeListener(emailFilterPropertyChangeListener); + JTree tree = getUI().getNavigationTree(); TreeModel treeModel = tree.getModel(); Enumeration<TreePath> paths = tree.getExpandedDescendants(new TreePath(treeModel.getRoot())); Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/DemandeTableModel.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/DemandeTableModel.java 2014-12-09 11:19:50 UTC (rev 725) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/DemandeTableModel.java 2014-12-11 14:13:27 UTC (rev 726) @@ -360,9 +360,6 @@ public final Object getValueAt(int rowIndex, int columnIndex) { DemandeUIModel entry = getEntry(rowIndex); ColumnIdentifier<DemandeUIModel> identifier = getIdentifier(columnIndex); - if (log.isDebugEnabled()) { - log.debug("columnIndex: " + columnIndex + " :: " + identifier.getPropertyName()); - } Object result = identifier.getValue(entry); return result; } Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2014-12-09 11:19:50 UTC (rev 725) +++ trunk/pom.xml 2014-12-11 14:13:27 UTC (rev 726) @@ -111,7 +111,7 @@ <h2Version>1.3.176</h2Version> <guavaVersion>18.0</guavaVersion> - <jaxxVersion>2.18-SNAPSHOT</jaxxVersion> + <jaxxVersion>2.19-SNAPSHOT</jaxxVersion> <!-- do not upgrade to 1.6.5-1 --> <swingXVersion>1.6.4</swingXVersion> <xworkVersion>2.3.16.3</xworkVersion>