<commit_before>/*
 * This is part of the Ktunaxa referral system.
 *
 * Copyright 2011 Ktunaxa Nation Council, http://www.ktunaxa.org/, Canada.
 */

package org.ktunaxa.referral.client.gui;

import com.smartgwt.client.types.Overflow;
import org.geomajas.gwt.client.widget.FeatureListGrid;
import org.geomajas.gwt.client.widget.FeatureSearch;
import org.geomajas.gwt.client.widget.MapWidget;
import org.geomajas.gwt.client.widget.event.DefaultSearchHandler;

import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.tab.Tab;
import com.smartgwt.client.widgets.tab.TabSet;
import org.geomajas.widget.searchandfilter.client.widget.attributesearch.AttributeSearchCreator;
import org.geomajas.widget.searchandfilter.client.widget.geometricsearch.FreeDrawingSearch;
import org.geomajas.widget.searchandfilter.client.widget.geometricsearch.GeometricSearchCreator;
import org.geomajas.widget.searchandfilter.client.widget.geometricsearch.GeometricSearchPanel;
import org.geomajas.widget.searchandfilter.client.widget.geometricsearch.GeometricSearchPanelCreator;
import org.geomajas.widget.searchandfilter.client.widget.geometricsearch.SelectionSearch;
import org.geomajas.widget.searchandfilter.client.widget.multifeaturelistgrid.MultiFeatureListGrid;
import org.geomajas.widget.searchandfilter.client.widget.search.CombinedSearchPanel;
import org.geomajas.widget.searchandfilter.client.widget.search.PanelSearchWidget;
import org.geomajas.widget.searchandfilter.client.widget.search.SearchWidgetRegistry;
import org.geomajas.widget.searchandfilter.client.widget.searchfavourites.SearchFavouritesListCreator;

/**
 * Panel that displays search tools: search for referral and geographical search / spatial operations.
 * 
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 */
public class SearchPanel extends VLayout {

	private static final String NAME = "SEARCH";

	public SearchPanel(MapWidget mapWidget) {
		setSize("100%", "100%");

		final TabSet tabs = new TabSet();
		Tab tab1 = new Tab("General Search");
		Tab tab2 = new Tab("Search Results");
		Tab tabReferral = new Tab("Referral");
		Tab tabValues = new Tab("Values");

		FeatureListGrid grid = new FeatureListGrid(mapWidget.getMapModel());
		grid.setBackgroundColor("#FFFFFF");
		FeatureSearch search = new FeatureSearch(mapWidget.getMapModel(), true);
		search.setBackgroundColor("#FFFFFF");
		search.addSearchHandler(new DefaultSearchHandler(grid) {

			public void afterSearch() {
				tabs.selectTab(1);
			}
		});

		// initialization for value searching
		MultiFeatureListGrid valueResultList = new MultiFeatureListGrid(mapWidget);
		valueResultList.setBackgroundColor("#FFFFFF");
		SearchWidgetRegistry.initialize(mapWidget, valueResultList);
		SearchWidgetRegistry.put(new AttributeSearchCreator());
		SearchWidgetRegistry.put(new GeometricSearchCreator(new GeometricSearchPanelCreator() {
			public GeometricSearchPanel createInstance(MapWidget mapWidget) {
				GeometricSearchPanel gsp = new GeometricSearchPanel(mapWidget);
				gsp.addSearchMethod(new SelectionSearch());
				gsp.addSearchMethod(new FreeDrawingSearch());
				return gsp;
			}
		}));
		SearchWidgetRegistry.put(new SearchFavouritesListCreator());
		VLayout valueSearch = new VLayout();
		CombinedSearchPanel combinedSearchPanel = new CombinedSearchPanel(mapWidget);
		combinedSearchPanel.initializeListUseAll();
		combinedSearchPanel.setHeight(1); // minimum height
		combinedSearchPanel.setOverflow(Overflow.VISIBLE); // but scale
		PanelSearchWidget panelSearchWidget = new PanelSearchWidget("PanelSearchWidget", "search widget",
				combinedSearchPanel);
		panelSearchWidget.setHeight(1); // minimum height
		panelSearchWidget.setOverflow(Overflow.VISIBLE); // but scale
		valueSearch.addMember(panelSearchWidget);
		valueSearch.addMember(valueResultList);

		tab1.setPane(search);
		tab2.setPane(grid);
		tabReferral.setPane(new VLayout()); // @todo provide proper content
		tabValues.setPane(valueSearch);
		tabs.setTabs(tab1, tab2, tabReferral, tabValues);
		addMember(tabs);
	}

