Page 1 of 1

Modify dialog warning message

Posted: Wed Sep 12, 2018 12:35 am
by damarislc
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?

Re: Modify dialog warning message

Posted: Wed Sep 12, 2018 9:25 am
by Radu
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

Re: Modify dialog warning message

Posted: Wed Sep 12, 2018 6:12 pm
by damarislc
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"

Re: Modify dialog warning message

Posted: Thu Sep 13, 2018 8:05 am
by Radu
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

Re: Modify dialog warning message

Posted: Thu Sep 13, 2018 6:27 pm
by damarislc
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?

Re: Modify dialog warning message

Posted: Fri Sep 14, 2018 9:56 am
by Radu
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/ ... sibilities

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/ ... tener.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/schem ... nical.html

http://blog.oxygenxml.com/2017/02/shari ... rules.html

Regards,
Radu