public void doOk() {
		this.isClosedByOk = true;
		String name = this.txfName.getText().trim();
		Object sel = this.cbxType.getSelectedItem();
		StockType type = StockType.SEMI;
		if (sel != null && sel instanceof StockType) {
			type = (StockType) sel;
		}

		int capacity = 64, maxTrays = 16, unitsPerRow = 8;

		try {
			capacity = Math.abs(Integer.parseInt(this.txfCapacity.getText()
					.trim()));
		}
		catch (NumberFormatException e) {
			JOptionPane.showMessageDialog(this,
					"Please enter a valid number for the capacity. ", "Error",
					JOptionPane.ERROR_MESSAGE);
			this.isClosedByOk = false;
			return;
		}

		try {
			maxTrays = Math.abs(Integer.parseInt(this.txfMaxTrays.getText()
					.trim()));
		}
		catch (NumberFormatException e) {
			JOptionPane
					.showMessageDialog(
							this,
							"Please enter a valid number for the maximum trays per storage unit. ",
							"Error", JOptionPane.ERROR_MESSAGE);
			this.isClosedByOk = false;
			return;
		}

		try {
			unitsPerRow = Math.abs(Integer.parseInt(this.txfUnitsPerRow
					.getText().trim()));
		}
		catch (NumberFormatException e) {
			JOptionPane
					.showMessageDialog(
							this,
							"Please enter a valid number for the storage units per row. ",
							"Error", JOptionPane.ERROR_MESSAGE);
			this.isClosedByOk = false;
			return;
		}

		if (this.stock != null) {
			try {
				Service.updateStock(this.stock, name, type, capacity, maxTrays,
						unitsPerRow);
			}
			catch (StockNotEmptyException e) {
				JOptionPane.showMessageDialog(this, e.getMessage(), "Error",
						JOptionPane.ERROR_MESSAGE);
				this.isClosedByOk = false;
				return;
			}
			JOptionPane.showMessageDialog(this,
					"The stock \"" + this.stock.getName()
							+ "\" was updated successfully. ", "Updated",
					JOptionPane.INFORMATION_MESSAGE);
		}
		else {
			this.stock = Service.createStock(name, type, capacity, maxTrays,
					unitsPerRow);
			JOptionPane.showMessageDialog(this,
					"The stock \"" + this.stock.getName()
							+ "\" was created successfully. ", "Created",
					JOptionPane.INFORMATION_MESSAGE);
		}
		this.setVisible(false);
	}