alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.tasklist.usertasks;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import org.netbeans.modules.tasklist.client.SuggestionAgent;
import org.netbeans.modules.tasklist.client.SuggestionManager;
import org.netbeans.modules.tasklist.providers.SuggestionProvider;
import org.openide.util.NbBundle;


/**
 * This class lists the tasks due today and tomorrow in the
 * suggestions window
 * 

* @todo Make it work for the case where the suggestions window * is left up for hours - in that case you may have to "update" * the view as tasks move into the due date range. * * @author Tor Norbye */ public class DueTasksProvider extends SuggestionProvider { final private static String TYPE = "nb-usertasks-due"; // NOI18N /** * Return the typenames of the suggestions that this provider * will create. * @return An array of string names. Should never be null. Most * providers will create Suggestions of a single type, so it will * be an array with one element. */ public String getType() { return TYPE; } public void notifyRun() { SuggestionManager manager = SuggestionManager.getDefault(); if (!manager.isEnabled(TYPE)) { return; } // Look up suggestions, register them UserTaskList list = UserTaskList.getDefault(); Iterator it = list.getTasks().iterator(); Date now = new Date(); while (it.hasNext()) { UserTask task = (UserTask)it.next(); if (task.isDue(now)) { String summary = task.getSummary(); // Rewrite the summary to include Due? if (task.getDueTime() < now.getTime()) { summary = NbBundle.getMessage(DueTasksProvider.class, "PastDueSummary", // NOI18N summary); } else { summary = NbBundle.getMessage(DueTasksProvider.class, "DueSummary", // NOI18N summary); } SuggestionAgent s = manager.createSuggestion(TYPE, summary, null, this); task.setSuggestion(s.getSuggestion()); s.setLine(task.getLine()); s.setDetails(task.getDetails()); s.setPriority(task.getPriority()); // XXX or bump to P1 ??? if (showingTasks == null) { showingTasks = new ArrayList(10); } showingTasks.add(s.getSuggestion()); } } if ((showingTasks != null) && (showingTasks.size() > 0)) { manager.register(TYPE, showingTasks, null); } } public void notifyStop() { // Unregister our suggestions if (showingTasks != null) { SuggestionManager manager = SuggestionManager.getDefault(); manager.register(TYPE, null, showingTasks); showingTasks = null; } } /** List of tasks currently registered */ private List showingTasks = null; }

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.