Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jdt-ui-dev] making the document read-only in javaEditor

I posted this earlier in eclipse.tools.jdt, but did not get a reply so I hope someone here can help me..

---------//---------

something like this has been in discussion twice in this newsgroup but still I see no solutions yet. Here are the details...

#problem: Using the Java Editor (CompilationUnitEditor), how to make certain parts inside the editor read only ?

#issues:

i am still figuring out what is the right way to do this. First approach that works is defining a collection of Positions for the document (source) being edited, track the cursor within these positions and once the cursor is inside the position, disable editing in the editor (in StyledText from the CompilationUnitEditor)

the problem with the above is it cannot bypass the Key bindings for quick edit like Ctrl+E for deleting the line (and when the selected text is not the whole line but only some text in a line), for that i'll have to track whether the positions to be protected are in the line that'll be removed. This seems bit inelegant. And, is there a way to iterate all
possible edits that can be made in the document excluding those that
are made by directly manipulating the text?

a quick search in eclipse's dev newsgroup points to two things

- *make the File readonly*: I tried this (calling setReadOnly(true) for the File) but, this again has the problem of locking up the document is a sense that it cannot be made writable again w/o closing and reopening the file

- *make the Document readonly*: i still have not found the way to do this. here, I am refereing to the 'Document' instance returned by the DocumentProvider of the editor. I actually do not see the the Document class and its parent/childs in the tree have any operations that support making the document read only. So I am still wandering what does it mean to say make the Document read-only (read this as an option in the newsgroup and lost the link). i can think of listening to the IDocumentListener so that I can get inside the pre change method and cancel the change to be performed, something like -

documentAboutToBeChanged(DocumentEvent event)
 {..I want to cancel this change request here..}

but this doesnot seem to be possible.

I am quite lost now.

i would appreciate any pointer to the right direction regarding this.

- sushil

--
Sushil Krishna Bajracharya
Department of Informatics
Bren School of ICS, UCI

http://www.ics.uci.edu/~sbajrach

Back to the top