This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 169987
Collapse All | Expand All

(-)a/spi.tasklist/apichanges.xml (+16 lines)
Lines 72-77 Link Here
72
<!-- ACTUAL CHANGES BEGIN HERE: -->
72
<!-- ACTUAL CHANGES BEGIN HERE: -->
73
73
74
<changes>
74
<changes>
75
    <change id="issue_support" >
76
        <api name="TaskListSPI"/>
77
        <summary>Task List implementation uses Indexing API to cache scanned tasks.</summary>
78
        <version major="1" minor="6"/>
79
        <date day="7" month="8" year="2009"/>
80
        <author login="saubrecht"/>
81
        <compatibility addition="yes"/>
82
        <description>
83
            <p>
84
             Task List API and user interface has been extended to support a generic URL
85
             as the resource the task is associated with. This allows for example
86
             bug tracking issues to be displayed in Task List window.
87
            </p>
88
        </description>
89
        <issue number="169975"/>
90
    </change>
75
    <change id="indexing_api" >
91
    <change id="indexing_api" >
76
        <api name="TaskListSPI"/>
92
        <api name="TaskListSPI"/>
77
        <summary>Task List implementation uses Indexing API to cache scanned tasks.</summary>
93
        <summary>Task List implementation uses Indexing API to cache scanned tasks.</summary>
(-)a/spi.tasklist/nbproject/project.properties (-1 / +1 lines)
Lines 3-6 Link Here
3
javac.source=1.5
3
javac.source=1.5
4
javadoc.arch=${basedir}/arch.xml
4
javadoc.arch=${basedir}/arch.xml
5
javadoc.apichanges=${basedir}/apichanges.xml
5
javadoc.apichanges=${basedir}/apichanges.xml
6
spec.version.base=1.4.0
6
spec.version.base=1.6.0
(-)a/spi.tasklist/src/org/netbeans/spi/tasklist/PushTaskScanner.java (+8 lines)
Lines 142-147 Link Here
142
        public void setTasks( FileObject file, List<? extends Task> tasks ) {
142
        public void setTasks( FileObject file, List<? extends Task> tasks ) {
143
            tm.setTasks( scanner, file, tasks );
143
            tm.setTasks( scanner, file, tasks );
144
        }
144
        }
145
146
        /**
147
         * Add/remove Tasks that aren't associated with a particular resource.
148
         * @param tasks Tasks associated with this TaskScanner or an empty list to remove previously provided Tasks.
149
         */
150
        public void setTasks( List<? extends Task> tasks ) {
151
            tm.setTasks( scanner, tasks );
152
        }
145
        
153
        
146
        /**
154
        /**
147
         * Remove from the Task List window all Tasks that were provided by this scanner.
155
         * Remove from the Task List window all Tasks that were provided by this scanner.
(-)a/spi.tasklist/src/org/netbeans/spi/tasklist/Task.java (-22 / +84 lines)
Lines 42-53 Link Here
42
package org.netbeans.spi.tasklist;
42
package org.netbeans.spi.tasklist;
43
43
44
import java.awt.event.ActionListener;
44
import java.awt.event.ActionListener;
45
import java.net.URL;
45
import java.util.HashSet;
46
import java.util.HashSet;
46
import java.util.Map;
47
import java.util.Map;
47
import java.util.Set;
48
import java.util.Set;
48
import org.netbeans.modules.tasklist.trampoline.TaskGroupFactory;
49
import org.netbeans.modules.tasklist.trampoline.TaskGroupFactory;
49
import java.util.logging.Level;
50
import java.util.logging.Level;
50
import java.util.logging.Logger;
51
import java.util.logging.Logger;
52
import javax.swing.Action;
51
import org.netbeans.modules.tasklist.trampoline.Accessor;
53
import org.netbeans.modules.tasklist.trampoline.Accessor;
52
import org.netbeans.modules.tasklist.trampoline.TaskGroup;
54
import org.netbeans.modules.tasklist.trampoline.TaskGroup;
53
import org.openide.filesystems.FileObject;
55
import org.openide.filesystems.FileObject;
Lines 60-75 Link Here
60
 */
62
 */