	public String getName() {
		return NAME;
	}
}<commit_msg>KTU-98 spatial analysis/search using search and filter widget<commit_after>/*
 * This is part of the Ktunaxa referral system.
 *
 * Copyright 2011 Ktunaxa Nation Council, http://www.ktunaxa.org/, Canada.
 */

package org.ktunaxa.referral.client.gui;

import com.smartgwt.client.types.Overflow;
import org.geomajas.gwt.client.widget.CardLayout;
import org.geomajas.gwt.client.widget.FeatureListGrid;
import org.geomajas.gwt.client.widget.FeatureSearch;
import org.geomajas.gwt.client.widget.MapWidget;
import org.geomajas.gwt.client.widget.event.DefaultSearchHandler;

import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.tab.Tab;
import com.smartgwt.client.widgets.tab.TabSet;
import org.geomajas.widget.searchandfilter.client.widget.attributesearch.AttributeSearchPanel;
import org.geomajas.widget.searchandfilter.client.widget.geometricsearch.FreeDrawingSearch;
import org.geomajas.widget.searchandfilter.client.widget.geometricsearch.GeometricSearchPanel;
import org.geomajas.widget.searchandfilter.client.widget.geometricsearch.SelectionSearch;
import org.geomajas.widget.searchandfilter.client.widget.multifeaturelistgrid.MultiFeatureListGrid;
import org.geomajas.widget.searchandfilter.client.widget.search.AbstractSearchPanel;
import org.geomajas.widget.searchandfilter.client.widget.search.CombinedSearchPanel;
import org.geomajas.widget.searchandfilter.client.widget.search.PanelSearchWidget;
import org.geomajas.widget.searchandfilter.client.widget.search.SearchController;
import org.geomajas.widget.searchandfilter.client.widget.search.SearchWidget;

import java.util.ArrayList;
import java.util.List;

/**
 * Panel that displays search tools: search for referral and geographical search / spatial operations.
 * 
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 */
public class SearchPanel extends VLayout {

	private static final String NAME = "SEARCH";

	private static final String CARD_EMPTY = "emptyCard";
	private static final String CARD_GEOMETRIC = "geometricCard";
	private static final String CARD_ATTRIBUTE = "attributeCard";
	//private static final String CARD_FAVOURITE = "favouriteCard";

