|
org.netbeans.modules.editor.guards/0 0.1 | |||||||||
PREV NEXT | FRAMES NO FRAMES |
See:
Description
Editor Guarded Sections | |
---|---|
org.netbeans.api.editor.guards | |
org.netbeans.spi.editor.guards | |
org.netbeans.spi.editor.guards.support |
GuardedSectionsAPI
The Guarded Sections module is supposed to operate over the Swing's StyledDocument
.
It allows clients to manipulate named guarded sections that prevents user to
modify the content. So if you like to create, modify or delete guarded sections the
GuardedSectionManager
is the best place where to start.
GuardedSectionsSPI
The module also allows to implement custom guarded section persistance in various content types like java, xml, ...
The easiest way is to subclass
AbstractGuardedSectionsProvider
.
In order to bind guarded sections to your editor see
GuardedSectionsFactory
.
String sectionName = ...; StyledDocument doc = ...; GuardedSectionManager guards = GuardedSectionManager.getInstance(doc); GuardedSection g = guards.findSimpleSection(sectionName); guards.createSimpleSection("new_name", doc.createPosition(g.getEndPosition().getOffset() + 1));
StyledDocument doc = ...; GuardedSectionManager guards = GuardedSectionManager.getInstance(doc); GuardedSection g = guards.findSimpleSection("sectionName"); g.deleteSection();
CloneableEditorSupport
to provide
guarded sections you should implement the GuardedEditorSupport
interface.
private final class MyGuardedEditor implements GuardedEditorSupport { ... }Further implement reading and writing of existing sections.
protected void loadFromStreamToKit(StyledDocument doc, InputStream stream, EditorKit kit) throws IOException, BadLocationException { if (guardedEditor == null) { guardedEditor = new MyGuardedEditor(); // remember the provider String mimeType = ((CloneableEditorSupport.Env) this.env).getMimeType(); guardedProvider = GuardedSectionsFactory.find(mimeType).create(guardedEditor); } // load content to kit if (guardedProvider != null) { guardedEditor.setDocument(doc); Reader reader = guardedProvider.createGuardedReader(stream, "your encoding"); try { kit.read(reader, doc, 0); } finally { reader.close(); } } else { kit.read(stream, doc, 0); } } protected void saveFromKitToStream(StyledDocument doc, EditorKit kit, OutputStream stream) throws IOException, BadLocationException { if (guardedProvider != null) { Writer writer = guardedProvider.createGuardedWriter(stream, null); try { kit.write(writer, doc, 0, doc.getLength()); } finally { writer.close(); } } else { kit.write(stream, doc, 0, doc.getLength()); } }Your module should also require a proper implementation. In case of java content add to your module manifest file:
OpenIDE-Module-Requires: org.netbeans.api.editor.guards.Java
|
|
|
The sources for the module are in NetBeans CVS in editor/guards directory.
A module using the Guarded Sections API should also require a proper implementation. Eg in case of java content add to your module manifest file:
OpenIDE-Module-Requires: org.netbeans.api.editor.guards.Java
A module implementing the Guarded Sections SPI should provide a token in the manifest file. Eg in case of java content add:
OpenIDE-Module-Provides: org.netbeans.api.editor.guards.Java
Read more about the implementation in the answers to architecture questions.
|
org.netbeans.modules.editor.guards/0 0.1 | |||||||||
PREV NEXT | FRAMES NO FRAMES |