Index: ant/manifest.mf =================================================================== RCS file: /cvs/ant/manifest.mf,v retrieving revision 1.43 diff -u -r1.43 manifest.mf --- ant/manifest.mf 11 Apr 2002 16:27:45 -0000 1.43 +++ ant/manifest.mf 29 May 2002 18:20:30 -0000 @@ -1,7 +1,7 @@ Manifest-Version: 1.0 OpenIDE-Module: org.apache.tools.ant.module/2 OpenIDE-Module-Localizing-Bundle: org/apache/tools/ant/module/Bundle.properties -OpenIDE-Module-Specification-Version: 2.9 +OpenIDE-Module-Specification-Version: 2.10 OpenIDE-Module-Implementation-Version: @BUILD_NUMBER_SUBST@ OpenIDE-Module-Install: org/apache/tools/ant/module/AntModule.class OpenIDE-Module-Layer: org/apache/tools/ant/module/resources/AntModuleLayer.xml Index: ant/src/org/apache/tools/ant/module/api/AntProjectCookie.java =================================================================== RCS file: /cvs/ant/src/org/apache/tools/ant/module/api/AntProjectCookie.java,v retrieving revision 1.1 diff -u -r1.1 AntProjectCookie.java --- ant/src/org/apache/tools/ant/module/api/AntProjectCookie.java 12 Feb 2001 21:00:40 -0000 1.1 +++ ant/src/org/apache/tools/ant/module/api/AntProjectCookie.java 29 May 2002 18:20:30 -0000 @@ -43,7 +43,7 @@ * @return the document, or null if it could not be parsed */ Document getDocument (); - /** Get the DOM root element () for the build script. + /** Get the DOM root element (<project>) for the build script. * @return the root element, or null if it could not be parsed */ Element getProjectElement (); @@ -59,4 +59,29 @@ * @param l the listener to remove */ void removeChangeListener (ChangeListener l); + + /** Extended cookie permitting queries of parse status. + * If only the basic cookie is available, you cannot + * determine if a project is already parsed or not, and + * methods which require it to be parsed for them to return + * may block until a parse is complete. + * @since 2.10 + */ + interface ParseStatus extends AntProjectCookie { + /** Check whether the project is currently parsed. + * Note that "parsed in error" is still considered parsed. + *

If not parsed, then if and when it does later become + * parsed, a change event should be fired. A project + * might become unparsed after being parsed, due to e.g. + * garbage collection; this need not fire any event. + *

If the project is currently parsed, the methods + * {@link AntProjectCookie#getDocument}, + * {@link AntProjectCookie#getProjectElement}, and + * {@link AntProjectCookie#getParseException} should + * not block. + * @return true if this project is currently parsed + */ + boolean isParsed(); + } + } Index: ant/src/org/apache/tools/ant/module/nodes/AntProjectNode.java =================================================================== RCS file: /cvs/ant/src/org/apache/tools/ant/module/nodes/AntProjectNode.java,v retrieving revision 1.24 diff -u -r1.24 AntProjectNode.java --- ant/src/org/apache/tools/ant/module/nodes/AntProjectNode.java 16 May 2002 17:20:30 -0000 1.24 +++ ant/src/org/apache/tools/ant/module/nodes/AntProjectNode.java 29 May 2002 18:20:30 -0000 @@ -41,73 +41,86 @@ import org.apache.tools.ant.module.AntModule; import org.apache.tools.ant.module.AntSettings; -import org.apache.tools.ant.module.api.AntProjectCookie; -import org.apache.tools.ant.module.api.ElementCookie; -import org.apache.tools.ant.module.api.IntrospectedInfo; +import org.apache.tools.ant.module.api.*; import org.apache.tools.ant.module.xml.ElementSupport; import org.apache.tools.ant.module.wizards.properties.*; +import org.openide.util.Utilities; /** A node that represents an Ant project. */ -public class AntProjectNode extends DataNode implements ChangeListener, PropertyChangeListener { - +public class AntProjectNode extends DataNode implements ChangeListener { + public AntProjectNode (DataObject obj) { - super (obj, new AntProjectChildren ((AntProjectCookie) obj.getCookie (AntProjectCookie.class))); - setIconBase ("org/apache/tools/ant/module/resources/AntIcon"); // NOI18N - AntProjectCookie cookie = (AntProjectCookie) getCookie (AntProjectCookie.class); - cookie.addChangeListener (WeakListener.change (this, cookie)); - obj.addPropertyChangeListener (WeakListener.propertyChange (this, obj)); - RequestProcessor.postRequest (new Runnable () { - public void run () { - updateDisplayName (); - updateElementCookie (); - } - }, 500); // don't even think about squeezing out folder recognizer thread... + this(obj, (AntProjectCookie)obj.getCookie(AntProjectCookie.class)); + } + private AntProjectNode(DataObject obj, AntProjectCookie cookie) { + super(obj, new AntProjectChildren(cookie)); + cookie.addChangeListener(WeakListener.change(this, cookie)); getCookieSet ().add (new ProjectNodeIndex (this)); } - - private void updateDisplayName () { - AntProjectCookie cookie = (AntProjectCookie) getCookie (AntProjectCookie.class); + + public Node.Cookie getCookie(Class c) { + if (c == ElementCookie.class || c == IntrospectionCookie.class) { + AntProjectCookie main = (AntProjectCookie)getDataObject().getCookie(AntProjectCookie.class); + Element projel = main.getProjectElement(); + if (projel != null) { + return new ElementSupport.Introspection(projel, Project.class.getName()); + } + } + return super.getCookie(c); + } + + public Image getIcon(int type) { + AntProjectCookie.ParseStatus cookie = (AntProjectCookie.ParseStatus)getDataObject().getCookie(AntProjectCookie.ParseStatus.class); if (cookie.getFile() == null && cookie.getFileObject() == null) { // Script has been invalidated perhaps? Don't continue, we would // just get an NPE from the getParseException. - return; - } - Element pel = cookie.getProjectElement (); - if (pel != null) { - String projectName = pel.getAttribute ("name"); // NOI18N - if (! projectName.equals("")) { // NOI18N - // Set the node description in the IDE to the name of the project - setShortDescription(NbBundle.getMessage (AntProjectNode.class, "LBL_named_script_description", projectName)); - } else { - // No name specified, OK. - setShortDescription(NbBundle.getMessage (AntProjectNode.class, "LBL_anon_script_description")); - } + return Utilities.loadImage("org/apache/tools/ant/module/resources/AntIconError.gif"); // NOI18N } - Throwable exc = cookie.getParseException (); - if (exc == null) { - setIconBase ("org/apache/tools/ant/module/resources/AntIcon"); // NOI18N + if (!cookie.isParsed()) { + // Assume for now it is not erroneous. + return Utilities.loadImage("org/apache/tools/ant/module/resources/AntIcon.gif"); // NOI18N + } + Throwable exc = cookie.getParseException(); + if (exc != null) { + return Utilities.loadImage("org/apache/tools/ant/module/resources/AntIconError.gif"); // NOI18N } else { - String m = exc.getLocalizedMessage (); - if (m == null || m.length () == 0) { - m = exc.toString (); - AntModule.err.annotate (exc, ErrorManager.UNKNOWN, "Strange parse error in " + ((DataObject) getCookie (DataObject.class)).getPrimaryFile (), null, null, null); // NOI18N - AntModule.err.notify (ErrorManager.INFORMATIONAL, exc); - } - setShortDescription (m); - setIconBase ("org/apache/tools/ant/module/resources/AntIconError"); // NOI18N + return Utilities.loadImage("org/apache/tools/ant/module/resources/AntIcon.gif"); // NOI18N } } - - private void updateElementCookie () { - AntProjectCookie main = (AntProjectCookie) getCookie (AntProjectCookie.class); - Element projel = main.getProjectElement (); - if (projel != null) { - getCookieSet ().add (new ElementSupport.Introspection (projel, Project.class.getName ())); + public Image getOpenedIcon(int type) { + return getIcon(type); + } + + public String getShortDescription() { + AntProjectCookie cookie = (AntProjectCookie)getDataObject().getCookie(AntProjectCookie.class); + if (cookie.getFile() == null && cookie.getFileObject() == null) { + // Script has been invalidated perhaps? Don't continue, we would + // just get an NPE from the getParseException. + return super.getShortDescription(); + } + Throwable exc = cookie.getParseException(); + if (exc != null) { + String m = exc.getLocalizedMessage(); + if (m != null) { + return m; + } else { + return exc.toString(); + } } else { - ElementCookie cookie = (ElementCookie) getCookie (ElementCookie.class); - if (cookie != null) { - getCookieSet ().remove (cookie); + Element pel = cookie.getProjectElement(); + if (pel != null) { + String projectName = pel.getAttribute("name"); // NOI18N + if (!projectName.equals("")) { // NOI18N + // Set the node description in the IDE to the name of the project + return NbBundle.getMessage(AntProjectNode.class, "LBL_named_script_description", projectName); + } else { + // No name specified, OK. + return NbBundle.getMessage(AntProjectNode.class, "LBL_anon_script_description"); + } + } else { + // ??? + return super.getShortDescription(); } } } @@ -280,16 +293,11 @@ props.put (pcp); } - public void propertyChange (PropertyChangeEvent evt) { - String prop = evt.getPropertyName (); - if (prop == null || prop.equals (DataObject.PROP_NAME)) { - updateDisplayName (); - } - } - public void stateChanged (ChangeEvent ev) { - updateDisplayName (); - updateElementCookie (); + fireIconChange(); + fireOpenedIconChange(); + fireShortDescriptionChange(null, null); + fireCookieChange(); firePropertyChange (null, null, null); } Index: ant/src/org/apache/tools/ant/module/xml/AntProjectSupport.java =================================================================== RCS file: /cvs/ant/src/org/apache/tools/ant/module/xml/AntProjectSupport.java,v retrieving revision 1.17 diff -u -r1.17 AntProjectSupport.java --- ant/src/org/apache/tools/ant/module/xml/AntProjectSupport.java 11 Feb 2002 12:24:17 -0000 1.17 +++ ant/src/org/apache/tools/ant/module/xml/AntProjectSupport.java 29 May 2002 18:20:30 -0000 @@ -43,7 +43,7 @@ import org.apache.tools.ant.module.AntModule; import org.apache.tools.ant.module.api.AntProjectCookie; -public class AntProjectSupport implements AntProjectCookie, DocumentListener, FileChangeListener, org.w3c.dom.events.EventListener, Runnable, ChangeListener { +public class AntProjectSupport implements AntProjectCookie.ParseStatus, DocumentListener, FileChangeListener, org.w3c.dom.events.EventListener, Runnable, ChangeListener { private File file; private FileObject fo; @@ -152,6 +152,10 @@ invalidate (); } + public boolean isParsed() { + return parsed; + } + public Document getDocument () { if (parsed) { return projDoc; @@ -246,7 +250,12 @@ } catch (Exception e) { // leave projDoc the way it is... exception = e; + if (!(exception instanceof SAXParseException)) { + AntModule.err.annotate(exception, ErrorManager.UNKNOWN, "Strange parse error in " + this, null, null, null); // NOI18N + AntModule.err.notify(ErrorManager.INFORMATIONAL, exception); + } } + fireChangeEvent(); parsed = true; }