mini refresh on set/remove pseudoclass?

Questions about XML that are not covered by the other forums should go here.
fjeneau
Posts: 4
Joined: Thu Sep 24, 2020 8:20 pm

mini refresh on set/remove pseudoclass?

Post by fjeneau » Thu Apr 01, 2021 1:41 am

Hi,

I have a class that shows/hides tags based on whether or not a pseudoclass is applied to the root.
...
private static final String PSEUDOCLASS = "show-all-data";
...
doOperation...
AuthorElement root = adc.getAuthorDocumentNode().getRootElement();
boolean dataShown = root.hasPseudoClass(PSEUDOCLASS);


Show/hide is done via element.setPseudoClass(PSEUDOCLASS) and element.removePseudoClass(PSEUDOCLASS).

The issue is that these tags do not show/hide unless I do a full page refresh via authorAccess.getEditorAccess().refresh().

Is there a way to refresh at the element level or refresh only on the inserted fragment or am I missing a method that redraws just psuedoclasses?

Radu
Posts: 7437
Joined: Fri Jul 09, 2004 5:18 pm

Re: mini refresh on set/remove pseudoclass?

Post by Radu » Thu Apr 01, 2021 8:48 am

Hi,

You should toggle the pseudo class using the AuthorDocumentController API:

Code: Select all

adc.setPseudoClass(String, AuthorElement)
because it also takes care of triggering the appropriate listeners which update the UI.

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

fjeneau
Posts: 4
Joined: Thu Sep 24, 2020 8:20 pm

Re: mini refresh on set/remove pseudoclass?

Post by fjeneau » Thu Apr 01, 2021 5:43 pm

Thanks -- this worked.

The note on WSAuthorEditorPageBase -> refresh(AuthorNode authorNode), "Note: This should be called on the AWT thread because it will generate a layout event," can I assume that adc.setPseudoClass(String, AuthorElement) does that?

Radu
Posts: 7437
Joined: Fri Jul 09, 2004 5:18 pm

Re: mini refresh on set/remove pseudoclass?

Post by Radu » Fri Apr 02, 2021 9:55 am

Hi,

Most of our API is not thread safe. So if you have started a separate thread and want to use our API you can do something like:

Code: Select all

    Runnable runnable = new Runnable() {
      
      @Override
      public void run() {
        //Work with API here.
      }
    };
    if(! SwingUtilities.isEventDispatchThread()) {
      SwingUtilities.invokeAndWait(runnable);
    } else {
      runnable.run();
    }
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Post Reply