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.TreeNode ; 25 import javax.swing.tree.TreePath ; 26 import org.netbeans.modules.tasklist.usertasks.UserTaskTreeTableNode; 27 import org.netbeans.modules.tasklist.usertasks.UserTaskView; 28 import org.netbeans.modules.tasklist.usertasks.model.UserTask; 29 import org.netbeans.modules.tasklist.usertasks.util.UTUtils; 30 import org.openide.util.NbBundle; 31 32 37 public class MoveRightAction extends UTViewAction { 38 private static final long serialVersionUID = 1; 39 40 45 public MoveRightAction(UserTaskView utv) { 46 super(utv, NbBundle.getMessage(MoveRightAction.class, 47 "MoveRight")); } 49 50 public void actionPerformed(ActionEvent event) { 51 TreePath sel = utv.getTreeTable().getSelectedPath(); 53 UserTaskTreeTableNode n = 54 (UserTaskTreeTableNode) sel.getLastPathComponent(); 55 TreeNode parent = n.getParent(); 56 int index = parent.getIndex(n); 57 UserTaskTreeTableNode newParent = 58 (UserTaskTreeTableNode) parent.getChildAt(index - 1); 59 TreePath newParentPath = sel.getParentPath(). 60 pathByAddingChild(newParent); 61 TreePath [] expanded = utv.getTreeTable().getExpandedNodesUnder(sel); 62 UserTask[] expandedTasks = new UserTask[expanded.length]; 63 for (int i = 0; i < expanded.length ; i++) { 64 expandedTasks[i] = ((UserTaskTreeTableNode) 65 expanded[i].getLastPathComponent()).getUserTask(); 66 } 67 utv.getTreeTable().clearSelection(); 68 69 UserTask ut = n.getUserTask(); 71 ut.getParentObjectList().remove(ut); 72 newParent.getUserTask().getSubtasks().add(ut); 73 74 utv.getTreeTable().expandPath(newParentPath); 76 index = newParent.getIndexOfObject(ut); 77 if (index >= 0) { 78 for (int i = 0; i < expandedTasks.length; i++) { 79 TreePath p = utv.getTreeTable().findPath(expandedTasks[i]); 80 if (p != null) 81 utv.getTreeTable().expandPath(p); 82 } 83 utv.getTreeTable().select(newParentPath.pathByAddingChild( 84 newParent.getChildAt(index))); 85 } 86 } 87 88 public void valueChanged(ListSelectionEvent e) { 89 TreePath [] sel = utv.getTreeTable().getSelectedPaths(); 90 if (utv.getTreeTable().getSortingModel().getSortedColumn() == -1 && 91 sel.length == 1) { 92 Object last = sel[0].getLastPathComponent(); 93 if (last instanceof UserTaskTreeTableNode) { 94 UserTaskTreeTableNode n = (UserTaskTreeTableNode) last; 95 TreeNode parent = n.getParent(); 96 if (parent == null) 97 UTUtils.LOGGER.fine(n.getUserTask() + 98 " does not have a parent"); int index = parent.getIndex(n); 100 setEnabled(index != 0); 101 } else { 102 setEnabled(false); 103 } 104 } else { 105 setEnabled(false); 106 } 107 } 108 } 109 | Popular Tags |