<commit_before>/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * 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 com.intellij.xml.actions.xmlbeans;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ArrayUtil;
import com.intellij.xml.XmlBundle;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.File;
import java.util.Arrays;
import java.util.List;

/**
 * @author <NAME>
 */
public class GenerateSchemaFromInstanceDocumentDialog extends DialogWrapper {
  private JPanel panel;
  private TextFieldWithBrowseButton generateFromUrl;
  private JLabel status;
  private JLabel statusText;
  private JLabel generateFromUrlText;
  private JLabel designTypeText;
  private JTextField detectEnumerationsLimit;
  private ComboBox detectSimpleContentTypes;
  private ComboBox designType;
  private JLabel detectEnumerationsLimitText;
  private JLabel detectSimpleContentTypesText;
  private JLabel resultSchemaFileNameText;
  private JTextField resultSchemaFileName;

  static final String LOCAL_ELEMENTS_GLOBAL_COMPLEX_TYPES = XmlBundle.message("local.elements.global.complex.types.option.name");
  static final String LOCAL_ELEMENTS_TYPES = XmlBundle.message("local.elements.types.option.name");
  static final String GLOBAL_ELEMENTS_LOCAL_TYPES = XmlBundle.message("global.elements.local.types.option.name");

  private static final List<String> designTypes = Arrays.asList(
    LOCAL_ELEMENTS_GLOBAL_COMPLEX_TYPES,
    LOCAL_ELEMENTS_TYPES,
    GLOBAL_ELEMENTS_LOCAL_TYPES
  );

  static final String STRING_TYPE = "string";
  static final String SMART_TYPE = "smart";
  private static final List<String> simpleContentTypes = Arrays.asList(STRING_TYPE, SMART_TYPE);
  private Runnable myOkAction;

  public GenerateSchemaFromInstanceDocumentDialog(Project project, VirtualFile file) {
    super(project, true);

    setTitle(XmlBundle.message("generate.schema.from.instance.document.dialog.title"));

    doInitFor(designTypeText, designType);
    configureComboBox(designType,designTypes);

    doInitFor(detectSimpleContentTypesText, detectSimpleContentTypes);
    configureComboBox(detectSimpleContentTypes, simpleContentTypes);


    doInitFor(detectEnumerationsLimitText, detectEnumerationsLimit);
    detectEnumerationsLimit.setText("10");


    UIUtils.configureBrowseButton(project, generateFromUrl, new String[] {"xml"}, XmlBundle.message("select.xml.document.dialog.title"), false);
    doInitFor(generateFromUrlText, generateFromUrl.getTextField());

    doInitFor(resultSchemaFileNameText, resultSchemaFileName);

    init();
    
    generateFromUrl.setText(file.getPresentableUrl());
    resultSchemaFileName.setText(file.getName() + ".xsd");
  }

  private void validateData() {
    String msg = doValidateWithData();
    setOKActionEnabled(msg == null);
    status.setText(msg == null ? "" : msg);
    status.setForeground(Color.RED);<commit_msg>IDEA-58114 Awkward naming of schema in "Generate schema from instance document"<commit_after>/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * 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 com.intellij.xml.actions.xmlbeans;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ArrayUtil;
import com.intellij.xml.XmlBundle;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.File;
import java.util.Arrays;
import java.util.List;

/**
 * @author <NAME>
 */
public class GenerateSchemaFromInstanceDocumentDialog extends DialogWrapper {
  private JPanel panel;
  private TextFieldWithBrowseButton generateFromUrl;
  private JLabel status;
  private JLabel statusText;
  private JLabel generateFromUrlText;
  private JLabel designTypeText;
  private JTextField detectEnumerationsLimit;
  private ComboBox detectSimpleContentTypes;
  private ComboBox designType;
  private JLabel detectEnumerationsLimitText;
  private JLabel detectSimpleContentTypesText;
  private JLabel resultSchemaFileNameText;
  private JTextField resultSchemaFileName;

  static final String LOCAL_ELEMENTS_GLOBAL_COMPLEX_TYPES = XmlBundle.message("local.elements.global.complex.types.option.name");
  static final String LOCAL_ELEMENTS_TYPES = XmlBundle.message("local.elements.types.option.name");
  static final String GLOBAL_ELEMENTS_LOCAL_TYPES = XmlBundle.message("global.elements.local.types.option.name");

  private static final List<String> designTypes = Arrays.asList(
    LOCAL_ELEMENTS_GLOBAL_COMPLEX_TYPES,
    LOCAL_ELEMENTS_TYPES,
    GLOBAL_ELEMENTS_LOCAL_TYPES
  );

  static final String STRING_TYPE = "string";
  static final String SMART_TYPE = "smart";
  private static final List<String> simpleContentTypes = Arrays.asList(STRING_TYPE, SMART_TYPE);
  private Runnable myOkAction;

  public GenerateSchemaFromInstanceDocumentDialog(Project project, VirtualFile file) {
    super(project, true);

    setTitle(XmlBundle.message("generate.schema.from.instance.document.dialog.title"));

    doInitFor(designTypeText, designType);
    configureComboBox(designType,designTypes);

    doInitFor(detectSimpleContentTypesText, detectSimpleContentTypes);
    configureComboBox(detectSimpleContentTypes, simpleContentTypes);


    doInitFor(detectEnumerationsLimitText, detectEnumerationsLimit);
    detectEnumerationsLimit.setText("10");


    UIUtils.configureBrowseButton(project, generateFromUrl, new String[] {"xml"}, XmlBundle.message("select.xml.document.dialog.title"), false);
    doInitFor(generateFromUrlText, generateFromUrl.getTextField());

    doInitFor(resultSchemaFileNameText, resultSchemaFileName);

    init();
    
    generateFromUrl.setText(file.getPresentableUrl());
    resultSchemaFileName.setText(file.getNameWithoutExtension() + ".xsd");
  }

  private void validateData() {
    String msg = doValidateWithData();
    setOKActionEnabled(msg == null);
    status.setText(msg == null ? "" : msg);
    status.setForeground(Color.RED);
{'fraction_non_alphanumeric': 0.08955029893423447, 'fraction_numerical': 0.00428905640759033, 'mean_word_length': 5.521186440677966, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 10}, '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': '7594717', 'n_tokens_mistral': 2223, 'n_tokens_neox': 2172, 'n_words': 521}