KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > core > syntax > JspUpToDateStatusProvider


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.core.syntax;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import javax.swing.event.DocumentEvent JavaDoc;
25 import javax.swing.event.DocumentListener JavaDoc;
26 import javax.swing.text.Document JavaDoc;
27 import org.netbeans.editor.Utilities;
28 import org.netbeans.modules.editor.NbEditorUtilities;
29 import org.netbeans.modules.web.core.syntax.spi.JSPColoringData;
30 import org.netbeans.spi.editor.errorstripe.UpToDateStatus;
31 import org.netbeans.spi.editor.errorstripe.UpToDateStatusProvider;
32 import org.openide.loaders.DataObject;
33 import org.openide.util.WeakListeners;
34
35 /**
36  *
37  * @author Jan Lahoda, Marek Fukala
38  */

39 final class JspUpToDateStatusProvider extends UpToDateStatusProvider implements DocumentListener JavaDoc, PropertyChangeListener JavaDoc {
40     
41     private UpToDateStatus upToDate;
42     
43     public static JspUpToDateStatusProvider get(Document JavaDoc doc) {
44         JspUpToDateStatusProvider provider = (JspUpToDateStatusProvider) doc.getProperty(JspUpToDateStatusProvider.class);
45         
46         if (provider == null) {
47             doc.putProperty(JspUpToDateStatusProvider.class, provider = new JspUpToDateStatusProvider(doc));
48         }
49         
50         return provider;
51     }
52     
53     /** Creates a new instance of AnnotationMarkProvider */
54     private JspUpToDateStatusProvider(Document JavaDoc document) {
55         upToDate = UpToDateStatus.UP_TO_DATE_OK;
56         document.addDocumentListener(this);
57         
58         //listen to parser results
59
DataObject documentDO = NbEditorUtilities.getDataObject(document);
60         if(documentDO != null && documentDO.isValid()) {
61             JSPColoringData jspcd = JspUtils.getJSPColoringData(document, documentDO.getPrimaryFile());
62             //jspcd.addPropertyChangeListener(this);
63
jspcd.addPropertyChangeListener(WeakListeners.propertyChange(this, jspcd));
64         }
65     }
66     
67     //the property changes are fired via JSPColoringData by TagLibParseSupport
68
public void propertyChange(PropertyChangeEvent JavaDoc evt) {
69         Boolean JavaDoc newValue = (Boolean JavaDoc)evt.getNewValue();
70         if(JSPColoringData.PROP_PARSING_IN_PROGRESS.equals(evt.getPropertyName()) && newValue.booleanValue())
71             setUpToDate(UpToDateStatus.UP_TO_DATE_PROCESSING);
72         if(JSPColoringData.PROP_PARSING_SUCCESSFUL.equals(evt.getPropertyName()))
73             setUpToDate(UpToDateStatus.UP_TO_DATE_OK);
74     }
75     
76     public synchronized UpToDateStatus getUpToDate() {
77         return upToDate;
78     }
79     
80     private void setUpToDate(UpToDateStatus upToDate) {
81         UpToDateStatus oldStatus = this.upToDate;
82         if(oldStatus.equals(upToDate)) return ;
83         this.upToDate = upToDate;
84         firePropertyChange(PROP_UP_TO_DATE, oldStatus, upToDate);
85     }
86     
87     public synchronized void removeUpdate(DocumentEvent JavaDoc e) {
88         setUpToDate(UpToDateStatus.UP_TO_DATE_DIRTY);
89     }
90     
91     public synchronized void insertUpdate(DocumentEvent JavaDoc e) {
92         setUpToDate(UpToDateStatus.UP_TO_DATE_DIRTY);
93     }
94     
95     public void changedUpdate(DocumentEvent JavaDoc e) {
96     }
97     
98 }
99
Popular Tags