This is an automated email from the git hooks/post-receive script. New commit to branch feature/9108_arbre_dans_swing_session in repository faxtomail. See https://gitlab.nuiton.org/codelutin/faxtomail.git commit d79136147e20d6a818d5af1b17efba2579cc6591 Author: Kevin Morin <morin@codelutin.com> Date: Tue Apr 4 17:52:22 2017 +0200 refs #9107 #9108 sauvegarde de l'état de l'arbre dans la session swing et plus dans le contexte --- .../faxtomail/ui/swing/FaxToMailUIContext.java | 3 + .../faxtomail/ui/swing/content/MainUIHandler.java | 13 ++-- .../ui/swing/content/demande/DemandeListUI.jaxx | 2 +- .../content/demande/DemandeListUIHandler.java | 40 +++++------ .../demande/actions/LoadFolderEmailsAction.java | 21 ++---- .../transmit/MailFolderChooserUIHandler.java | 16 ++--- .../faxtomail/ui/swing/util/FaxToMailUIUtil.java | 30 -------- .../ui/swing/util/FolderTreeSwingSessionState.java | 82 ++++++++++++++++++++++ 8 files changed, 121 insertions(+), 86 deletions(-) diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/FaxToMailUIContext.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/FaxToMailUIContext.java index 50b5465..cc0b16d 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/FaxToMailUIContext.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/FaxToMailUIContext.java @@ -44,6 +44,7 @@ import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeListUI; 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.DemandeListUISwingSessionState; +import com.franciaflex.faxtomail.ui.swing.util.FolderTreeSwingSessionState; import com.franciaflex.faxtomail.ui.swing.util.UIMessageNotifier; import com.franciaflex.faxtomail.ui.swing.util.data.Handler; import com.google.common.base.Preconditions; @@ -84,6 +85,7 @@ import org.nuiton.util.pagination.PaginationResult; import javax.swing.JFrame; import javax.swing.JOptionPane; +import javax.swing.JTree; import java.awt.Color; import java.awt.Component; import java.awt.Container; @@ -275,6 +277,7 @@ public class FaxToMailUIContext extends AbstractBean implements Closeable, UIMes additionalStates.put(BeanFilterableComboBox.class, new BeanFilterableComboBoxState()); additionalStates.put(BeanDoubleList.class, new BeanDoubleListState()); additionalStates.put(DemandeListUI.class, new DemandeListUISwingSessionState()); + additionalStates.put(JTree.class, new FolderTreeSwingSessionState()); File uiConfigFile = getConfig().getUIConfigFile(); this.swingSession = new SwingSession(uiConfigFile, false, additionalStates); if (!uiConfigFile.exists()) { diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/MainUIHandler.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/MainUIHandler.java index b8a7545..d44e79a 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/MainUIHandler.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/MainUIHandler.java @@ -161,8 +161,6 @@ public class MainUIHandler extends AbstractFaxToMailUIHandler<FaxToMailUIContext } } -// SwingUtil.getLayer(ui.getBody()).setUI(new BetaLayerUI()); - getContext().addPropertyChangeListener(FaxToMailUIContext.PROPERTY_ACTION_IN_PROGRESS, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { @@ -170,7 +168,6 @@ public class MainUIHandler extends AbstractFaxToMailUIHandler<FaxToMailUIContext MainUI ui = getUI(); ui.getSearchButton().setEnabled(!inProgress); ui.getDemandListButton().setEnabled(!inProgress); -// ui.getExitButton().setEnabled(!inProgress); } }); @@ -185,14 +182,14 @@ public class MainUIHandler extends AbstractFaxToMailUIHandler<FaxToMailUIContext // l'utilisateur a peut etre seulement les droits sur les archives DemandeListUI demandeListUI = (DemandeListUI) getCurrentBody(); if (CollectionUtils.isEmpty(demandeListUI.getModel().getFolders())) { -// JOptionPane.showMessageDialog(demandeListUI, t("faxtomail.demandeList.noRigthsFound"), -// t("faxtomail.demandeList.title"), JOptionPane.ERROR_MESSAGE); - getUI().getDemandListButton().setVisible(false); getContext().setScreen(FaxToMailScreen.SEARCH); + } else { + // on force l'ajout du splitpane car l'ui de liste change de nom en fonction du dossier + // pour pouvoir sauvegarder le tri des colonnes dans la session en fonction du dossier + // mais on veut que l'arbre et le séparateur soient constants + getContext().getSwingSession().add(demandeListUI.getMainSplitPane(), true); } - - } @Override diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUI.jaxx b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUI.jaxx index b289a82..6f51673 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUI.jaxx +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUI.jaxx @@ -66,7 +66,7 @@ <JMenuItem id='moveMenu'/> </JPopupMenu> - <JSplitPane constraints='BorderLayout.CENTER' id="mainSplitPane"> + <JSplitPane constraints='BorderLayout.CENTER' id="mainSplitPane" name="demandeListUIMainSplitPane"> <JScrollPane> <JTree id="navigationTree" onMouseClicked='handler.autoSelectNodeInTree(event, treePopup)'/> diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUIHandler.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUIHandler.java index dc8d1d6..33dc05d 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUIHandler.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeListUIHandler.java @@ -315,10 +315,8 @@ public class DemandeListUIHandler extends AbstractFaxToMailDemandListHandler<Dem // init tree final JTree navigationTree = ui.getNavigationTree(); - - List<MailFolder> foldersToExpand = getContext().getListExpandedFolders(); final Map<MailFolder, FolderTreeNode> nodesByFolder = - FaxToMailUIUtil.initFolderTree(getContext(), navigationTree, model.getFolders(), foldersToExpand, true); + FaxToMailUIUtil.initFolderTree(getContext(), navigationTree, model.getFolders(), true); getContext().addPropertyChangeListener(FaxToMailUIContext.PROPERTY_ACTION_IN_PROGRESS, actionInProgressListener); @@ -346,23 +344,25 @@ public class DemandeListUIHandler extends AbstractFaxToMailDemandListHandler<Dem getContext().setCurrentMailFolder(folder); loadFolderDemands(nodesByFolder); - MailFolder folderWithShowReplyAction = folder; - while (folderWithShowReplyAction.getParent() != null - && folderWithShowReplyAction.getShowReplyAction() == null) { - folderWithShowReplyAction = folderWithShowReplyAction.getParent(); - } - getModel().setReplyActivated(Boolean.TRUE.equals(folderWithShowReplyAction.getShowReplyAction())); + if (folder != null) { + MailFolder folderWithShowReplyAction = folder; + while (folderWithShowReplyAction.getParent() != null + && folderWithShowReplyAction.getShowReplyAction() == null) { + folderWithShowReplyAction = folderWithShowReplyAction.getParent(); + } + getModel().setReplyActivated(Boolean.TRUE.equals(folderWithShowReplyAction.getShowReplyAction())); - MailFolder folderWithShowForwardAction = folder; - while (folderWithShowForwardAction.getParent() != null - && folderWithShowForwardAction.getShowForwardAction() == null) { - folderWithShowForwardAction = folderWithShowForwardAction.getParent(); - } - getModel().setForwardActivated(Boolean.TRUE.equals(folderWithShowForwardAction.getShowForwardAction())); + MailFolder folderWithShowForwardAction = folder; + while (folderWithShowForwardAction.getParent() != null + && folderWithShowForwardAction.getShowForwardAction() == null) { + folderWithShowForwardAction = folderWithShowForwardAction.getParent(); + } + getModel().setForwardActivated(Boolean.TRUE.equals(folderWithShowForwardAction.getShowForwardAction())); - DefaultMutableTreeNode node = nodesByFolder.get(folder); - if (node != null) { - navigationTree.setSelectionPath(new TreePath(node.getPath())); + DefaultMutableTreeNode node = nodesByFolder.get(folder); + if (node != null) { + navigationTree.setSelectionPath(new TreePath(node.getPath())); + } } } }); @@ -733,10 +733,6 @@ public class DemandeListUIHandler extends AbstractFaxToMailDemandListHandler<Dem } } - JTree tree = getUI().getNavigationTree(); - List<MailFolder> folders = FaxToMailUIUtil.getExpandedFolders(tree); - getContext().setListExpandedFolders(folders); - // remove refresh shortcut JRootPane rootPane = getContext().getMainUI().getRootPane(); rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).remove(KeyStroke.getKeyStroke(REFRESH_KEY)); diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/LoadFolderEmailsAction.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/LoadFolderEmailsAction.java index 0aff361..cc2ac67 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/LoadFolderEmailsAction.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/actions/LoadFolderEmailsAction.java @@ -26,7 +26,6 @@ package com.franciaflex.faxtomail.ui.swing.content.demande.actions; import com.franciaflex.faxtomail.persistence.entities.Email; import com.franciaflex.faxtomail.persistence.entities.FaxToMailUser; -import com.franciaflex.faxtomail.persistence.entities.MailField; import com.franciaflex.faxtomail.persistence.entities.MailFolder; import com.franciaflex.faxtomail.persistence.entities.WaitingState; import com.franciaflex.faxtomail.ui.swing.FaxToMailUIContext; @@ -44,10 +43,7 @@ import org.jdesktop.swingx.JXTable; import org.nuiton.topia.persistence.TopiaEntities; import org.nuiton.util.pagination.PaginationResult; -import javax.swing.JSplitPane; import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; import java.util.List; import java.util.Map; @@ -104,13 +100,17 @@ public class LoadFolderEmailsAction extends AbstractFaxToMailAction<DemandeListU boolean sortable = Boolean.TRUE.equals(folderWithCanChangeOrderInTable.getCanChangeOrderInTable()); String columns = handler.populateColumnModel(dataTable, sortable); + // on change de nom en fonction du dossier pour pouvoir sauvegarder le tri des colonnes + // dans la session en fonction du dossier getUI().setName("demandeListUI" + folder.getTopiaId()); getContext().getSwingSession().add(getUI(), true); - JSplitPane mainSplitPane = getUI().getMainSplitPane(); - mainSplitPane.setName("demandeListUIMainSplitPane"); - getContext().getSwingSession().add(mainSplitPane, true); + // on force l'ajout du splitpane car l'ui de liste change de nom en fonction du dossier + // mais on veut que l'arbre et le séparateur soient constants + getContext().getSwingSession().add(getUI().getMainSplitPane(), true); + // on change de nom en fonction des colonnes pour pouvoir sauvegarder la taille des colonnes + // dans la session en fonction des colonnes affichées dataTable.setName("dataTable" + columns); getContext().getSwingSession().add(dataTable, true); @@ -133,13 +133,6 @@ public class LoadFolderEmailsAction extends AbstractFaxToMailAction<DemandeListU MailFolder folder = model.getSelectedFolder(); FaxToMailUser currentUser = getContext().getCurrentUser(); - List<MailField> columns = handler.getColumns(); - Collection<MailField> fields = new HashSet<MailField>(); - if (columns != null) { - fields.addAll(columns); - } - fields.add(MailField.TAKEN_BY); - PaginationResult<Email> paginationResult = getContext().newServiceContext().getEmailService() .getEmailForFolder(folder, currentUser, diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/transmit/MailFolderChooserUIHandler.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/transmit/MailFolderChooserUIHandler.java index 7fad488..b653456 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/transmit/MailFolderChooserUIHandler.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/transmit/MailFolderChooserUIHandler.java @@ -34,14 +34,14 @@ import com.franciaflex.faxtomail.ui.swing.util.FolderTreeNode; import jaxx.runtime.validator.swing.SwingValidator; import org.nuiton.jaxx.application.swing.util.Cancelable; -import javax.swing.*; +import javax.swing.JComponent; +import javax.swing.JTree; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; -import java.awt.*; +import java.awt.Component; import java.util.Collection; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; @@ -79,23 +79,20 @@ public class MailFolderChooserUIHandler extends AbstractFaxToMailUIHandler<MailF getRootMailFoldersWithMoveRights(getContext().getCurrentUser()); JTree navigationTree = ui.getNavigationTree(); - List<MailFolder> foldersToExpand = getContext().getTransmitExpandedFolders(); Map<MailFolder, FolderTreeNode> nodesByFolder = - FaxToMailUIUtil.initFolderTree(getContext(), navigationTree, folders, foldersToExpand, false); + FaxToMailUIUtil.initFolderTree(getContext(), navigationTree, folders, false); for (MailFolder folder : nodesByFolder.keySet()) { DefaultMutableTreeNode node = nodesByFolder.get(folder); if (node.getClass().isAssignableFrom(FolderTreeNode.class)) { FolderTreeNode folderTreeNode = (FolderTreeNode) node; - MailFolder folderWithAllowMoveDemandIntoFolder = folder; // le dossier n'est pas grisé si: // - le n'est pas le dossier courrant // - l'utilsateur à les droits sur le dossier // - le dossier cible à les mêmes etatAttente/typeDemande que toutes les demandes à bouger - folderTreeNode.setCanSelect(!currentMailFolder.equals(folder) && - folderWithAllowMoveDemandIntoFolder.isFolderMoveable() && + folderTreeNode.setCanSelect(!currentMailFolder.equals(folder) && folder.isFolderMoveable() && (foldersWithWaitingState == null || foldersWithWaitingState.contains(folder))); } } @@ -118,9 +115,6 @@ public class MailFolderChooserUIHandler extends AbstractFaxToMailUIHandler<MailF @Override public void onCloseUI() { - JTree tree = getUI().getNavigationTree(); - List<MailFolder> folders = FaxToMailUIUtil.getExpandedFolders(tree); - getContext().setTransmitExpandedFolders(folders); } @Override diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/FaxToMailUIUtil.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/FaxToMailUIUtil.java index 78e7b8a..5df1307 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/FaxToMailUIUtil.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/FaxToMailUIUtil.java @@ -88,7 +88,6 @@ import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeModel; -import javax.swing.tree.TreePath; import java.awt.Color; import java.awt.Component; import java.awt.Desktop; @@ -119,7 +118,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; -import java.util.Enumeration; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -155,7 +153,6 @@ public final class FaxToMailUIUtil extends ApplicationUIUtil { public static Map<MailFolder, FolderTreeNode> initFolderTree(final FaxToMailUIContext context, JTree navigationTree, Collection<MailFolder> folders, - List<MailFolder> foldersToExpand, final boolean colorNotAffectedFolders) { DefaultMutableTreeNode root = new DefaultMutableTreeNode("root"); @@ -235,36 +232,9 @@ public final class FaxToMailUIUtil extends ApplicationUIUtil { renderer.setLeafIcon(folderIcon); navigationTree.setCellRenderer(renderer); - // expand nodes - for (MailFolder folder : foldersToExpand) { - DefaultMutableTreeNode node = nodesByFolder.get(folder); - // le node peut être null, s'il n'est pas dans l'arbre car - // l'utilisateur n'a pas les droits de déplacement par exemple - if (node != null) { - TreePath treePath = new TreePath(node.getPath()); - navigationTree.expandPath(treePath); - } - } - return nodesByFolder; } - public static List<MailFolder> getExpandedFolders(JTree tree) { - TreeModel treeModel = tree.getModel(); - Enumeration<TreePath> paths = tree.getExpandedDescendants(new TreePath(treeModel.getRoot())); - java.util.List<MailFolder> folders = new ArrayList<MailFolder>(); - if (paths != null) { - while (paths.hasMoreElements()) { - TreePath path = paths.nextElement(); - Object lastPathComponent = path.getLastPathComponent(); - if (FolderTreeNode.class.isAssignableFrom(lastPathComponent.getClass())) { - folders.add(((FolderTreeNode) lastPathComponent).getMailFolder()); - } - } - } - return folders; - } - /** * Creates the tree nodes and returns a map of the nodes by folder * @param parent the node parent diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/FolderTreeSwingSessionState.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/FolderTreeSwingSessionState.java new file mode 100644 index 0000000..f6c9b16 --- /dev/null +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/FolderTreeSwingSessionState.java @@ -0,0 +1,82 @@ +package com.franciaflex.faxtomail.ui.swing.util; + +import com.franciaflex.faxtomail.persistence.entities.MailFolder; +import jaxx.runtime.swing.session.State; + +import javax.swing.JTree; +import javax.swing.tree.TreePath; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Kevin Morin (Code Lutin) + * @since x.x + */ +public class FolderTreeSwingSessionState implements State { + + protected List<String> expandedFolderIds; + + public FolderTreeSwingSessionState() { + } + + public List<String> getExpandedFolderIds() { + return expandedFolderIds; + } + + public void setExpandedFolderIds(List<String> expandedFolderIds) { + this.expandedFolderIds = expandedFolderIds; + } + + protected JTree checkComponent(Object o) { + if (o == null) { + throw new IllegalArgumentException("null component"); + } + if (!(o instanceof JTree)) { + throw new IllegalArgumentException("invalid component"); + } + return (JTree) o; + } + + @Override + public State getState(Object o) { + JTree tree = checkComponent(o); + FolderTreeSwingSessionState result = new FolderTreeSwingSessionState(); + + List<String> expandedFolderIds = new ArrayList<>(); + for (int i = 0 ; i < tree.getRowCount() ; i++) { + if (tree.isExpanded(i)) { + TreePath path = tree.getPathForRow(i); + FolderTreeNode folderNode = (FolderTreeNode) path.getLastPathComponent(); + MailFolder mailFolder = folderNode.getMailFolder(); + if (mailFolder != null) { + expandedFolderIds.add(mailFolder.getTopiaId()); + } + } + } + result.setExpandedFolderIds(expandedFolderIds); + + return result; + } + + @Override + public void setState(Object o, State state) { + if (!(state instanceof FolderTreeSwingSessionState)) { + throw new IllegalArgumentException("invalid state"); + } + + JTree tree = checkComponent(o); + FolderTreeSwingSessionState jTreeSwingSessionState = (FolderTreeSwingSessionState) state; + + for (int i = 0 ; i < tree.getRowCount() ; i++) { + TreePath path = tree.getPathForRow(i); + FolderTreeNode folderNode = (FolderTreeNode) path.getLastPathComponent(); + MailFolder mailFolder = folderNode.getMailFolder(); + if (mailFolder != null && jTreeSwingSessionState.getExpandedFolderIds().contains(mailFolder.getTopiaId())) { + tree.expandRow(i); + } else { + tree.collapseRow(i); + } + } + } + +} -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.