Skip to content

Commit

Permalink
hiding and showing folders of a mailbox. close #2708
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dimension committed Nov 27, 2024
1 parent 9e775f1 commit 519ccba
Show file tree
Hide file tree
Showing 7 changed files with 1,739 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="mnuRemoveFolderActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="mnuHideFolder">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/icons16/baseline_visibility_off_black_48dp.png"/>
</Property>
<Property name="text" type="java.lang.String" value="Ordner ausblenden"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="mnuHideFolderActionPerformed"/>
</Events>
</MenuItem>
<Menu class="javax.swing.JMenu" name="mnuShowFolders">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/icons16/baseline_visibility_black_48dp.png"/>
</Property>
<Property name="text" type="java.lang.String" value="Ordner einblenden"/>
</Properties>
</Menu>
</SubComponents>
</Container>
<Container class="javax.swing.JPopupMenu" name="popEmailList">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@
import com.jdimension.jlawyer.client.mail.sidebar.SaveToCasePanel;
import com.jdimension.jlawyer.client.processing.ProgressIndicator;
import com.jdimension.jlawyer.client.settings.ClientSettings;
import com.jdimension.jlawyer.client.settings.MailboxSettings;
import com.jdimension.jlawyer.client.settings.ServerSettings;
import com.jdimension.jlawyer.client.settings.UserSettings;
import com.jdimension.jlawyer.client.utils.*;
Expand Down Expand Up @@ -741,6 +742,7 @@
import javax.mail.util.SharedByteArrayInputStream;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DropMode;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.RowSorter.SortKey;
import javax.swing.SwingUtilities;
Expand Down Expand Up @@ -1104,7 +1106,7 @@ private void traverseFolders(MailboxSetup ms, Folder[] children, DefaultMutableT
return;
}

if ((child.getType() & Folder.HOLDS_MESSAGES) != 0) {
if ((child.getType() & Folder.HOLDS_MESSAGES) != 0) {

FolderContainer childContainer = new FolderContainer(child);

Expand All @@ -1120,12 +1122,18 @@ private void traverseFolders(MailboxSetup ms, Folder[] children, DefaultMutableT
Arrays.sort(htKeysSorted);
for (String key : htKeysSorted) {
FolderContainer childContainer = childHt.get(key);
DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(childContainer);
if (childContainer.getFolder().equals(this.inboxFolders.get(ms).getFolder())) {
this.inboxFolderNodes.put(ms, childNode);

String fullParentPath=this.getFullPathInMailbox(new TreePath(currentNode.getPath()));
String fullChildPath=fullParentPath + File.separator + childContainer.getFolder().getName();
boolean isHidden=MailboxSettings.getInstance().isFolderHidden(ms, fullChildPath);
if (!isHidden) {
DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(childContainer);
if (childContainer.getFolder().equals(this.inboxFolders.get(ms).getFolder())) {
this.inboxFolderNodes.put(ms, childNode);
}
currentNode.add(childNode);
traverseFolders(ms, childContainer.getFolder().list(), childNode);
}
currentNode.add(childNode);
traverseFolders(ms, childContainer.getFolder().list(), childNode);

try {
if (childContainer.getFolder().isOpen()) {
Expand Down Expand Up @@ -1164,6 +1172,8 @@ private void initComponents() {
mnuNewFolder = new javax.swing.JMenuItem();
mnuEmptyTrash = new javax.swing.JMenuItem();
mnuRemoveFolder = new javax.swing.JMenuItem();
mnuHideFolder = new javax.swing.JMenuItem();
mnuShowFolders = new javax.swing.JMenu();
popEmailList = new javax.swing.JPopupMenu();
mnuMarkRead = new javax.swing.JMenuItem();
mnuMarkUnread = new javax.swing.JMenuItem();
Expand Down Expand Up @@ -1230,6 +1240,19 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
});
popFolders.add(mnuRemoveFolder);

mnuHideFolder.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons16/baseline_visibility_off_black_48dp.png"))); // NOI18N
mnuHideFolder.setText("Ordner ausblenden");
mnuHideFolder.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnuHideFolderActionPerformed(evt);
}
});
popFolders.add(mnuHideFolder);

mnuShowFolders.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons16/baseline_visibility_black_48dp.png"))); // NOI18N
mnuShowFolders.setText("Ordner einblenden");
popFolders.add(mnuShowFolders);

mnuMarkRead.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/agt_action_success.png"))); // NOI18N
mnuMarkRead.setText("als gelesen markieren");
mnuMarkRead.addActionListener(new java.awt.event.ActionListener() {
Expand Down Expand Up @@ -1411,7 +1434,6 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
}
});

jToolBar1.setFloatable(false);
jToolBar1.setRollover(true);
jToolBar1.setOpaque(false);

Expand Down Expand Up @@ -1741,23 +1763,27 @@ private void treeFoldersMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRS
this.treeFolders.setSelectionRow(row);

DefaultMutableTreeNode tn = (DefaultMutableTreeNode) this.treeFolders.getSelectionPath().getLastPathComponent();
FolderContainer folderC = (FolderContainer) tn.getUserObject();
Folder f = folderC.getFolder();
if (CommonMailUtils.INBOX.equalsIgnoreCase(f.getName()) || CommonMailUtils.SENT.equalsIgnoreCase(f.getName()) || CommonMailUtils.TRASH.equalsIgnoreCase(f.getName())) {
this.mnuRemoveFolder.setEnabled(false);
} else {
this.mnuRemoveFolder.setEnabled(true);
}
if (tn.getUserObject() instanceof FolderContainer) {
FolderContainer folderC = (FolderContainer) tn.getUserObject();
Folder f = folderC.getFolder();
if (CommonMailUtils.INBOX.equalsIgnoreCase(f.getName()) || CommonMailUtils.SENT.equalsIgnoreCase(f.getName()) || CommonMailUtils.TRASH.equalsIgnoreCase(f.getName())) {
this.mnuRemoveFolder.setEnabled(false);
this.mnuHideFolder.setEnabled(false);
} else {
this.mnuRemoveFolder.setEnabled(true);
this.mnuHideFolder.setEnabled(true);
}

this.mnuEmptyTrash.setEnabled(CommonMailUtils.TRASH.equalsIgnoreCase(f.getName()) || CommonMailUtils.isTrash(f.getName()));
this.mnuEmptyTrash.setEnabled(CommonMailUtils.TRASH.equalsIgnoreCase(f.getName()) || CommonMailUtils.isTrash(f.getName()));

if (f instanceof POP3Folder) {
this.mnuNewFolder.setEnabled(false);
this.mnuRemoveFolder.setEnabled(false);
this.mnuEmptyTrash.setEnabled(false);
}
if (f instanceof POP3Folder) {
this.mnuNewFolder.setEnabled(false);
this.mnuRemoveFolder.setEnabled(false);
this.mnuEmptyTrash.setEnabled(false);
}

this.popFolders.show(evt.getComponent(), evt.getX(), evt.getY());
this.popFolders.show(evt.getComponent(), evt.getX(), evt.getY());
}
}
}//GEN-LAST:event_treeFoldersMouseReleased

