<commit_before>/*
 * DomUI Java User Interface library
 * Copyright (c) 2010 by <NAME>, Itris B.V.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * See the "sponsors" file for a list of supporters.
 *
 * The latest version of DomUI and related code, support and documentation
 * can be found at http://www.domui.org/
 * The contact for the project is <NAME> <<EMAIL>>.
 */
package to.etc.domui.component.searchpanel.lookupcontrols;

import to.etc.domui.component.input.ComboFixed;
import to.etc.domui.component.input.ValueLabelPair;
import to.etc.domui.component.meta.ClassMetaModel;
import to.etc.domui.component.meta.MetaManager;
import to.etc.domui.component.meta.MetaUtils;
import to.etc.domui.component.meta.PropertyMetaModel;
import to.etc.domui.component.meta.SearchPropertyMetaModel;
import to.etc.webapp.nls.NlsContext;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;

/**
 * Represents factory for enum values or boolean values lookup. For lookup condition uses combo box automaticaly populated with localized values of enum constants or boolean values.
 *
 * @author <a href="mailto:vm<EMAIL>"><NAME></a>
 * Created on 1 Aug 2009
 */
final class EnumAndBoolLookupFactory2<T> implements ILookupFactory<T> {
	@Nonnull @Override public FactoryPair<T> createControl(@Nonnull SearchPropertyMetaModel spm) {
		PropertyMetaModel<T> pmm = (PropertyMetaModel<T>) spm.getProperty();

		// Create a domainvalued combobox by default.
		Object[] vals = pmm.getDomainValues();
		if(null == vals)
			throw new IllegalStateException(pmm + ": no domainValues");
		ClassMetaModel ecmm = null;
		List<ValueLabelPair<T>> vl = new ArrayList<>();
		for(Object o : vals) {
			String label = pmm.getDomainValueLabel(NlsContext.getLocale(), o);	// Label known to property?
			if(label == null) {
				if(ecmm == null)
					ecmm = MetaManager.findClassMeta(pmm.getActualType()); 		// Try to get the property's type.
				label = ecmm.getDomainLabel(NlsContext.getLocale(), o);
				if(label == null)
					label = o == null ? "" : o.toString();
			}
			vl.add(new ValueLabelPair<>((T) o, label));
		}

		final ComboFixed<T> c = new ComboFixed<>(vl);
		String s = pmm.getDefaultHint();
		if(s != null) {
			c.setTitle(s);
		}
		String hint = MetaUtils.findHintText(spm);
		if(hint != null)
			c.setTitle(hint);
		return new FactoryPair<>(new ObjectLookupQueryBuilder<T>(pmm.getName()), c);
	}<commit_msg>Add hibernate objects for user tables.<commit_after>/*
 * DomUI Java User Interface library
 * Copyright (c) 2010 by <NAME>, Itris B.V.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * See the "sponsors" file for a list of supporters.
 *
 * The latest version of DomUI and related code, support and documentation
 * can be found at http://www.domui.org/
 * The contact for the project is <NAME> <<EMAIL>>.
 */
package to.etc.domui.component.searchpanel.lookupcontrols;

import to.etc.domui.component.input.ValueLabelPair;
import to.etc.domui.component.meta.ClassMetaModel;
import to.etc.domui.component.meta.MetaManager;
import to.etc.domui.component.meta.MetaUtils;
import to.etc.domui.component.meta.PropertyMetaModel;
import to.etc.domui.component.meta.SearchPropertyMetaModel;
import to.etc.domui.component2.combo.ComboFixed2;
import to.etc.webapp.nls.NlsContext;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;

/**
 * Represents factory for enum values or boolean values lookup. For lookup condition uses combo box automaticaly populated with localized values of enum constants or boolean values.
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * Created on 1 Aug 2009
 */
final class EnumAndBoolLookupFactory2<T> implements ILookupFactory<T> {
	@Nonnull @Override public FactoryPair<T> createControl(@Nonnull SearchPropertyMetaModel spm) {
		PropertyMetaModel<T> pmm = (PropertyMetaModel<T>) spm.getProperty();

		// Create a domainvalued combobox by default.
		Object[] vals = pmm.getDomainValues();
		if(null == vals)
			throw new IllegalStateException(pmm + ": no domainValues");
		ClassMetaModel ecmm = null;
		List<ValueLabelPair<T>> vl = new ArrayList<>();
		for(Object o : vals) {
			String label = pmm.getDomainValueLabel(NlsContext.getLocale(), o);	// Label known to property?
			if(label == null) {
				if(ecmm == null)
					ecmm = MetaManager.findClassMeta(pmm.getActualType()); 		// Try to get the property's type.
				label = ecmm.getDomainLabel(NlsContext.getLocale(), o);
				if(label == null)
					label = o == null ? "" : o.toString();
			}
			vl.add(new ValueLabelPair<>((T) o, label));
		}

		final ComboFixed2<T> c = new ComboFixed2<>(vl);
		String s = pmm.getDefaultHint();
		if(s != null) {
			c.setTitle(s);
		}
		String hint = MetaUtils.findHintText(spm);
		if(hint != null)
			c.setTitle(hint);
		return new FactoryPair<>(new ObjectLookupQueryBuilder<T>(pmm.getName()), c);
	}
{'fraction_non_alphanumeric': 0.10923297719661935, 'fraction_numerical': 0.007973210014351778, 'mean_word_length': 4.28390901432182, 'pattern_counts': {'":': 2, '<': 45, '<?xml version=': 0, '>': 45, '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': '2410931', 'n_tokens_mistral': 2014, 'n_tokens_neox': 1873, 'n_words': 639}