1 19 20 package org.netbeans.modules.web.core.syntax; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import javax.swing.event.DocumentEvent ; 25 import javax.swing.event.DocumentListener ; 26 import javax.swing.text.Document ; 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 39 final class JspUpToDateStatusProvider extends UpToDateStatusProvider implements DocumentListener , PropertyChangeListener { 40 41 private UpToDateStatus upToDate; 42 43 public static JspUpToDateStatusProvider get(Document 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 54 private JspUpToDateStatusProvider(Document document) { 55 upToDate = UpToDateStatus.UP_TO_DATE_OK; 56 document.addDocumentListener(this); 57 58 DataObject documentDO = NbEditorUtilities.getDataObject(document); 60 if(documentDO != null && documentDO.isValid()) { 61 JSPColoringData jspcd = JspUtils.getJSPColoringData(document, documentDO.getPrimaryFile()); 62 jspcd.addPropertyChangeListener(WeakListeners.propertyChange(this, jspcd)); 64 } 65 } 66 67 public void propertyChange(PropertyChangeEvent evt) { 69 Boolean newValue = (Boolean )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 e) { 88 setUpToDate(UpToDateStatus.UP_TO_DATE_DIRTY); 89 } 90 91 public synchronized void insertUpdate(DocumentEvent e) { 92 setUpToDate(UpToDateStatus.UP_TO_DATE_DIRTY); 93 } 94 95 public void changedUpdate(DocumentEvent e) { 96 } 97 98 } 99 | Popular Tags |