61
public final class Task {
63
public final class Task {
62
    
64
    
63
    private FileObject resource;
65
    private final URL url;
64
    private TaskGroup group;
66
    private final FileObject file;
65
    private String description;
67
    private final TaskGroup group;
66
    private int line;
68
    private final String description;
67
    private ActionListener al;
69
    private final int line;
70
    private final ActionListener defaultAction;
71
    private final Action[] actions;
68
    
72
    
69
    static {
73
    static {
70
        Accessor.DEFAULT = new AccessorImpl();
74
        Accessor.DEFAULT = new AccessorImpl();
71
    }
75
    }
72
    
76
    
77
78
    /**
79
     * Create a new Task
80
     *
81
     * @param resource Resource which the Task applies to, cannot be null.
82
     * @param groupName Name of the group this task belongs to (error, warning, todo, etc).
83
     * @param description A brief summary of the task (one line if possible), cannot be null.
84
     *
85
     * @return New task.
86
     * @since 1.6
87
     */
88
    public static Task create( URL resource, String groupName, String description ) {
89
        return new Task( null, resource, getTaskGroup( groupName ), description, -1, null, null );
90
    }
91
92
    /**
93
     * Create a new Task
94
     * <p>Since version 1.4 the Task List implementation uses Indexing API to persist
95
     * tasks created by FileTaskScanners. If a file hasn't changed since the last scan
96
     * then the tasks associated with that file are loaded from cache to improve
97
     * Task List performance. Therefore task's ActionListener and popup Actions
98
     * aren't available when the task is restored from cache. Task providers must
99
     * switch to PushTaskScanner if ActionListener and popup actions are required
100
     * to be available at all times.</p>
101
     *
102
     * @param resource Resource which the Task applies to, cannot be null.
103
     * @param groupName Name of the group this task belongs to (error, warning, todo, etc).
104
     * @param description A brief summary of the task (one line if possible), cannot be null.
105
     * @param defaultAction Task's default action, e.g. double-click or Enter key in the Task List window.
106
     * @param popupActions Actions to show in task's popup menu.
107
     *
108
     * @return New task.
109
     * @since 1.6
110
     */
111
    public static Task create( URL resource, String groupName, String description, ActionListener defaultAction, Action[] popupActions ) {
112
        return new Task( null, resource, getTaskGroup( groupName ), description, -1, defaultAction, popupActions );
113
    }
114
73
    /**
115
    /**
74
     * Create a new Task
116
     * Create a new Task
75
     * 
117
     * 
Lines 81-87 Link Here
81
     * @return New task.
123
     * @return New task.
82
     */
124
     */
83
    public static Task create( FileObject resource, String groupName, String description, int line ) {
125
    public static Task create( FileObject resource, String groupName, String description, int line ) {
84
        return new Task( resource, getTaskGroup( groupName ), description, line, null );
126
        assert null != resource;
127
        return new Task(resource, null, getTaskGroup(groupName), description, line, null, null);
85
    }
128
    }
86
    
129
    
87
    /**
130
    /**
Lines 101-128 Link Here
101
     * @return New task.
144
     * @return New task.
102
     */
145
     */
103
    public static Task create( FileObject resource, String groupName, String description, ActionListener al ) {
146
    public static Task create( FileObject resource, String groupName, String description, ActionListener al ) {
104
        return new Task( resource, getTaskGroup( groupName ), description, -1, al );
147
        assert null != resource;
148
        return new Task(resource, null, getTaskGroup(groupName), description, -1, al, null);
105
    }
149
    }
106
    
150
    
107
    /** Creates a new instance of Task */
151
    /** Creates a new instance of Task */
108
    private Task( FileObject resource, TaskGroup group, String description, int line, ActionListener al ) {
152
    private Task( FileObject file, URL url, TaskGroup group, String description, int line, ActionListener defaultAction, Action[] actions ) {
109
        assert null != group;
153
        assert null != group;
110
        assert null != description;
154
        assert null != description;
111
        assert null != resource;
155
        assert null == file || null == url;
112
        
156
        
113
        this.resource = resource;
157
        this.file = file;
158
        this.url = url;
114
        this.group = group;
159
        this.group = group;
115
        this.description = description;
160
        this.description = description;
116
        this.line = line;
161
        this.line = line;
117
        this.al = al;
162
        this.defaultAction = defaultAction;
163
        this.actions = actions;
118
    }
164
    }
119
    
165
120
    /**
166
    /**
121
     * Resource (file or folder) this taks applies to.
167
     * Resource this taks applies to.
122
     * @return Resource (file or folder) this taks applies to.
168
     * @return Resource this taks applies to.
123
     */
169
     */
124
    FileObject getResource() {
170
    URL getURL() {
125
        return resource;
171
        return url;
172
    }
173
174
    /**
175
     * Resource this taks applies to.
176
     * @return Resource this taks applies to.
177
     */
178
    FileObject getFile() {
179
        return file;
126
    }
180
    }
127
    
181
    
128
    /**
182
    /**
Lines 153-160 Link Here
153
     * Action to be invoked when user double-clicks the task in the Task List window.
207
     * Action to be invoked when user double-clicks the task in the Task List window.
154
     * @return Task's default action or null if not available.
208
     * @return Task's default action or null if not available.
155
     */
209
     */
156
    ActionListener getActionListener() {
210
    ActionListener getDefaultAction() {
157
        return al;
211
        return defaultAction;
212
    }
213
214
    Action[] getActions() {
215
        return actions;
158
    }
216
    }
159
    
217
    
160
    /**
218
    /**
Lines 199-206 Link Here
199
        if (this.group != test.group && this.group != null &&
257
        if (this.group != test.group && this.group != null &&
200
            !this.group.equals(test.group))
258
            !this.group.equals(test.group))
201
            return false;
259
            return false;
202
        if (this.resource != test.resource && this.resource != null &&
260
        if (this.url != test.url && this.url != null &&
203
            !this.resource.equals(test.resource))
261
            !this.url.equals(test.url))
262
            return false;
263
        if (this.file != test.file && this.file != null &&
264
            !this.url.equals(test.file))
204
            return false;
265
            return false;
205
        return true;
266
        return true;
206
    }
267
    }
Lines 212-218 Link Here
212
        hash = 17 * hash + this.line;
273
        hash = 17 * hash + this.line;
213
        hash = 17 * hash + (this.description != null ? this.description.hashCode() : 0);
274
        hash = 17 * hash + (this.description != null ? this.description.hashCode() : 0);
214
        hash = 17 * hash + (this.group != null ? this.group.hashCode() : 0);
275
        hash = 17 * hash + (this.group != null ? this.group.hashCode() : 0);
215
        hash = 17 * hash + (this.resource != null ? this.resource.hashCode() : 0);
276
        hash = 17 * hash + (this.file != null ? this.file.hashCode() : 0);
277
        hash = 17 * hash + (this.url != null ? this.url.hashCode() : 0);
216
        return hash;
278
        return hash;
217
    }
279
    }
218
    
280
    
Lines 220-226 Link Here
220
    public String toString() {
282
    public String toString() {
221
        StringBuffer buffer = new StringBuffer();
283
        StringBuffer buffer = new StringBuffer();
222
        buffer.append( "[" ); 
284
        buffer.append( "[" ); 
223
        buffer.append( getResource() );
285
        buffer.append( null == url ? getFile() : getURL() );
224
        buffer.append( ", " ); 
286
        buffer.append( ", " ); 
225
        buffer.append( getLine() );
287
        buffer.append( getLine() );
226
        buffer.append( ", " ); 
288
        buffer.append( ", " ); 
(-)a/spi.tasklist/test/unit/src/org/netbeans/spi/tasklist/TaskTest.java (-14 / +59 lines)
Lines 43-52 Link Here
43
43
44
import java.awt.event.ActionEvent;
44
import java.awt.event.ActionEvent;
45
import java.awt.event.ActionListener;
45
import java.awt.event.ActionListener;
46
import java.net.URL;
47
import javax.swing.Action;
46
import junit.framework.*;
48
import junit.framework.*;
47
import org.netbeans.junit.*;
49
import org.netbeans.junit.*;
48
import org.netbeans.modules.tasklist.trampoline.TaskGroupFactory;
50
import org.netbeans.modules.tasklist.trampoline.TaskGroupFactory;
49
import org.openide.filesystems.FileObject;
51
import org.openide.filesystems.FileObject;
52
import org.openide.filesystems.FileStateInvalidException;
50
import org.openide.filesystems.FileUtil;
53
import org.openide.filesystems.FileUtil;
51
54
52
55
Lines 92-98 Link Here
92
        return suite;
95
        return suite;
93
    }
96
    }
94
97
95
    public void testGetters() {
98
    public void testGetters() throws FileStateInvalidException {
96
        String description = "task description";
99
        String description = "task description";
97
        int lineNo = 123;
100
        int lineNo = 123;
98
        FileObject resource = FileUtil.getConfigRoot();
101
        FileObject resource = FileUtil.getConfigRoot();
Lines 101-109 Link Here
101
        
104
        
102
        assertEquals( description, t.getDescription() );
105
        assertEquals( description, t.getDescription() );
103
        assertEquals( lineNo, t.getLine() );
106
        assertEquals( lineNo, t.getLine() );
104
        assertEquals( resource, t.getResource() );
107
        assertEquals( resource, t.getFile() );
108
        assertNull( t.getURL() );
109
        assertNull( t.getActions() );
105
        assertEquals( TaskGroupFactory.getDefault().getGroup( TASK_GROUP_NAME), t.getGroup() );
110
        assertEquals( TaskGroupFactory.getDefault().getGroup( TASK_GROUP_NAME), t.getGroup() );
106
        assertNull( t.getActionListener() );
111
        assertNull( t.getDefaultAction() );
107
        
112
        
108
        ActionListener al = new ActionListener() {
113
        ActionListener al = new ActionListener() {
109
            public void actionPerformed(ActionEvent arg0) {
114
            public void actionPerformed(ActionEvent arg0) {
Lines 115-132 Link Here
115
        
120
        
116
        assertEquals( description, t.getDescription() );
121
        assertEquals( description, t.getDescription() );
117
        assertEquals( -1, t.getLine() );
122
        assertEquals( -1, t.getLine() );
118
        assertEquals( resource, t.getResource() );
123
        assertEquals( resource, t.getFile() );
124
        assertNull( t.getURL() );
125
        assertNull( t.getActions() );
119
        assertEquals( TaskGroupFactory.getDefault().getGroup( TASK_GROUP_NAME), t.getGroup() );
126
        assertEquals( TaskGroupFactory.getDefault().getGroup( TASK_GROUP_NAME), t.getGroup() );
120
        assertEquals( al, t.getActionListener() );
127
        assertEquals( al, t.getDefaultAction() );
128
129
        URL url = resource.getURL();
130
131
        t = Task.create(url, TASK_GROUP_NAME, description );
132
133
        assertEquals( description, t.getDescription() );
134
        assertEquals( -1, t.getLine() );
135
        assertEquals( url, t.getURL() );
136
        assertNull( t.getFile() );
137
        assertNull( t.getActions() );
138
        assertEquals( TaskGroupFactory.getDefault().getGroup( TASK_GROUP_NAME), t.getGroup() );
139
        assertNull( t.getDefaultAction() );
140
141
        Action[] actions = new Action[1];
142
        t = Task.create(url, TASK_GROUP_NAME, description, al, actions );
143
144
        assertEquals( description, t.getDescription() );
145
        assertEquals( -1, t.getLine() );
146
        assertEquals( url, t.getURL() );
147
        assertNull( t.getFile() );
148
        assertEquals( TaskGroupFactory.getDefault().getGroup( TASK_GROUP_NAME), t.getGroup() );
149
        assertEquals( al, t.getDefaultAction() );
150
        assertSame( actions, t.getActions() );
121
    }
151
    }
122
152
123
    public void testNullValues() {
153
    public void testNullValues() {
124
        String description = "task description";
154
        String description = "task description";
125
        int lineNo = 123;
155
        int lineNo = 123;
126
        FileObject resource = FileUtil.getConfigRoot();
156
        FileObject resource = FileUtil.getConfigRoot();
127
        
157
128
        try {
158
        try {
129
            Task.create(null, TASK_GROUP_NAME, description, lineNo );
159
            Task.create((FileObject)null, TASK_GROUP_NAME, description, lineNo );
160
            fail( "resource cannot be null" );
161
        } catch( AssertionError e ) {
162
            //that's what we want
163
        }
164
165
        try {
166
            Task.create((URL)null, TASK_GROUP_NAME, description );
130
            fail( "resource cannot be null" );
167
            fail( "resource cannot be null" );
131
        } catch( AssertionError e ) {
168
        } catch( AssertionError e ) {
132
            //that's what we want
169
            //that's what we want
Lines 147-153 Link Here
147
        }
184
        }
148
    }
185
    }
149
186
150
    public void testNegativeLineNumberAllowed() {
187
    public void testNegativeLineNumberAllowed() throws FileStateInvalidException {
151
        String description = "task description";
188
        String description = "task description";
152
        int lineNo = -1;
189
        int lineNo = -1;
153
        FileObject resource = FileUtil.getConfigRoot();
190
        FileObject resource = FileUtil.getConfigRoot();
Lines 156-166 Link Here
156
        
193
        
157
        assertEquals( description, t.getDescription() );
194
        assertEquals( description, t.getDescription() );
158
        assertEquals( lineNo, t.getLine() );
195
        assertEquals( lineNo, t.getLine() );
159
        assertEquals( resource, t.getResource() );
196
        assertEquals( resource, t.getFile() );
160
        assertEquals( TaskGroupFactory.getDefault().getGroup( TASK_GROUP_NAME), t.getGroup() );
197
        assertEquals( TaskGroupFactory.getDefault().getGroup( TASK_GROUP_NAME), t.getGroup() );
161
    }
198
    }
162
199
163
    public void testUnknownTaskGroup() {
200
    public void testUnknownTaskGroup() throws FileStateInvalidException {
164
        String description = "task description";
201
        String description = "task description";
165
        int lineNo = 123;
202
        int lineNo = 123;
166
        FileObject resource = FileUtil.getConfigRoot();
203
        FileObject resource = FileUtil.getConfigRoot();
Lines 169-186 Link Here
169
        
206
        
170
        assertEquals( description, t.getDescription() );
207
        assertEquals( description, t.getDescription() );
171
        assertEquals( lineNo, t.getLine() );
208
        assertEquals( lineNo, t.getLine() );
172
        assertEquals( resource, t.getResource() );
209
        assertEquals( resource, t.getFile() );
173
        assertEquals( TaskGroupFactory.getDefault().getDefaultGroup(), t.getGroup() );
210
        assertEquals( TaskGroupFactory.getDefault().getDefaultGroup(), t.getGroup() );
174
    }
211
    }
175
212
176
    public void testEquals() {
213
    public void testEquals() throws FileStateInvalidException {
177
        String description = "task description";
214
        String description = "task description";
178
        int lineNo = 123;
215
        int lineNo = 123;
179
        FileObject resource = FileUtil.getConfigRoot();
216
        FileObject resource = FileUtil.getConfigRoot();
180
        
217
181
        Task t1 = Task.create(resource, TASK_GROUP_NAME, description, lineNo );
218
        Task t1 = Task.create(resource, TASK_GROUP_NAME, description, lineNo );
182
        Task t2 = Task.create(resource, TASK_GROUP_NAME, description, lineNo );
219
        Task t2 = Task.create(resource, TASK_GROUP_NAME, description, lineNo );
183
        
220
221
        assertEquals( t1, t2 );
222
        assertEquals( t1.hashCode(), t2.hashCode() );
223
224
        URL url = FileUtil.getConfigRoot().getURL();
225
226
        t1 = Task.create(url, TASK_GROUP_NAME, description );
227
        t2 = Task.create(url, TASK_GROUP_NAME, description );
228
184
        assertEquals( t1, t2 );
229
        assertEquals( t1, t2 );
185
        assertEquals( t1.hashCode(), t2.hashCode() );
230
        assertEquals( t1.hashCode(), t2.hashCode() );
186
    }
231
    }

Return to bug 169987