Index: xml/text-edit/src/org/netbeans/modules/xml/text/folding/XmlFoldManager.java =================================================================== RCS file: /cvs/xml/text-edit/src/org/netbeans/modules/xml/text/folding/XmlFoldManager.java,v retrieving revision 1.17 diff -u -u -r1.17 XmlFoldManager.java --- xml/text-edit/src/org/netbeans/modules/xml/text/folding/XmlFoldManager.java 21 Sep 2007 17:42:17 -0000 1.17 +++ xml/text-edit/src/org/netbeans/modules/xml/text/folding/XmlFoldManager.java 27 Sep 2007 09:58:52 -0000 @@ -43,6 +43,7 @@ import org.netbeans.spi.editor.fold.FoldOperation; import org.openide.util.Exceptions; import org.openide.util.NbBundle; +import org.openide.util.RequestProcessor; /** * This class is an implementation of @see org.netbeans.spi.editor.fold.FoldManager @@ -69,6 +70,7 @@ XmlFoldManager.this.clearChanges(); } + //always called from AWT thread public void updateFinished() { // System.out.println("DocumentModel update = " + (System.currentTimeMillis() - startTime) + "ms."); XmlFoldManager.this.updateFolds(null); @@ -113,20 +115,35 @@ } public void initFolds(FoldHierarchyTransaction transaction) { - try { - Document doc = getOperation().getHierarchy().getComponent().getDocument(); - //filtering of the PlainDocument set during the JEditorPane initializatin - if (!(doc instanceof BaseDocument)) { - return; + + Document doc = getOperation().getHierarchy().getComponent().getDocument(); + //filtering of the PlainDocument set during the JEditorPane initializatin + if (!(doc instanceof BaseDocument)) { + return; + } + RequestProcessor.getDefault().post(new Runnable() { + public void run() { + try { + //set the DocumentModel initialization to lazy mode, in such case + //the model initial creation is not done synchronously with the + //DocumentModel.getDocumentModel() call but rather than that + //the model initialization happens after some time. The client + //needs to listen on the DocumentModelStateListener.updateFinished() + //to get the parsed model. + getDocument().putProperty("lazy_model", new Object()); //NOI18N + + //should return quickly, however model is not ready yet + model = DocumentModel.getDocumentModel(getDocument()); + + //we will get notification once the model is parsed + model.addDocumentModelStateListener(DMLS); + + model.addDocumentModelListener(DML); + } catch (DocumentModelException ex) { + Exceptions.printStackTrace(ex); + } } - model = DocumentModel.getDocumentModel((BaseDocument) getDocument()); - model.addDocumentModelStateListener(DMLS); - model.addDocumentModelListener(DML); - - updateFolds(transaction); - } catch (DocumentModelException ex) { - Exceptions.printStackTrace(ex); - } + }); } //start collecting changes Index: xml/tageditorsupport/src/org/netbeans/modules/editor/structure/api/DocumentModel.java =================================================================== RCS file: /cvs/xml/tageditorsupport/src/org/netbeans/modules/editor/structure/api/DocumentModel.java,v retrieving revision 1.42 diff -u -u -r1.42 DocumentModel.java --- xml/tageditorsupport/src/org/netbeans/modules/editor/structure/api/DocumentModel.java 21 Sep 2007 17:42:16 -0000 1.42 +++ xml/tageditorsupport/src/org/netbeans/modules/editor/structure/api/DocumentModel.java 27 Sep 2007 09:58:53 -0000 @@ -178,7 +178,11 @@ if E1.startOffset == E2.startOffset then if E1.endOffset > E2.endOffset then the E1 is before E2 */ - initDocumentModel(); + if(doc.getProperty("lazy_model") == null) { //NOI18N + initDocumentModel(); + } else { + requestModelUpdate(false); + } this.changesWatcher = new DocumentChangesWatcher(); getDocument().addDocumentListener(WeakListeners.document(changesWatcher, doc));