KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SnowMailClient > view > folders > RemoveSelectedFolder


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   } // Constructor
27

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         //TreePath selectionPath = tree.getSelectionPath();
38
if(node!=null)
39         {
40           //FolderTreeNode fileNode = (FolderTreeNode) selectionPath.getLastPathComponent();
41
FolderTreeNode parent = node.getParentNode(); // first get parent...
42

43           node.removeThisFolder();
44
45
46           tree.setSelectionPath(new TreePath(parent.getPath()));
47
48           // ### ugly
49
tree.updateUI();
50         }
51      }
52      catch(Exception JavaDoc e2)
53      {
54        // e2.printStackTrace();
55

56        JOptionPane.showMessageDialog(tree, "Error: "+e2.getMessage(), "Cannot remove folder",
57           JOptionPane.ERROR_MESSAGE);
58      }
59   }
60
61 } // RemoveSelectedFolder
Popular Tags