KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > usertasks > actions > ClearCompletedAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tasklist.usertasks.actions;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import javax.swing.event.ListSelectionEvent JavaDoc;
25
26 import org.netbeans.modules.tasklist.usertasks.model.UserTask;
27 import org.netbeans.modules.tasklist.usertasks.UserTaskView;
28 import org.openide.DialogDisplayer;
29 import org.openide.NotifyDescriptor;
30 import org.openide.util.NbBundle;
31
32 /**
33  * Clears "percent complete" properties of all subtasks recursively.
34  *
35  * @author tl
36  */

37 public class ClearCompletedAction extends UTViewAction {
38     private static final long serialVersionUID = 2;
39
40     /**
41      * Constructor.
42      *
43      * @param utv view associated with this task.
44      */

45     public ClearCompletedAction(UserTaskView utv) {
46         super(utv, NbBundle.getMessage(ClearCompletedAction.class,
47                 "ClearCompleted")); // NOI18N
48
}
49     
50     /**
51      * Clears the percent complete information for the specified task
52      * and all it's subtasks.
53      *
54      * @param ut a task
55      */

56     private void clearCompleted(UserTask ut) {
57         if (!ut.isValuesComputed())
58             ut.setDone(false);
59         Iterator JavaDoc it = ut.getSubtasks().iterator();
60         while (it.hasNext()) {
61             clearCompleted((UserTask) it.next());
62         }
63     }
64     
65     public void actionPerformed(ActionEvent JavaDoc arg0) {
66         NotifyDescriptor nd = new NotifyDescriptor.Confirmation(
67             NbBundle.getMessage(PurgeTasksAction.class, "ClearCompletedQuestion"), // NOI18N
68
NbBundle.getMessage(PurgeTasksAction.class, "ClearCompletedTitle"), // NOI18N
69
NotifyDescriptor.OK_CANCEL_OPTION
70         );
71         if (DialogDisplayer.getDefault().notify(nd) == NotifyDescriptor.OK_OPTION) {
72             clearCompleted(getSingleSelectedTask());
73             /*if (nodes[0] instanceof UserTaskNode) {
74                 UserTask ptsk = ((UserTaskNode) nodes[0]).getTask();
75                 clearCompleted(ptsk);
76             } else {
77                 UserTaskList utl =
78                     ((UserTaskListNode) nodes[0]).getUserTaskList();
79                 Iterator it = utl.getSubtasks().iterator();
80                 while (it.hasNext()) {
81                     UserTask ut = (UserTask) it.next();
82                     clearCompleted(ut);
83                 }
84             }todo */

85         }
86     }
87
88     public void valueChanged(ListSelectionEvent JavaDoc arg0) {
89         // todo does not work for the task list node
90
setEnabled(getSingleSelectedTask() != null);
91     }
92 }
93
Popular Tags