Author: kmorin Date: 2014-04-03 18:13:47 +0200 (Thu, 03 Apr 2014) New Revision: 29 Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/29 Log: refs #4659 [ECRAN] Recherche 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/actions/SaveDemandeAndExitAction.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/SearchAction.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/ShowDemandeListAction.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/ShowRechercheAction.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/DemandeUI.css trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchUI.css trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchUIHandler.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/AbstractFaxToMailDemandListHandler.java 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/attachment/AttachmentCellEditor.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/attachment/AttachmentItem.css 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-04-03 15:06:12 UTC (rev 28) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/FaxToMailUIContext.java 2014-04-03 16:13:47 UTC (rev 29) @@ -41,6 +41,7 @@ import com.franciaflex.faxtomail.services.service.ValidationService; import com.franciaflex.faxtomail.ui.swing.content.MainUI; import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIModel; +import com.franciaflex.faxtomail.ui.swing.content.search.SearchUIModel; import com.franciaflex.faxtomail.ui.swing.util.UIMessageNotifier; import com.google.common.base.Preconditions; import com.google.common.collect.Maps; @@ -221,6 +222,8 @@ protected List<MailFolder> expandedFolders = new ArrayList<MailFolder>(); + protected SearchUIModel search; + public static FaxToMailUIContext newContext(FaxToMailConfiguration config) { Preconditions.checkNotNull(config); Preconditions.checkState(applicationContext == null, @@ -550,14 +553,6 @@ } protected void saveContextToConfig() { -// if (log.isInfoEnabled()) { -// log.info("Save config (programId: " + getProgramId() + ", cruiseId: " + -// getCruiseId() + ", protocolId: " + getProtocolId() + ", locale: " + -// getLocale() + ")"); -// } -// config.setProgramId(getProgramId()); -// config.setCruiseId(getCruiseId()); -// config.setProtocolId(getProtocolId()); config.setI18nLocale(getLocale()); config.save(); } @@ -721,4 +716,12 @@ public void setExpandedFolders(List<MailFolder> expandedFolders) { this.expandedFolders = expandedFolders; } + + public SearchUIModel getSearch() { + return search; + } + + public void setSearch(SearchUIModel search) { + this.search = search; + } } Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/SaveDemandeAndExitAction.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/SaveDemandeAndExitAction.java 2014-04-03 15:06:12 UTC (rev 28) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/SaveDemandeAndExitAction.java 2014-04-03 16:13:47 UTC (rev 29) @@ -17,6 +17,6 @@ public void postSuccessAction() { super.postSuccessAction(); - getContext().setScreen(FaxToMailScreen.LIST); + getContext().setScreen(AbstractChangeScreenAction.PREVIOUS_SCREEN.getContextValue(handler.getUI())); } } Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/SearchAction.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/SearchAction.java 2014-04-03 15:06:12 UTC (rev 28) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/SearchAction.java 2014-04-03 16:13:47 UTC (rev 29) @@ -23,6 +23,8 @@ @Override public void doAction() throws Exception { SearchUIModel model = getModel(); + getContext().setSearch(model); + Email email = model.toEntity(); List<Email> emails = getContext().getEmailService().search(email, model.getMinReceptionDate(), model.getMaxReceptionDate(), model.getMinModificationDate(), model.getMaxModificationDate(), model.getModifiedBy(), Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/ShowDemandeListAction.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/ShowDemandeListAction.java 2014-04-03 15:06:12 UTC (rev 28) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/ShowDemandeListAction.java 2014-04-03 16:13:47 UTC (rev 29) @@ -36,4 +36,10 @@ public ShowDemandeListAction(MainUIHandler handler) { super(handler, true, FaxToMailScreen.LIST); } + + @Override + public void postSuccessAction() { + super.postSuccessAction(); + getContext().setSearch(null); + } } Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/ShowRechercheAction.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/ShowRechercheAction.java 2014-04-03 15:06:12 UTC (rev 28) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/ShowRechercheAction.java 2014-04-03 16:13:47 UTC (rev 29) @@ -36,4 +36,5 @@ public ShowRechercheAction(MainUIHandler handler) { super(handler, true, FaxToMailScreen.SEARCH); } + } 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-04-03 15:06:12 UTC (rev 28) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUIHandler.java 2014-04-03 16:13:47 UTC (rev 29) @@ -221,6 +221,11 @@ } @Override + protected String[] getEditableTableProperties() { + return new String[] { Email.PROPERTY_PRIORITY, Email.PROPERTY_ATTACHMENT }; + } + + @Override protected void onDoubleClickOnDemande(DemandeUIModel selectedEmail) { super.onDoubleClickOnDemande(selectedEmail); selectedEmail.removePropertyChangeListener(selectedDemandeChangeListener); @@ -277,34 +282,12 @@ super.beforeOpenPopup(rowIndex, columnIndex); int selectedRowCount = getUI().getDataTable().getSelectedRowCount(); - log.info(selectedRowCount == 1); DemandeListUIModel model = getModel(); model.setAddAttachmentEnabled(selectedRowCount == 1); model.setReplyEnabled(selectedRowCount == 1); } - @Override - public void autoSelectRowInTable(MouseEvent e, JPopupMenu popup) { - boolean rightClick = SwingUtilities.isRightMouseButton(e); - if (rightClick) { - // get the coordinates of the mouse click - Point p = e.getPoint(); - - JXTable source = (JXTable) e.getSource(); - - int[] selectedRows = source.getSelectedRows(); - - // get the row index at this point - int rowIndex = source.rowAtPoint(p); - if (rowIndex == -1 || !ArrayUtils.contains(selectedRows, rowIndex)) { - source.clearSelection(); - } - } - - super.autoSelectRowInTable(e, popup); - } - public void autoSelectNodeInTree(MouseEvent e, JPopupMenu popup) { boolean rightClick = SwingUtilities.isRightMouseButton(e); @@ -374,11 +357,6 @@ log.debug("reply"); } - public void addAttachment() { - //TODO - log.debug("addAttachment"); - } - public void archive() { //TODO log.debug("archive"); Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUI.css =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUI.css 2014-04-03 15:06:12 UTC (rev 28) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUI.css 2014-04-03 16:13:47 UTC (rev 29) @@ -273,7 +273,7 @@ #backButton { text: "faxtomail.demande.back.button.label"; actionIcon: cancel; - _applicationAction: { com.franciaflex.faxtomail.ui.swing.actions.ShowDemandeListAction.class }; + _applicationAction: { com.franciaflex.faxtomail.ui.swing.actions.GoToPreviousScreenAction.class }; } #saveButton { Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchUI.css =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchUI.css 2014-04-03 15:06:12 UTC (rev 28) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchUI.css 2014-04-03 16:13:47 UTC (rev 29) @@ -51,6 +51,11 @@ text: "faxtomail.demande.takenBy.label"; } +#takenByComboBox { + property: takenBy; + selectedItem: { model.getTakenBy() }; +} + #modifiedBetweenLabel { text: "faxtomail.search.modifiedBetween.label"; } @@ -170,6 +175,6 @@ } #dataTable { - editable: false; + editable: true; autoCreateRowSorter: true; } \ No newline at end of file Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchUIHandler.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchUIHandler.java 2014-04-03 15:06:12 UTC (rev 28) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchUIHandler.java 2014-04-03 16:13:47 UTC (rev 29) @@ -25,6 +25,7 @@ import com.franciaflex.faxtomail.persistence.entities.DemandStatus; import com.franciaflex.faxtomail.persistence.entities.Email; import com.franciaflex.faxtomail.services.service.ReferentielService; +import com.franciaflex.faxtomail.ui.swing.actions.SearchAction; import com.franciaflex.faxtomail.ui.swing.actions.ShowDemandeAction; import com.franciaflex.faxtomail.ui.swing.actions.ShowDemandeListAction; import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeListUIModel; @@ -84,21 +85,24 @@ public void beforeInit(SearchUI ui) { super.beforeInit(ui); - SearchUIModel searchUIModel = new SearchUIModel(); - searchUIModel.setTakenBy(getContext().getCurrentUser()); - searchUIModel.setModifiedBy(getContext().getCurrentUser()); + SearchUIModel searchUIModel = getContext().getSearch(); + if (searchUIModel == null) { + searchUIModel = new SearchUIModel(); + searchUIModel.setTakenBy(getContext().getCurrentUser()); + searchUIModel.setModifiedBy(getContext().getCurrentUser()); - Date now = new Date(); - Calendar cal = Calendar.getInstance(); - cal.add(Calendar.MONTH, -2); - Date twoMonthsAgo = cal.getTime(); + Date now = new Date(); + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.MONTH, -2); + Date twoMonthsAgo = cal.getTime(); - searchUIModel.setMaxModificationDate(now); - searchUIModel.setMinModificationDate(twoMonthsAgo); - searchUIModel.setMaxReceptionDate(now); - searchUIModel.setMinReceptionDate(twoMonthsAgo); - searchUIModel.setMaxPrintingDate(now); - searchUIModel.setMinPrintingDate(twoMonthsAgo); + searchUIModel.setMaxModificationDate(now); + searchUIModel.setMinModificationDate(twoMonthsAgo); + searchUIModel.setMaxReceptionDate(now); + searchUIModel.setMinReceptionDate(twoMonthsAgo); + searchUIModel.setMaxPrintingDate(now); + searchUIModel.setMinPrintingDate(twoMonthsAgo); + } getUI().setContextValue(searchUIModel); } @@ -109,37 +113,57 @@ ReferentielService referentielService = getContext().getReferentielService(); + SearchUIModel model = getModel(); initBeanFilterableComboBox(ui.getTakenByComboBox(), getContext().getUserService().getAllUsers(), - getModel().getTakenBy()); + model.getTakenBy()); initBeanFilterableComboBox(ui.getModifiedByComboBox(), getContext().getUserService().getAllUsers(), - getModel().getModifiedBy()); + model.getModifiedBy()); initBeanFilterableComboBox(ui.getDocTypeComboBox(), referentielService.getAllDemandType(), - null); + model.getDemandType()); initBeanFilterableComboBox(ui.getPriorityComboBox(), referentielService.getAllPriority(), - null); + model.getPriority()); initBeanFilterableComboBox(ui.getEtatAttenteComboBox(), referentielService.getAllEtatAttente(), - null); + model.getEtatAttente()); initBeanFilterableComboBox(ui.getStatusComboBox(), Arrays.asList(DemandStatus.values()), - null); + model.getDemandStatus()); - JXTable dataTable = getUI().getDataTable(); + final JXTable dataTable = getUI().getDataTable(); final AbstractApplicationTableModel<DemandeUIModel> tableModel = initDemandeTable(dataTable, true); - getModel().addPropertyChangeListener(SearchUIModel.PROPERTY_RESULTS, new PropertyChangeListener() { + model.addPropertyChangeListener(SearchUIModel.PROPERTY_RESULTS, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { List<DemandeUIModel> emails = (List<DemandeUIModel>) evt.getNewValue(); tableModel.setRows(emails); showInformationMessage(t("faxtomail.search.resultNb", emails.size())); + + DemandeUIModel currentEmail = getContext().getCurrentEmail(); + if (currentEmail != null) { + int row = tableModel.getRowIndex(currentEmail); + if (row > 0) { + dataTable.setRowSelectionInterval(row, row); + } + } } }); + if (getContext().getSearch() != null) { + try { + SearchAction searchAction = getContext().getActionFactory().createLogicAction(this, SearchAction.class); + searchAction.doAction(); + + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error("error while searching", e); + } + } + } } @Override @@ -153,7 +177,6 @@ log.debug("closing: " + ui); } clearValidators(); - } @Override @@ -183,4 +206,9 @@ getContext().setCurrentMailFolder(selectedEmail.getMailFolder()); getContext().getActionEngine().runAction(new ShowDemandeListAction(getContext().getMainUI().getHandler())); } + + @Override + protected String[] getEditableTableProperties() { + return new String[] { Email.PROPERTY_ATTACHMENT }; + } } Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/AbstractFaxToMailDemandListHandler.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/AbstractFaxToMailDemandListHandler.java 2014-04-03 15:06:12 UTC (rev 28) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/AbstractFaxToMailDemandListHandler.java 2014-04-03 16:13:47 UTC (rev 29) @@ -15,6 +15,7 @@ import com.franciaflex.faxtomail.ui.swing.util.attachment.AttachmentCellEditor; import com.franciaflex.faxtomail.ui.swing.util.attachment.AttachmentCellRenderer; import com.google.common.base.Function; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -146,7 +147,8 @@ } } - final AbstractApplicationTableModel<DemandeUIModel> tableModel = new DemandeTableModel(columnModel); + final AbstractApplicationTableModel<DemandeUIModel> tableModel = new DemandeTableModel(columnModel, + getEditableTableProperties()); table.setModel(tableModel); table.setColumnModel(columnModel); table.getTableHeader().setReorderingAllowed(false); @@ -222,6 +224,29 @@ return tableModel; } + @Override + public void autoSelectRowInTable(MouseEvent e, JPopupMenu popup) { + boolean rightClick = SwingUtilities.isRightMouseButton(e); + if (rightClick) { + // get the coordinates of the mouse click + Point p = e.getPoint(); + + JXTable source = (JXTable) e.getSource(); + + int[] selectedRows = source.getSelectedRows(); + + // get the row index at this point + int rowIndex = source.rowAtPoint(p); + if (rowIndex == -1 || !ArrayUtils.contains(selectedRows, rowIndex)) { + source.clearSelection(); + } + } + + super.autoSelectRowInTable(e, popup); + } + + protected abstract String[] getEditableTableProperties(); + protected void onDoubleClickOnDemande(DemandeUIModel selectedEmail) { } 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-04-03 15:06:12 UTC (rev 28) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/DemandeTableModel.java 2014-04-03 16:13:47 UTC (rev 29) @@ -44,8 +44,7 @@ */ public class DemandeTableModel extends AbstractApplicationTableModel<DemandeUIModel> { - private static final Log log = - LogFactory.getLog(DemandeTableModel.class); + private static final Log log = LogFactory.getLog(DemandeTableModel.class); public static final Map<String, ColumnIdentifier<Email>> COLUMN_IDENTIFIERS = new HashMap<String, ColumnIdentifier<Email>>() {{ put(Email.PROPERTY_SENDER, @@ -158,11 +157,12 @@ }}; - public DemandeTableModel(TableColumnModelExt columnModel) { + public DemandeTableModel(TableColumnModelExt columnModel, String... editableProperties) { super(columnModel, false, false); List<ColumnIdentifier> nonEditableColumns = new ArrayList<ColumnIdentifier>(COLUMN_IDENTIFIERS.values()); - nonEditableColumns.remove(COLUMN_IDENTIFIERS.get(Email.PROPERTY_PRIORITY)); - nonEditableColumns.remove(COLUMN_IDENTIFIERS.get(Email.PROPERTY_ATTACHMENT)); + for (String editableProperty : editableProperties) { + nonEditableColumns.remove(COLUMN_IDENTIFIERS.get(editableProperty)); + } setNoneEditableCols(nonEditableColumns.toArray(new ColumnIdentifier[nonEditableColumns.size()])); } Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/attachment/AttachmentCellEditor.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/attachment/AttachmentCellEditor.java 2014-04-03 15:06:12 UTC (rev 28) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/attachment/AttachmentCellEditor.java 2014-04-03 16:13:47 UTC (rev 29) @@ -63,14 +63,6 @@ return new AttachmentCellEditor(FaxToMailUIContext.getApplicationContext()); } - protected JTable table; - - protected AbstractApplicationTableModel<AbstractFaxToMailBeanUIModel> tableModel; - - protected Integer rowIndex; - - protected Integer columnIndex; - protected final ButtonAttachment editorButton; protected FaxToMailUIContext context; @@ -102,14 +94,12 @@ boolean isSelected, int row, int column) { - this.table = table; - this.tableModel = (AbstractApplicationTableModel<AbstractFaxToMailBeanUIModel>) table.getModel(); + AbstractApplicationTableModel<AbstractFaxToMailBeanUIModel> tableModel = + (AbstractApplicationTableModel<AbstractFaxToMailBeanUIModel>) table.getModel(); - rowIndex = row; - columnIndex = column; + int modelRow = table.convertRowIndexToModel(row); + final DemandeUIModel model = (DemandeUIModel) tableModel.getEntry(modelRow); - final DemandeUIModel model = (DemandeUIModel) tableModel.getEntry(row); - editorButton.init(model); listener = new AttachmentEditorUIModel.AttachmentListener() { Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/attachment/AttachmentItem.css =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/attachment/AttachmentItem.css 2014-04-03 15:06:12 UTC (rev 28) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/attachment/AttachmentItem.css 2014-04-03 16:13:47 UTC (rev 29) @@ -20,4 +20,6 @@ actionIcon: "delete"; toolTipText: "faxtomail.attachmentEditor.action.remove.tip"; enabled: { getAttachment() != null && getAttachment().getTopiaId() == null }; + //TODO check + visible: { getHandler().getModel().isEditable() }; } \ No newline at end of file