Disabling editing within the editor??

Post here questions and problems related to oXygen frameworks/document types.
sderrick
Posts: 264
Joined: Sat Jul 10, 2010 4:03 pm

Disabling editing within the editor??

Post by sderrick »

I'm setting up the applet to have a tabbed interface. Enabling the user to open multiple documents at the same time. Each tab has its own editor instance. This is working fine.

Some of the documents the user can open are for reference only and should not be edited. I can of course not allow them to be saved but it would be more user friendly and understandable to the user if the editor refused any attempt to change the text in these "read-only" documents.

I tried

Code: Select all

editor.setEnabled(false); 
where I instantiate the editor and set it up for insertion into a jTabbedPane, but this doesn't seem to have any effect?

Code: Select all

mbepEditor editor = new mbepEditor(factory, true, true, true, true);
editor.setBorder(BorderFactory.createEmptyBorder(15, 0, 0, 0));
editor.setVisibleSideView("outline", true);
editor.setVisibleSideView("attributes", true);
editor.setVisibleSideView("elements", true);
editor.setVisibleSideView("review", false);
editor.setVisibleSideView("validationProblems", false);
editor.setDocumentContent(fullPath, content);
editor.setUserID(userID);
if(url.contains("working_files"))
editor.setEnabled(false);
what am I doing wrong?

Scott
sderrick
Posts: 264
Joined: Sat Jul 10, 2010 4:03 pm

Re: Disabling editing within the editor??

Post by sderrick »

I was hoping for a quick easy solution?

Is there none?

Scott
Radu
Posts: 9053
Joined: Fri Jul 09, 2004 5:18 pm

Re: Disabling editing within the editor??

Post by Radu »

Hi Scott,

In your case the mbepEditor is a kind of JPanel, right? Disabling a Swing JPanel does not disable all components inside it. And even if you would recursively disable all descendants, there would still be the toolbar actions which can make modifications to the document.

An opened editor EditorComponentProvider.getWSEditorAccess() can have multiple pages.
The Text and Author pages both implement the WSTextBasedEditorPage interface which has the method:

Code: Select all

  /**
* Sets the specified flag to indicate whether or not this page should be editable.
*
* @param editable <code>true</code> if the page should be editable.
*
* @since 12.2
*/
public void setEditable(boolean editable);

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
sderrick
Posts: 264
Joined: Sat Jul 10, 2010 4:03 pm

Re: Disabling editing within the editor??

Post by sderrick »

Radu,

Hopefully I'm doing multiple editors correctly? I took this from the FAQ.
7, Does the XML Author component support multiple documents being open simultaneously? What are the licensing ramifications?

A single AuthorComponentFactory instance can create multiple EditorComponentProvider editors which can then be added and managed by the developer who is customizing the component in a Swing JTabbedPane. A single license (floating or user-based) is enough for this.
I create a mbepTabbedView which extends a JPanel. This view has a final member of type AuthorComponentFactory,

Code: Select all

factory = AuthorComponentFactory.getInstance();  
When I add a tab, or document to be edited, I create an mbepEditor which extends a JPane, this uses the views factory to create a editorComponentProvider

Code: Select all

editorComponent = factory.createEditorComponentProvider(
new String[]{EditorPageConstants.PAGE_AUTHOR, EditorPageConstants.PAGE_TEXT},
// The page
EditorPageConstants.PAGE_TEXT);
for each document. The mbepEditor is inserted into the JTabbedPane.

So each editorComponent edits a single document and the JTabbedPanet handles the tabs... Which I thought was what the FAQ hinted at?

Scott
Radu
Posts: 9053
Joined: Fri Jul 09, 2004 5:18 pm

Re: Disabling editing within the editor??

Post by Radu »

Hi Scott,

That looks OK. So after you load XML content in an editorComponent, you can call:

Code: Select all

((WSTextBasedEditorPage)editorComponent.getWSEditorAccess().getCurrentPage()).setEditable(false);
You should also add a page changed listener:

Code: Select all

editorComponent.getWSEditorAccess().addPageChangedListener(pageChangedListener);
and again disable the selected page after the user changes from Text to Author or the other way around.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
sderrick
Posts: 264
Joined: Sat Jul 10, 2010 4:03 pm

Re: Disabling editing within the editor??

Post by sderrick »

Ah, good call on the listener to catch the text to author mode.

thanks,

Scott
Radu
Posts: 9053
Joined: Fri Jul 09, 2004 5:18 pm

Re: Disabling editing within the editor??

Post by Radu »

Hi Scott,

Ideally in one of our future version we'll update our API to add this method:

Code: Select all

editorComponent.getWSEditorAccess().setEditable(false)
instead of having to disable editing in each editing page which is quite convoluted.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Radu
Posts: 9053
Joined: Fri Jul 09, 2004 5:18 pm

Re: Disabling editing within the editor??

Post by Radu »

Hi,

Just to update this thread, Oxygen 18.0 should have that new API which disables editing in all editor pages that I previously discussed.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply