<commit_before>package cz.metacentrum.perun.webgui.tabs.attributestabs;

import com.google.gwt.cell.client.FieldUpdater;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.*;
import cz.metacentrum.perun.webgui.client.PerunWebSession;
import cz.metacentrum.perun.webgui.client.UiElements;
import cz.metacentrum.perun.webgui.client.resources.ButtonType;
import cz.metacentrum.perun.webgui.client.resources.SmallIcons;
import cz.metacentrum.perun.webgui.json.JsonCallbackEvents;
import cz.metacentrum.perun.webgui.json.JsonUtils;
import cz.metacentrum.perun.webgui.json.attributesManager.ConvertAttributeToUnique;
import cz.metacentrum.perun.webgui.json.attributesManager.GetAttributeRights;
import cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights;
import cz.metacentrum.perun.webgui.json.attributesManager.UpdateAttribute;
import cz.metacentrum.perun.webgui.json.servicesManager.GetServicesByAttrDefinition;
import cz.metacentrum.perun.webgui.model.AttributeDefinition;
import cz.metacentrum.perun.webgui.model.AttributeRights;
import cz.metacentrum.perun.webgui.model.PerunError;
import cz.metacentrum.perun.webgui.model.Service;
import cz.metacentrum.perun.webgui.tabs.TabItem;
import cz.metacentrum.perun.webgui.tabs.servicestabs.ServiceDetailTabItem;
import cz.metacentrum.perun.webgui.widgets.CustomButton;
import cz.metacentrum.perun.webgui.widgets.ExtendedTextBox;
import cz.metacentrum.perun.webgui.widgets.TabMenu;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * Detail of Attribute definition
 *
 * @author <NAME> <<EMAIL>>
 */
public class AttributeDefinitionDetailTabItem implements TabItem {

	/**
	 * Perun web session
	 */
	private PerunWebSession session = PerunWebSession.getInstance();

	/**
	 * Content widget - should be simple panel
	 */
	private SimplePanel contentWidget = new SimplePanel();

	/**
	 * Title widget
	 */
	private Label titleWidget = new Label("Attribute");

	private AttributeDefinition def;
	private ArrayList<AttributeRights> rights = new ArrayList<AttributeRights>();

	private final CheckBox selfRead = new CheckBox();
	private final CheckBox selfWrite = new CheckBox();
	private final CheckBox voRead = new CheckBox();
	private final CheckBox voWrite = new CheckBox();
	private final CheckBox groupRead = new CheckBox();
	private final CheckBox groupWrite = new CheckBox();
	private final CheckBox facilityRead = new CheckBox();
	private final CheckBox facilityWrite = new CheckBox();

	private final CheckBox unique = new CheckBox();

	/**
	 * Creates a tab instance
	 */
	public AttributeDefinitionDetailTabItem(AttributeDefinition def){
		this.def = def;
	}

	public boolean isPrepared(){
		return true;
	}

