<commit_before>/*
 * Copyright 2012 Corpuslinguistic working group Humboldt University Berlin.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package annis.gui.querybuilder;

import annis.gui.PluginSystem;
import annis.gui.controlpanel.ControlPanel;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vaadin.ui.themes.ChameleonTheme;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import net.xeoh.plugins.base.util.PluginManagerUtil;

/**
 * Wrapper for selecting and showing the desired query builder.
 * @author <NAME> <<EMAIL>>
 */
public class QueryBuilderChooser extends Panel implements Property.ValueChangeListener
{
  private PluginSystem pluginSystem;
  private ControlPanel controlPanel;
  private ComboBox cbChooseBuilder;
  private Map<String, String> caption2Short;
  private Map<String, QueryBuilderPlugin> pluginRegistry;
  private Component lastComponent;
  private VerticalLayout layout;
  
  public QueryBuilderChooser(ControlPanel controlPanel, PluginSystem pluginSystem)
  {
    this.controlPanel = controlPanel;
    this.pluginSystem = pluginSystem;
    
    this.pluginRegistry = new HashMap<String, QueryBuilderPlugin>();
    this.caption2Short = new HashMap<String, String>();
    
    setStyleName(ChameleonTheme.PANEL_BORDERLESS);
    
    layout = (VerticalLayout) getContent();
    layout.setSizeFull();
    layout.setSpacing(true);
    setSizeFull();
    
    // add combobox to choose the query builder
    cbChooseBuilder = new ComboBox();
    cbChooseBuilder.setNewItemsAllowed(false);
    cbChooseBuilder.setNullSelectionAllowed(false);
    cbChooseBuilder.setImmediate(true);
    
    PluginManagerUtil util = new PluginManagerUtil(pluginSystem.getPluginManager());
    Collection<QueryBuilderPlugin> builders = util.getPlugins(QueryBuilderPlugin.class);
    
    for(QueryBuilderPlugin b : builders)
    {
      caption2Short.put(b.getCaption(), b.getShortName());
      pluginRegistry.put(b.getShortName(), b);
      cbChooseBuilder.addItem(b.getCaption());
    }
    
    cbChooseBuilder.addListener((Property.ValueChangeListener) this);
    
    addComponent(cbChooseBuilder);
    layout.setExpandRatio(cbChooseBuilder, 0.0f);
  }

  @Override
  public void valueChange(ValueChangeEvent event)
  {
    String shortName = caption2Short.get((String) event.getProperty().getValue());
    if(shortName == null)
    {
      getWindow().showNotification("Invalid selection (caption not found)", 
        Window.Notification.TYPE_WARNING_MESSAGE);<commit_msg>prompt user for input<commit_after>/*
 * Copyright 2012 Corpuslinguistic working group Humboldt University Berlin.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package annis.gui.querybuilder;

import annis.gui.PluginSystem;
import annis.gui.controlpanel.ControlPanel;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vaadin.ui.themes.ChameleonTheme;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import net.xeoh.plugins.base.util.PluginManagerUtil;

/**
 * Wrapper for selecting and showing the desired query builder.
 * @author <NAME> <<EMAIL>>
 */
public class QueryBuilderChooser extends Panel implements Property.ValueChangeListener
{
  private PluginSystem pluginSystem;
  private ControlPanel controlPanel;
  private ComboBox cbChooseBuilder;
  private Map<String, String> caption2Short;
  private Map<String, QueryBuilderPlugin> pluginRegistry;
  private Component lastComponent;
  private VerticalLayout layout;
  
  public QueryBuilderChooser(ControlPanel controlPanel, PluginSystem pluginSystem)
  {
    this.controlPanel = controlPanel;
    this.pluginSystem = pluginSystem;
    
    this.pluginRegistry = new HashMap<String, QueryBuilderPlugin>();
    this.caption2Short = new HashMap<String, String>();
    
    setStyleName(ChameleonTheme.PANEL_BORDERLESS);
    
    layout = (VerticalLayout) getContent();
    layout.setSizeFull();
    layout.setSpacing(true);
    setSizeFull();
    
    // add combobox to choose the query builder
    cbChooseBuilder = new ComboBox();
    cbChooseBuilder.setNewItemsAllowed(false);
    cbChooseBuilder.setNullSelectionAllowed(false);
    cbChooseBuilder.setImmediate(true);
    cbChooseBuilder.setInputPrompt("Choose a query builder");
    
    
    PluginManagerUtil util = new PluginManagerUtil(pluginSystem.getPluginManager());
    Collection<QueryBuilderPlugin> builders = util.getPlugins(QueryBuilderPlugin.class);
    
    for(QueryBuilderPlugin b : builders)
    {
      caption2Short.put(b.getCaption(), b.getShortName());
      pluginRegistry.put(b.getShortName(), b);
      cbChooseBuilder.addItem(b.getCaption());
    }
    
    cbChooseBuilder.addListener((Property.ValueChangeListener) this);
    
    addComponent(cbChooseBuilder);
    layout.setExpandRatio(cbChooseBuilder, 0.0f);
  }

  @Override
  public void valueChange(ValueChangeEvent event)
  {
    String shortName = caption2Short.get((String) event.getProperty().getValue());
    if(shortName == null)
    {
      getWindow().showNotification("Invalid selection (caption not found)", 
        Window.Notification.TYPE_WARNING_MESSAGE);
{'fraction_non_alphanumeric': 0.09164502825721704, 'fraction_numerical': 0.0042767679853367956, 'mean_word_length': 4.456666666666667, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '3141745', 'n_tokens_mistral': 1873, 'n_tokens_neox': 1797, 'n_words': 472}