|
What this is
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-2000 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.tasklist.suggestions; import java.awt.Image; import org.openide.util.Utilities; import org.netbeans.modules.tasklist.core.Task; import org.netbeans.modules.tasklist.client.SuggestionPerformer; import org.netbeans.modules.tasklist.client.SuggestionPriority; import org.openide.loaders.DataObject; import org.openide.nodes.Node; import org.openide.text.Line; import org.openide.text.DataEditorSupport; // XXX todo: fire property change whenever anything changes in the node... /** Class which represents a task in the * tasklist. * @author Tor Norbye */ public class SuggestionImpl extends Task implements Node.Cookie { private Object seed = null; private SuggestionType stype = null; protected SuggestionImpl() { } public SuggestionImpl(String summary, SuggestionType stype, SuggestionPerformer action, Object data) { super(summary, null); this.seed = data; this.stype = stype; setAction(action); if (stype != null) { setType(stype.getName()); } } /** Return the name of the file associated with this * task, or the empty string if none. * @return basename, or empty string */ public String getFileBaseName() { Line l = getLine(); if (l != null) { DataObject dobj = (DataObject) l.getLookup().lookup(DataObject.class);; if (dobj != null) { return dobj.getPrimaryFile().getNameExt(); } } return ""; } /** Return line number associated with the task. * @return Line number, or "0" if no particular line is * associated. Will always be 0 if there is no * associated file. */ public int getLineNumber() { Line l = getLine(); if (l == null) { return 0; } else { return l.getLineNumber()+1; } } /** * Class used to represent location with correctly defined order * and to string. */ public static class Location implements Comparable { public String filename; public int line; public Location(String filename, int line) { this.filename = filename; this.line = line; } public int compareTo(Object o) { Location rhs = (Location)o; int c1 = this.filename.compareTo(rhs.filename); if (c1 != 0) return c1; else return (this.line < rhs.line)? -1 : ((this.line == rhs.line)?0:1); } public String toString() { return filename + ":" + line; } } /** @return path/file:line location or null. */ public Location getLocation() { Line l = getLine(); if (l != null) { DataObject dobj = (DataObject) l.getLookup().lookup(DataObject.class);; if (dobj != null) { return new Location(dobj.getPrimaryFile().getPath(),l.getLineNumber()); } } return null; } /** Generate a string summary of the task; only used * for debugging. DO NOT depend on this format for anything! * Use generate() instead. * @return summary string */ public String toString() { return "SuggestionImpl#" + System.identityHashCode(this) + /*(" + super.toString() + ")" */ "[\"" + getSummary() + "\", " + getFileBaseName() + ":" + getLineNumber() + /* ", " + stype + */ "]"; // NOI18N } /** Create a node for this item */ public Node [] createNode() { if (hasSubtasks()) { return new Node[] {new SuggestionNode(this, new SuggestionChildren(this))}; } else { return new Node[] {new SuggestionNode(this)}; } } /** Create an identical copy of a task (a deep copy, e.g. the list of subtasks will be cloned as well */ protected Object clone() { SuggestionImpl t = new SuggestionImpl(); t.copyFrom(this); return t; } /** Copy all the fields in the given task into this object. Should only be called on an object of the EXACT same type. Thus, if you're implementing a subclass of Task, say UserTask, you can implement copy assuming that the passed in Task parameter is of type UserTask. When overriding, remember to call super.copyFrom. |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
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.