<commit_before>package org.wtk.jquery.ui.dialog;

import net.sf.json.JSONFunction;
import net.sf.json.JSONObject;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.IAjaxCallDecorator;
import org.apache.wicket.behavior.IBehavior;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.StringResourceModel;
import org.wtk.behavior.ajax.EventlessAjaxBehavior;
import org.wtk.behavior.ajax.EventlessAjaxFormSubmitBehavior;
import org.wtk.component.panel.base.BasePanel;
import org.wtk.component.support.plugin.PluginManager;
import org.wtk.jquery.model.JQuery;
import org.wtk.jquery.model.JQueryOption;
import org.wtk.jquery.ui.util.JQueryOptionSerializer;
import org.wtk.model.Titled;
import org.wtk.util.Ajax;
import org.wtk.util.ModelUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import static java.lang.String.format;
import static org.wtk.component.list.ComponentListView.ITEM_ID;
import static org.wtk.jquery.model.JQuery.Position;


/**
 * jQuery UI Dialog.
 * <p/>
 * For demo and options details see <a href="http://jqueryui.com/demos/dialog/">jQuery UI site</a>.
 *
 * @author <NAME>
 */
public class JQueryDialog<T extends Serializable> extends BasePanel<T> implements Titled {
	private static final JQueryOptionSerializer<JQueryDialog> optionSerializer = new JQueryOptionSerializer<JQueryDialog>(JQueryDialog.class);

	private EventlessAjaxBehavior closeEvent;
	private Integer height;
	private Integer maxHeight;
	private Integer maxWidth;
	private Integer minHeight = 150;
	private Integer minWidth = 150;
	private Integer width = 300;
	private JQuery.Effect hideEffect;
	private JQuery.Effect showEffect;
	private JQueryDialog wrappingDialog;
	private Position position = Position.CENTER_CENTER;
	private String closeText;
	private String cssClass;
	private String title;
	private List<IDialogButton> buttons;

	private boolean bgiFrame = false;
	private boolean draggable = true;
	private boolean modal = true;
	private boolean resizable = true;
	private int zIndex = 1000;

	public JQueryDialog() {
		this(null);
	}

	public JQueryDialog(IModel model) {
		super(ITEM_ID, model);

		setOutputMarkupPlaceholderTag(true);
		closeEvent = new AjaxCloseEvent();
		add(closeEvent);
	}

	public BasePanel wrap(Form form) {
		wrappingDialog = new JQueryDialogFormWrapper(this, form);
		return this;
	}

	public JQueryDialog<T> add(IDialogButton button) {
		return addButton(button);
	}

	public JQueryDialog<T> remove(IDialogButton button) {
		return removeButton(button);
	}

	public JQueryDialog<T> addButton(IDialogButton button) {
		if (buttons == null) {
			buttons = new ArrayList<IDialogButton>();
		}
		buttons.add(button);
		add((IBehavior) button);
		return this;
	}

	public JQueryDialog<T> removeButton(IDialogButton button) {
		if (buttons != null) {
			buttons.remove(button);
			remove((IBehavior) button);
		}
		return this;
	}

	public void show() {
		getPlugin().show(this);
	}

	public void close() {
		getPlugin().close(this);
	}

	@JQueryOption()
	public Integer getHeight() {
		return height;
	}

	public JQueryDialog<T> setHeight(Integer height) {
		this.height = height;
		return this;
	}

	@JQueryOption()
	public Integer getMaxHeight() {
		return maxHeight;
	}

	public JQueryDialog<T> setMaxHeight(Integer maxHeight) {
		this.maxHeight = maxHeight;
		return this;
	}

	@JQueryOption()
	public Integer getMaxWidth() {
		return maxWidth;
	}

	public JQueryDialog<T> setMaxWidth(Integer maxWidth) {
		this.maxWidth = maxWidth;
		return this;
	}

	@JQueryOption()
	public Integer getMinHeight() {
		return minHeight;
	}

	public JQueryDialog<T> setMinHeight(Integer minHeight) {
		this.minHeight = minHeight;
		return this;
	}

	@JQueryOption()
	public Integer getMinWidth() {
		return minWidth;
	}

	public JQueryDialog<T> setMinWidth(Integer minWidth) {
		this.minWidth = minWidth;
		return this;
	}

	@JQueryOption()
	public Integer getWidth() {
		return width;
	}

	public JQueryDialog<T> setWidth(Integer width) {
		this.width = width;
		return this;
	}

	@JQueryOption()
	public Position getPosition() {
		return position;
	}

	public JQueryDialog<T> setPosition(Position position) {
		this.position = position;
		return this;
	}

	@JQueryOption("buttons")
	public JSONObject getButtonsObject() {
		final JSONObject jsonObject = new JSONObject();
		for (IDialogButton button : buttons) {
			final String text = ModelUtils.toString(button.getTextModel());
			final JSONFunction jsonFunction = new JSONFunction(button.getCallScript());
			jsonObject.put(text, jsonFunction);
		}
		return jsonObject;
	}

	@JQueryOption()
	public String getCloseText() {
		if (closeText == null) {
			closeText = getSafeString("jquery.dialog.close");
		}
		return closeText;
	}

