Customizing a button bar via java

LabKey Support Forum (Inactive)
Customizing a button bar via java Matt V  2017-09-01 11:28
Status: Closed
 
I'm trying to customize a button bar for my site's datasets using a java customizer. I've added that definition to each dataset's query.xml: <javaCustomizer>org.labkey.bcc.query.MyCustomizer</javaCustomizer>. The goal is to hide and/or rename some of the standard buttons. However, when I getItems() from the buttonBarConfig, the standard buttons are not returned. I can see them in the ButtonBar class when debugging the site and loading a dataset page. That is, _elementList seems to have all the standard buttons in debug, but that version of _elementList isn't what's returned in my customizer.

A stripped down version of the code with some things I was trying looks like:

public class MyCustomizer extends AbstractTableCustomizer
{
     if (ti instanceof AbstractTableInfo)
        {
            AbstractTableInfo ati = (AbstractTableInfo)ti;

            customizeButtonBar(ati);
        }
    }
    private void customizeButtonBar(AbstractTableInfo ti) {
        ButtonBarConfig buttonBarCfg = ti.getButtonBarConfig();
        buttonBarCfg.setIncludeStandardButtons(false);

        Set<String> hiddenStandardButtons = buttonBarCfg.getHiddenStandardButtons();

        List<ButtonConfig> buttons = buttonBarCfg.getItems();
        List<ButtonConfigFactory> queryButtons = LDKService.get().getQueryButtons(ti);

        buttonBarCfg.setItems(buttons);
        ti.setButtonBarConfig(buttonBarCfg);
    }
}

Due to the large number of datasets, I'm hesitant to rely on XML customizations. Any change would have to be repeated across a significant number of files. It's easier and more sustainable to add the customizer to each query when adding new datasets and then control the button configs in a single java class.

Is there a way outside of the XML that I can achieve this without modifying the labkey core code?
Alternatively, is there a way to use XInclude (https://www.xml.com/pub/a/2002/07/31/xinclude.html) to import the buttonbarconfig from another xml file? Tried that as well to no avail.

Thanks!
 
 
Jon (LabKey DevOps) responded:  2017-09-01 14:13
Hi Matt,

You should be able to override and extend the existing ButtonBarConfig via Java and put it in a class of your own in your own module and you wouldn't have to modify core labkey code to do it.. The DefaultEHRCustomizer.java that is used in conjunction with the ONPRC_EHR module appears to do exactly this.

Regarding XInclude, it doesn't appear that we hook into this since it's not apart of XML1.0 or the XML infoset, but it does look very intriguing.

Let me pass this onto our developers for future consideration. I'm not sure how far the extensibility would go, but it would be worth having them look into it further.

Regards,

Jon
 
Matt V responded:  2017-09-12 10:56
Hey Jon,
Thanks for the reply. I've been poking around and am not seeing a way to modify the standard buttons, just some additional ones.

For example, after enabling the standard buttons via:
  cfg.setIncludeStandardButtons(true);

the getItems call:
  List<ButtonConfig> existingBtns = cfg.getItems();

doesn't list things like insert, print, export, qc state, etc. Tried digging further into what
  List<ButtonConfigFactory> buttons = EHRService.get().getTbarButtons(ti);
but that doesn't seem to be it either.

Best I can tell, the standard buttons are added after this customizer runs so I can't actually modify them.

It's entirely possible I'm missing something here. Any suggestions?
 
Jon (LabKey DevOps) responded:  2017-09-18 14:00
Hi Matt,

You are right, we don't create the buttons until very late. During the rendering phase, we merge the built-in buttons and the button configurations together in the ButtonBar.setConfigs() function.

You could modify the built-in buttons by including the button item you would want to use to the name of the button you'd like to override, such as the "Insert New" button.

Please note that we don't have a good way of applying customizations across many tables with the way the current design of the system. We would have to extend the functionality of our UserSchemaCustomizer to work with all schemas rather than just linked and external ones, but that would require some development resources to get that done. If you are interested in getting onto a development contract/work order, please let us know and we'll be glad to explore this option with you.

Regards,

Jon