public void setTitle() {
   if (isAdd) {
     Warehouse w = (Warehouse) ddlbWarehouseId.getSelectedItem();
     this.setTitle(w.getWarehouseName() + " | " + myPart.getPartName());
   } else {
     this.setTitle(item.getWarehouse().getWarehouseName() + " | " + myPart.getPartName());
   }
 }
  /** Reload fields with model data Used when model notifies view of change */
  public void refreshFields() {
    if (isAdd) {
      ddlbWarehouseId.setSelectedIndex(0);
      fldItemQuantity.setText("");
    } else {
      ddlbWarehouseId.getModel().setSelectedItem(item.getWarehouse().getId());
      fldItemQuantity.setText(Double.toString(item.getQuantity()));
    }
    // lblPersonName.setText(personDog.getOwner().getFullName());
    lblPartName.setText(myPart.getPartName());

    // update window title
    setTitle();

    // flag as unchanged
    setChanged(false);
  }
  /**
   * Constructor
   *
   * @param title
   */
  public PartOwnerDetailView(
      String title,
      Part p,
      InventoryItem i,
      InventoryItemList iList,
      WarehouseList wList,
      MDIParent m) {
    super(title, m);

    myPart = p;
    this.iList = iList;
    item = i;

    // if personDog is null then this is an add
    if (item == null) isAdd = true;
    else isAdd = false;

    // register as an observer
    if (!isAdd) {
      item.addObserver(this);
      // also register as an observer to person and to dog in case the names change
      item.getWarehouse().addObserver(this);
      item.getPart().addObserver(this);
    }

    // prep layout and fields
    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(3, 2));

    panel.add(new JLabel("Warehouse name: "));
    List<Long> keyList = new ArrayList<Long>();
    List<Warehouse> valList = new ArrayList<Warehouse>();
    for (Warehouse w : wList.getList()) {
      keyList.add(w.getId());
      valList.add(w);
    }
    if (keyList != null && valList != null) {
      ddlbWarehouseId =
          new JComboBox(
              new KVComboModel<Long, Warehouse>(
                  keyList.toArray(new Long[keyList.size()]),
                  valList.toArray(new Warehouse[valList.size()])));
      ddlbWarehouseId.getModel().setSelectedItem(1);
      // add a listener to know when gender changes so we can flag record as changed to prompt for
      // save
      ddlbWarehouseId.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              // get the selected value
              Warehouse newWarehouse = (Warehouse) ddlbWarehouseId.getSelectedItem();
              setTitle();
              if (!isAdd && newWarehouse.getId() != item.getWarehouse().getId()) setChanged(true);
            }
          });
    }
    // if edit, then disable person selection
    if (!isAdd) ddlbWarehouseId.setEnabled(false);
    panel.add(ddlbWarehouseId);

    panel.add(new JLabel("Part name"));
    lblPartName = new JLabel(myPart.getPartName());
    panel.add(lblPartName);

    panel.add(new JLabel("Quantity"));
    fldItemQuantity = new JTextField("");
    fldItemQuantity.addKeyListener(new TextfieldChangeListener());
    panel.add(fldItemQuantity);

    this.add(panel, BorderLayout.CENTER);

    // add a Save button to write field changes back to model data
    panel = new JPanel();
    panel.setLayout(new FlowLayout());
    JButton button = new JButton("Save Record");
    button.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            saveModel();
          }
        });
    panel.add(button);

    this.add(panel, BorderLayout.SOUTH);

    // load fields with model data
    refreshFields();

    // can't call this on JPanel
    // this.pack();
    this.setPreferredSize(new Dimension(450, 150));
  }