1 19 20 package org.netbeans.modules.tasklist.usertasks; 21 22 import com.toedter.calendar.JDateChooserCellEditor; 23 import java.awt.Graphics ; 24 import java.awt.Point ; 25 import java.awt.datatransfer.DataFlavor ; 26 import java.awt.datatransfer.StringSelection ; 27 import java.awt.datatransfer.Transferable ; 28 import java.awt.dnd.DropTarget ; 29 import java.awt.event.ActionEvent ; 30 import java.awt.event.MouseAdapter ; 31 import java.awt.event.MouseEvent ; 32 import java.io.Serializable ; 33 import java.util.ArrayList ; 34 import java.util.Arrays ; 35 import java.util.Iterator ; 36 import java.util.List ; 37 import javax.swing.Action ; 38 import javax.swing.ImageIcon ; 39 import javax.swing.JComponent ; 40 import javax.swing.JPopupMenu ; 41 import javax.swing.JScrollPane ; 42 import javax.swing.ListSelectionModel ; 43 import javax.swing.SwingUtilities ; 44 import javax.swing.TransferHandler ; 45 import javax.swing.event.ListSelectionEvent ; 46 import javax.swing.event.ListSelectionListener ; 47 import javax.swing.table.TableColumnModel ; 48 import javax.swing.tree.TreePath ; 49 import org.netbeans.modules.tasklist.core.export.ExportAction; 50 import org.netbeans.modules.tasklist.core.export.ImportAction; 51 import org.netbeans.modules.tasklist.core.filter.Filter; 52 import org.netbeans.modules.tasklist.core.filter.FilterAction; 53 import org.netbeans.modules.tasklist.core.filter.RemoveFilterAction; 54 import org.netbeans.modules.tasklist.usertasks.actions.CollapseAllAction; 55 import org.netbeans.modules.tasklist.usertasks.actions.ExpandAllUserTasksAction; 56 import org.netbeans.modules.tasklist.usertasks.actions.GoToUserTaskAction; 57 import org.netbeans.modules.tasklist.usertasks.actions.PauseAction; 58 import org.netbeans.modules.tasklist.usertasks.actions.ScheduleAction; 59 import org.netbeans.modules.tasklist.usertasks.actions.StartTaskAction; 60 import org.netbeans.modules.tasklist.usertasks.editors.CategoryTableCellEditor; 61 import org.netbeans.modules.tasklist.usertasks.editors.EffortTableCellEditor; 62 import org.netbeans.modules.tasklist.usertasks.editors.OwnerTableCellEditor; 63 import org.netbeans.modules.tasklist.usertasks.editors.PercentsTableCellEditor; 64 import org.netbeans.modules.tasklist.usertasks.editors.PriorityTableCellEditor; 65 import org.netbeans.modules.tasklist.usertasks.renderers.PriorityTableCellRenderer; 66 import org.netbeans.modules.tasklist.usertasks.renderers.SummaryTreeCellRenderer; 67 import org.netbeans.modules.tasklist.usertasks.treetable.DefaultMutableTreeTableNode; 68 import org.netbeans.modules.tasklist.usertasks.treetable.DefaultTreeTableModel; 69 import org.netbeans.modules.tasklist.usertasks.treetable.TreeTable; 70 import org.netbeans.modules.tasklist.usertasks.treetable.TreeTableDragGestureRecognizer; 71 import org.netbeans.modules.tasklist.usertasks.util.UTUtils; 72 import org.openide.awt.MouseUtils; 73 import org.openide.nodes.Node; 74 import org.netbeans.modules.tasklist.usertasks.model.UserTask; 75 import org.netbeans.modules.tasklist.usertasks.model.UserTaskList; 76 import org.netbeans.modules.tasklist.usertasks.model.UserTaskObjectList; 77 import org.netbeans.modules.tasklist.usertasks.options.Settings; 78 import org.netbeans.modules.tasklist.usertasks.renderers.CategoryTableCellRenderer; 79 import org.netbeans.modules.tasklist.usertasks.renderers.DateTableCellRenderer; 80 import org.netbeans.modules.tasklist.usertasks.renderers.DoneTreeTableCellRenderer; 81 import org.netbeans.modules.tasklist.usertasks.renderers.DueDateTableCellRenderer; 82 import org.netbeans.modules.tasklist.usertasks.renderers.DurationTableCellRenderer; 83 import org.netbeans.modules.tasklist.usertasks.renderers.EffortTableCellRenderer; 84 import org.netbeans.modules.tasklist.usertasks.renderers.LineTableCellRenderer; 85 import org.netbeans.modules.tasklist.usertasks.renderers.OwnerTableCellRenderer; 86 import org.netbeans.modules.tasklist.usertasks.renderers.PercentsTableCellRenderer; 87 import org.netbeans.modules.tasklist.usertasks.transfer.MyTransferHandler; 88 import org.netbeans.modules.tasklist.usertasks.treetable.AdvancedTreeTableNode; 89 import org.netbeans.modules.tasklist.usertasks.treetable.SortingHeaderRenderer; 90 import org.openide.actions.CopyAction; 91 import org.openide.actions.CutAction; 92 import org.openide.actions.DeleteAction; 93 import org.openide.actions.PasteAction; 94 import org.openide.util.Utilities; 95 import org.openide.util.actions.SystemAction; 96 97 102 public class UserTasksTreeTable extends TreeTable { 103 private UserTask selected; 104 private UserTaskView utv; 105 106 113 public UserTasksTreeTable(UserTaskView utv, UserTaskList utl, 114 Filter filter) { 115 super(new DefaultTreeTableModel( 116 new DefaultMutableTreeTableNode(), new String [] {""})); this.utv = utv; 118 setTreeTableModel( 121 new UserTasksTreeTableModel(utl, getSortingModel(), filter)); 122 setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 123 setShowHorizontalLines(true); 124 setShowVerticalLines(true); 125 setAutoResizeMode(AUTO_RESIZE_OFF); 126 getTree().setCellRenderer(new SummaryTreeCellRenderer()); 127 getTree().setShowsRootHandles(true); 128 getTree().setToggleClickCount(3); 129 getTree().setRootVisible(false); 130 131 setAutoCreateColumnsFromModel(false); 132 133 149 150 getSelectionModel().addListSelectionListener( 151 new ListSelectionListener () { 152 public void valueChanged(ListSelectionEvent e) { 153 int row = getSelectedRow(); 154 UserTask ut = null; 155 if (row >= 0) { 156 Object node = getNodeForRow(row); 157 if (node instanceof UserTaskTreeTableNode) { 158 ut = ((UserTaskTreeTableNode) node).getUserTask(); 159 } 160 } 161 if (selected != null && selected.getAnnotation() != null) 162 selected.getAnnotation().setHighlight(false); 163 selected = ut; 164 if (selected != null && selected.getAnnotation() != null) 165 selected.getAnnotation().setHighlight(true); 166 } 167 } 168 ); 169 170 addMouseListener(new MouseUtils.PopupMouseAdapter() { 171 public void showPopup(MouseEvent e) { 172 int row = rowAtPoint(e.getPoint()); 173 int col = columnAtPoint(e.getPoint()); 174 Action [] actions; 175 176 if (row < 0 || col < 0) 177 return; 178 179 if (!getSelectionModel().isSelectedIndex(row)) { 180 setRowSelectionInterval(row, row); 181 } 182 actions = getActions_(); 183 184 JPopupMenu pm = Utilities.actionsToPopup(actions, 185 UserTasksTreeTable.this); 186 187 if (pm != null) 188 pm.show(UserTasksTreeTable.this, e.getX(), e.getY()); 189 } 190 }); 191 192 addMouseListener(new MouseAdapter () { 193 @Override 194 public void mouseClicked(MouseEvent e) { 195 if (e.getClickCount() == 2) { 196 int row = rowAtPoint(e.getPoint()); 197 if (!getSelectionModel().isSelectedIndex(row)) { 198 setRowSelectionInterval(row, row); 199 } 200 UserTasksTreeTable.this.utv.showTaskAction. 201 actionPerformed(new ActionEvent ( 202 UserTasksTreeTable.this.utv.getTreeTable(), 0, "")); 203 } 204 } 205 }); 206 207 setColumnsConfig(createDefaultColumnsConfig()); 208 209 TreeTableDragGestureRecognizer.enableDnD(this); 210 setTransferHandler(new MyTransferHandler()); 211 setAutoscrolls(true); 212 } 213 214 @Override 215 protected void configureEnclosingScrollPane() { 216 super.configureEnclosingScrollPane(); 217 final JScrollPane sp = (JScrollPane ) SwingUtilities.getAncestorOfClass( 218 JScrollPane .class, this); 219 sp.addMouseListener(new MouseUtils.PopupMouseAdapter() { 220 public void showPopup(MouseEvent e) { 221 JPopupMenu pm = Utilities.actionsToPopup(getActions_(), 222 UserTasksTreeTable.this); 223 224 if (pm != null) 225 pm.show(sp, e.getX(), e.getY()); 226 } 227 }); 228 } 229 230 235 private TreeTable.ColumnsConfig createDefaultColumnsConfig() { 236 TreeTable.ColumnsConfig ret = new TreeTable.ColumnsConfig(); 237 ret.ascending = false; 238 ret.columnWidths = new int[] {18, 18, 400, 60, 60, 60, 80, 80, 80}; 239 ret.sortedColumn = UserTasksTreeTableModel.PRIORITY; 240 ret.columns = new int[] { 241 UserTasksTreeTableModel.DONE, 242 UserTasksTreeTableModel.PRIORITY, 243 UserTasksTreeTableModel.SUMMARY, 244 UserTasksTreeTableModel.CATEGORY, 245 UserTasksTreeTableModel.OWNER, 246 UserTasksTreeTableModel.PERCENT_COMPLETE, 247 UserTasksTreeTableModel.EFFORT, 248 UserTasksTreeTableModel.REMAINING_EFFORT, 249 UserTasksTreeTableModel.SPENT_TIME 250 }; 251 return ret; 252 } 253 254 public Node createNode(Object obj) { 255 UserTaskList utl = ((UserTasksTreeTableModel) getTreeTableModel()). 256 getUserTaskList(); 257 UserTaskTreeTableNode node = (UserTaskTreeTableNode) obj; 258 UserTask ut = node.getUserTask(); 259 return new UserTaskNode(node, ut, utl, this); 260 } 261 262 public void createDefaultColumnsFromModel() { 263 super.createDefaultColumnsFromModel(); 264 265 TableColumnModel tcm = getColumnModel(); 266 if (tcm.getColumnCount() < 14) 267 return; 268 269 JDateChooserCellEditor dc = new JDateChooserCellEditor(); 270 271 SortingHeaderRenderer r = new SortingHeaderRenderer(); 272 r.setIcon(new ImageIcon ( 273 UserTasksTreeTable.class.getResource("checkbox.gif"))); tcm.getColumn(UserTasksTreeTableModel.DONE).setHeaderRenderer(r); 275 tcm.getColumn(UserTasksTreeTableModel.DONE).setCellRenderer( 276 new DoneTreeTableCellRenderer()); 277 tcm.getColumn(UserTasksTreeTableModel.DONE).setMinWidth(17); 278 279 tcm.getColumn(UserTasksTreeTableModel.PERCENT_COMPLETE). 280 setCellEditor(new PercentsTableCellEditor()); 281 tcm.getColumn(UserTasksTreeTableModel.PERCENT_COMPLETE).setCellRenderer( 282 new PercentsTableCellRenderer()); 283 284 DurationTableCellRenderer dr = new DurationTableCellRenderer(); 285 tcm.getColumn(UserTasksTreeTableModel.REMAINING_EFFORT).setCellRenderer(dr); 286 287 tcm.getColumn(UserTasksTreeTableModel.SPENT_TIME).setCellRenderer(dr); 288 tcm.getColumn(UserTasksTreeTableModel.SPENT_TIME).setCellEditor( 289 new EffortTableCellEditor()); 290 291 tcm.getColumn(UserTasksTreeTableModel.LINE_NUMBER).setCellRenderer( 292 new LineTableCellRenderer()); 293 294 DateTableCellRenderer dcr = new DateTableCellRenderer(); 295 tcm.getColumn(UserTasksTreeTableModel.CREATED).setCellRenderer(dcr); 296 297 tcm.getColumn(UserTasksTreeTableModel.LAST_EDITED).setCellRenderer(dcr); 298 299 tcm.getColumn(UserTasksTreeTableModel.DUE_DATE).setCellRenderer(dcr); 300 301 tcm.getColumn(UserTasksTreeTableModel.COMPLETED_DATE) 302 .setCellRenderer(dcr); 303 304 tcm.getColumn(UserTasksTreeTableModel.CATEGORY). 305 setCellEditor(new CategoryTableCellEditor()); 306 tcm.getColumn(UserTasksTreeTableModel.CATEGORY). 307 setCellRenderer(new CategoryTableCellRenderer()); 308 309 SortingHeaderRenderer priorityRenderer = new SortingHeaderRenderer(); 310 priorityRenderer.setIcon(new ImageIcon ( 311 UserTasksTreeTable.class.getResource("priority.gif"))); tcm.getColumn(UserTasksTreeTableModel.PRIORITY).setHeaderRenderer( 313 priorityRenderer); 314 tcm.getColumn(UserTasksTreeTableModel.PRIORITY).setCellRenderer( 315 new PriorityTableCellRenderer()); 316 tcm.getColumn(UserTasksTreeTableModel.PRIORITY).setCellEditor( 317 new PriorityTableCellEditor()); 318 tcm.getColumn(UserTasksTreeTableModel.PRIORITY).setCellRenderer( 319 new PriorityTableCellRenderer()); 320 321 tcm.getColumn(UserTasksTreeTableModel.EFFORT).setCellRenderer( 322 new EffortTableCellRenderer()); 323 tcm.getColumn(UserTasksTreeTableModel.EFFORT).setCellEditor( 324 new EffortTableCellEditor()); 325 326 tcm.getColumn(UserTasksTreeTableModel.OWNER). 327 setCellEditor(new OwnerTableCellEditor()); 328 tcm.getColumn(UserTasksTreeTableModel.OWNER). 329 setCellRenderer(new OwnerTableCellRenderer()); 330 331 tcm.getColumn(UserTasksTreeTableModel.DUE_DATE).setCellRenderer( 332 new DueDateTableCellRenderer()); 333 tcm.getColumn(UserTasksTreeTableModel.DUE_DATE).setWidth(100); 334 tcm.getColumn(UserTasksTreeTableModel.DUE_DATE).setCellEditor(dc); 335 336 tcm.getColumn(UserTasksTreeTableModel.START).setCellRenderer(dcr); 337 tcm.getColumn(UserTasksTreeTableModel.START).setCellEditor(dc); 338 339 tcm.getColumn(UserTasksTreeTableModel.SPENT_TIME_TODAY).setCellRenderer(dr); 340 } 341 342 347 public TreePath findPath(UserTask task) { 348 List <UserTask> l = new ArrayList <UserTask>(); 349 while (task != null) { 350 l.add(0, task); 351 task = task.getParent(); 352 } 353 AdvancedTreeTableNode n = 354 (AdvancedTreeTableNode) getTreeTableModel().getRoot(); 355 356 for (int i = 0; i < l.size(); i++) { 357 int index = n.getIndexOfObject(l.get(i)); 358 if (index == -1) 359 return null; 360 n = (AdvancedTreeTableNode) n.getChildAt(index); 361 } 362 return new TreePath (n.getPathToRoot()); 363 } 364 365 public javax.swing.Action [] getActions_() { 366 return new Action [] { 367 utv.newTaskAction, 368 null, 370 new StartTaskAction(utv), 371 PauseAction.getInstance(), 372 null, 373 utv.showTaskAction, 374 new GoToUserTaskAction(utv), 375 null, 376 SystemAction.get(CutAction.class), 377 SystemAction.get(CopyAction.class), 378 SystemAction.get(PasteAction.class), 379 utv.pasteAtTopLevelAction, 380 null, 381 SystemAction.get(DeleteAction.class), 382 null, 383 utv.moveUpAction, 384 utv.moveDownAction, 385 utv.moveLeftAction, 386 utv.moveRightAction, 387 null, 388 SystemAction.get(FilterAction.class), 389 SystemAction.get(RemoveFilterAction.class), 390 null, 391 utv.purgeTasksAction, 392 utv.clearCompletedAction, 393 SystemAction.get(ScheduleAction.class), 394 null, 395 SystemAction.get(ExpandAllUserTasksAction.class), 396 SystemAction.get(CollapseAllAction.class), 397 null, 398 SystemAction.get(ImportAction.class), 399 SystemAction.get(ExportAction.class), 400 401 null, 403 utv.propertiesAction 404 }; 405 } 406 407 protected Serializable writeReplaceNode(Object node) { 408 return ((UserTaskTreeTableNode) node).getUserTask().getUID(); 409 } 410 411 protected Object readResolveNode(Object parent, Object node) { 412 AdvancedTreeTableNode p = (AdvancedTreeTableNode) parent; 413 String uid = (String ) node; 414 415 for (int i = 0; i < p.getChildCount(); i++) { 416 UserTaskTreeTableNode ch = 417 (UserTaskTreeTableNode) p.getChildAt(i); 418 UserTask ut = ch.getUserTask(); 419 if (uid.equals(ut.getUID())) 420 return ch; 421 } 422 423 return null; 424 } 425 426 public String getToolTipText(java.awt.event.MouseEvent event) { 427 Point point = event.getPoint(); 428 int row = rowAtPoint(point); 429 430 String result = null; 431 if (row >= 0) { 432 Object node = getNodeForRow(row); 433 434 if (node instanceof UserTaskTreeTableNode) { 435 result = ((UserTaskTreeTableNode) node).getUserTask().getDetails(); 436 result = UTUtils.prepareForTooltip(result); 437 if (result.length() == 0) 438 result = null; 439 } 440 } 441 return result; 442 } 443 444 445 public void paint(Graphics g) { 446 super.paint(g); 447 } 448 449 } 450 451 452 453 454 | Popular Tags |