<commit_before>/*
 * Copyright 2015 JBoss Inc
 *
 * 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 org.jbpm.designer.client.popup;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.Dependent;
import javax.inject.Inject;

import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.ValueListBox;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Window;
import org.jboss.errai.marshalling.client.Marshalling;
import org.jbpm.designer.client.resources.i18n.DesignerEditorConstants;
import org.jbpm.designer.client.shared.AssignmentData;
import org.jbpm.designer.client.shared.AssignmentRow;
import org.jbpm.designer.client.shared.Variable.VariableType;
import org.uberfire.ext.widgets.common.client.common.popups.BaseModal;

@Dependent
public class ActivityDataIOEditor extends BaseModal {

    /**
     * Callback interface which should be implemented by callers to retrieve the
     * edited Assignments data.
     */
    public interface GetDataCallback {
        void getData(String assignmentData);
    }
    GetDataCallback callback = null;

    boolean hasInputVars = true;
    boolean isSingleInputVar = false;
    boolean hasOutputVars = true;
    boolean isSingleOutputVar = false;

    @Inject
    private ActivityDataIOEditorWidget inputAssignmentsWidget;

    @Inject
    private ActivityDataIOEditorWidget outputAssignmentsWidget;

    private Button btnSave;

    private Button btnCancel;


    public ActivityDataIOEditor() {
        super();
    }

    private List<String> dataTypes = new ArrayList<String>();
    private List<String> dataTypeDisplayNames = new ArrayList<String>();

    /**
     * Class containing a list of values for a ValueListBox<String>.
     * This is used by the ListBoxes in the dialog to keep their drop-down lists
     * up to date with updated with new values (CustomDataTypes / Constants) as
     * the user adds them.
     */
    class ListBoxValues {
        List<String> acceptableValuesWithCustomValues = new ArrayList<String>();
        List<String> acceptableValuesWithoutCustomValues = new ArrayList<String>();
        List<String> customValues = new ArrayList<String>();

        void update(ValueListBox<String> listBox, boolean showCustomValues) {
            if (showCustomValues) {
                String currentValue = listBox.getValue();
                String currentEditValuePrompt = getEditValuePrompt();
                String newEditValuePrompt = AssignmentListItemWidget.EDIT_PREFIX + currentValue + AssignmentListItemWidget.EDIT_SUFFIX;
                if (isCustomValue(currentValue)) {
                    if (newEditValuePrompt.equals(currentEditValuePrompt)) {
                        // ok already
                    }
                    else if (currentEditValuePrompt != null) {
                        acceptableValuesWithCustomValues.remove(currentEditValuePrompt);
                        acceptableValuesWithCustomValues.add(0, newEditValuePrompt);
                    }
                    else {
                        acceptableValuesWithCustomValues.add(0, newEditValuePrompt);
                    }
                }
                else if (currentEditValuePrompt != null) {
                    acceptableValuesWithCustomValues.remove(currentEditValuePrompt);
                }
                listBox.setAcceptableValues(acceptableValuesWithCustomValues);
            }
            else {
                listBox.setAcceptableValues(acceptableValuesWithoutCustomValues);
            }
        }

        void addValues(List<String> acceptableValues) {
            clearNonCustomValues();
            if (acceptableValues != null) {
                acceptableValuesWithCustomValues.addAll(acceptableValues);
                for (int i = 0; i < acceptableValues.size(); i++) {
                    String value = acceptableValues.get(i);
                    if (!acceptableValuesWithoutCustomValues.contains(value)
                            && !value.endsWith("...")) {
                        acceptableValuesWithoutCustomValues.add(value);
                    }
                }
            }
        }

        private void clearNonCustomValues() {
            acceptableValuesWithCustomValues.clear();
            acceptableValuesWithCustomValues.addAll(customValues);
            acceptableValuesWithoutCustomValues.clear();
        }

        private String getEditValuePrompt() {
            if (acceptableValuesWithCustomValues.size() > 0) {
                String value = acceptableValuesWithCustomValues.get(0);
                if (value.startsWith(AssignmentListItemWidget.EDIT_PREFIX))
                {
                    return value;
                }
            }
            return null;<commit_msg>BZ1252028: Change scope of custom data-types and constants in DataIOEditor to current activity<commit_after>/*
 * Copyright 2015 JBoss Inc
 *
 * 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 org.jbpm.designer.client.popup;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.Dependent;
import javax.inject.Inject;

import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.ValueListBox;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Window;
import org.jboss.errai.marshalling.client.Marshalling;
import org.jbpm.designer.client.resources.i18n.DesignerEditorConstants;
import org.jbpm.designer.client.shared.AssignmentData;
import org.jbpm.designer.client.shared.AssignmentRow;
import org.jbpm.designer.client.shared.Variable.VariableType;
import org.uberfire.ext.widgets.common.client.common.popups.BaseModal;

@Dependent
public class ActivityDataIOEditor extends BaseModal {

    /**
     * Callback interface which should be implemented by callers to retrieve the
     * edited Assignments data.
     */
    public interface GetDataCallback {
        void getData(String assignmentData);
    }
    GetDataCallback callback = null;

    boolean hasInputVars = true;
    boolean isSingleInputVar = false;
    boolean hasOutputVars = true;
    boolean isSingleOutputVar = false;

    @Inject
    private ActivityDataIOEditorWidget inputAssignmentsWidget;

    @Inject
    private ActivityDataIOEditorWidget outputAssignmentsWidget;

    private Button btnSave;

    private Button btnCancel;


    public ActivityDataIOEditor() {
        super();
    }

    private List<String> dataTypes = new ArrayList<String>();
    private List<String> dataTypeDisplayNames = new ArrayList<String>();

    /**
     * Class containing a list of values for a ValueListBox<String>.
     * This is used by the ListBoxes in the dialog to keep their drop-down lists
     * up to date with updated with new values (CustomDataTypes / Constants) as
     * the user adds them.
     */
    class ListBoxValues {
        List<String> acceptableValuesWithCustomValues = new ArrayList<String>();
        List<String> acceptableValuesWithoutCustomValues = new ArrayList<String>();
        List<String> customValues = new ArrayList<String>();

        void update(ValueListBox<String> listBox, boolean showCustomValues) {
            if (showCustomValues) {
                String currentValue = listBox.getValue();
                String currentEditValuePrompt = getEditValuePrompt();
                String newEditValuePrompt = AssignmentListItemWidget.EDIT_PREFIX + currentValue + AssignmentListItemWidget.EDIT_SUFFIX;
                if (isCustomValue(currentValue)) {
                    if (newEditValuePrompt.equals(currentEditValuePrompt)) {
                        // ok already
                    }
                    else if (currentEditValuePrompt != null) {
                        acceptableValuesWithCustomValues.remove(currentEditValuePrompt);
                        acceptableValuesWithCustomValues.add(0, newEditValuePrompt);
                    }
                    else {
                        acceptableValuesWithCustomValues.add(0, newEditValuePrompt);
                    }
                }
                else if (currentEditValuePrompt != null) {
                    acceptableValuesWithCustomValues.remove(currentEditValuePrompt);
                }
                listBox.setAcceptableValues(acceptableValuesWithCustomValues);
            }
            else {
                listBox.setAcceptableValues(acceptableValuesWithoutCustomValues);
            }
        }

        void addValues(List<String> acceptableValues) {
            clear();
            if (acceptableValues != null) {
                acceptableValuesWithCustomValues.addAll(acceptableValues);
                for (int i = 0; i < acceptableValues.size(); i++) {
                    String value = acceptableValues.get(i);
                    if (!acceptableValuesWithoutCustomValues.contains(value)
                            && !value.endsWith("...")) {
                        acceptableValuesWithoutCustomValues.add(value);
                    }
                }
            }
        }

        private void clear() {
            customValues.clear();
            acceptableValuesWithCustomValues.clear();
            acceptableValuesWithoutCustomValues.clear();
        }

        private String getEditValuePrompt() {
            if (acceptableValuesWithCustomValues.size() > 0) {
                String value = acceptableValuesWithCustomValues.get(0);
                if (value.startsWith(AssignmentListItemWidget.EDIT_PREFIX))
                {
                    return value;
                }
            }
            return null;
{'fraction_non_alphanumeric': 0.07790782735918068, 'fraction_numerical': 0.003383321141185077, 'mean_word_length': 2.4523358585858586, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '381211', 'n_tokens_mistral': 2761, 'n_tokens_neox': 2639, 'n_words': 659}