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 206907
Collapse All | Expand All

(-)a/editor.lib/src/org/netbeans/editor/BaseDocument.java (-8 / +52 lines)
Lines 106-117 Link Here
106
import org.netbeans.modules.editor.lib.drawing.DrawGraphics;
106
import org.netbeans.modules.editor.lib.drawing.DrawGraphics;
107
import org.netbeans.modules.editor.lib.impl.MarkVector;
107
import org.netbeans.modules.editor.lib.impl.MarkVector;
108
import org.netbeans.modules.editor.lib.impl.MultiMark;
108
import org.netbeans.modules.editor.lib.impl.MultiMark;
109
import org.netbeans.modules.editor.lib2.document.ContentEdit;
109
import org.netbeans.modules.editor.lib2.document.*;
110
import org.netbeans.modules.editor.lib2.document.EditorDocumentContent;
111
import org.netbeans.modules.editor.lib2.document.LineElementRoot;
112
import org.netbeans.modules.editor.lib2.document.ReadWriteBuffer;
113
import org.netbeans.modules.editor.lib2.document.ReadWriteUtils;
114
import org.netbeans.modules.editor.lib2.document.StableCompoundEdit;
115
import org.netbeans.spi.lexer.MutableTextInput;
110
import org.netbeans.spi.lexer.MutableTextInput;
116
import org.netbeans.spi.lexer.TokenHierarchyControl;
111
import org.netbeans.spi.lexer.TokenHierarchyControl;
117
import org.openide.filesystems.FileObject;
112
import org.openide.filesystems.FileObject;
Lines 131-136 Link Here
131
126
132
    static {
127
    static {
133
        EditorPackageAccessor.register(new Accessor());
128
        EditorPackageAccessor.register(new Accessor());
129
        EditorDocumentHandler.setEditorDocumentServices(BaseDocument.class, BaseDocumentServices.INSTANCE);
134
    }
130
    }
135
131
136
    // -J-Dorg.netbeans.editor.BaseDocument.level=FINE
132
    // -J-Dorg.netbeans.editor.BaseDocument.level=FINE
Lines 347-352 Link Here
347
    private UndoableEdit removeUpdateLineUndo;
343
    private UndoableEdit removeUpdateLineUndo;
348
344
349
    private DocumentFilter.FilterBypass filterBypass;
345
    private DocumentFilter.FilterBypass filterBypass;
346
    
347
    private int runExclusiveDepth;
350
348
351
    private Preferences prefs;
349
    private Preferences prefs;