	public Widget draw() {

		titleWidget.setText(def.getName());
		final TabItem tab = this;

		// create main panel for content
		final FlexTable mainPage = new FlexTable();
		mainPage.setWidth("100%");

		final ExtendedTextBox description = new ExtendedTextBox();
		description.setWidth("100%");
		description.getTextBox().setText(def.getDescription());
		final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {
			@Override
			public boolean validateTextBox() {
				if (description.getTextBox().getText().trim().isEmpty()) {
					description.setError("Description can't be empty.");
					return false;
				}
				description.setOk();
				return true;
			}
		};

		final ExtendedTextBox displayName = new ExtendedTextBox();
		displayName.setWidth("100%");
		displayName.getTextBox().setText(def.getDisplayName());
		final ExtendedTextBox.TextBoxValidator validatorName = new ExtendedTextBox.TextBoxValidator() {
			@Override
			public boolean validateTextBox() {
				if (displayName.getTextBox().getText().trim().isEmpty()) {
					displayName.setError("Display name can't be empty.");
					return false;
				}
				displayName.setOk();
				return true;
			}
		};

		description.setValidator(validator);
		displayName.setValidator(validatorName);


		//unique.setEnabled(false);
		unique.setValue(def.isUnique());

		if (Arrays.asList("core","virt").contains(def.getDefinition())) {

			unique.setEnabled(false);

		} else {

			unique.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
				@Override<commit_msg>GUI: Block conversion of entityless attributes to unique<commit_after>package cz.metacentrum.perun.webgui.tabs.attributestabs;

import com.google.gwt.cell.client.FieldUpdater;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.*;
import cz.metacentrum.perun.webgui.client.PerunWebSession;
import cz.metacentrum.perun.webgui.client.UiElements;
import cz.metacentrum.perun.webgui.client.resources.ButtonType;
import cz.metacentrum.perun.webgui.client.resources.SmallIcons;
import cz.metacentrum.perun.webgui.json.JsonCallbackEvents;
import cz.metacentrum.perun.webgui.json.JsonUtils;
import cz.metacentrum.perun.webgui.json.attributesManager.ConvertAttributeToUnique;
import cz.metacentrum.perun.webgui.json.attributesManager.GetAttributeRights;
import cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights;
import cz.metacentrum.perun.webgui.json.attributesManager.UpdateAttribute;
import cz.metacentrum.perun.webgui.json.servicesManager.GetServicesByAttrDefinition;
import cz.metacentrum.perun.webgui.model.AttributeDefinition;
import cz.metacentrum.perun.webgui.model.AttributeRights;
import cz.metacentrum.perun.webgui.model.PerunError;
import cz.metacentrum.perun.webgui.model.Service;
import cz.metacentrum.perun.webgui.tabs.TabItem;
import cz.metacentrum.perun.webgui.tabs.servicestabs.ServiceDetailTabItem;
import cz.metacentrum.perun.webgui.widgets.CustomButton;
import cz.metacentrum.perun.webgui.widgets.ExtendedTextBox;
import cz.metacentrum.perun.webgui.widgets.TabMenu;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * Detail of Attribute definition
 *
 * @author <NAME> <<EMAIL>>
 */
public class AttributeDefinitionDetailTabItem implements TabItem {

	/**
	 * Perun web session
	 */
	private PerunWebSession session = PerunWebSession.getInstance();

	/**
	 * Content widget - should be simple panel
	 */
	private SimplePanel contentWidget = new SimplePanel();

	/**
	 * Title widget
	 */
	private Label titleWidget = new Label("Attribute");

	private AttributeDefinition def;
	private ArrayList<AttributeRights> rights = new ArrayList<AttributeRights>();

	private final CheckBox selfRead = new CheckBox();
	private final CheckBox selfWrite = new CheckBox();
	private final CheckBox voRead = new CheckBox();
	private final CheckBox voWrite = new CheckBox();
	private final CheckBox groupRead = new CheckBox();
	private final CheckBox groupWrite = new CheckBox();
	private final CheckBox facilityRead = new CheckBox();
	private final CheckBox facilityWrite = new CheckBox();

	private final CheckBox unique = new CheckBox();

	/**
	 * Creates a tab instance
	 */
	public AttributeDefinitionDetailTabItem(AttributeDefinition def){
		this.def = def;
	}

	public boolean isPrepared(){
		return true;
	}

	public Widget draw() {

		titleWidget.setText(def.getName());
		final TabItem tab = this;

		// create main panel for content
		final FlexTable mainPage = new FlexTable();
		mainPage.setWidth("100%");

		final ExtendedTextBox description = new ExtendedTextBox();
		description.setWidth("100%");
		description.getTextBox().setText(def.getDescription());
		final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {
			@Override
			public boolean validateTextBox() {
				if (description.getTextBox().getText().trim().isEmpty()) {
					description.setError("Description can't be empty.");
					return false;
				}
				description.setOk();
				return true;
			}
		};

		final ExtendedTextBox displayName = new ExtendedTextBox();
		displayName.setWidth("100%");
		displayName.getTextBox().setText(def.getDisplayName());
		final ExtendedTextBox.TextBoxValidator validatorName = new ExtendedTextBox.TextBoxValidator() {
			@Override
			public boolean validateTextBox() {
				if (displayName.getTextBox().getText().trim().isEmpty()) {
					displayName.setError("Display name can't be empty.");
					return false;
				}
				displayName.setOk();
				return true;
			}
		};

		description.setValidator(validator);
		displayName.setValidator(validatorName);


		//unique.setEnabled(false);
		unique.setValue(def.isUnique());

		if (Arrays.asList("core","virt").contains(def.getDefinition()) || def.getEntity().equals("entityless")) {

			unique.setEnabled(false);

		} else {

			unique.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
				@Override
{'fraction_non_alphanumeric': 0.11357104843001596, 'fraction_numerical': 0.0019159127195316659, 'mean_word_length': 5.2723631508678235, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '382837', 'n_tokens_mistral': 2985, 'n_tokens_neox': 2734, 'n_words': 535}