setEditable odd behavior

Post here questions and problems related to oXygen frameworks/document types.
sderrick
Posts: 210

setEditable odd behavior

Sun May 31, 2015 9:25 pm

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?
alex_jitianu
Posts: 604

Re: setEditable odd behavior

Mon Jun 01, 2015 11:02 am

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
sderrick
Posts: 210

Re: setEditable odd behavior

Mon Jun 01, 2015 6:01 pm

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?
alex_jitianu
Posts: 604

Re: setEditable odd behavior

Tue Jun 02, 2015 8:45 am

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
sderrick
Posts: 210

Re: setEditable odd behavior

Tue Jun 02, 2015 4:07 pm

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
Radu
Posts: 5224

Re: setEditable odd behavior

Fri Dec 18, 2015 2:35 pm

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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
sderrick
Posts: 210

Re: setEditable odd behavior

Fri Dec 18, 2015 6:37 pm

great news and good work.. :D

Return to “SDK-API, Frameworks - Document Types”

Who is online

Users browsing this forum: No registered users and 2 guests