<commit_before>package devopsdistilled.operp.client.items;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import net.miginfocom.swing.MigLayout;
import devopsdistilled.operp.server.data.entity.items.Brand;
import devopsdistilled.operp.server.data.entity.items.Item;
import devopsdistilled.operp.server.data.entity.items.Product;

public class ItemPane implements ItemModelObserver {

	private ItemModel model;

	private ItemPaneController controller;

	private JDialog dialog;
	private JPanel pane;
	private JComponent owner;
	private JTextField textField;
	private JTextField textField_3;
	private JComboBox<Brand> comboBrands;
	private JComboBox<Product> comboProducts;

	public ItemPane(ItemPaneController itemPaneController, ItemModel itemModel) {

		this.model = itemModel;
		model.registerObserver(this);
		this.controller = itemPaneController;
	}

	public void init() {
		pane = new JPanel();
		pane.setLayout(new MigLayout("", "[][][grow][]", "[][][][][]"));

		JLabel lblProductName = new JLabel("Product Name");
		pane.add(lblProductName, "cell 0 0,alignx trailing");

		comboProducts = new JComboBox<Product>();
		pane.add(comboProducts, "flowx,cell 2 0,growx");

		JLabel lblBrandName = new JLabel("Brand Name");
		pane.add(lblBrandName, "cell 0 1,alignx trailing");

		comboBrands = new JComboBox<Brand>();

		pane.add(comboBrands, "flowx,cell 2 1,growx");

		JLabel lblItemId = new JLabel("Item Name");
		pane.add(lblItemId, "cell 0 2,alignx trailing");

		textField = new JTextField();

		pane.add(textField, "cell 2 2,growx");
		textField.setColumns(10);

		JLabel lblPrice = new JLabel("Price");
		pane.add(lblPrice, "cell 0 3,alignx trailing");

		textField_3 = new JTextField();
		pane.add(textField_3, "cell 2 3,growx");
		textField_3.setColumns(10);

		JButton btnCancel = new JButton("Cancel");
		btnCancel.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				getDialog().setVisible(false);
			}
		});
		pane.add(btnCancel, "flowx,cell 2 4");
		JButton btnSave = new JButton("Save");
		btnSave.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				Item item = new Item();
				Brand brand = (Brand) comboBrands.getSelectedItem();
				Product product = (Product) comboProducts.getSelectedItem();
				item.setBrand(brand);
				item.setProduct(product);

				if (controller.validate(item)) {
					controller.save(item);
				}
			}
		});
		pane.add(btnSave, "cell 2 4");

		JButton btnNewProduct = new JButton("New Product");
		pane.add(btnNewProduct, "cell 2 0");

		JButton btnNewBrand = new JButton("New Brand");
		btnNewBrand.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
			}
		});
		pane.add(btnNewBrand, "cell 2 1");

		dialog = new JDialog();

		controller.loadData();
	}

	public ItemPane() {
		// TODO Auto-generated constructor stub
	}

	public JComponent getPane() {
		return pane;
	}

	public JDialog getDialog() {
		dialog.getContentPane().add(getPane());
		dialog.setSize(640, 800);
		dialog.setLocationRelativeTo(owner);
		dialog.setVisible(true);
		return dialog;
	}

	@Override
	public void updateAll() {
		// TODO Auto-generated method stub

	}

	@Override
	public void updateProducts() {
		List<Product> products = model.getProducts();
		for (Product product : products) {
			comboProducts.addItem(product);
		}
		comboProducts.setSelectedItem(null);
	}

	@Override
	public void updateBrands() {
		List<Brand> brands = model.getBrands();
		for (Brand brand : brands) {
			comboBrands.addItem(brand);
		}
		comboBrands.setSelectedItem(null);
	}

	public void setOwner(JComponent owner) {
		this.owner = owner;
	}

}<commit_msg>Extend SubTaskPane<commit_after>package devopsdistilled.operp.client.items;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import net.miginfocom.swing.MigLayout;
import devopsdistilled.operp.client.abstracts.SubTaskPane;
import devopsdistilled.operp.server.data.entity.items.Brand;
import devopsdistilled.operp.server.data.entity.items.Item;
import devopsdistilled.operp.server.data.entity.items.Product;

public class ItemPane extends SubTaskPane implements ItemModelObserver {

	private final ItemModel model;

	private final ItemPaneController controller;

	private JPanel pane;
	private JTextField textField;
	private JTextField textField_3;
	private JComboBox<Brand> comboBrands;
	private JComboBox<Product> comboProducts;

	public ItemPane(ItemPaneController itemPaneController, ItemModel itemModel) {

		this.model = itemModel;
		model.registerObserver(this);
		this.controller = itemPaneController;
	}

	public void init() {
		pane = new JPanel();
		pane.setLayout(new MigLayout("", "[][][grow][]", "[][][][][]"));

		JLabel lblProductName = new JLabel("Product Name");
		pane.add(lblProductName, "cell 0 0,alignx trailing");

		comboProducts = new JComboBox<Product>();
		pane.add(comboProducts, "flowx,cell 2 0,growx");

		JLabel lblBrandName = new JLabel("Brand Name");
		pane.add(lblBrandName, "cell 0 1,alignx trailing");

		comboBrands = new JComboBox<Brand>();

		pane.add(comboBrands, "flowx,cell 2 1,growx");

		JLabel lblItemId = new JLabel("Item Name");
		pane.add(lblItemId, "cell 0 2,alignx trailing");

		textField = new JTextField();

		pane.add(textField, "cell 2 2,growx");
		textField.setColumns(10);

		JLabel lblPrice = new JLabel("Price");
		pane.add(lblPrice, "cell 0 3,alignx trailing");

		textField_3 = new JTextField();
		pane.add(textField_3, "cell 2 3,growx");
		textField_3.setColumns(10);

		JButton btnCancel = new JButton("Cancel");
		btnCancel.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				getDialog().setVisible(false);
			}
		});
		pane.add(btnCancel, "flowx,cell 2 4");
		JButton btnSave = new JButton("Save");
		btnSave.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				Item item = new Item();
				Brand brand = (Brand) comboBrands.getSelectedItem();
				Product product = (Product) comboProducts.getSelectedItem();
				item.setBrand(brand);
				item.setProduct(product);

				if (controller.validate(item)) {
					controller.save(item);
				}
			}
		});
		pane.add(btnSave, "cell 2 4");

		JButton btnNewProduct = new JButton("New Product");
		pane.add(btnNewProduct, "cell 2 0");

		JButton btnNewBrand = new JButton("New Brand");
		btnNewBrand.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
			}
		});
		pane.add(btnNewBrand, "cell 2 1");


		controller.loadData();
	}

	@Override
	public JComponent getPane() {
		return pane;
	}

	@Override
	public void updateAll() {
		// TODO Auto-generated method stub

	}

	@Override
	public void updateProducts() {
		List<Product> products = model.getProducts();
		for (Product product : products) {
			comboProducts.addItem(product);
		}
		comboProducts.setSelectedItem(null);
	}

	@Override
	public void updateBrands() {
		List<Brand> brands = model.getBrands();
		for (Brand brand : brands) {
			comboBrands.addItem(brand);
		}
		comboBrands.setSelectedItem(null);
	}

}
{'fraction_non_alphanumeric': 0.124950884086444, 'fraction_numerical': 0.0091683038637852, 'mean_word_length': 4.793626707132018, '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': '2653880', 'n_tokens_mistral': 2852, 'n_tokens_neox': 2485, 'n_words': 551}