Lines 43-48
Link Here
|
43 |
import org.netbeans.spi.editor.fold.FoldOperation; |
43 |
import org.netbeans.spi.editor.fold.FoldOperation; |
44 |
import org.openide.util.Exceptions; |
44 |
import org.openide.util.Exceptions; |
45 |
import org.openide.util.NbBundle; |
45 |
import org.openide.util.NbBundle; |
|
|
46 |
import org.openide.util.RequestProcessor; |
46 |
|
47 |
|
47 |
/** |
48 |
/** |
48 |
* This class is an implementation of @see org.netbeans.spi.editor.fold.FoldManager |
49 |
* This class is an implementation of @see org.netbeans.spi.editor.fold.FoldManager |
Lines 69-74
Link Here
|
69 |
XmlFoldManager.this.clearChanges(); |
70 |
XmlFoldManager.this.clearChanges(); |
70 |
} |
71 |
} |
71 |
|
72 |
|
|
|
73 |
//always called from AWT thread |
72 |
public void updateFinished() { |
74 |
public void updateFinished() { |
73 |
// System.out.println("DocumentModel update = " + (System.currentTimeMillis() - startTime) + "ms."); |
75 |
// System.out.println("DocumentModel update = " + (System.currentTimeMillis() - startTime) + "ms."); |
74 |
XmlFoldManager.this.updateFolds(null); |
76 |
XmlFoldManager.this.updateFolds(null); |
Lines 113-132
Link Here
|
113 |
} |
115 |
} |
114 |
|
116 |
|
115 |
public void initFolds(FoldHierarchyTransaction transaction) { |
117 |
public void initFolds(FoldHierarchyTransaction transaction) { |
116 |
try { |
118 |
|
117 |
Document doc = getOperation().getHierarchy().getComponent().getDocument(); |
119 |
Document doc = getOperation().getHierarchy().getComponent().getDocument(); |
118 |
//filtering of the PlainDocument set during the JEditorPane initializatin |
120 |
//filtering of the PlainDocument set during the JEditorPane initializatin |
119 |
if (!(doc instanceof BaseDocument)) { |
121 |
if (!(doc instanceof BaseDocument)) { |
120 |
return; |
122 |
return; |
|
|
123 |
} |
124 |
RequestProcessor.getDefault().post(new Runnable() { |
125 |
public void run() { |
126 |
try { |
127 |
//set the DocumentModel initialization to lazy mode, in such case |
128 |
//the model initial creation is not done synchronously with the |
129 |
//DocumentModel.getDocumentModel() call but rather than that |
130 |
//the model initialization happens after some time. The client |
131 |
//needs to listen on the DocumentModelStateListener.updateFinished() |
132 |
//to get the parsed model. |
133 |
getDocument().putProperty("lazy_model", new Object()); //NOI18N |
134 |
|
135 |
//should return quickly, however model is not ready yet |
136 |
model = DocumentModel.getDocumentModel(getDocument()); |
137 |
|
138 |
//we will get notification once the model is parsed |
139 |
model.addDocumentModelStateListener(DMLS); |
140 |
|
141 |
model.addDocumentModelListener(DML); |
142 |
} catch (DocumentModelException ex) { |
143 |
Exceptions.printStackTrace(ex); |
144 |
} |
121 |
} |
145 |
} |
122 |
model = DocumentModel.getDocumentModel((BaseDocument) getDocument()); |
146 |
}); |
123 |
model.addDocumentModelStateListener(DMLS); |
|
|
124 |
model.addDocumentModelListener(DML); |
125 |
|
126 |
updateFolds(transaction); |
127 |
} catch (DocumentModelException ex) { |
128 |
Exceptions.printStackTrace(ex); |
129 |
} |
130 |
} |
147 |
} |
131 |
|
148 |
|
132 |
//start collecting changes |
149 |
//start collecting changes |