This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 8007
Collapse All | Expand All

(-)arch/arch-openide-editor.xml (+6 lines)
Lines 375-380 Link Here
375
This property can be used by the modules and is part of the Editor API.
375
This property can be used by the modules and is part of the Editor API.
376
</api>
376
</api>
377
377
378
<api type="import" group="property" name="persistentData" category="friend" >
379
The value of this document property will be serialized as part of CloneableEditor's data
380
and at the time when the CloneableEditor gets deserialized the value gets
381
restored and set back into the document.
382
</api>
383
378
</answer>
384
</answer>
379
385
380
386
(-)src/org/openide/text/CloneableEditor.java (-1 / +28 lines)
Lines 59-64 Link Here
59
    /** Position of cursor. Used to keep the value between deserialization
59
    /** Position of cursor. Used to keep the value between deserialization
60
     * and initialization time. */
60
     * and initialization time. */
61
    private int cursorPosition = -1;
61
    private int cursorPosition = -1;
62
    
63
    /**
64
     * Persistent data for the document associated with the editor pane.
65
     */
66
    private Object documentPersistentData;
62
67
63
    // #20647. More important custom component.
68
    // #20647. More important custom component.
64
    /** Custom editor component, which is used if specified by document
69
    /** Custom editor component, which is used if specified by document
Lines 72-77 Link Here
72
    
77
    
73
    static final long serialVersionUID = -185739563792410059L;
78
    static final long serialVersionUID = -185739563792410059L;
74
    
79
    
80
    /**
81
     * Document property used for storing and retrieving of the data to be persisted
82
     * during the CloneableEditor serialization.
83
     */
84
    static final String PERSISTENT_DATA_DOCUMENT_PROPERTY = "persistentData";
85
    
75
    /** For externalization of subclasses only  */
86
    /** For externalization of subclasses only  */
76
    public CloneableEditor() {
87
    public CloneableEditor() {
77
        this(null);
88
        this(null);
Lines 197-202 Link Here
197
        
208
        
198
        pane.setEditorKit (support.kit ());
209
        pane.setEditorKit (support.kit ());
199
210
211
        // Set the document's persistent data into the document prior assigning
212
        // of the document to the component
213
        if (documentPersistentData != null) {
214
            doc.putProperty(PERSISTENT_DATA_DOCUMENT_PROPERTY, documentPersistentData);
215
        }
216
200
        pane.setDocument (doc);
217
        pane.setDocument (doc);
201
        if (doc instanceof NbDocument.CustomEditor) {
218
        if (doc instanceof NbDocument.CustomEditor) {
202
            NbDocument.CustomEditor ce = (NbDocument.CustomEditor)doc;
219
            NbDocument.CustomEditor ce = (NbDocument.CustomEditor)doc;
Lines 486-500 Link Here
486
                    }
503
                    }
487
                }
504
                }
488
            }
505
            }
506
            
507
            // Gather document persistent data
508
            Document doc = p.getDocument();
509
            documentPersistentData = (doc != null)
510
                    ? doc.getProperty(PERSISTENT_DATA_DOCUMENT_PROPERTY)
511
                    : null;
489
        }
512
        }
490
        
513
        
491
        out.writeObject(new Integer(pos));
514
        out.writeObject(new Integer(pos));
515
        
516
        out.writeObject(documentPersistentData);
492
    }
517
    }
493
518
494
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
519
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
495
        super.readExternal(in);
520
        super.readExternal(in);
496
        
521
        
497
        int offset;
522
        int offset;
523
        Object docPersistentData;
498
524
499
        Object firstObject = in.readObject ();
525
        Object firstObject = in.readObject ();
500
526
Lines 540-550 Link Here
540
            }
566
            }
541
            // load cursor position
567
            // load cursor position
542
            offset = ((Integer)in.readObject()).intValue();
568
            offset = ((Integer)in.readObject()).intValue();
543
569
            docPersistentData = in.readObject();
544
        }
570
        }
545
571
546
        if (!discard ()) {
572
        if (!discard ()) {
547
            cursorPosition = offset;
573
            cursorPosition = offset;
574
            documentPersistentData = docPersistentData;
548
        }
575
        }
549
        
576
        
550
        updateName();
577
        updateName();
(-)test/unit/src/org/openide/text/CloneableEditorTest.java (+25 lines)
Lines 23-28 Link Here
23
import java.util.Set;
23
import java.util.Set;
24
import javax.swing.SwingUtilities;
24
import javax.swing.SwingUtilities;
25
import javax.swing.text.BadLocationException;
25
import javax.swing.text.BadLocationException;
26
import javax.swing.text.Document;
26
import javax.swing.text.Position;
27
import javax.swing.text.Position;
27
import javax.swing.text.StyledDocument;
28
import javax.swing.text.StyledDocument;
28
29
Lines 128-133 Link Here
128
        assertEquals ("One is there again", 1, panes.length);
129
        assertEquals ("One is there again", 1, panes.length);
129
    }
130
    }
130
131
132
    public void testDocumentPersistentDataIssue8007() throws Exception {
133
        support.open();
134
135
        CloneableEditor ed = (CloneableEditor)support.getRef().getAnyComponent();
136
        NbMarshalledObject obj = new NbMarshalledObject(ed);
137
138
        javax.swing.JEditorPane[] panes = support.getOpenedPanes();
139
        assertNotNull(panes);
140
        assertEquals("One pane expected", 1, panes.length);
141
        Document doc = panes[0].getDocument();
142
        assertNotNull(doc);
143
        doc.putProperty(CloneableEditor.PERSISTENT_DATA_DOCUMENT_PROPERTY, new Integer(10));
144
145
        ed.close();
146
147
        ed = (CloneableEditor)obj.get();
148
        panes = support.getOpenedPanes();
149
        assertNotNull(panes);
150
        assertEquals("One pane expected", 1, panes.length);
151
        assertEquals("Integer(10) expected",
152
                doc.getProperty(CloneableEditor.PERSISTENT_DATA_DOCUMENT_PROPERTY),
153
                new Integer(10)
154
        );
155
    }
131
    
156
    
132
    //
157
    //
133
    // Implementation of the CloneableEditorSupport.Env
158
    // Implementation of the CloneableEditorSupport.Env

Return to bug 8007