Index: arch/arch-openide-editor.xml =================================================================== RCS file: /cvs/openide/arch/arch-openide-editor.xml,v retrieving revision 1.18 diff -u -r1.18 arch-openide-editor.xml --- arch/arch-openide-editor.xml 9 Sep 2004 18:09:52 -0000 1.18 +++ arch/arch-openide-editor.xml 28 Oct 2004 21:24:20 -0000 @@ -375,6 +375,12 @@ This property can be used by the modules and is part of the Editor API. + +The value of this document property will be serialized as part of CloneableEditor's data +and at the time when the CloneableEditor gets deserialized the value gets +restored and set back into the document. + + Index: src/org/openide/text/CloneableEditor.java =================================================================== RCS file: /cvs/openide/src/org/openide/text/CloneableEditor.java,v retrieving revision 1.81 diff -u -r1.81 CloneableEditor.java --- src/org/openide/text/CloneableEditor.java 14 Oct 2004 08:34:12 -0000 1.81 +++ src/org/openide/text/CloneableEditor.java 28 Oct 2004 21:24:24 -0000 @@ -59,6 +59,11 @@ /** Position of cursor. Used to keep the value between deserialization * and initialization time. */ private int cursorPosition = -1; + + /** + * Persistent data for the document associated with the editor pane. + */ + private Object documentPersistentData; // #20647. More important custom component. /** Custom editor component, which is used if specified by document @@ -72,6 +77,12 @@ static final long serialVersionUID = -185739563792410059L; + /** + * Document property used for storing and retrieving of the data to be persisted + * during the CloneableEditor serialization. + */ + static final String PERSISTENT_DATA_DOCUMENT_PROPERTY = "persistentData"; + /** For externalization of subclasses only */ public CloneableEditor() { this(null); @@ -197,6 +208,12 @@ pane.setEditorKit (support.kit ()); + // Set the document's persistent data into the document prior assigning + // of the document to the component + if (documentPersistentData != null) { + doc.putProperty(PERSISTENT_DATA_DOCUMENT_PROPERTY, documentPersistentData); + } + pane.setDocument (doc); if (doc instanceof NbDocument.CustomEditor) { NbDocument.CustomEditor ce = (NbDocument.CustomEditor)doc; @@ -486,15 +503,24 @@ } } } + + // Gather document persistent data + Document doc = p.getDocument(); + documentPersistentData = (doc != null) + ? doc.getProperty(PERSISTENT_DATA_DOCUMENT_PROPERTY) + : null; } out.writeObject(new Integer(pos)); + + out.writeObject(documentPersistentData); } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); int offset; + Object docPersistentData; Object firstObject = in.readObject (); @@ -540,11 +566,12 @@ } // load cursor position offset = ((Integer)in.readObject()).intValue(); - + docPersistentData = in.readObject(); } if (!discard ()) { cursorPosition = offset; + documentPersistentData = docPersistentData; } updateName(); Index: test/unit/src/org/openide/text/CloneableEditorTest.java =================================================================== RCS file: /cvs/openide/test/unit/src/org/openide/text/CloneableEditorTest.java,v retrieving revision 1.1 diff -u -r1.1 CloneableEditorTest.java --- test/unit/src/org/openide/text/CloneableEditorTest.java 16 Aug 2004 17:03:46 -0000 1.1 +++ test/unit/src/org/openide/text/CloneableEditorTest.java 28 Oct 2004 21:24:25 -0000 @@ -23,6 +23,7 @@ import java.util.Set; import javax.swing.SwingUtilities; import javax.swing.text.BadLocationException; +import javax.swing.text.Document; import javax.swing.text.Position; import javax.swing.text.StyledDocument; @@ -128,6 +129,30 @@ assertEquals ("One is there again", 1, panes.length); } + public void testDocumentPersistentDataIssue8007() throws Exception { + support.open(); + + CloneableEditor ed = (CloneableEditor)support.getRef().getAnyComponent(); + NbMarshalledObject obj = new NbMarshalledObject(ed); + + javax.swing.JEditorPane[] panes = support.getOpenedPanes(); + assertNotNull(panes); + assertEquals("One pane expected", 1, panes.length); + Document doc = panes[0].getDocument(); + assertNotNull(doc); + doc.putProperty(CloneableEditor.PERSISTENT_DATA_DOCUMENT_PROPERTY, new Integer(10)); + + ed.close(); + + ed = (CloneableEditor)obj.get(); + panes = support.getOpenedPanes(); + assertNotNull(panes); + assertEquals("One pane expected", 1, panes.length); + assertEquals("Integer(10) expected", + doc.getProperty(CloneableEditor.PERSISTENT_DATA_DOCUMENT_PROPERTY), + new Integer(10) + ); + } // // Implementation of the CloneableEditorSupport.Env