Page 1 of 1

setEditable odd behavior

Posted: Sun May 31, 2015 9:25 pm
by sderrick
I set some documents as not editable.

When in Author mode if I try to edit the document a small popup displays saying
Cannot insert text in read only Context
, nice

When in text mode, our main editing mode, it does prevent editing but no popup? Can I enable that popup in text mode?

Re: setEditable odd behavior

Posted: Mon Jun 01, 2015 11:02 am
by alex_jitianu
Hello,

Unfortunately that message doesn't come from a common place. It is specific to the Author mode. You could use the API to present a similar message when the user edits in the text mode:

Code: Select all


		// Create the AuthorComponent
editorComponent = factory.createEditorComponentProvider(
new String[] {EditorPageConstants.PAGE_TEXT},
// The initial page
EditorPageConstants.PAGE_TEXT);


if (EditorPageConstants.PAGE_TEXT.equals(editorComponent.getWSEditorAccess().getCurrentPageID())) {
final WSXMLTextEditorPage page = (WSXMLTextEditorPage) editorComponent.getWSEditorAccess().getCurrentPage();
JTextComponent comp = (JTextComponent) page.getTextComponent();
comp.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
insertUpdate(e);
}
@Override
public void insertUpdate(DocumentEvent e) {
if (!page.isEditable()) {
// TODO Present a pop-up.
}
}
@Override
public void changedUpdate(DocumentEvent e) {
insertUpdate(e);
}
});
}
Best regards,
Alex

Re: setEditable odd behavior

Posted: Mon Jun 01, 2015 6:01 pm
by sderrick
I added the document listener.

Code: Select all

docListener = new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
System.out.println("removeUpdate");
insertUpdate(e);
}

@Override
public void insertUpdate(DocumentEvent e) {
System.out.println("insertUpdate");
if (!editable && EditorPageConstants.PAGE_TEXT.equals(editorComponent.getWSEditorAccess().getCurrentPageID())) {
JOptionPane.showMessageDialog(null, "Cannot insert text in read only Context!", "InfoBox: Text Insert", JOptionPane.INFORMATION_MESSAGE);
}
}

@Override
public void changedUpdate(DocumentEvent e) {
System.out.println("changedUpdate");
insertUpdate(e);
}
};

final WSTextEditorPage page = (WSTextEditorPage) editorComponent.getWSEditorAccess().getCurrentPage();
JTextComponent comp = (JTextComponent) page.getTextComponent();
comp.getDocument().addDocumentListener(docListener);
Unfortunately it is only called if the document is editable. Any document that has this function called

Code: Select all

((WSTextBasedEditorPage) page).setEditable(editableFlag);
where editableFlag == false

the listener is not called and no popup to let the user know they are trying to edit a read only document?

Re: setEditable odd behavior

Posted: Tue Jun 02, 2015 8:45 am
by alex_jitianu
Hello,

Ups! I'm sorry for sending you on a wild goose chase... You can try a KeyListener instead. I've tested such a listener and it receives events:

Code: Select all

JTextComponent comp = (JTextComponent) page.getTextComponent();
comp.addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent e) {
System.out.println("Key typed");
}
public void keyReleased(KeyEvent e) {}
public void keyPressed(KeyEvent e) {}
});
Best regards,
Alex

Re: setEditable odd behavior

Posted: Tue Jun 02, 2015 4:07 pm
by sderrick
Alex,

Excellent! I'll give it a go. No problem chasing gooses. I think sometimes I'm in the Goose manufacturing business!

Thanks for all the great help. Your tech support is unsurpassed.

Scott

Re: setEditable odd behavior

Posted: Fri Dec 18, 2015 2:35 pm
by Radu
Hi,

Just to update this thread, in Oxygen 17.1 trying to edit in the Text editing mode with a read-only document should result in an error tooltip shown to the user.

Regards,
Radu

Re: setEditable odd behavior

Posted: Fri Dec 18, 2015 6:37 pm
by sderrick
great news and good work.. :D