Page 1 of 1

Disabling editing within the editor??

Posted: Thu May 21, 2015 5:23 pm
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

Re: Disabling editing within the editor??

Posted: Fri May 22, 2015 1:23 am
by sderrick
I was hoping for a quick easy solution?

Is there none?

Scott

Re: Disabling editing within the editor??

Posted: Fri May 22, 2015 8:46 am
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

Re: Disabling editing within the editor??

Posted: Fri May 22, 2015 6:21 pm
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

Re: Disabling editing within the editor??

Posted: Mon May 25, 2015 10:30 am
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

Re: Disabling editing within the editor??

Posted: Mon May 25, 2015 3:34 pm
by sderrick
Ah, good call on the listener to catch the text to author mode.

thanks,

Scott

Re: Disabling editing within the editor??

Posted: Mon May 25, 2015 3:39 pm
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

Re: Disabling editing within the editor??

Posted: Thu May 05, 2016 9:36 am
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