diff -r e0e61c2b312a spi.tasklist/apichanges.xml --- a/spi.tasklist/apichanges.xml Tue Mar 31 09:42:07 2009 +0200 +++ b/spi.tasklist/apichanges.xml Thu Aug 06 15:47:05 2009 +0200 @@ -72,6 +72,22 @@ + + + Task List implementation uses Indexing API to cache scanned tasks. + + + + + +

+ Task List API and user interface has been extended to support a generic URL + as the resource the task is associated with. This allows for example + bug tracking issues to be displayed in Task List window. +

+
+ +
Task List implementation uses Indexing API to cache scanned tasks. diff -r e0e61c2b312a spi.tasklist/nbproject/project.properties --- a/spi.tasklist/nbproject/project.properties Tue Mar 31 09:42:07 2009 +0200 +++ b/spi.tasklist/nbproject/project.properties Thu Aug 06 15:47:05 2009 +0200 @@ -3,4 +3,4 @@ javac.source=1.5 javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml -spec.version.base=1.4.0 +spec.version.base=1.6.0 diff -r e0e61c2b312a spi.tasklist/src/org/netbeans/spi/tasklist/PushTaskScanner.java --- a/spi.tasklist/src/org/netbeans/spi/tasklist/PushTaskScanner.java Tue Mar 31 09:42:07 2009 +0200 +++ b/spi.tasklist/src/org/netbeans/spi/tasklist/PushTaskScanner.java Thu Aug 06 15:47:05 2009 +0200 @@ -142,6 +142,14 @@ public void setTasks( FileObject file, List tasks ) { tm.setTasks( scanner, file, tasks ); } + + /** + * Add/remove Tasks that aren't associated with a particular resource. + * @param tasks Tasks associated with this TaskScanner or an empty list to remove previously provided Tasks. + */ + public void setTasks( List tasks ) { + tm.setTasks( scanner, tasks ); + } /** * Remove from the Task List window all Tasks that were provided by this scanner. diff -r e0e61c2b312a spi.tasklist/src/org/netbeans/spi/tasklist/Task.java --- a/spi.tasklist/src/org/netbeans/spi/tasklist/Task.java Tue Mar 31 09:42:07 2009 +0200 +++ b/spi.tasklist/src/org/netbeans/spi/tasklist/Task.java Thu Aug 06 15:47:05 2009 +0200 @@ -42,12 +42,14 @@ package org.netbeans.spi.tasklist; import java.awt.event.ActionListener; +import java.net.URL; import java.util.HashSet; import java.util.Map; import java.util.Set; import org.netbeans.modules.tasklist.trampoline.TaskGroupFactory; import java.util.logging.Level; import java.util.logging.Logger; +import javax.swing.Action; import org.netbeans.modules.tasklist.trampoline.Accessor; import org.netbeans.modules.tasklist.trampoline.TaskGroup; import org.openide.filesystems.FileObject; @@ -60,16 +62,56 @@ */ public final class Task { - private FileObject resource; - private TaskGroup group; - private String description; - private int line; - private ActionListener al; + private final URL url; + private final FileObject file; + private final TaskGroup group; + private final String description; + private final int line; + private final ActionListener defaultAction; + private final Action[] actions; static { Accessor.DEFAULT = new AccessorImpl(); } + + /** + * Create a new Task + * + * @param resource Resource which the Task applies to, cannot be null. + * @param groupName Name of the group this task belongs to (error, warning, todo, etc). + * @param description A brief summary of the task (one line if possible), cannot be null. + * + * @return New task. + * @since 1.6 + */ + public static Task create( URL resource, String groupName, String description ) { + return new Task( null, resource, getTaskGroup( groupName ), description, -1, null, null ); + } + + /** + * Create a new Task + *

Since version 1.4 the Task List implementation uses Indexing API to persist + * tasks created by FileTaskScanners. If a file hasn't changed since the last scan + * then the tasks associated with that file are loaded from cache to improve + * Task List performance. Therefore task's ActionListener and popup Actions + * aren't available when the task is restored from cache. Task providers must + * switch to PushTaskScanner if ActionListener and popup actions are required + * to be available at all times.

+ * + * @param resource Resource which the Task applies to, cannot be null. + * @param groupName Name of the group this task belongs to (error, warning, todo, etc). + * @param description A brief summary of the task (one line if possible), cannot be null. + * @param defaultAction Task's default action, e.g. double-click or Enter key in the Task List window. + * @param popupActions Actions to show in task's popup menu. + * + * @return New task. + * @since 1.6 + */ + public static Task create( URL resource, String groupName, String description, ActionListener defaultAction, Action[] popupActions ) { + return new Task( null, resource, getTaskGroup( groupName ), description, -1, defaultAction, popupActions ); + } + /** * Create a new Task * @@ -81,7 +123,8 @@ * @return New task. */ public static Task create( FileObject resource, String groupName, String description, int line ) { - return new Task( resource, getTaskGroup( groupName ), description, line, null ); + assert null != resource; + return new Task(resource, null, getTaskGroup(groupName), description, line, null, null); } /** @@ -101,28 +144,39 @@ * @return New task. */ public static Task create( FileObject resource, String groupName, String description, ActionListener al ) { - return new Task( resource, getTaskGroup( groupName ), description, -1, al ); + assert null != resource; + return new Task(resource, null, getTaskGroup(groupName), description, -1, al, null); } /** Creates a new instance of Task */ - private Task( FileObject resource, TaskGroup group, String description, int line, ActionListener al ) { + private Task( FileObject file, URL url, TaskGroup group, String description, int line, ActionListener defaultAction, Action[] actions ) { assert null != group; assert null != description; - assert null != resource; + assert null == file || null == url; - this.resource = resource; + this.file = file; + this.url = url; this.group = group; this.description = description; this.line = line; - this.al = al; + this.defaultAction = defaultAction; + this.actions = actions; } - + /** - * Resource (file or folder) this taks applies to. - * @return Resource (file or folder) this taks applies to. + * Resource this taks applies to. + * @return Resource this taks applies to. */ - FileObject getResource() { - return resource; + URL getURL() { + return url; + } + + /** + * Resource this taks applies to. + * @return Resource this taks applies to. + */ + FileObject getFile() { + return file; } /** @@ -153,8 +207,12 @@ * Action to be invoked when user double-clicks the task in the Task List window. * @return Task's default action or null if not available. */ - ActionListener getActionListener() { - return al; + ActionListener getDefaultAction() { + return defaultAction; + } + + Action[] getActions() { + return actions; } /** @@ -199,8 +257,11 @@ if (this.group != test.group && this.group != null && !this.group.equals(test.group)) return false; - if (this.resource != test.resource && this.resource != null && - !this.resource.equals(test.resource)) + if (this.url != test.url && this.url != null && + !this.url.equals(test.url)) + return false; + if (this.file != test.file && this.file != null && + !this.url.equals(test.file)) return false; return true; } @@ -212,7 +273,8 @@ hash = 17 * hash + this.line; hash = 17 * hash + (this.description != null ? this.description.hashCode() : 0); hash = 17 * hash + (this.group != null ? this.group.hashCode() : 0); - hash = 17 * hash + (this.resource != null ? this.resource.hashCode() : 0); + hash = 17 * hash + (this.file != null ? this.file.hashCode() : 0); + hash = 17 * hash + (this.url != null ? this.url.hashCode() : 0); return hash; } @@ -220,7 +282,7 @@ public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append( "[" ); - buffer.append( getResource() ); + buffer.append( null == url ? getFile() : getURL() ); buffer.append( ", " ); buffer.append( getLine() ); buffer.append( ", " ); diff -r e0e61c2b312a spi.tasklist/test/unit/src/org/netbeans/spi/tasklist/TaskTest.java --- a/spi.tasklist/test/unit/src/org/netbeans/spi/tasklist/TaskTest.java Tue Mar 31 09:42:07 2009 +0200 +++ b/spi.tasklist/test/unit/src/org/netbeans/spi/tasklist/TaskTest.java Thu Aug 06 15:47:05 2009 +0200 @@ -43,10 +43,13 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.net.URL; +import javax.swing.Action; import junit.framework.*; import org.netbeans.junit.*; import org.netbeans.modules.tasklist.trampoline.TaskGroupFactory; import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileStateInvalidException; import org.openide.filesystems.FileUtil; @@ -92,7 +95,7 @@ return suite; } - public void testGetters() { + public void testGetters() throws FileStateInvalidException { String description = "task description"; int lineNo = 123; FileObject resource = FileUtil.getConfigRoot(); @@ -101,9 +104,11 @@ assertEquals( description, t.getDescription() ); assertEquals( lineNo, t.getLine() ); - assertEquals( resource, t.getResource() ); + assertEquals( resource, t.getFile() ); + assertNull( t.getURL() ); + assertNull( t.getActions() ); assertEquals( TaskGroupFactory.getDefault().getGroup( TASK_GROUP_NAME), t.getGroup() ); - assertNull( t.getActionListener() ); + assertNull( t.getDefaultAction() ); ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent arg0) { @@ -115,18 +120,50 @@ assertEquals( description, t.getDescription() ); assertEquals( -1, t.getLine() ); - assertEquals( resource, t.getResource() ); + assertEquals( resource, t.getFile() ); + assertNull( t.getURL() ); + assertNull( t.getActions() ); assertEquals( TaskGroupFactory.getDefault().getGroup( TASK_GROUP_NAME), t.getGroup() ); - assertEquals( al, t.getActionListener() ); + assertEquals( al, t.getDefaultAction() ); + + URL url = resource.getURL(); + + t = Task.create(url, TASK_GROUP_NAME, description ); + + assertEquals( description, t.getDescription() ); + assertEquals( -1, t.getLine() ); + assertEquals( url, t.getURL() ); + assertNull( t.getFile() ); + assertNull( t.getActions() ); + assertEquals( TaskGroupFactory.getDefault().getGroup( TASK_GROUP_NAME), t.getGroup() ); + assertNull( t.getDefaultAction() ); + + Action[] actions = new Action[1]; + t = Task.create(url, TASK_GROUP_NAME, description, al, actions ); + + assertEquals( description, t.getDescription() ); + assertEquals( -1, t.getLine() ); + assertEquals( url, t.getURL() ); + assertNull( t.getFile() ); + assertEquals( TaskGroupFactory.getDefault().getGroup( TASK_GROUP_NAME), t.getGroup() ); + assertEquals( al, t.getDefaultAction() ); + assertSame( actions, t.getActions() ); } public void testNullValues() { String description = "task description"; int lineNo = 123; FileObject resource = FileUtil.getConfigRoot(); - + try { - Task.create(null, TASK_GROUP_NAME, description, lineNo ); + Task.create((FileObject)null, TASK_GROUP_NAME, description, lineNo ); + fail( "resource cannot be null" ); + } catch( AssertionError e ) { + //that's what we want + } + + try { + Task.create((URL)null, TASK_GROUP_NAME, description ); fail( "resource cannot be null" ); } catch( AssertionError e ) { //that's what we want @@ -147,7 +184,7 @@ } } - public void testNegativeLineNumberAllowed() { + public void testNegativeLineNumberAllowed() throws FileStateInvalidException { String description = "task description"; int lineNo = -1; FileObject resource = FileUtil.getConfigRoot(); @@ -156,11 +193,11 @@ assertEquals( description, t.getDescription() ); assertEquals( lineNo, t.getLine() ); - assertEquals( resource, t.getResource() ); + assertEquals( resource, t.getFile() ); assertEquals( TaskGroupFactory.getDefault().getGroup( TASK_GROUP_NAME), t.getGroup() ); } - public void testUnknownTaskGroup() { + public void testUnknownTaskGroup() throws FileStateInvalidException { String description = "task description"; int lineNo = 123; FileObject resource = FileUtil.getConfigRoot(); @@ -169,18 +206,26 @@ assertEquals( description, t.getDescription() ); assertEquals( lineNo, t.getLine() ); - assertEquals( resource, t.getResource() ); + assertEquals( resource, t.getFile() ); assertEquals( TaskGroupFactory.getDefault().getDefaultGroup(), t.getGroup() ); } - public void testEquals() { + public void testEquals() throws FileStateInvalidException { String description = "task description"; int lineNo = 123; FileObject resource = FileUtil.getConfigRoot(); - + Task t1 = Task.create(resource, TASK_GROUP_NAME, description, lineNo ); Task t2 = Task.create(resource, TASK_GROUP_NAME, description, lineNo ); - + + assertEquals( t1, t2 ); + assertEquals( t1.hashCode(), t2.hashCode() ); + + URL url = FileUtil.getConfigRoot().getURL(); + + t1 = Task.create(url, TASK_GROUP_NAME, description ); + t2 = Task.create(url, TASK_GROUP_NAME, description ); + assertEquals( t1, t2 ); assertEquals( t1.hashCode(), t2.hashCode() ); }