	public SearchPanel(MapWidget mapWidget) {
		setSize("100%", "100%");

		final TabSet tabs = new TabSet();
		Tab tab1 = new Tab("General Search");
		Tab tab2 = new Tab("Search Results");
		Tab tabReferral = new Tab("Referral");
		Tab tabValues = new Tab("Values");

		FeatureListGrid grid = new FeatureListGrid(mapWidget.getMapModel());
		grid.setBackgroundColor("#FFFFFF");
		FeatureSearch search = new FeatureSearch(mapWidget.getMapModel(), true);
		search.setBackgroundColor("#FFFFFF");
		search.addSearchHandler(new DefaultSearchHandler(grid) {

			public void afterSearch() {
				tabs.selectTab(1);
			}
		});

		// initialization for value searching
		MultiFeatureListGrid valueResultList = new MultiFeatureListGrid(mapWidget);
		valueResultList.setBackgroundColor("#FFFFFF");
		CardLayout searchPanels = new CardLayout();
		GeometricSearchPanel gsp = new GeometricSearchPanel(mapWidget);
		gsp.addSearchMethod(new SelectionSearch());
		gsp.addSearchMethod(new FreeDrawingSearch());
		PanelSearchWidget geometricSearch = new CardPanelSearchWidget("GeometricSearch", "Search on geometry", gsp,
				searchPanels, CARD_GEOMETRIC);
		PanelSearchWidget attributeSearch = new CardPanelSearchWidget("AttributeSearch", "Search on attributes",
				new AttributeSearchPanel(mapWidget), searchPanels, CARD_ATTRIBUTE);
		//PanelSearchWidget favouriteSearch = new CardPanelSearchWidget("FavouritesSearch", "Select favourite",
		//		new SearchFavouritesListPanel(mapWidget), searchPanels, CARD_FAVOURITE);
		searchPanels.addCard(CARD_EMPTY, new VLayout()); // add empty card option
		searchPanels.showCard(CARD_EMPTY);
		searchPanels.setHeight(1); // minimum height
		searchPanels.setOverflow(Overflow.VISIBLE); // but scale
		List<SearchWidget> searchWidgetList = new ArrayList<SearchWidget>();
		searchWidgetList.add(attributeSearch);
		searchWidgetList.add(geometricSearch);
		//searchWidgetList.add(favouriteSearch);

		VLayout valueSearch = new VLayout();
		CombinedSearchPanel combinedSearchPanel = new CombinedSearchPanel(mapWidget);
		combinedSearchPanel.initializeList(searchWidgetList);
		combinedSearchPanel.setHeight(1); // minimum height
		combinedSearchPanel.setOverflow(Overflow.VISIBLE); // but scale
		PanelSearchWidget searchCombined = new PanelSearchWidget("PanelSearchWidget", "search widget",
				combinedSearchPanel);
		SearchController searchController = new SearchController(mapWidget, false);
		searchController.addSearchHandler(valueResultList);
		searchCombined.addSearchRequestHandler(searchController);
		// following lines make sure the criterion type select is not visible
		//searchCombined.setHeight(1); // minimum height
		//searchCombined.setOverflow(Overflow.VISIBLE); // but scale
		valueSearch.addMember(searchCombined);
		valueSearch.addMember(searchPanels);

		valueSearch.addMember(valueResultList);

		tab1.setPane(search);
		tab2.setPane(grid);
		tabReferral.setPane(new VLayout()); // @todo provide proper content
		tabValues.setPane(valueSearch);
		tabs.setTabs(tab1, tab2, tabReferral, tabValues);
		addMember(tabs);
	}

	public String getName() {
		return NAME;
	}

	private static class CardPanelSearchWidget extends PanelSearchWidget {
		private CardLayout cardLayout;
		private String cardKey;
		private boolean isShowingOrHiding; // to prevent infinite loop

		public CardPanelSearchWidget(String id, String name, AbstractSearchPanel searchPanel, CardLayout cardLayout,
				String cardKey) {
			super(id, name, searchPanel);
			this.cardLayout = cardLayout;
			this.cardKey = cardKey;
			cardLayout.addCard(cardKey, this);
		}

		@Override
		public void showForSearch() {
			super.showForSearch();
			cardLayout.showCard(cardKey);
		}

		@Override
		public void showForSave(SaveRequestHandler handler) {
			super.showForSave(handler);
			cardLayout.showCard(cardKey);
		}

		@Override
		public void show() {
			// have to prevent infinite loops
			if (this != cardLayout.getCurrentCard()) {
				cardLayout.showCard(cardKey);
			}
			super.show();
		}
	}
}
{'fraction_non_alphanumeric': 0.1023292076795634, 'fraction_numerical': 0.003995711918916285, 'mean_word_length': 5.95728813559322, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '418128', 'n_tokens_mistral': 3263, 'n_tokens_neox': 2965, 'n_words': 585}