<commit_before>/*
 * Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
 * Haulmont Technology proprietary and confidential.
 * Use is subject to license terms.

 * Author: <NAME>
 * Created: 26.05.2010 16:52:04
 *
 * $Id$
 */
package cuba.client.web.ui.report.browse;

import com.haulmont.chile.core.model.MetaClass;
import com.haulmont.chile.core.model.MetaProperty;
import com.haulmont.chile.core.model.MetaPropertyPath;
import com.haulmont.cuba.core.global.MessageProvider;
import com.haulmont.cuba.gui.components.AbstractLookup;
import com.haulmont.cuba.gui.components.IFrame;
import com.haulmont.cuba.gui.components.Table;
import com.haulmont.cuba.gui.data.impl.CollectionDatasourceImpl;
import com.haulmont.cuba.web.gui.components.WebTable;
import com.haulmont.cuba.web.gui.components.WebVBoxLayout;

import java.util.Map;

public class CommonLookupController extends AbstractLookup {
    public CommonLookupController(IFrame frame) {
        super(frame);
    }

    @Override
    protected void init(Map<String, Object> params) {
        super.init(params);
        WebVBoxLayout vbox = getComponent("vbox");
        final MetaClass metaClass = (MetaClass) params.get("param$class");
        final Class javaClass = metaClass.getJavaClass();
        setCaption(MessageProvider.getMessage(javaClass, javaClass.getSimpleName()));
        CollectionDatasourceImpl cds = new CollectionDatasourceImpl(getDsContext(), getDsContext().getDataService(), "mainDs", metaClass, "_minimal");
        WebTable table = new WebTable() {
            @Override
            protected void initComponent(com.haulmont.cuba.web.toolkit.ui.Table component) {
                super.initComponent(component);
                for (MetaProperty prop : metaClass.getOwnProperties()) {//todo: reimplement - not all properties
                    MetaPropertyPath mpp = new MetaPropertyPath(metaClass, prop);
                    Table.Column column = new Table.Column(mpp);
                    column.setCaption(MessageProvider.getMessage(javaClass, javaClass.getSimpleName() + "." + prop.getName()));
                    addColumn(column);
                }
            }
        };
        table.setId("table");
        table.setDatasource(cds);
        vbox.add(table);
        vbox.expand(table, "100%", "100%");
        table.setMultiSelect(true);
        table.refresh();
        this.setLookupComponent(table);
    }
}<commit_msg>[Reporting] update common lookup component<commit_after>/*
 * Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
 * Haulmont Technology proprietary and confidential.
 * Use is subject to license terms.

 * Author: <NAME>
 * Created: 26.05.2010 16:52:04
 *
 * $Id$
 */
package cuba.client.web.ui.report.browse;

import com.haulmont.chile.core.model.Instance;
import com.haulmont.chile.core.model.MetaClass;
import com.haulmont.chile.core.model.MetaProperty;
import com.haulmont.chile.core.model.MetaPropertyPath;
import com.haulmont.cuba.core.global.MessageProvider;
import com.haulmont.cuba.gui.components.AbstractLookup;
import com.haulmont.cuba.gui.components.IFrame;
import com.haulmont.cuba.gui.data.impl.CollectionDatasourceImpl;
import com.haulmont.cuba.web.gui.components.WebComponentsHelper;
import com.haulmont.cuba.web.gui.components.WebLabel;
import com.haulmont.cuba.web.gui.components.WebTable;
import com.haulmont.cuba.web.gui.components.WebVBoxLayout;
import com.vaadin.ui.Component;

import java.util.ArrayList;
import java.util.Map;

public class CommonLookupController extends AbstractLookup {
    public CommonLookupController(IFrame frame) {
        super(frame);
    }

    @Override
    protected void init(Map<String, Object> params) {
        super.init(params);
        WebVBoxLayout vbox = getComponent("vbox");
        final MetaClass metaClass = (MetaClass) params.get("param$class");
        final Class javaClass = metaClass.getJavaClass();
        setCaption(MessageProvider.getMessage(javaClass, javaClass.getSimpleName()));
        final CollectionDatasourceImpl cds = new CollectionDatasourceImpl(getDsContext(), getDsContext().getDataService(), "mainDs", metaClass, "_minimal");
        final WebTable table = new WebTable() {
            @Override
            protected void initComponent(com.haulmont.cuba.web.toolkit.ui.Table component) {
                super.initComponent(component);
                com.vaadin.ui.Table.ColumnGenerator generator = new com.vaadin.ui.Table.ColumnGenerator() {
                    @Override
                    public Component generateCell(com.vaadin.ui.Table source, Object itemId, Object columnId) {
                        Object inst = cds.getItem(itemId);
                        WebLabel label = new WebLabel();
                        label.setValue(((Instance) inst).getInstanceName());
                        return WebComponentsHelper.unwrap(label);
                    }
                };

                MetaPropertyPath nameProperty = new MetaPropertyPath(metaClass, new ArrayList<MetaProperty>(metaClass.getOwnProperties()).get(0));
                Column column = new Column(nameProperty);
                column.setCaption("Name");
                addColumn(column);
                addGeneratedColumn(nameProperty, generator); //todo: govnokod. write ticket to gorodnov
            }
        };
        table.setId("table");
        table.setDatasource(cds);
        vbox.add(table);
        vbox.expand(table, "100%", "100%");
        table.setMultiSelect(true);
        table.refresh();
        this.setLookupComponent(table);
    }
}
{'fraction_non_alphanumeric': 0.11053292661044321, 'fraction_numerical': 0.008792391889467073, 'mean_word_length': 3.0100719424460434, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '3754464', 'n_tokens_mistral': 1638, 'n_tokens_neox': 1538, 'n_words': 296}