1 package SnowMailClient.view.folders; 2 3 import snow.utils.gui.Icons; 4 import SnowMailClient.model.folders.*; 5 import SnowMailClient.SnowMailClientApp; 6 7 import java.awt.*; 8 import java.awt.event.*; 9 import javax.swing.*; 10 import javax.swing.event.*; 11 import javax.swing.tree.*; 12 13 public class RemoveSelectedFolder extends AbstractAction implements TreeSelectionListener 14 { 15 16 JTree tree; 17 FolderTreeNode node; 18 19 public RemoveSelectedFolder( FolderTreeNode node, JTree tree) 20 { 21 super("Remove folder"+(node!=null?" "+node.getFolderName():"")); 22 putValue(AbstractAction.SMALL_ICON, Icons.CrossIcon.shared10); 23 this.tree = tree; 24 this.node = node; 25 tree.getSelectionModel().addTreeSelectionListener(this); 26 } 28 public void valueChanged(TreeSelectionEvent e) 29 { 30 this.setEnabled( tree.getSelectionCount()==1 ); 31 } 32 33 public void actionPerformed(ActionEvent e) 34 { 35 try 36 { 37 if(node!=null) 39 { 40 FolderTreeNode parent = node.getParentNode(); 43 node.removeThisFolder(); 44 45 46 tree.setSelectionPath(new TreePath(parent.getPath())); 47 48 tree.updateUI(); 50 } 51 } 52 catch(Exception e2) 53 { 54 56 JOptionPane.showMessageDialog(tree, "Error: "+e2.getMessage(), "Cannot remove folder", 57 JOptionPane.ERROR_MESSAGE); 58 } 59 } 60 61 } | Popular Tags |