<commit_before>/*
 * Copyright (C) 2013 The Language Archive, Max Planck Institute for Psycholinguistics
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package nl.mpi.yaas.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.mpi.flap.model.DataNodeLink;
import nl.mpi.flap.model.ModelException;
import static nl.mpi.yaas.client.YaasTreeItem.FAILURE;
import nl.mpi.yaas.common.data.DataNodeId;
import nl.mpi.yaas.common.data.HighlighableDataNode;
import nl.mpi.yaas.common.data.IconTableBase64;

/**
 * @since Feb 06, 2014 11:37 AM (creation date)
 * @author <NAME> <<EMAIL>>
 */
public class ResultsPanel extends TabPanel implements HistoryListener {

    private static final Logger logger = Logger.getLogger("");
    private final DataNodeTable dataNodeTable;
    private final SearchOptionsServiceAsync searchOptionsService;
    private final HistoryController historyController;
    private IconTableBase64 iconTableBase64;
//    final String lastDatabaseName;
    private DataNodeTree dataNodeTree;

    public ResultsPanel(final DataNodeTable dataNodeTable, SearchOptionsServiceAsync searchOptionsService, HistoryController historyController) {
        this.dataNodeTable = dataNodeTable;
        this.searchOptionsService = searchOptionsService;
        this.historyController = historyController;
        this.setVisible(false);
    }

    public void historyChange() {
//        final String databaseName = historyController.getDatabaseName();
//        if (databaseName != null&& !lastDatabaseName.equals(databaseName)) {
//            RootPanel.get("searchOptionsPanel").add(loadingImage);
//            searchOptionsService.getImageDataForTypes(databaseName, new AsyncCallback<IconTableBase64>() {
//                public void onFailure(Throwable caught) {
//                    RootPanel.get("searchOptionsPanel").add(new Label(NO__DATABASE__SELECTED));
//                    RootPanel.get("searchOptionsPanel").remove(loadingImage);
//                }
//
//                public void onSuccess(IconTableBase64 result) {
//
//                }
//            });
//        }
    }

    public void setIconTableBase64(IconTableBase64 iconTableBase64) {
        this.iconTableBase64 = iconTableBase64;
    }

    public void addDatabaseTree(String databaseName, DataNodeId[] dataNodeIds) {
        // todo: this could end up being a threading issue with iconTableBase64 being set from the wrong database
        remove(dataNodeTree);
        dataNodeTree = new DataNodeTree(dataNodeTable, searchOptionsService, iconTableBase64);
        for (DataNodeId dataNodeId : dataNodeIds) {
            dataNodeTree.addResultsToTree(databaseName, dataNodeId);
        }
        this.insert(dataNodeTree, databaseName, 0);<commit_msg>refs #3688 Added a temporary solution to a race condition loading the icons. The real solution is being worked on and will involve combining what are currently multiple server requests into a single query.<commit_after>/*
 * Copyright (C) 2013 The Language Archive, Max Planck Institute for Psycholinguistics
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package nl.mpi.yaas.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.mpi.flap.model.DataNodeLink;
import nl.mpi.flap.model.ModelException;
import static nl.mpi.yaas.client.YaasTreeItem.FAILURE;
import nl.mpi.yaas.common.data.DataNodeId;
import nl.mpi.yaas.common.data.HighlighableDataNode;
import nl.mpi.yaas.common.data.IconTableBase64;

/**
 * @since Feb 06, 2014 11:37 AM (creation date)
 * @author <NAME> <<EMAIL>>
 */
public class ResultsPanel extends TabPanel implements HistoryListener {

    private static final Logger logger = Logger.getLogger("");
    private final DataNodeTable dataNodeTable;
    private final SearchOptionsServiceAsync searchOptionsService;
    private final HistoryController historyController;
    private IconTableBase64 iconTableBase64;
//    final String lastDatabaseName;
    private DataNodeTree dataNodeTree;
    // todo: replace the variabls dataNodeTreeRootIds and dataNodeTreeDb by updating the web service provide all the required information (db, root nodes, icons, stats) in one connection
    private DataNodeId[] dataNodeTreeRootIds = null;
    private String dataNodeTreeDb = null;

    public ResultsPanel(final DataNodeTable dataNodeTable, SearchOptionsServiceAsync searchOptionsService, HistoryController historyController) {
        this.dataNodeTable = dataNodeTable;
        this.searchOptionsService = searchOptionsService;
        this.historyController = historyController;
        this.setVisible(false);
    }

    public void historyChange() {
//        final String databaseName = historyController.getDatabaseName();
//        if (databaseName != null&& !lastDatabaseName.equals(databaseName)) {
//            RootPanel.get("searchOptionsPanel").add(loadingImage);
//            searchOptionsService.getImageDataForTypes(databaseName, new AsyncCallback<IconTableBase64>() {
//                public void onFailure(Throwable caught) {
//                    RootPanel.get("searchOptionsPanel").add(new Label(NO__DATABASE__SELECTED));
//                    RootPanel.get("searchOptionsPanel").remove(loadingImage);
//                }
//
//                public void onSuccess(IconTableBase64 result) {
//
//                }
//            });
//        }
    }

    public void setIconTableBase64(IconTableBase64 iconTableBase64) {
        this.iconTableBase64 = iconTableBase64;
        if (dataNodeTreeRootIds != null) {
            // todo: replace this overly complicated reload process by updating the web service provide all the required information (db, root nodes, icons, stats) in one connection
            addDatabaseTree(dataNodeTreeDb, dataNodeTreeRootIds);
        }
    }

    public void addDatabaseTree(String databaseName, DataNodeId[] dataNodeIds) {
        // todo: this could end up being a threading issue with iconTableBase64 being set from the wrong database
        remove(dataNodeTree);
        dataNodeTreeRootIds = dataNodeIds;
        dataNodeTreeDb = databaseName;
        dataNodeTree = new DataNodeTree(dataNodeTable, searchOptionsService, iconTableBase64);
        for (DataNodeId dataNodeId : dataNodeIds) {
            dataNodeTree.addResultsToTree(databaseName, dataNodeId);
        }
        this.insert(dataNodeTree, databaseName, 0);
{'fraction_non_alphanumeric': 0.0856152512998267, 'fraction_numerical': 0.012940496822645869, 'mean_word_length': 3.6140724946695095, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4370147', 'n_tokens_mistral': 2404, 'n_tokens_neox': 2294, 'n_words': 687}