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.UserTaskListTreeTableNode; 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.model.UserTaskObjectList; 30 import org.netbeans.modules.tasklist.usertasks.treetable.AdvancedTreeTableNode; 31 import org.netbeans.modules.tasklist.usertasks.util.UTUtils; 32 import org.openide.util.NbBundle; 33 34 39 public class MoveLeftAction extends UTViewAction { 40 private static final long serialVersionUID = 1; 41 42 47 public MoveLeftAction(UserTaskView utv) { 48 super(utv, NbBundle.getMessage(MoveLeftAction.class, 49 "MoveLeft")); } 51 52 public void actionPerformed(ActionEvent event) { 53 TreePath sel = utv.getTreeTable().getSelectedPath(); 55 UserTaskTreeTableNode n = 56 (UserTaskTreeTableNode) sel.getLastPathComponent(); 57 UserTaskTreeTableNode parent = (UserTaskTreeTableNode) n.getParent(); 58 AdvancedTreeTableNode newParent = 59 (AdvancedTreeTableNode) parent.getParent(); 60 TreePath newParentPath = sel.getParentPath().getParentPath(); 61 TreePath [] expanded = utv.getTreeTable().getExpandedNodesUnder( 62 newParentPath); 63 UserTask[] expandedTasks = new UserTask[expanded.length]; 64 for (int i = 0; i < expanded.length ; i++) { 65 if (expanded[i].getLastPathComponent() instanceof 66 UserTaskTreeTableNode) { 67 expandedTasks[i] = ((UserTaskTreeTableNode) 68 expanded[i].getLastPathComponent()).getUserTask(); 69 } 70 } 71 utv.getTreeTable().clearSelection(); 72 int selColumn = utv.getTreeTable().getSelectedColumn(); 73 74 UserTask ut = n.getUserTask(); 76 int index = UTUtils.identityIndexOf(ut.getParentObjectList(), ut); 77 while (ut.getParentObjectList().size() > index + 1) { 78 ut.getSubtasks().add(ut.getParentObjectList().remove(index + 1)); 79 } 80 ut.getParentObjectList().remove(ut); 81 UserTaskObjectList newParentList; 82 if (newParent instanceof UserTaskTreeTableNode) 83 newParentList = ((UserTaskTreeTableNode) newParent). 84 getUserTask().getSubtasks(); 85 else 86 newParentList = ((UserTaskListTreeTableNode) newParent). 87 getUserTaskList().getSubtasks(); 88 int parentIndex = UTUtils.identityIndexOf( 89 newParentList, parent.getUserTask()); 90 newParentList.add(parentIndex + 1, ut); 91 92 index = newParent.getIndexOfObject(ut); 94 if (index >= 0) { 95 TreePath newPath = newParentPath.pathByAddingChild( 96 newParent.getChildAt(index)); 97 utv.getTreeTable().expandPath(newPath); 98 for (int i = 0; i < expandedTasks.length; i++) { 99 if (expandedTasks[i] != null) { 100 TreePath p = utv.getTreeTable().findPath(expandedTasks[i]); 101 if (p != null) 102 utv.getTreeTable().expandPath(p); 103 } 104 } 105 utv.getTreeTable().select(newPath); 106 utv.getTreeTable().getColumnModel().getSelectionModel(). 107 addSelectionInterval(selColumn, selColumn); 108 } 109 } 110 111 public void valueChanged(ListSelectionEvent e) { 112 TreePath [] sel = utv.getTreeTable().getSelectedPaths(); 113 if (utv.getTreeTable().getSortingModel().getSortedColumn() == -1 && 114 sel.length == 1) { 115 Object last = sel[0].getLastPathComponent(); 116 if (last instanceof UserTaskTreeTableNode) { 117 UserTaskTreeTableNode n = (UserTaskTreeTableNode) last; 118 setEnabled(n.getUserTask().getParent() != null); 119 } else { 120 setEnabled(false); 121 } 122 } else { 123 setEnabled(false); 124 } 125 } 126 } 127 | Popular Tags |