Author: kmorin Date: 2014-08-05 11:25:13 +0200 (Tue, 05 Aug 2014) New Revision: 468 Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/468 Log: test modif syst?\195?\168me transaction (ca build pas, c'est normal) Added: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/Command.java Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceContext.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/actions/LoadFolderEmailsAction.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/content/demande/DemandesUIHandler.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchToGroupUIHandler.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/AbstractFaxToMailUIHandler.java Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceContext.java =================================================================== --- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceContext.java 2014-08-05 08:22:38 UTC (rev 467) +++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceContext.java 2014-08-05 09:25:13 UTC (rev 468) @@ -24,10 +24,19 @@ * #L% */ +import java.io.Closeable; +import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.Date; +import com.franciaflex.faxtomail.persistence.entities.FaxToMailTopiaApplicationContext; +import com.franciaflex.faxtomail.services.service.ConfigurationService; +import com.franciaflex.faxtomail.services.service.EmailService; +import com.franciaflex.faxtomail.services.service.MailFolderService; +import com.franciaflex.faxtomail.services.service.ReferentielService; +import com.franciaflex.faxtomail.services.service.UserService; +import com.franciaflex.faxtomail.services.service.ValidationService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.jaxx.application.ApplicationTechnicalException; @@ -37,26 +46,35 @@ import com.franciaflex.faxtomail.services.service.LdapService; import com.franciaflex.faxtomail.services.service.ldap.LdapServiceMock; -public class FaxToMailServiceContext { +public class FaxToMailServiceContext implements Closeable { private static final Log log = LogFactory.getLog(FaxToMailServiceContext.class); protected FaxToMailConfiguration applicationConfig; + protected FaxToMailTopiaApplicationContext topiaApplicationContext; + protected FaxToMailTopiaPersistenceContext persistenceContext; + public FaxToMailServiceContext(FaxToMailTopiaApplicationContext topiaApplicationContext) { + this.topiaApplicationContext = topiaApplicationContext; + } + public FaxToMailConfiguration getApplicationConfig() { return applicationConfig; } - public void setPersistenceContext(FaxToMailTopiaPersistenceContext persistenceContext) { - this.persistenceContext = persistenceContext; - } - public FaxToMailTopiaPersistenceContext getPersistenceContext() { + if (persistenceContext == null) { + persistenceContext = topiaApplicationContext.newPersistenceContext(); + } return persistenceContext; } + public FaxToMailTopiaApplicationContext getTopiaApplicationContext() { + return topiaApplicationContext; + } + public void setApplicationConfig(FaxToMailConfiguration applicationConfig) { this.applicationConfig = applicationConfig; } @@ -88,4 +106,43 @@ Date now = new Date(); return now; } + + public DecoratorService getDecoratorService() { + return newService(DecoratorService.class); + } + + public ValidationService getValidationService() { + return newService(ValidationService.class); + } + + public MailFolderService getMailFolderService() { + return newService(MailFolderService.class); + } + + public UserService getUserService() { + return newService(UserService.class); + } + + public LdapService getLdapService() { + return newService(LdapService.class); + } + + public EmailService getEmailService() { + return newService(EmailService.class); + } + + public ReferentielService getReferentielService() { + return newService(ReferentielService.class); + } + + public ConfigurationService getConfigurationService() { + return newService(ConfigurationService.class); + } + + @Override + public void close() throws IOException { + if (persistenceContext != null) { + persistenceContext.close(); + } + } } 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-08-05 08:22:38 UTC (rev 467) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/FaxToMailUIContext.java 2014-08-05 09:25:13 UTC (rev 468) @@ -45,6 +45,7 @@ import jaxx.runtime.swing.session.State; import jaxx.runtime.swing.session.SwingSession; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -133,11 +134,6 @@ protected FaxToMailTopiaApplicationContext topiaApplicationContext; /** - * Service context used by any service. - */ - protected final FaxToMailServiceContext serviceContext; - - /** * Swing session used to save ui states. */ protected final SwingSession swingSession; @@ -225,12 +221,9 @@ protected FaxToMailUIContext(FaxToMailConfiguration config) { this.config = config; this.resourceLoader = new RessourceClassLoader(Thread.currentThread().getContextClassLoader()); - this.serviceContext = new FaxToMailServiceContext(); topiaApplicationContext = new FaxToMailTopiaApplicationContext(config.getTopiaProperties()); - FaxToMailTopiaPersistenceContext persistenceContext = topiaApplicationContext.newPersistenceContext(); - serviceContext.setPersistenceContext(persistenceContext); - serviceContext.setApplicationConfig(config); + FaxToMailServiceContext serviceContext = newServiceContext(); InitFaxToMailService initExtranetService = serviceContext.newService(InitFaxToMailService.class); @@ -287,20 +280,6 @@ faxToMailActionEngine = new ApplicationActionEngine(faxToMailActionFactory); } - /** - * Ferme la transaction actuelle et en ouvre une nouvelle pour casser le problème d'isolation - * des données. Cela permet d'ouvrir une nouvelle transaction qui verra les modifications faites - * par le serveur hors de la transaction précédente. - */ - public void createNewTransaction() { - // ne pas faire le close deux fois, ca lance une exception - if (!serviceContext.getPersistenceContext().isClosed()) { - serviceContext.getPersistenceContext().close(); - } - FaxToMailTopiaPersistenceContext persistenceContext = topiaApplicationContext.newPersistenceContext(); - serviceContext.setPersistenceContext(persistenceContext); - } - @Override public ApplicationConfiguration getConfiguration() { return config; @@ -384,43 +363,50 @@ String principal = getLoggedInUsername(); // l'authentification par defaut se fait par trigramme + final FaxToMailServiceContext serviceContext = newServiceContext(); try { - FaxToMailUser currentUser = getLdapService().getUserFromPrincipal(principal); - if (log.isInfoEnabled()) { - log.info("Connected as " + currentUser.getFirstName() + " " + currentUser.getLastName()); + try { + FaxToMailUser currentUser = serviceContext.getLdapService().getUserFromPrincipal(principal); + if (log.isInfoEnabled()) { + log.info("Connected as " + currentUser.getFirstName() + " " + currentUser.getLastName()); + } + setCurrentUser(currentUser); + } catch (AuthenticationException ex) { + if (log.isWarnEnabled()) { + log.warn("Can't anthenticate user", ex); + } + } - setCurrentUser(currentUser); - } catch (AuthenticationException ex) { - if (log.isWarnEnabled()) { - log.warn("Can't anthenticate user", ex); - } - } - // si ca n'a pas fonctionné, on retente par login mot de passe - while (getCurrentUser() == null) { - JXLoginPane pane = new JXLoginPane(); - pane.setLoginService(new LoginService() { - @Override - public boolean authenticate(String name, char[] password, String server) throws Exception { - boolean result = false; - try { - FaxToMailUser user = getLdapService().authenticateUser(name, String.valueOf(password)); - setCurrentUser(user); - result = true; - } catch (AuthenticationException ex) { - if (log.isWarnEnabled()) { - log.warn("Can't anthenticate user", ex); + // si ca n'a pas fonctionné, on retente par login mot de passe + while (getCurrentUser() == null) { + JXLoginPane pane = new JXLoginPane(); + pane.setLoginService(new LoginService() { + @Override + public boolean authenticate(String name, char[] password, String server) throws Exception { + boolean result = false; + try { + FaxToMailUser user = serviceContext.getLdapService().authenticateUser(name, String.valueOf(password)); + setCurrentUser(user); + result = true; + } catch (AuthenticationException ex) { + if (log.isWarnEnabled()) { + log.warn("Can't anthenticate user", ex); + } } + return result; } - return result; - } - }); + }); - // show login dialog - Status loginStatus = JXLoginPane.showLoginDialog(null, pane); - if (loginStatus == Status.CANCELLED) { - throw new ApplicationTechnicalException("Authentication canceled"); + // show login dialog + Status loginStatus = JXLoginPane.showLoginDialog(null, pane); + if (loginStatus == Status.CANCELLED) { + throw new ApplicationTechnicalException("Authentication canceled"); + } } + + } finally { + IOUtils.closeQuietly(serviceContext); } } @@ -494,38 +480,13 @@ //-- Service methods --// //------------------------------------------------------------------------// - public DecoratorService getDecoratorService() { - return serviceContext.newService(DecoratorService.class); + public FaxToMailServiceContext newServiceContext() { + FaxToMailServiceContext serviceContext = new FaxToMailServiceContext(); + serviceContext.setTopiaApplicationContext(topiaApplicationContext); + serviceContext.setApplicationConfig(config); + return serviceContext; } - public ValidationService getValidationService() { - return serviceContext.newService(ValidationService.class); - } - - public MailFolderService getMailFolderService() { - return serviceContext.newService(MailFolderService.class); - } - - public UserService getUserService() { - return serviceContext.newService(UserService.class); - } - - public LdapService getLdapService() { - return serviceContext.newService(LdapService.class); - } - - public EmailService getEmailService() { - return serviceContext.newService(EmailService.class); - } - - public ReferentielService getReferentielService() { - return serviceContext.newService(ReferentielService.class); - } - - public ConfigurationService getConfigurationService() { - return serviceContext.newService(ConfigurationService.class); - } - //------------------------------------------------------------------------// //-- DataContext methods --// //------------------------------------------------------------------------// @@ -671,11 +632,6 @@ firePropertyChange(PROPERTY_LOCALE, null, locale); } - public Configuration getFaxToMailConfiguration() { - // make sure configuration is loaded by current service context - return getConfigurationService().getConfiguration(); - } - public FaxToMailUser getCurrentUser() { return currentUser; } Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/LoadFolderEmailsAction.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/LoadFolderEmailsAction.java 2014-08-05 08:22:38 UTC (rev 467) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/LoadFolderEmailsAction.java 2014-08-05 09:25:13 UTC (rev 468) @@ -127,4 +127,5 @@ super.postFailedAction(error); getUI().getNavigationTree().setEnabled(true); } + } 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-08-05 08:22:38 UTC (rev 467) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUIHandler.java 2014-08-05 09:25:13 UTC (rev 468) @@ -268,9 +268,9 @@ navigationTree.setEnabled(false); MailFolder folder = folderNode.getMailFolder(); - // open new transaction for current folder - getContext().createNewTransaction(); - folder = getContext().getMailFolderService().getMailFolder(folder.getTopiaId()); // Fix lazy exception +// // open new transaction for current folder +// getContext().createNewTransaction(); +// folder = getContext().getMailFolderService().getMailFolder(folder.getTopiaId()); // Fix lazy exception getModel().setSelectedFolder(folder); getContext().setCurrentMailFolder(folder); Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandesUIHandler.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandesUIHandler.java 2014-08-05 08:22:38 UTC (rev 467) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandesUIHandler.java 2014-08-05 09:25:13 UTC (rev 468) @@ -71,6 +71,7 @@ private static final Log log = LogFactory.getLog(DemandesUIHandler.class); protected DelegateTabContainerHandler delegateTabHandler; + protected Configuration config; @Override public void beforeInit(DemandesUI ui) { @@ -82,6 +83,8 @@ DemandesUIModel model = new DemandesUIModel(); + config = getContext().newServiceContext().getConfigurationService().getConfiguration(); + this.ui.setContextValue(model); } @@ -146,7 +149,6 @@ } protected boolean isActionEnabled(DemandeUIModel model, MailAction action) { - Configuration config = getContext().getFaxToMailConfiguration(); EtatAttente etatAttente = model.getEtatAttente(); boolean valid = model.isValid(); @@ -165,6 +167,7 @@ boolean editable = model.isEditable(); boolean archived = model.getArchiveDate() != null; + boolean transmitEnabled = editable && isActionEnabled(model, MailAction.TRANSMIT); getModel().setTransmitEnabled(transmitEnabled); Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchToGroupUIHandler.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchToGroupUIHandler.java 2014-08-05 08:22:38 UTC (rev 467) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchToGroupUIHandler.java 2014-08-05 09:25:13 UTC (rev 468) @@ -28,6 +28,7 @@ import com.franciaflex.faxtomail.persistence.entities.EmailFilter; import com.franciaflex.faxtomail.persistence.entities.FaxToMailUser; import com.franciaflex.faxtomail.persistence.entities.MailField; +import com.franciaflex.faxtomail.services.FaxToMailServiceContext; import com.franciaflex.faxtomail.services.service.ReferentielService; import com.franciaflex.faxtomail.ui.swing.actions.GroupAction; import com.franciaflex.faxtomail.ui.swing.actions.SearchAction; @@ -36,6 +37,7 @@ import com.franciaflex.faxtomail.ui.swing.util.AbstractFaxToMailDemandListHandler; import com.franciaflex.faxtomail.ui.swing.util.Cancelable; +import com.franciaflex.faxtomail.ui.swing.util.Command; import jaxx.runtime.validator.swing.SwingValidator; import org.apache.commons.logging.Log; @@ -111,128 +113,137 @@ public void afterInit(SearchToGroupUI ui) { initUI(ui); - ReferentielService referentielService = getContext().getReferentielService(); + FaxToMailServiceContext serviceContext = getContext().newServiceContext(); + Command command = new Command(serviceContext) { + @Override + protected void doAction() { - List<FaxToMailUser> users = getContext().getUserService().getAllActiveUsers(); - SearchUIModel model = getModel(); - initBeanFilterableComboBox(ui.getTakenByComboBox(), - users, - model.getTakenBy()); - initBeanFilterableComboBox(ui.getModifiedByComboBox(), - users, - model.getModifiedBy()); - initBeanFilterableComboBox(ui.getArchivedByComboBox(), - users, - model.getArchivedBy()); - initBeanFilterableComboBox(ui.getTransferByComboBox(), - users, - model.getTransferBy()); - initBeanFilterableComboBox(ui.getPrintedByComboBox(), - users, - model.getPrintingBy()); - initBeanFilterableComboBox(ui.getRepliedByComboBox(), - users, - model.getReplyBy()); + SearchToGroupUI ui = getUI(); + ReferentielService referentielService = serviceContext.getReferentielService(); - initCheckBoxComboBox(ui.getDocTypeComboBox(), - referentielService.getAllDemandType(), - model.getDemandType(), - EmailFilter.PROPERTY_DEMAND_TYPE, - true); - initCheckBoxComboBox(ui.getPriorityComboBox(), - referentielService.getAllPriority(), - model.getPriority(), - EmailFilter.PROPERTY_PRIORITY, - true); - initCheckBoxComboBox(ui.getEtatAttenteComboBox(), - referentielService.getAllEtatAttente(), - model.getEtatAttente(), - EmailFilter.PROPERTY_ETAT_ATTENTE, - true); - initCheckBoxComboBox(ui.getStatusComboBox(), - Arrays.asList(DemandStatus.values()), - model.getDemandStatus(), - EmailFilter.PROPERTY_DEMAND_STATUS, - false); - initCheckBoxComboBox(ui.getGammeComboBox(), - referentielService.getAllRange(), - model.getGamme(), - EmailFilter.PROPERTY_GAMME, - false); + List<FaxToMailUser> users = serviceContext.getUserService().getAllActiveUsers(); + SearchUIModel model = getModel(); + initBeanFilterableComboBox(ui.getTakenByComboBox(), + users, + model.getTakenBy()); + initBeanFilterableComboBox(ui.getModifiedByComboBox(), + users, + model.getModifiedBy()); + initBeanFilterableComboBox(ui.getArchivedByComboBox(), + users, + model.getArchivedBy()); + initBeanFilterableComboBox(ui.getTransferByComboBox(), + users, + model.getTransferBy()); + initBeanFilterableComboBox(ui.getPrintedByComboBox(), + users, + model.getPrintingBy()); + initBeanFilterableComboBox(ui.getRepliedByComboBox(), + users, + model.getReplyBy()); - final JXTable dataTable = getUI().getDataTable(); - dataTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + initCheckBoxComboBox(ui.getDocTypeComboBox(), + referentielService.getAllDemandType(), + model.getDemandType(), + EmailFilter.PROPERTY_DEMAND_TYPE, + true); + initCheckBoxComboBox(ui.getPriorityComboBox(), + referentielService.getAllPriority(), + model.getPriority(), + EmailFilter.PROPERTY_PRIORITY, + true); + initCheckBoxComboBox(ui.getEtatAttenteComboBox(), + referentielService.getAllEtatAttente(), + model.getEtatAttente(), + EmailFilter.PROPERTY_ETAT_ATTENTE, + true); + initCheckBoxComboBox(ui.getStatusComboBox(), + Arrays.asList(DemandStatus.values()), + model.getDemandStatus(), + EmailFilter.PROPERTY_DEMAND_STATUS, + false); + initCheckBoxComboBox(ui.getGammeComboBox(), + referentielService.getAllRange(), + model.getGamme(), + EmailFilter.PROPERTY_GAMME, + false); - initDemandeTable(dataTable, true); + final JXTable dataTable = getUI().getDataTable(); + dataTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - model.addPropertyChangeListener(SearchUIModel.PROPERTY_RESULTS, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - List<DemandeUIModel> emails = (List<DemandeUIModel>) evt.getNewValue(); - AbstractApplicationTableModel<DemandeUIModel> dataTableModel = (AbstractApplicationTableModel<DemandeUIModel>) dataTable.getModel(); - dataTableModel.setRows(emails); - showInformationMessage(t("faxtomail.search.resultNb", emails.size())); + initDemandeTable(dataTable, true); - DemandeUIModel currentEmail = getContext().getCurrentEmail(); - if (currentEmail != null) { - int row = dataTableModel.getRowIndex(currentEmail); - if (row > 0) { - dataTable.setRowSelectionInterval(row, row); + model.addPropertyChangeListener(SearchUIModel.PROPERTY_RESULTS, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + List<DemandeUIModel> emails = (List<DemandeUIModel>) evt.getNewValue(); + AbstractApplicationTableModel<DemandeUIModel> dataTableModel = (AbstractApplicationTableModel<DemandeUIModel>) dataTable.getModel(); + dataTableModel.setRows(emails); + showInformationMessage(t("faxtomail.search.resultNb", emails.size())); + + DemandeUIModel currentEmail = getContext().getCurrentEmail(); + if (currentEmail != null) { + int row = dataTableModel.getRowIndex(currentEmail); + if (row > 0) { + dataTable.setRowSelectionInterval(row, row); + } } } - } - }); + }); - if (getContext().getSearch() != null) { - try { - SearchToGroupAction searchAction = getContext().getActionFactory().createLogicAction(this, SearchToGroupAction.class); - searchAction.doAction(); + if (getContext().getSearch() != null) { + try { + SearchToGroupAction searchAction = getContext().getActionFactory().createLogicAction(SearchToGroupUIHandler.this, SearchToGroupAction.class); + searchAction.doAction(); - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error("error while searching", e); + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error("error while searching", e); + } + getContext().getErrorHelper().showErrorDialog(t("faxtomail.search.action.error")); } - getContext().getErrorHelper().showErrorDialog(t("faxtomail.search.action.error")); } - } - dataTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { - @Override - public void valueChanged(ListSelectionEvent e) { - if (!e.getValueIsAdjusting()) { - ListSelectionModel selectionModel = (ListSelectionModel) e.getSource(); - SearchUIModel model = getModel(); - int selectedIndex = selectionModel.getLeadSelectionIndex(); + dataTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + if (!e.getValueIsAdjusting()) { + ListSelectionModel selectionModel = (ListSelectionModel) e.getSource(); + SearchUIModel model = getModel(); + int selectedIndex = selectionModel.getLeadSelectionIndex(); + AbstractApplicationTableModel<DemandeUIModel> dataTableModel = (AbstractApplicationTableModel<DemandeUIModel>) dataTable.getModel(); + DemandeUIModel selectedModel = selectedIndex < 0 ? null : dataTableModel.getEntry(selectedIndex); + model.setGroupEnabled(!selectionModel.isSelectionEmpty() && isDemandSelectable(selectedModel)); + } + } + }); + + HighlightPredicate rowAlreadyInGroupPredicate = new HighlightPredicate() { + @Override + public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { + int viewRow = adapter.row; + int modelRow = adapter.convertRowIndexToModel(viewRow); AbstractApplicationTableModel<DemandeUIModel> dataTableModel = (AbstractApplicationTableModel<DemandeUIModel>) dataTable.getModel(); - DemandeUIModel selectedModel = selectedIndex < 0 ? null : dataTableModel.getEntry(selectedIndex); - model.setGroupEnabled(!selectionModel.isSelectionEmpty() && isDemandSelectable(selectedModel)); + DemandeUIModel row = dataTableModel.getEntry(modelRow); + return !isDemandSelectable(row); } - } - }); + }; + dataTable.addHighlighter(new ColorHighlighter(rowAlreadyInGroupPredicate, null, Color.GRAY, Color.GRAY, Color.WHITE)); - HighlightPredicate rowAlreadyInGroupPredicate = new HighlightPredicate() { - @Override - public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { - int viewRow = adapter.row; - int modelRow = adapter.convertRowIndexToModel(viewRow); - AbstractApplicationTableModel<DemandeUIModel> dataTableModel = (AbstractApplicationTableModel<DemandeUIModel>) dataTable.getModel(); - DemandeUIModel row = dataTableModel.getEntry(modelRow); - return !isDemandSelectable(row); + // int combo box for result per page + ui.getResultPerPageCombo().setModel(new DefaultComboBoxModel<Integer>(new Integer[] {10, 20, 30, 40, 50})); + int resultPerPage = getConfig().getResultPerPage(); + ui.getModel().setResultPerPage(resultPerPage); + ui.getResultPerPageCombo().setSelectedItem(resultPerPage); + ui.getResultPerPageCombo().addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + updateResultPerPage(e); + } + }); } }; - dataTable.addHighlighter(new ColorHighlighter(rowAlreadyInGroupPredicate, null, Color.GRAY, Color.GRAY, Color.WHITE)); - - // int combo box for result per page - ui.getResultPerPageCombo().setModel(new DefaultComboBoxModel<Integer>(new Integer[] {10, 20, 30, 40, 50})); - int resultPerPage = getConfig().getResultPerPage(); - ui.getModel().setResultPerPage(resultPerPage); - ui.getResultPerPageCombo().setSelectedItem(resultPerPage); - ui.getResultPerPageCombo().addItemListener(new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - updateResultPerPage(e); - } - }); + command.execute(); } public void searchDemandes() { Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/AbstractFaxToMailUIHandler.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/AbstractFaxToMailUIHandler.java 2014-08-05 08:22:38 UTC (rev 467) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/AbstractFaxToMailUIHandler.java 2014-08-05 09:25:13 UTC (rev 468) @@ -112,12 +112,7 @@ public Component getTopestUI() { Component result; ApplicationActionUI actionUI = getContext().getActionUI(); -// if (actionUI.isVisible()) { - result = actionUI; -// } else { -// result = getContext().getMainUI(); -// } - return result; + return actionUI; } public void clearValidators() { @@ -130,8 +125,7 @@ @Override public <O> Decorator<O> getDecorator(Class<O> type, String name) { - DecoratorService decoratorService = - getContext().getDecoratorService(); + DecoratorService decoratorService = getContext().newServiceContext().getDecoratorService(); Preconditions.checkNotNull(type); Added: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/Command.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/Command.java (rev 0) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/Command.java 2014-08-05 09:25:13 UTC (rev 468) @@ -0,0 +1,29 @@ +package com.franciaflex.faxtomail.ui.swing.util; + +import com.franciaflex.faxtomail.services.FaxToMailServiceContext; +import org.apache.commons.io.IOUtils; + +/** + * @author Kevin Morin (Code Lutin) + * @since x.x + */ +public abstract class Command { + + protected FaxToMailServiceContext serviceContext; + + protected Command(FaxToMailServiceContext serviceContext) { + this.serviceContext = serviceContext; + } + + protected abstract void doAction(); + + public void execute() { + try { + doAction(); + + } finally { + IOUtils.closeQuietly(serviceContext); + } + } + +}