Load programmatically alternative CSS

Post here questions and problems related to oXygen frameworks/document types.
Johann
Posts: 62

Load programmatically alternative CSS

Wed Sep 07, 2016 3:39 pm

Hello everyone,

In the last version of the oxygen SDK, is there a way to load programmatically an alternative CSS ?

My document has two CSS, a "normal" one and a "light" one. The light one is used to increase performance (indeed, with the "normal" one, the refresh of the page can take more than 30 seconds whereas with the "light" one it only takes 2 seconds).

So, for some actions, I would like to switch between these CSS "programmatically". I know there is the "CSSAlternativesToolbar" but I do not want the user to switch between the CSS.

Thanks for your help,

Johann
Radu
Posts: 5376

Re: Load programmatically alternative CSS

Thu Sep 08, 2016 8:13 am

Hi Johann,

We do not have such API but we do have some plans for it so I added your feedback to the opened issue. I will update this thread when the issue is fixed.

As workarounds:

1) If your actions make multiple insertions and deletions in the document, we have special APIs which accelerate multiple changes:

AuthorDocumentController.multipleDelete(AuthorElement, int[], int[])

and:

AuthorDocumentController.insertMultipleFragments(AuthorElement, AuthorDocumentFragment[], int[])

So calling such APIs would be much faster than repeatedly inserting/deleting XML in various places. We use this API ourselves to insert table columns for example.

2) You can set a custom pseudo class on the root element:

authorDocumentController.setPseudoClass("fast", authorDocumentController.getAuthorDocumentNode().getRootElement());

and you can have special CSS selectors matching on this pseudo class which will get triggered like:

Code: Select all

::root:fast para {
  content: "";
}

and then remove the pseudo class at the end so that the specific selectors no longer match.

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

Re: Load programmatically alternative CSS

Fri Sep 09, 2016 6:27 pm

Hi Radu,

In fact, even the refresh takes a long time on the document without performing any action...
In using pseudo class before opening my document (as you suggested), I have a "reasonable" refresh.

Thanks for your workaround,

Johann
Radu
Posts: 5376

Re: Load programmatically alternative CSS

Mon Sep 12, 2016 9:04 am

Hi Johann,

My colleague Alex reminded me of two API methods which here added in 17.0:

Code: Select all

ro.sync.ecss.extensions.api.AuthorDocumentController.disableLayoutUpdate()


and:

Code: Select all

 ro.sync.ecss.extensions.api.AuthorDocumentController.enableLayoutUpdate(AuthorNode)


Basically if you call the disable layout update, then call our API to make changes, and then enable layout update you might not need any more the pseudo class approach. You need to call "enableLayoutUpdate" in a try{}finally block so that it is always executed no matter of what exceptions your code throws.

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

Re: Load programmatically alternative CSS

Mon Sep 12, 2016 11:41 am

Hi Radu,

I've just tested these two methods like this :

Code: Select all

try {
   authorDocumentController.disableLayoutUpdate();
   new InsertOrReplaceFragmentOperation().doOperation(authorAccess, argumentsMap);
} catch (Exception e) {
   LOGGER.error(e.getMessage());
} finally {
   authorDocumentController.enableLayoutUpdate(null);
}


Because I added

Code: Select all

authorDocumentController.disableLayoutUpdate();


I get this error on the InsertOrReplaceFragmentOperation :

Code: Select all

javax.swing.text.BadLocationException: Offset must be between 0 and 86 but was 18195


and the operation is not well performed.

Johann
alex_jitianu
Posts: 624

Re: Load programmatically alternative CSS

Tue Sep 13, 2016 12:27 pm

Hi Johann,

Thank you for reporting this issue. It looks like when you disable the layout events, as an undesired side effect, the selection model and caret also remain stale. I will add an issue to resolve this problem. Meanwhile, if you still want to use disableLayoutUpdate() you'll have to directly use our API and make sure that you do not rely on the selection model once the update sequence begins.

Best regards,
Alex

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

Who is online

Users browsing this forum: No registered users and 0 guests