KickJava   Java API By Example, From Geeks To Geeks.

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


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.beans.PropertyChangeEvent JavaDoc;
24 import java.beans.PropertyChangeListener JavaDoc;
25 import javax.swing.AbstractAction JavaDoc;
26 import javax.swing.ImageIcon JavaDoc;
27 import javax.swing.event.ListSelectionEvent JavaDoc;
28 import javax.swing.tree.TreePath JavaDoc;
29 import org.netbeans.modules.tasklist.core.util.ObjectListEvent;
30 import org.netbeans.modules.tasklist.core.util.ObjectListListener;
31 import org.netbeans.modules.tasklist.usertasks.UserTaskTreeTableNode;
32 import org.netbeans.modules.tasklist.usertasks.model.StartedUserTask;
33 import org.netbeans.modules.tasklist.usertasks.model.UserTask;
34 import org.netbeans.modules.tasklist.usertasks.UserTaskView;
35 import org.openide.util.NbBundle;
36 import org.openide.util.Utilities;
37
38 /**
39  * Starts a task
40  *
41  * @author tl
42  */

43 public class StartTaskAction extends UTViewAction implements
44         PropertyChangeListener JavaDoc, ObjectListListener {
45     private UserTask ut;
46     
47     /**
48      * Constructor.
49      *
50      * @param utv a user task view.
51      */

52     public StartTaskAction(UserTaskView utv) {
53         super(utv, NbBundle.getMessage(StartTaskAction.class,
54                 "StartTask")); // NOI18N
55
putValue(SMALL_ICON, new ImageIcon JavaDoc(Utilities.loadImage(
56                 "org/netbeans/modules/tasklist/usertasks/actions/" + // NOI18N
57
"startTask.gif"))); // NOI18N
58
}
59     
60     public void actionPerformed(ActionEvent JavaDoc e) {
61         if (StartedUserTask.getInstance().getStarted() != null)
62             StartedUserTask.getInstance().start(null);
63         if (ut.getOwner().trim().length() == 0)
64             ut.setOwner(System.getProperty("user.name"));
65         ut.start();
66     }
67
68     public void valueChanged(ListSelectionEvent JavaDoc e) {
69         if (ut != null) {
70             ut.removePropertyChangeListener(this);
71             ut.getDependencies().removeListener(this);
72             ut = null;
73         }
74         
75         TreePath JavaDoc[] paths = utv.getTreeTable().getSelectedPaths();
76         if (paths.length == 1) {
77             Object JavaDoc last = paths[0].getLastPathComponent();
78             if (last instanceof UserTaskTreeTableNode) {
79                 UserTask ut = ((UserTaskTreeTableNode) last).getUserTask();
80                 this.ut = ut;
81                 this.ut.addPropertyChangeListener(this);
82                 this.ut.getDependencies().addListener(this);
83             }
84         }
85         updateEnabled();
86     }
87
88     private void updateEnabled() {
89         setEnabled(ut != null && ut.isStartable() && !ut.isStarted());
90     }
91     
92     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
93         if (evt.getPropertyName() == "started" ||
94                 evt.getPropertyName() == "spentTimeComputed" ||
95                 evt.getPropertyName() == "progress") {
96             setEnabled(ut.isStartable() && !ut.isStarted());
97         }
98     }
99
100     public void listChanged(ObjectListEvent e) {
101         updateEnabled();
102     }
103 }
104
Popular Tags