Expand Down Expand Up @@ -1801,34 +1827,6 @@ private void mnuNewFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-

}//GEN-LAST:event_mnuNewFolderActionPerformed

private void treeFoldersMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_treeFoldersMousePressed
if (evt.isPopupTrigger()) {
int row = this.treeFolders.getRowForLocation(evt.getX(), evt.getY());
this.treeFolders.setSelectionRow(row);

DefaultMutableTreeNode tn = (DefaultMutableTreeNode) this.treeFolders.getSelectionPath().getLastPathComponent();
FolderContainer folderC = (FolderContainer) tn.getUserObject();
Folder f = folderC.getFolder();
if (CommonMailUtils.INBOX.equalsIgnoreCase(f.getName()) || CommonMailUtils.SENT.equalsIgnoreCase(f.getName()) || CommonMailUtils.TRASH.equalsIgnoreCase(f.getName())) {
this.mnuRemoveFolder.setEnabled(false);
} else {
this.mnuRemoveFolder.setEnabled(true);
}

this.mnuEmptyTrash.setEnabled(CommonMailUtils.TRASH.equalsIgnoreCase(f.getName()) || CommonMailUtils.isTrash(f.getName()) || CommonMailUtils.isTrash(f.getName()));

if (f instanceof POP3Folder) {
this.mnuNewFolder.setEnabled(false);
this.mnuRemoveFolder.setEnabled(false);
this.mnuEmptyTrash.setEnabled(false);
}

this.popFolders.show(evt.getComponent(), evt.getX(), evt.getY());
}


}//GEN-LAST:event_treeFoldersMousePressed

private void mnuRemoveFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuRemoveFolderActionPerformed
DefaultMutableTreeNode tn = (DefaultMutableTreeNode) this.treeFolders.getSelectionPath().getLastPathComponent();
FolderContainer folderC = (FolderContainer) tn.getUserObject();
Expand Down Expand Up @@ -2394,12 +2392,108 @@ private void cmdSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR
this.treeFoldersValueChangedImpl(new TreeSelectionEvent(this.tblMails, this.treeFolders.getSelectionPath(), false, null, null), sortCol, -1, this.txtSearchString.getText());
}//GEN-LAST:event_cmdSearchActionPerformed

private void mnuHideFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuHideFolderActionPerformed
DefaultMutableTreeNode tn = (DefaultMutableTreeNode) this.treeFolders.getSelectionPath().getLastPathComponent();
FolderContainer folderC = (FolderContainer) tn.getUserObject();
Folder f = folderC.getFolder();

