KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > piagetproject > treestructure > DeleteAction


1 /*
2  * DeleteAction.java
3  *
4  * Created on June 28, 2005, 1:30 PM
5  *
6  * To change this template, choose Tools | Options and locate the template under
7  * the Source Creation and Management node. Right-click the template and choose
8  * Open. You can then make changes to the template in the Source Editor.
9  */

10
11 package org.netbeans.modules.piagetproject.treestructure;
12
13 import java.io.File JavaDoc;
14 import java.io.IOException JavaDoc;
15 import javax.swing.AbstractAction JavaDoc;
16 import javax.swing.Action JavaDoc;
17 import org.openide.nodes.AbstractNode;
18
19 /**
20  *
21  * @author loicsegapelli
22  */

23 public class DeleteAction extends AbstractAction JavaDoc {
24     
25     AbstractNode node;
26     String JavaDoc filepath;
27     
28     /** Creates a new instance of DeleteAction */
29     public DeleteAction(AbstractNode node, String JavaDoc filepath) {
30         this.node = node;
31         this.filepath = filepath;
32         putValue(Action.NAME, "delete");
33     }
34     
35     public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
36         File JavaDoc f = new File JavaDoc(filepath);
37         delete(f);
38         try {
39             node.destroy();
40         } catch (IOException JavaDoc ex) {
41             ex.printStackTrace(System.out);
42         }
43     }
44     
45     private void delete(File JavaDoc f) {
46         if(f.isDirectory()) {
47             File JavaDoc content [] = f.listFiles();
48             for (int i=0; i<content.length; i++) delete(content [i]);
49         }
50         f.delete();
51     }
52     
53 }
54
Popular Tags