Search in sources :

Example 1 with CorpusSet

use of org.corpus_tools.annis.gui.CorpusSet in project ANNIS by korpling.

the class CorpusListPanel method attach.

@Override
public void attach() {
    super.attach();
    // Get the initial corpus list, this must become before the binder is set,
    // to make sure any selected value is also an item.
    CorporaApi api = new CorporaApi(Helper.getClient(ui));
    try {
        List<String> corpora = api.listCorpora();
        availableCorpora = new ListDataProvider<>(corpora);
        availableCorpora.setFilter(filter);
        tblCorpora.setDataProvider(availableCorpora);
        if (ui.getInstanceConfig() != null && ui.getInstanceConfig().getCorpusSets() != null) {
            TreeSet<String> corpusSetNames = new TreeSet<>(ui.getInstanceConfig().getCorpusSets().stream().map(CorpusSet::getName).collect(Collectors.toList()));
            cbSelection.setItems(corpusSetNames);
            if (ui.getInstanceConfig().getDefaultCorpusSet() != null && !ui.getInstanceConfig().getDefaultCorpusSet().isEmpty()) {
                cbSelection.setSelectedItem(ui.getInstanceConfig().getDefaultCorpusSet());
            }
        }
        if (corpora.isEmpty() && Helper.getUser(ui.getSecurityContext()).isPresent()) {
            Notification.show("No corpora found. Please login " + "(use button at upper right corner) to see more corpora.", Notification.Type.HUMANIZED_MESSAGE);
        }
    } catch (ApiException e) {
        ExceptionDialog.show(e, "Coould not get corpus list", getUI());
    }
    Binder<QueryUIState> binder = new Binder<>();
    MultiSelect<String> corpusSelection = tblCorpora.asMultiSelect();
    binder.forField(corpusSelection).bind(QueryUIState::getSelectedCorpora, QueryUIState::setSelectedCorpora);
    binder.setBean(ui.getQueryState());
    binder.addValueChangeListener(event -> {
        Set<String> selectedCorpora = new HashSet<>(ui.getQueryState().getSelectedCorpora());
        autoGenQueries.setSelectedCorpusInBackground(selectedCorpora);
        ui.getQueryController().corpusSelectionChangedInBackground();
        // trigger a resort
        tblCorpora.clearSortOrder();
        tblCorpora.setSortOrder(new GridSortOrderBuilder<String>().thenDesc(selectedColumn).thenAsc(nameColumn).build());
        tblCorpora.scrollTo(0);
    });
    IDGenerator.assignIDForFields(CorpusListPanel.this, tblCorpora, txtFilter);
}
Also used : CorporaApi(org.corpus_tools.annis.api.CorporaApi) CorpusSet(org.corpus_tools.annis.gui.CorpusSet) GridSortOrderBuilder(com.vaadin.data.provider.GridSortOrderBuilder) Binder(com.vaadin.data.Binder) QueryUIState(org.corpus_tools.annis.gui.objects.QueryUIState) TreeSet(java.util.TreeSet) ApiException(org.corpus_tools.annis.ApiException) HashSet(java.util.HashSet)

Aggregations

Binder (com.vaadin.data.Binder)1 GridSortOrderBuilder (com.vaadin.data.provider.GridSortOrderBuilder)1 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 ApiException (org.corpus_tools.annis.ApiException)1 CorporaApi (org.corpus_tools.annis.api.CorporaApi)1 CorpusSet (org.corpus_tools.annis.gui.CorpusSet)1 QueryUIState (org.corpus_tools.annis.gui.objects.QueryUIState)1