352
    private final PreferenceChangeListener prefsListener = new PreferenceChangeListener() {
350
    private final PreferenceChangeListener prefsListener = new PreferenceChangeListener() {
Lines 997-1003 Link Here
997
    
995
    
998
    private void checkModifiable(int offset) throws BadLocationException {
996
    private void checkModifiable(int offset) throws BadLocationException {
999
        if (!modifiable) {
997
        if (!modifiable) {
1000
            throw new GuardedException("Modification prohibited", offset);
998
            throw new GuardedException("Modification prohibited", offset); // NOI18N
1001
        }
999
        }
1002
    }
1000
    }
1003
1001
Lines 1618-1623 Link Here
1618
    final void atomicLockImpl () {
1616
    final void atomicLockImpl () {
1619
        boolean alreadyAtomicLocker;
1617
        boolean alreadyAtomicLocker;
1620
        synchronized (this) {
1618
        synchronized (this) {
1619
            if (runExclusiveDepth > 0) {
1620
                throw new IllegalStateException(
1621
                        "Document modifications or atomic locking not allowed in runExclusive()"); // NOI18N
1622
            }
1621
            alreadyAtomicLocker = Thread.currentThread() == getCurrentWriter() && atomicDepth > 0;
1623
            alreadyAtomicLocker = Thread.currentThread() == getCurrentWriter() && atomicDepth > 0;
1622
            if (alreadyAtomicLocker) {
1624
            if (alreadyAtomicLocker) {
1623
                atomicDepth++;
1625
                atomicDepth++;
Lines 1765-1770 Link Here
1765
        return atomicDepth;
1767
        return atomicDepth;
1766
    }
1768
    }
1767
1769
1770
    void runExclusive(Runnable r) {
1771
        boolean writeLockDone = false;
1772
        synchronized (this) {
1773
            Thread currentWriter = getCurrentWriter();
1774
            if (currentWriter != Thread.currentThread()) {
1775
                assert (runExclusiveDepth == 0) : "runExclusiveDepth=" + runExclusiveDepth + " != 0"; // NOI18N
1776
                writeLock();
1777
                writeLockDone = true;
1778
            }
1779
            runExclusiveDepth++;   
1780
        }
1781
        try {
1782
            r.run();
1783
        } finally {
1784
            runExclusiveDepth--;
1785
            if (writeLockDone) {
1786
                writeUnlock();
1787
                assert (runExclusiveDepth == 0) : "runExclusiveDepth=" + runExclusiveDepth + " != 0"; // NOI18N
1788
            }
1789
            
1790
        }
1791
    }
1792
1768
    @Override
1793
    @Override
1769
    public void addDocumentListener(DocumentListener listener) {
1794
    public void addDocumentListener(DocumentListener listener) {
1770
        if (LOG_LISTENER.isLoggable(Level.FINE)) {
1795
        if (LOG_LISTENER.isLoggable(Level.FINE)) {
Lines 2013-2019 Link Here
2013
        if (atomicEdits == null)
2038
        if (atomicEdits == null)
2014
            atomicEdits = new AtomicCompoundEdit();
2039
            atomicEdits = new AtomicCompoundEdit();
2015
    }
2040
    }
2016
2041
    
2017
    public @Override String toString() {
2042
    public @Override String toString() {
2018
        return super.toString() +
2043
        return super.toString() +
2019
            ", mimeType='" + mimeType + "'" + //NOI18N
2044
            ", mimeType='" + mimeType + "'" + //NOI18N
Lines 2356-2359 Link Here
2356
            handleInsertString(offset, text, attrs);
2381
            handleInsertString(offset, text, attrs);
2357
        }
2382
        }
2358
    }
2383
    }
2384
2385
    /**
2386
    * Implementation of EditorDocumentServices for BaseDocument.
2387
    *
2388
    * @author Miloslav Metelka
2389
    */
2390
    private static final class BaseDocumentServices implements EditorDocumentServices {
2391
        
2392
        static final EditorDocumentServices INSTANCE = new BaseDocumentServices();
2393
2394
        @Override
2395
        public void runExclusive(Document doc, Runnable r) {
2396
            BaseDocument bDoc = (BaseDocument) doc;
2397
            bDoc.runExclusive(r);
2398
        }
2399
2400
2401
    }
2402
2359
}
2403
}
(-)a/editor.lib/test/unit/src/org/netbeans/editor/BaseDocumentTest.java (+189 lines)
Lines 47-52 Link Here
47
import javax.swing.undo.UndoManager;
47
import javax.swing.undo.UndoManager;
48
import org.netbeans.junit.NbTestCase;
48
import org.netbeans.junit.NbTestCase;
49
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
49
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
50
import org.openide.util.Exceptions;
51
import org.openide.util.RequestProcessor;
50
52
51
/**
53
/**
52
 * Test functionality of BaseDocument.
54
 * Test functionality of BaseDocument.
Lines 58-64 Link Here
58
    public BaseDocumentTest(String testName) {
60
    public BaseDocumentTest(String testName) {
59
        super(testName);
61
        super(testName);
60
    }
62
    }
63
64
    public void testRunExclusive() throws Exception {
65
        final BaseDocument doc = new BaseDocument(false, "text/plain"); // NOI18N
66
        doc.insertString(0, "Nazdar", null);
67
        
68
        doc.runExclusive(new Runnable() {
69
            @Override
70
            public void run() {
71
                try {
72
                    doc.getText(0, doc.getLength());
73
                } catch (Exception ex) {
74
                    fail("Unexpected exception ex=" + ex);
75
                }
76
            }
77
        });
78
        
79
        doc.runExclusive(new Runnable() {
80
            @Override
81
            public void run() {
82
                try {
83
                    doc.insertString(0, "a", null);
84
                    fail("Exception expected upon insertString()");
85
                } catch (IllegalStateException ex) {
86
                    // Expected
87
                } catch (Exception ex) {
88
                    fail("Unexpected exception ex=" + ex);
89
                }
90
            }
91
        });
92
        
93
        doc.runExclusive(new Runnable() {
94
            @Override
95
            public void run() {
96
                try {
97
                    doc.runAtomic(new Runnable() {
98
                        @Override
99
                        public void run() {
100
                            fail("Should never run");
101
                        }
102
                    });
103
                    fail("Exception expected upon runAtomic()");
104
                } catch (IllegalStateException ex) {
105
                    // Expected
106
                } catch (Exception ex) {
107
                    fail("Unexpected exception ex=" + ex);
108
                }
109
            }
110
        });
111
        
112
        doc.runAtomic(new Runnable() {
113
            @Override
114
            public void run() {
115
                doc.runExclusive(new Runnable() {
116
                    @Override
117
                    public void run() {
118
                        try {
119
                            doc.getText(0, doc.getLength());
120
                        } catch (BadLocationException ex) {
121
                            fail("Unexpected exception ex=" + ex);
122
                        }
123
                    }
124
                });
125
            }
126
        });
127
        
128
        doc.runAtomic(new Runnable() {
129
            @Override
130
            public void run() {
131
                doc.runExclusive(new Runnable() {
132
                    @Override
133
                    public void run() {
134
                        try {
135
                            doc.insertString(0, "a", null);
136
                        } catch (IllegalStateException ex) {
137
                            // Expected
138
                        } catch (BadLocationException ex) {
139
                            fail("Unexpected exception ex=" + ex);
140
                        }
141
                    }
142
                });
143
            }
144
        });
145
        
146
        // doc.render() in runExclusive()
147
        doc.runExclusive(new Runnable() {
148
            @Override
149
            public void run() {
150
                doc.render(new Runnable() {
151
                    @Override
152
                    public void run() {
153
                        try {
154
                            doc.getText(0, doc.getLength());
155
                        } catch (BadLocationException ex) {
156
                            fail("Unexpected exception ex=" + ex);
157
                        }
158
                    }
159
                });
160
            }
161
        });
162
163
        // Nested runExclusive()
164
        doc.runExclusive(new Runnable() {
165
            @Override
166
            public void run() {
167
                doc.runExclusive(new Runnable() {
168
                    @Override
169
                    public void run() {
170
                        try {
171
                            doc.getText(0, doc.getLength());
172
                        } catch (BadLocationException ex) {
173
                            fail("Unexpected exception ex=" + ex);
174
                        }
175
                    }
176
                });
177
            }
178
        });
179
    }
61
    
180
    
181
    
182
    public void testRunExclusiveThreading() throws Exception {
183
        final BaseDocument doc = new BaseDocument(false, "text/plain"); // NOI18N
184
        doc.insertString(0, "Nazdar", null);
185
186
        // Test thread access (runExclusive() and attempt read lock.
187
        final boolean t2Started[] = new boolean[1];
188
        final boolean t2DocAccess[] = new boolean[1];
189
        doc.runExclusive(new Runnable() {
190
            @Override
191
            public void run() {
192
                RequestProcessor.getDefault().post(new Runnable() {
193
                    @Override
194
                    public void run() {
195
                        t2Started[0] = true;
196
                        doc.render(new Runnable() {
197
                            @Override
198
                            public void run() {
199
                                t2DocAccess[0] = true;
200
                            }
201
                        });
202
                    }
203
                });
204
                while (!t2Started[0]) {
205
                    tSleep(1);
206
                }
207
                tSleep(5);
208
                assertFalse("Read lock access granted when in runExclusive", t2DocAccess[0]);
209
            }
210
        });
211
        tSleep(2);
212
        assertTrue("Read lock access not granted in T2", t2DocAccess[0]);
213
214
        // Reversed test (read lock and attempt runExclusive()).
215
        t2Started[0] = false;
216
        t2DocAccess[0] = false;
217
        doc.render(new Runnable() {
218
            @Override
219
            public void run() {
220
                RequestProcessor.getDefault().post(new Runnable() {
221
                    @Override
222
                    public void run() {
223
                        t2Started[0] = true;
224
                        doc.runExclusive(new Runnable() {
225
                            @Override
226
                            public void run() {
227
                                t2DocAccess[0] = true;
228
                            }
229
                        });
230
                    }
231
                });
232
                while (!t2Started[0]) {
233
                    tSleep(1);
234
                }
235
                tSleep(5);
236
                assertFalse("runExclusive doc access granted when in render()", t2DocAccess[0]);
237
            }
238
        });
239
        tSleep(2);
240
        assertTrue("runExclusive() access not granted in T2", t2DocAccess[0]);
241
    }
242
    
243
    private static final void tSleep(long millis) {
244
        try {
245
            Thread.sleep(millis);
246
        } catch (InterruptedException ex) {
247
            fail("Failed sleep");
248
        }
249
    }
250
62
    public void testBackwardBiasPosition() throws Exception {
251
    public void testBackwardBiasPosition() throws Exception {
63
        BaseDocument doc = new BaseDocument(false, "text/plain"); // NOI18N
252
        BaseDocument doc = new BaseDocument(false, "text/plain"); // NOI18N
64
        UndoManager undoManager = new UndoManager();
253
        UndoManager undoManager = new UndoManager();
(-)a/editor.lib2/apichanges.xml (+15 lines)
Lines 107-112 Link Here
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
108
109
    <changes>
109
    <changes>
110
        <change id="EditorDocumentUtils.runExclusive">
111
            <summary>EditorDocumentUtils.runExclusive method added</summary>
112
            <version major="1" minor="56"/>
113
            <date day="12" month="3" year="2012"/>
114
            <author login="mmetelka"/>
115
            <compatibility binary="compatible" source="compatible" semantic="compatible" addition="yes"/>
116
            <description>
117
                <p>
118
                    Added EditorDocumentUtils.runExclusive(Runnable) method for gaining
119
                    exclusive access to document without making any document mutations.
120
                </p>
121
            </description>
122
            <issue number="206907"/>
123
        </change>
124
110
        <change id="EditorActionRegistration-weight">
125
        <change id="EditorActionRegistration-weight">
111
            <summary>Add "weight" attribute to EditorActionRegistration.</summary>
126
            <summary>Add "weight" attribute to EditorActionRegistration.</summary>
112
            <version major="1" minor="53"/>
127
            <version major="1" minor="53"/>
(-)a/editor.lib2/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.editor.lib2/1
2
OpenIDE-Module: org.netbeans.modules.editor.lib2/1
3
OpenIDE-Module-Implementation-Version: 26
3
OpenIDE-Module-Implementation-Version: 27
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/lib2/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/lib2/Bundle.properties
5
OpenIDE-Module-Layer: org/netbeans/modules/editor/lib2/resources/layer.xml
5
OpenIDE-Module-Layer: org/netbeans/modules/editor/lib2/resources/layer.xml
6
OpenIDE-Module-Needs: org.netbeans.modules.editor.actions
6
OpenIDE-Module-Needs: org.netbeans.modules.editor.actions
(-)a/editor.lib2/nbproject/project.properties (-1 / +1 lines)
Lines 43-49 Link Here
43
is.autoload=true
43
is.autoload=true
44
javac.source=1.6
44
javac.source=1.6
45
javac.compilerargs=-Xlint:unchecked
45
javac.compilerargs=-Xlint:unchecked
46
spec.version.base=1.55.0
46
spec.version.base=1.56.0
47
47
48
javadoc.arch=${basedir}/arch.xml
48
javadoc.arch=${basedir}/arch.xml
49
javadoc.apichanges=${basedir}/apichanges.xml
49
javadoc.apichanges=${basedir}/apichanges.xml
(-)a/editor.lib2/nbproject/project.xml (+1 lines)
Lines 187-192 Link Here
187
            </test-dependencies>
187
            </test-dependencies>
188
            <public-packages>
188
            <public-packages>
189
                <package>org.netbeans.api.editor</package>
189
                <package>org.netbeans.api.editor</package>
190
                <package>org.netbeans.api.editor.document</package>
190
                <package>org.netbeans.spi.editor.codegen</package>
191
                <package>org.netbeans.spi.editor.codegen</package>
191
                <package>org.netbeans.spi.editor.highlighting</package>
192
                <package>org.netbeans.spi.editor.highlighting</package>
192
                <package>org.netbeans.spi.editor.highlighting.support</package>
193
                <package>org.netbeans.spi.editor.highlighting.support</package>
(-)a/editor.lib2/src/org/netbeans/api/editor/document/EditorDocumentUtils.java (+94 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.api.editor.document;
43
44
import javax.swing.text.Document;
45
import org.netbeans.modules.editor.lib2.document.EditorDocumentHandler;
46
47
/**
48
 * Utilities operation on top of an editor document.
49
 *
50
 * @author Miloslav Metelka
51
 * @since 1.56
52
 */
53
public final class EditorDocumentUtils {
54
    
55
    private EditorDocumentUtils() {
56
        // No instances
57
    }
58
    
59
    /**
60
     * Execute a non mutating runnable under an exclusive document lock over the document
61
     * (no other read locks or write locks are taking place).
62
     * <br/>
63
     * Nested calls to {@link #runExclusive(Document, Runnable) } are allowed.
64
     * The given runnable may also call {@link Document#render(Runnable) }.
65
     * <br/>
66
     * However any mutations by {@link Document#insertString(int, String, javax.swing.text.AttributeSet) }
67
     * or {@link Document#remove(int, int) } are prohibited.
68
     * <br/>
69
     * Calling atomic transactions (BaseDocument.runAtomic() or NbDocument.runAtomic())
70
     * from the given runnable is prohibited as well.
71
     * <br/>
72
     * Calls to {@link #runExclusive(Document, Runnable) } within an atomic section
73
     * are allowed (but no document mutations may be done during runExclusive() call).
74
     * <br/>
75
     * Calls to {@link Document#render(java.lang.Runnable) } within
76
     * {@link #runExclusive(Document, Runnable) } are allowed.
77
     * <br/>
78
     * Calls to {@link #runExclusive(Document, Runnable) } within
79
     * {@link Document#render(java.lang.Runnable) } are prohibited and may lead to starvation.
80
     * 
81
     * @param doc document being exclusively locked. For non-editor document implementations
82
     * (currently <code>org.netbeans.editor.BaseDocument</code>) the implementation
83
     * synchronizes over the document and does not check for mutations within runExclusive().
84
     * @param r runnable to be performed. It is not allowed to mutate the document by any insertions or removals.
85
     * @throws IllegalStateException in case the given runnable wants to mutate the document.
86
     *
87
     * @since 1.56
88
     */
89
    public static void runExclusive(Document doc, Runnable r) {
90
        EditorDocumentHandler.runExclusive(doc, r);
91
    }
92
    
93
    
94
}
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/document/EditorDocumentHandler.java (+81 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.editor.lib2.document;
43
44
import javax.swing.text.Document;
45
46
/**
47
 * Performer of various document services implemented currently
48
 * by org.netbeans.editor.BaseDocument in editor.lib module.
49
 *
50
 * @author Miloslav Metelka
51
 */
52
public final class EditorDocumentHandler {
53
    
54
    private EditorDocumentHandler() {
55
        // no instances
56
    }
57
58
    public static Class editorDocClass;
59
    
60
    public static EditorDocumentServices editorDocServices;
61
    
62
    public static void setEditorDocumentServices(Class docClass, EditorDocumentServices docServices) {
63
        // Currently expect just a single implementation: BaseDocument
64
        if (editorDocClass != null) {
65
            throw new IllegalStateException("Only single registration expected. Already registered: " + editorDocClass);
66
        }
67
        EditorDocumentHandler.editorDocClass = docClass;
68
        EditorDocumentHandler.editorDocServices = docServices;
69
    }
70
    
71
    public static void runExclusive(Document doc, Runnable r) {
72
        if (doc.getClass() == editorDocClass) {
73
            editorDocServices.runExclusive(doc, r);
74
        } else {
75
            synchronized (doc) {
76
                r.run();
77
            }
78
        }
79
    }
80
    
81
}
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/document/EditorDocumentServices.java (+62 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.editor.lib2.document;
43
44
import javax.swing.text.Document;
45
46
/**
47
 * Various services for a document implementation
48
 * (currently only org.netbeans.editor.BaseDocument).
49
 * <br/>
50
 * This class together with EditorDocumentHandler allows an efficient
51
 * performing of methods from {@link org.netbeans.api.editor.document.EditorDocumentUtils}.
52
 *
53
 * @author Miloslav Metelka
54
 */
55
public interface EditorDocumentServices {
56
    
57
    /**
58
     * @see {@link org.netbeans.api.editor.document.EditorDocumentUtils#runExclusive(java.lang.Runnable)}.
59
     */
60
    void runExclusive(Document doc, Runnable r);
61
    
62
}

Return to bug 206907