Next navigation respects filters and sorting (it uses visualization layer instead of data layer). //FIXME for prev navigation.
1.1 --- a/tasklist.core/src/org/netbeans/modules/tasklist/core/Task.java Wed Jan 14 17:49:24 2004 +0000
1.2 +++ b/tasklist.core/src/org/netbeans/modules/tasklist/core/Task.java Wed Jan 14 18:59:45 2004 +0000
1.3 @@ -64,7 +64,7 @@
1.4 * @author Tor Norbye
1.5 * @author Tim Lebedkov
1.6 */
1.7 -public class Task extends Suggestion implements Cloneable {
1.8 +public class Task extends Suggestion implements Cloneable, Node.Cookie {
1.9 private static final Logger LOGGER = TLUtils.getLogger(Task.class);
1.10
1.11 static {
2.1 --- a/tasklist.core/src/org/netbeans/modules/tasklist/core/TaskListView.java Wed Jan 14 17:49:24 2004 +0000
2.2 +++ b/tasklist.core/src/org/netbeans/modules/tasklist/core/TaskListView.java Wed Jan 14 18:59:45 2004 +0000
2.3 @@ -31,6 +31,7 @@
2.4 import javax.swing.*;
2.5 import javax.swing.table.TableColumn;
2.6 import javax.swing.table.TableColumnModel;
2.7 +import javax.swing.tree.TreeNode;
2.8 import javax.swing.table.TableModel;
2.9
2.10 import org.netbeans.modules.tasklist.core.columns.ColumnsConfiguration;
2.11 @@ -45,12 +46,14 @@
2.12 import org.openide.explorer.ExplorerManager;
2.13 import org.openide.nodes.FilterNode;
2.14 import org.openide.nodes.Node;
2.15 +import org.openide.nodes.Children;
2.16 import org.openide.util.HelpCtx;
2.17 import org.openide.util.Lookup;
2.18 import org.openide.util.NbBundle;
2.19 import org.openide.awt.StatusDisplayer;
2.20 import org.openide.ErrorManager;
2.21 import org.openide.explorer.ExplorerUtils;
2.22 +import org.openide.explorer.view.Visualizer;
2.23 import org.openide.actions.FindAction;
2.24 import org.openide.cookies.InstanceCookie;
2.25 import org.openide.filesystems.FileSystem;
2.26 @@ -1343,21 +1346,72 @@
2.27 /** When true, we've already warned about the need to wrap */
2.28 private boolean wrapWarned = false;
2.29
2.30 + private Node findNextVisitable(TreeNode last) {
2.31 +
2.32 + // find next candidate
2.33 +
2.34 + TreeNode next = null;
2.35 + if (last.getChildCount() > 0) {
2.36 + next = last.getChildAt(0);
2.37 + } else {
2.38 + int index = last.getParent().getIndex(last);
2.39 + assert index != -1;
2.40 + index++;
2.41 + if (index < last.getParent().getChildCount()) {
2.42 + next = last.getParent().getChildAt(index);
2.43 + }
2.44 + }
2.45 +
2.46 + // try wrap around if warned
2.47 +
2.48 + if (next == null && wrapWarned) {
2.49 + TreeNode parent = last;
2.50 + while (parent.getParent() != null) {
2.51 + parent = parent.getParent();
2.52 + }
2.53 + if (parent.getChildCount() > 0) {
2.54 + next = parent.getChildAt(0);
2.55 + }
2.56 + }
2.57 +
2.58 + if (next == null) return null;
2.59 +
2.60 + // assure it's visitable
2.61 +
2.62 + Node nextNode = Visualizer.findNode(next);
2.63 + Task task = (Task) nextNode.getCookie(Task.class);
2.64 + if (task != null && task.isVisitable()) {
2.65 + return nextNode;
2.66 + } else {
2.67 + return findNextVisitable(next);
2.68 + }
2.69 + }
2.70 +
2.71 + /** @return last selected or null */
2.72 + private Node findLastSelected() {
2.73 + Node[] selected = getExplorerManager().getSelectedNodes();
2.74 + Node last;
2.75 + if (selected != null && selected.length != 0) {
2.76 + last = selected[selected.length -1];
2.77 + } else {
2.78 + Node[] all = getExplorerManager().getRootContext().getChildren().getNodes();
2.79 + if (all == null || all.length == 0) {
2.80 + return null;
2.81 + } else {
2.82 + last = all[0];
2.83 + }
2.84 + }
2.85 + return last;
2.86 + }
2.87 +
2.88 /** Show the next task in the view */
2.89 protected final void nextTask() {
2.90 - ObservableList list = getModel();
2.91 - Task curr = getCurrentTask();
2.92 - Task next = null;
2.93 - if (curr == null) {
2.94 - List sgs = list.getRoot().getSubtasks();
2.95 - if (sgs != null) {
2.96 - next = (Task) sgs.get(0);
2.97 - } else {
2.98 - return;
2.99 - }
2.100 - } else {
2.101 - next = TLUtils.findNext(curr, wrapWarned);
2.102 - }
2.103 +
2.104 + Node last = findLastSelected();
2.105 + if (last == null) return;
2.106 +
2.107 + Node next = findNextVisitable(Visualizer.findVisualizer(last));
2.108 +
2.109 String msg = NbBundle.getBundle(TaskListView.class).
2.110 getString("MSG_AtLastError"); // NOI18N
2.111 if ((next == null) && !wrapWarned) {
2.112 @@ -1366,21 +1420,56 @@
2.113 } else {
2.114 wrapWarned = false;
2.115 }
2.116 +
2.117 if (next != null) {
2.118 - if (next.getLine() != null) {
2.119 - TaskAnnotation anno = getAnnotation(next);
2.120 + Task nextTask = (Task) next.getCookie(Task.class);
2.121 + if (nextTask.getLine() != null) {
2.122 + TaskAnnotation anno = getAnnotation(nextTask);
2.123 if (anno != null) {
2.124 - showTask(next, anno);
2.125 + showTask(nextTask, anno);
2.126 }
2.127 }
2.128 - select(next);
2.129 - //StatusDisplayer.getDefault().setStatusText(next.getSummary());
2.130 + select(nextTask); // XXX call EM directly
2.131 }
2.132
2.133 +// ObservableList list = getModel();
2.134 +// Task curr = getCurrentTask();
2.135 +// Task next = null;
2.136 +// if (curr == null) {
2.137 +// List sgs = list.getRoot().getSubtasks();
2.138 +// if (sgs != null) {
2.139 +// next = (Task) sgs.get(0);
2.140 +// } else {
2.141 +// return;
2.142 +// }
2.143 +// } else {
2.144 +// next = TLUtils.findNext(curr, wrapWarned);
2.145 +// }
2.146 +// String msg = NbBundle.getBundle(TaskListView.class).
2.147 +// getString("MSG_AtLastError"); // NOI18N
2.148 +// if ((next == null) && !wrapWarned) {
2.149 +// StatusDisplayer.getDefault().setStatusText(msg);
2.150 +// wrapWarned = true;
2.151 +// } else {
2.152 +// wrapWarned = false;
2.153 +// }
2.154 +// if (next != null) {
2.155 +// if (next.getLine() != null) {
2.156 +// TaskAnnotation anno = getAnnotation(next);
2.157 +// if (anno != null) {
2.158 +// showTask(next, anno);
2.159 +// }
2.160 +// }
2.161 +// select(next);
2.162 +// //StatusDisplayer.getDefault().setStatusText(next.getSummary());
2.163 +// }
2.164 +
2.165 }
2.166
2.167 /** Show the previous task in the view */
2.168 protected final void prevTask() {
2.169 + // FIXME it must work with view instead data model
2.170 + // to detect actual sorting, see above method
2.171 ObservableList list = getModel();
2.172 Task curr = getCurrentTask();
2.173 Task prev = null;
3.1 --- a/tasklist.core/src/org/netbeans/modules/tasklist/core/TaskNode.java Wed Jan 14 17:49:24 2004 +0000
3.2 +++ b/tasklist.core/src/org/netbeans/modules/tasklist/core/TaskNode.java Wed Jan 14 18:59:45 2004 +0000
3.3 @@ -70,7 +70,15 @@
3.4 this.item = item;
3.5 assert item.getList() != null;
3.6 init();
3.7 - }
3.8 + }
3.9 +
3.10 + public Node.Cookie getCookie(Class type) {
3.11 + if (type == Task.class) {
3.12 + return getTask();
3.13 + } else {
3.14 + return super.getCookie(type);
3.15 + }
3.16 + }
3.17
3.18 /**
3.19 * Non-leaf/parent