1 19 20 package org.netbeans.modules.tasklist.usertasks.actions; 21 22 import java.awt.event.ActionEvent ; 23 import javax.swing.event.ListSelectionEvent ; 24 import javax.swing.tree.TreePath ; 25 import org.netbeans.modules.tasklist.usertasks.UserTaskTreeTableNode; 26 import org.netbeans.modules.tasklist.usertasks.UserTaskView; 27 import org.netbeans.modules.tasklist.usertasks.model.UserTask; 28 import org.openide.DialogDisplayer; 29 import org.openide.NotifyDescriptor; 30 import org.openide.util.NbBundle; 31 32 38 public class PurgeTasksAction extends UTViewAction { 39 private static final long serialVersionUID = 2; 40 41 46 public PurgeTasksAction(UserTaskView utv) { 47 super(utv, NbBundle.getMessage(PurgeTasksAction.class, 48 "LBL_PurgeTodo")); } 50 51 public void actionPerformed(ActionEvent e) { 52 NotifyDescriptor nd = new NotifyDescriptor.Confirmation( 53 NbBundle.getMessage(PurgeTasksAction.class, "PurgeTasks"), NbBundle.getMessage(PurgeTasksAction.class, "PurgeTasksTitle"), NotifyDescriptor.OK_CANCEL_OPTION 56 ); 57 if (DialogDisplayer.getDefault().notify(nd) == NotifyDescriptor.OK_OPTION) { 58 TreePath [] tp = utv.getTreeTable().getSelectedPaths(); 59 UserTask[] uts = new UserTask[tp.length]; 60 for (int i = 0; i < tp.length; i++) { 61 UserTaskTreeTableNode n = (UserTaskTreeTableNode) 62 tp[i].getLastPathComponent(); 63 uts[i] = n.getUserTask(); 64 } 65 uts = UserTask.reduce(uts); 66 for (int i = 0; i < uts.length; i++) { 67 uts[i].purgeCompleted(); 68 if (uts[i].isDone()) { 69 if (uts[i].getParent() != null) 70 uts[i].getParent().getSubtasks().remove(uts[i]); 71 else 72 uts[i].getList().getSubtasks().remove(uts[i]); 73 } 74 } 75 } 76 } 77 78 public void valueChanged(ListSelectionEvent e) { 79 TreePath [] tp = utv.getTreeTable().getSelectedPaths(); 80 setEnabled(tp.length > 0); 81 } 82 } 83 | Popular Tags |