Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Generic Editor - Read Only?(Is there a way to make the generic editor read-only?)
Generic Editor - Read Only? [message #1837521] Mon, 01 February 2021 15:36 Go to next message
Tobias Haf is currently offline Tobias HafFriend
Messages: 5
Registered: July 2009
Junior Member
I'm currently switching from dedicated editor instances to the extension based generic editor. Since I want to prevent that the user is able to edit the shown files I override getEditable() in my custom editor instances to return always false.
Is there a way with the generic editor to make the editor read-only as well?

Thanks!
Re: Generic Editor - Read Only? [message #1837917 is a reply to message #1837521] Wed, 10 February 2021 13:39 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

Generic Editor is a text editor/text viewer/styledtext widget combination similar to any other TextEditor. So usual ways to mark a Text Editor as readonly should apply. If not, it can be a bug and should be reported.
Re: Generic Editor - Read Only? [message #1837927 is a reply to message #1837917] Wed, 10 February 2021 20:56 Go to previous messageGo to next message
Tobias Haf is currently offline Tobias HafFriend
Messages: 5
Registered: July 2009
Junior Member
Thanks for your reply! What is a "usual way"? The way I used with my dedicated Editor (override getEditable()) is not working since there's noting I could put that code into, right? All I have is a plugin.xml and the various exensions aka presentation reconcilers and hyperlink detectors... :-)

Thanks!
Re: Generic Editor - Read Only? [message #1837928 is a reply to message #1837927] Wed, 10 February 2021 21:05 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

Although it's not very elegant, you can probably try to tweak one of your reconcilers so that on `install(...)` it invokes `viewer.getTextWidget().setEditble(false)`
Re: Generic Editor - Read Only? [message #1837929 is a reply to message #1837928] Wed, 10 February 2021 21:06 Go to previous messageGo to next message
Tobias Haf is currently offline Tobias HafFriend
Messages: 5
Registered: July 2009
Junior Member
I see, will try that, thanks a lot!
Re: Generic Editor - Read Only? [message #1838110 is a reply to message #1837929] Tue, 16 February 2021 09:06 Go to previous messageGo to next message
Tobias Haf is currently offline Tobias HafFriend
Messages: 5
Registered: July 2009
Junior Member
Sadly this does not work sinceorg.eclipse.ui.texteditor.AbstractTextEditor.isEditable() is called after my PresentationReconciler is installed.

@Override
public boolean isEditable() {
	IDocumentProvider provider= getDocumentProvider();
	if (provider instanceof IDocumentProviderExtension) {
		IDocumentProviderExtension extension= (IDocumentProviderExtension) provider;
		return extension.isModifiable(getEditorInput());
	}
	return false;
}


Based on the implementation above I need a way to hook into the document provider extension. Any ideas how to do that?

Thanks in advance for any support!
Re: Generic Editor - Read Only? [message #1838133 is a reply to message #1838110] Wed, 17 February 2021 08:20 Go to previous messageGo to next message
Tobias Haf is currently offline Tobias HafFriend
Messages: 5
Registered: July 2009
Junior Member
Okay, I found a solution, by using my own IDocumentProvider for the extensions I use the generic editor for:

public class MyDocumentProvider extends TextFileDocumentProvider {
	
	@Override
	public boolean isModifiable(final @Nullable Object element) {
		return false;
	}	
}


<extension
       point="org.eclipse.ui.editors.documentProviders">
    <provider
          class="com.example.MyDocumentProvider"
          extensions="foo"
          id="myplugin.provider1">
    </provider>
 </extension>


Sadly I have to maintain the extensions now in two places. The content types registered for the generic editor and in the document provider extension. Or is it possible to reference a content type there, too?
Re: Generic Editor - Read Only? [message #1838134 is a reply to message #1838133] Wed, 17 February 2021 08:39 Go to previous message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

Didn't you find a way to invoke viewer.getTextWidget().setEditable(false) ?

Having document provider attached to content-types would be great. Please open an enhancement request to Eclipse Platform via bugs.eclipse.org about that.
Previous Topic:Possible Eclipse Bug??
Next Topic:Anti aliasing font in editor
Goto Forum:
  


Current Time: Tue Apr 23 10:05:41 GMT 2024

Powered by FUDForum. Page generated in 0.03944 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top