int response = JOptionPane.showConfirmDialog(this, "Ordner " + folderC.toString() + " ausblenden?", "Ordner ausblenden", JOptionPane.YES_NO_OPTION);
if (response == JOptionPane.YES_OPTION) {

MailboxSetup ms=getMailboxSetup(tn);
if(ms!=null) {
String fullPath=this.getFullPathInMailbox(new TreePath(((DefaultMutableTreeNode) tn).getPath()));
MailboxSettings.getInstance().hideFolder(ms, fullPath);

this.treeFolders.setSelectionPath(new TreePath(((DefaultMutableTreeNode) tn.getParent()).getPath()));
DefaultTreeModel dm = (DefaultTreeModel) this.treeFolders.getModel();
dm.removeNodeFromParent(tn);
}
}
}//GEN-LAST:event_mnuHideFolderActionPerformed

private void treeFoldersMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_treeFoldersMousePressed
if (evt.isPopupTrigger()) {
int row = this.treeFolders.getRowForLocation(evt.getX(), evt.getY());
this.treeFolders.setSelectionRow(row);

DefaultMutableTreeNode tn = (DefaultMutableTreeNode) this.treeFolders.getSelectionPath().getLastPathComponent();
if (tn.getUserObject() instanceof FolderContainer) {
FolderContainer folderC = (FolderContainer) tn.getUserObject();
Folder f = folderC.getFolder();
if (CommonMailUtils.INBOX.equalsIgnoreCase(f.getName()) || CommonMailUtils.SENT.equalsIgnoreCase(f.getName()) || CommonMailUtils.TRASH.equalsIgnoreCase(f.getName())) {
this.mnuRemoveFolder.setEnabled(false);
this.mnuHideFolder.setEnabled(false);
} else {
this.mnuRemoveFolder.setEnabled(true);
this.mnuHideFolder.setEnabled(true);
}

this.mnuEmptyTrash.setEnabled(CommonMailUtils.TRASH.equalsIgnoreCase(f.getName()) || CommonMailUtils.isTrash(f.getName()));

if (f instanceof POP3Folder) {
this.mnuNewFolder.setEnabled(false);
this.mnuRemoveFolder.setEnabled(false);
this.mnuEmptyTrash.setEnabled(false);
}

this.mnuShowFolders.removeAll();
MailboxSetup ms=this.getMailboxSetup(tn);
if(ms!=null) {
String[] hiddenFolders=MailboxSettings.getInstance().getHiddenFolders(ms);
for(String s: hiddenFolders) {
JMenuItem showItem = new JMenuItem(s);
showItem.addActionListener(e -> {
MailboxSettings.getInstance().showFolder(ms, s);
this.cmdRefreshActionPerformed(null);
});
this.mnuShowFolders.add(showItem);
}
}

this.popFolders.show(evt.getComponent(), evt.getX(), evt.getY());
}
}
}//GEN-LAST:event_treeFoldersMousePressed

private MailboxSetup getMailboxSetup(DefaultMutableTreeNode dm) {
while(dm.getParent()!=null && dm.getParent().getParent()!=null) {
dm=(DefaultMutableTreeNode)dm.getParent();
}
String mailAddress = dm.getUserObject().toString();

UserSettings uset = UserSettings.getInstance();
List<MailboxSetup> mailboxes = uset.getMailboxes(uset.getCurrentUser().getPrincipalId());
if (mailboxes.isEmpty()) {
return null;
}

for (MailboxSetup ms : mailboxes) {
if (ms.getEmailAddress().equals(mailAddress)) {
return ms;
}
}

return null;

}

// returns the full path within a mailbox, omitting the mailboxes mail adress
private String getFullPathInMailbox(TreePath tp) {
return getFullPathImpl(tp, 2);
}

private String getFullPath(TreePath tp) {
return getFullPathImpl(tp, 1);
}

// returns the full path including the mailboxes mail adress as root
private String getFullPathImpl(TreePath tp, int startIndex) {
StringBuilder sb = new StringBuilder();

Object[] paths = tp.getPath();
// ignore the root, start at index 1
for (int i = 1; i < paths.length; i++) {
for (int i = startIndex; i < paths.length; i++) {
String name=paths[i].toString();
if(paths[i] instanceof DefaultMutableTreeNode) {
if(((DefaultMutableTreeNode)paths[i]).getUserObject() instanceof FolderContainer) {
Expand Down Expand Up @@ -3196,6 +3290,7 @@ public void run() {
protected javax.swing.JLabel lblPanelTitle;
private com.jdimension.jlawyer.client.mail.MailContentUI mailContentUI;
private javax.swing.JMenuItem mnuEmptyTrash;
private javax.swing.JMenuItem mnuHideFolder;
private javax.swing.JMenuItem mnuMarkRead;
private javax.swing.JMenuItem mnuMarkUnread;
private javax.swing.JMenuItem mnuNewFolder;
Expand All @@ -3205,6 +3300,7 @@ public void run() {
private javax.swing.JMenuItem mnuSearchSaveNoAttachments;
private javax.swing.JMenuItem mnuSearchSaveOnlyAttachments;
private javax.swing.JMenuItem mnuSearchSaveSeparate;
private javax.swing.JMenu mnuShowFolders;
private javax.swing.JPanel pnlActions;
private javax.swing.JPanel pnlActionsChild;
private javax.swing.JPopupMenu popEmailList;
Expand Down
Loading

0 comments on commit 519ccba

Please sign in to comment.