1 19 20 package org.netbeans.modules.tasklist.usertasks.actions; 21 22 import java.awt.event.ActionEvent ; 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.PropertyChangeListener ; 25 import javax.swing.AbstractAction ; 26 import javax.swing.ImageIcon ; 27 import javax.swing.event.ListSelectionEvent ; 28 import javax.swing.tree.TreePath ; 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 43 public class StartTaskAction extends UTViewAction implements 44 PropertyChangeListener , ObjectListListener { 45 private UserTask ut; 46 47 52 public StartTaskAction(UserTaskView utv) { 53 super(utv, NbBundle.getMessage(StartTaskAction.class, 54 "StartTask")); putValue(SMALL_ICON, new ImageIcon (Utilities.loadImage( 56 "org/netbeans/modules/tasklist/usertasks/actions/" + "startTask.gif"))); } 59 60 public void actionPerformed(ActionEvent 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 e) { 69 if (ut != null) { 70 ut.removePropertyChangeListener(this); 71 ut.getDependencies().removeListener(this); 72 ut = null; 73 } 74 75 TreePath [] paths = utv.getTreeTable().getSelectedPaths(); 76 if (paths.length == 1) { 77 Object 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 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 |