Modify dialog warning message

Post here questions and problems related to oXygen frameworks/document types.
damarislc
Posts: 5

Modify dialog warning message

Wed Sep 12, 2018 12:35 am

Hello,

I'm modifying the filteredElements to delete a task child element when trying to insert into a task topic context (as well for a reference and a concept) as follow:

Code: Select all

public List<CIElement> filterElements(final List<CIElement> elements,
      final WhatElementsCanGoHereContext context) {

    List<CIElement> filteredElements = super.filterElements(elements, context);

    if ((context != null) && (filteredElements != null)) {
      Stack<ContextElement> elementStack = context.getElementStack();
      if(elementStack != null) {
        ContextElement contextElement = context.getElementStack().peek();
        String contextName = contextElement.getQName();
        //compare with the topic element
        if(TOPIC_ELEMENTS.contains(contextName)) {
          for(Iterator<CIElement> iterator = filteredElements.iterator(); iterator.hasNext();) {
            CIElement element = iterator.next();
            //remove invalid element
            if(contextName.equals(element.getQName()))
            {
              filteredElements.remove(element);
              break;
            }
          }
        }
      }
    }
    return filteredElements;
  }


It is working fine, it doesn't allow me to introduce an invalid child for the topic in the Author mode and I'm getting the following message when attempt to do it:
Image

I need to edit that dialog to send a custom message, how can I do it?
Radu
Posts: 5813

Re: Modify dialog warning message

Wed Sep 12, 2018 9:25 am

Hi,

We do not have API to allow the interception of any error message issued by the application.
How exactly do you attempt to insert the task node when the dialog pops up? Copy paste?

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
damarislc
Posts: 5

Re: Modify dialog warning message

Wed Sep 12, 2018 6:12 pm

No, actually, this code is to avoid that user can insert a task as a child of a topic task, and should show the message "A task topic cannot have an embedded <task> element"
Radu
Posts: 5813

Re: Modify dialog warning message

Thu Sep 13, 2018 8:05 am

Hi,

I would like to know how the end user tries to insert that task. They cannot use the content completion window because you've already removed that choice for them. So are they using a toolbar action? If so, maybe you can remove that particular toolbar button.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
damarislc
Posts: 5

Re: Modify dialog warning message

Thu Sep 13, 2018 6:27 pm

Hi,

They will try to insert a task as follows:

1. In a task topic context:
Image

2. They will type or search for the task element:
Image

If they try to insert the task, the error dialog message will be prompt.

If its not possible to change the message of the UI, is it a way to show a ISO Schematron message when the error is catch?
Radu
Posts: 5813

Re: Modify dialog warning message

Fri Sep 14, 2018 9:56 am

Hi,

Thanks for the extra details.

Here are two possibilities to work around this:

1) In the Oxygen Preferences->"Editor / Edit Modes / Author / Schema-Aware" page there is a checkbox called "Show all possible elements in the content completion window". Unchecking it should no longer display the "task" element in the content completion list.
There are some possibilities to share application settings with others:

https://www.oxygenxml.com/doc/versions/20.1/ug-editor/topics/sharing-possibilities.html#sharing-possibilities

2) Using Java API: f you edit your custom document type configuration in the Oxygen Preferences->"Document Type Associations" page, in the Extensions tab one of those extensions is a "Author Extension state listener":

https://www.oxygenxml.com/doc/versions/20.1/ug-editor/topics/dg-author-extension-state-listener.html

You can implement the interface something like:

Code: Select all

  /**
   * @see ro.sync.ecss.extensions.api.AuthorExtensionStateListener#activated(ro.sync.ecss.extensions.api.AuthorAccess)
   */
  @Override
  public void activated(final AuthorAccess authorAccess) {
    authorAccess.getDocumentController().setDocumentFilter(new AuthorDocumentFilter() {
      /**
       * @see ro.sync.ecss.extensions.api.AuthorDocumentFilter#insertFragment(ro.sync.ecss.extensions.api.AuthorDocumentFilterBypass, int, ro.sync.ecss.extensions.api.node.AuthorDocumentFragment)
       */
      @Override
      public void insertFragment(AuthorDocumentFilterBypass filterBypass, int offset,
          AuthorDocumentFragment frag) {
        //Here you can look at the nodes inside the fragment and you have a chance to show your dialog and avoid calling the super implementation.
        super.insertFragment(filterBypass, offset, frag);
      }
    });
  }


That "insertFragment" callback should arrive in your code before Oxygen does the default behavior. The AuthorDocumentFragment has enough information inside it to know what will be inserted so sometimes you may reject the insertion (no longer calling the super implementation) and instead show your own dialog.

About this remark you had:

If its not possible to change the message of the UI, is it a way to show a ISO Schematron message when the error is catch?


Indeed you can also create a Schematron schema which will present a validation error when tasks are embedded inside each other. But all validation errors are signaled after the content has been changed and they are not shown in a modal dialog, they are shown as red highlights in the editor area.
But in general having Schematron rules (and quick fixes) for various project related checks are a very good idea. Some blog post links to show you what can be done and how you can share the rules in your framework configuration:

http://blog.oxygenxml.com/2015/05/schematron-checks-to-help-technical.html

http://blog.oxygenxml.com/2017/02/sharing-schematron-validation-rules.html

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

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

Who is online

Users browsing this forum: No registered users and 2 guests