	public JQueryDialog<T> setCloseText(String closeText) {
		this.closeText = closeText;
		return this;
	}
<commit_msg>fixed JQueryDialog null pointer bug<commit_after>package org.wtk.jquery.ui.dialog;

import net.sf.json.JSONFunction;
import net.sf.json.JSONObject;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.IAjaxCallDecorator;
import org.apache.wicket.behavior.IBehavior;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.StringResourceModel;
import org.wtk.behavior.ajax.EventlessAjaxBehavior;
import org.wtk.behavior.ajax.EventlessAjaxFormSubmitBehavior;
import org.wtk.component.panel.base.BasePanel;
import org.wtk.component.support.plugin.PluginManager;
import org.wtk.jquery.model.JQuery;
import org.wtk.jquery.model.JQueryOption;
import org.wtk.jquery.ui.util.JQueryOptionSerializer;
import org.wtk.model.Titled;
import org.wtk.util.Ajax;
import org.wtk.util.ModelUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import static java.lang.String.format;
import static org.wtk.component.list.ComponentListView.ITEM_ID;
import static org.wtk.jquery.model.JQuery.Position;


/**
 * jQuery UI Dialog.
 * <p/>
 * For demo and options details see <a href="http://jqueryui.com/demos/dialog/">jQuery UI site</a>.
 *
 * @author <NAME>
 */
public class JQueryDialog<T extends Serializable> extends BasePanel<T> implements Titled {
	private static final JQueryOptionSerializer<JQueryDialog> optionSerializer = new JQueryOptionSerializer<JQueryDialog>(JQueryDialog.class);

	private EventlessAjaxBehavior closeEvent;
	private Integer height;
	private Integer maxHeight;
	private Integer maxWidth;
	private Integer minHeight = 150;
	private Integer minWidth = 150;
	private Integer width = 300;
	private JQuery.Effect hideEffect;
	private JQuery.Effect showEffect;
	private JQueryDialog wrappingDialog;
	private Position position = Position.CENTER_CENTER;
	private String closeText;
	private String cssClass;
	private String title;
	private List<IDialogButton> buttons;

	private boolean bgiFrame = false;
	private boolean draggable = true;
	private boolean modal = true;
	private boolean resizable = true;
	private int zIndex = 1000;

	public JQueryDialog() {
		this(null);
	}

	public JQueryDialog(IModel model) {
		super(ITEM_ID, model);

		setOutputMarkupPlaceholderTag(true);
		closeEvent = new AjaxCloseEvent();
		add(closeEvent);
	}

	public BasePanel wrap(Form form) {
		wrappingDialog = new JQueryDialogFormWrapper(this, form);
		return this;
	}

	public JQueryDialog<T> add(IDialogButton button) {
		return addButton(button);
	}

	public JQueryDialog<T> remove(IDialogButton button) {
		return removeButton(button);
	}

	public JQueryDialog<T> addButton(IDialogButton button) {
		if (buttons == null) {
			buttons = new ArrayList<IDialogButton>();
		}
		buttons.add(button);
		add((IBehavior) button);
		return this;
	}

	public JQueryDialog<T> removeButton(IDialogButton button) {
		if (buttons != null) {
			buttons.remove(button);
			remove((IBehavior) button);
		}
		return this;
	}

	public void show() {
		getPlugin().show(this);
	}

	public void close() {
		getPlugin().close(this);
	}

	@JQueryOption()
	public Integer getHeight() {
		return height;
	}

	public JQueryDialog<T> setHeight(Integer height) {
		this.height = height;
		return this;
	}

	@JQueryOption()
	public Integer getMaxHeight() {
		return maxHeight;
	}

	public JQueryDialog<T> setMaxHeight(Integer maxHeight) {
		this.maxHeight = maxHeight;
		return this;
	}

	@JQueryOption()
	public Integer getMaxWidth() {
		return maxWidth;
	}

	public JQueryDialog<T> setMaxWidth(Integer maxWidth) {
		this.maxWidth = maxWidth;
		return this;
	}

	@JQueryOption()
	public Integer getMinHeight() {
		return minHeight;
	}

	public JQueryDialog<T> setMinHeight(Integer minHeight) {
		this.minHeight = minHeight;
		return this;
	}

	@JQueryOption()
	public Integer getMinWidth() {
		return minWidth;
	}

	public JQueryDialog<T> setMinWidth(Integer minWidth) {
		this.minWidth = minWidth;
		return this;
	}

	@JQueryOption()
	public Integer getWidth() {
		return width;
	}

	public JQueryDialog<T> setWidth(Integer width) {
		this.width = width;
		return this;
	}

	@JQueryOption()
	public Position getPosition() {
		return position;
	}

	public JQueryDialog<T> setPosition(Position position) {
		this.position = position;
		return this;
	}

	@JQueryOption("buttons")
	public JSONObject getButtonsJSONObject() {
		if (buttons == null) {
			return null;
		}
		final JSONObject jsonObject = new JSONObject();
		for (IDialogButton button : buttons) {
			final String text = ModelUtils.toString(button.getTextModel());
			final JSONFunction jsonFunction = new JSONFunction(button.getCallScript());
			jsonObject.put(text, jsonFunction);
		}
		return jsonObject;
	}

	@JQueryOption()
	public String getCloseText() {
		if (closeText == null) {
			closeText = getSafeString("jquery.dialog.close");
		}
		return closeText;
	}

	public JQueryDialog<T> setCloseText(String closeText) {
		this.closeText = closeText;
		return this;
	}

{'fraction_non_alphanumeric': 0.10612855007473841, 'fraction_numerical': 0.0025909317389138015, 'mean_word_length': 4.903529411764706, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, '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': '5400917', 'n_tokens_mistral': 3425, 'n_tokens_neox': 3198, 'n_words': 747}