<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: 07.05.2010 14:35:35
 *
 * $Id$
 */
package com.haulmont.cuba.web.ui.report.definition.edit

import com.haulmont.cuba.core.entity.Entity
import com.haulmont.cuba.core.global.MessageProvider
import com.haulmont.cuba.gui.AppConfig
import com.haulmont.cuba.gui.UserSessionClient
import com.haulmont.cuba.gui.autocomplete.AutoCompleteSupport
import com.haulmont.cuba.gui.autocomplete.JpqlSuggestionFactory
import com.haulmont.cuba.gui.autocomplete.Suggester
import com.haulmont.cuba.gui.autocomplete.Suggestion
import com.haulmont.cuba.gui.components.actions.RemoveAction
import com.haulmont.cuba.gui.data.CollectionDatasource
import com.haulmont.cuba.gui.data.Datasource
import com.haulmont.cuba.gui.data.ValueListener
import com.haulmont.cuba.gui.data.impl.DsListenerAdapter
import com.haulmont.cuba.report.BandDefinition
import com.haulmont.cuba.report.DataSet
import com.haulmont.cuba.report.DataSetType
import com.haulmont.cuba.report.Orientation
import com.haulmont.cuba.security.entity.EntityOp
import com.haulmont.cuba.gui.components.*

public class BandDefinitionEditor extends AbstractEditor implements Suggester {

    private static volatile Collection<com.haulmont.chile.core.model.MetaClass> metaClasses;

    def BandDefinitionEditor(IFrame frame) {
        super(frame);
    }

    def void setItem(Entity item) {
        BandDefinition definition = (BandDefinition) item
        definition.setParentBandDefinition(parentDefinition)
        definition.position = position ?: definition.position
        if (!definition.orientation) { definition.orientation = Orientation.HORIZONTAL }
        super.setItem(definition);
        selectFirstDataset()
    }

    private BandDefinition parentDefinition
    private Integer position

    public void init(Map<String, Object> params) {
        super.init(params);
        parentDefinition = params['param$parentDefinition']
        position = (Integer) params['param$position']

        Table table = getComponent('dataSets')
        table.addAction(new RemoveAction(table, false))

        table.addAction(new ActionAdapter('create', [
                actionPerform: {
                    Component component ->
                    DataSet dataset = new DataSet()
                    dataset.bandDefinition = (BandDefinition) item
                    dataset.name = dataset.bandDefinition.name ?: 'dataset'
                    dataset.type = DataSetType.GROOVY
                    table.datasource.addItem(dataset)
                },
                getCaption: {
                    MessageProvider.getMessage(AppConfig.instance.messagesPack, 'actions.Create')
                },
                isEnabled: {
                    UserSessionClient.userSession.isEntityOpPermitted(table.datasource.metaClass, EntityOp.CREATE)
                }
        ]))

        initDataSetControls()
    }

    def initDataSetControls() {
        LookupField lookupField = getComponent('type')
        AutoCompleteTextField textField = getComponent('text')
        TextField nameField = getComponent('datasetName')
        Label label = getComponent('dataSet_text')

        lookupField.addListener(
                [
                        valueChanged: {Object source, String property, Object prevValue, Object value ->
                            [textField, label].each {Component c -> c.visible = !(value && [DataSetType.SINGLE, DataSetType.MULTI].contains(value))}

                            textField.setSuggester(DataSetType.JPQL.equals(value) ? this : null)
                        }
                ] as ValueListener
        )

        def enableDatasetControls = {
            boolean value -><commit_msg>- fix<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: 07.05.2010 14:35:35
 *
 * $Id$
 */
package com.haulmont.cuba.web.ui.report.definition.edit

import com.haulmont.cuba.core.entity.Entity
import com.haulmont.cuba.core.global.MessageProvider
import com.haulmont.cuba.gui.AppConfig
import com.haulmont.cuba.gui.UserSessionClient
import com.haulmont.cuba.gui.autocomplete.AutoCompleteSupport
import com.haulmont.cuba.gui.autocomplete.JpqlSuggestionFactory
import com.haulmont.cuba.gui.autocomplete.Suggester
import com.haulmont.cuba.gui.autocomplete.Suggestion
import com.haulmont.cuba.gui.components.actions.RemoveAction
import com.haulmont.cuba.gui.data.CollectionDatasource
import com.haulmont.cuba.gui.data.Datasource
import com.haulmont.cuba.gui.data.ValueListener
import com.haulmont.cuba.gui.data.impl.DsListenerAdapter
import com.haulmont.cuba.report.BandDefinition
import com.haulmont.cuba.report.DataSet
import com.haulmont.cuba.report.DataSetType
import com.haulmont.cuba.report.Orientation
import com.haulmont.cuba.security.entity.EntityOp
import com.haulmont.cuba.gui.components.*

public class BandDefinitionEditor extends AbstractEditor implements Suggester {

    private static volatile Collection<com.haulmont.chile.core.model.MetaClass> metaClasses;

    def BandDefinitionEditor(IFrame frame) {
        super(frame);
    }

    def void setItem(Entity item) {
        BandDefinition definition = (BandDefinition) item
        definition.setParentBandDefinition(parentDefinition)
        definition.position = position ?: definition.position
        if (!definition.orientation) { definition.orientation = Orientation.HORIZONTAL }
        super.setItem(definition);
        selectFirstDataset()
    }

    private BandDefinition parentDefinition
    private Integer position

    public void init(Map<String, Object> params) {
        super.init(params);
        parentDefinition = params['param$parentDefinition']
        position = (Integer) params['param$position']

        Table table = getComponent('dataSets')
        table.addAction(new RemoveAction(table, false))

        table.addAction(new ActionAdapter('create', [
                actionPerform: {
                    Component component ->
                    DataSet dataset = new DataSet()
                    dataset.bandDefinition = (BandDefinition) item
                    dataset.name = dataset.bandDefinition.name ?: 'dataset'
                    dataset.type = DataSetType.GROOVY
                    table.datasource.addItem(dataset)
                },
                getCaption: {
                    MessageProvider.getMessage(AppConfig.messagesPack, 'actions.Create')
                },
                isEnabled: {
                    UserSessionClient.userSession.isEntityOpPermitted(table.datasource.metaClass, EntityOp.CREATE)
                }
        ]))

        initDataSetControls()
    }

    def initDataSetControls() {
        LookupField lookupField = getComponent('type')
        AutoCompleteTextField textField = getComponent('text')
        TextField nameField = getComponent('datasetName')
        Label label = getComponent('dataSet_text')

        lookupField.addListener(
                [
                        valueChanged: {Object source, String property, Object prevValue, Object value ->
                            [textField, label].each {Component c -> c.visible = !(value && [DataSetType.SINGLE, DataSetType.MULTI].contains(value))}

                            textField.setSuggester(DataSetType.JPQL.equals(value) ? this : null)
                        }
                ] as ValueListener
        )

        def enableDatasetControls = {
            boolean value ->
{'fraction_non_alphanumeric': 0.08990801917346807, 'fraction_numerical': 0.004663816556548776, 'mean_word_length': 2.7115384615384617, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, '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': '1224431', 'n_tokens_mistral': 2144, 'n_tokens_neox': 1988, 'n_words': 381}