/** Set context to edit */
  public void setPropertyImpl(Property prop) {

    PropertyName name = (PropertyName) prop;
    if (name == null) {
      sameLastNames = new Property[0];
      cLast.setValues(PropertyName.getLastNames(getRoot().getGedcom(), true));
      cLast.setText("");
      cFirst.setValues(PropertyName.getFirstNames(getRoot().getGedcom(), true));
      cFirst.setText("");
      tSuff.setText("");
      tNick.setText("");
    } else {
      // keep track of who has the same last name
      sameLastNames = name.getSameLastNames();
      // first, last, suff
      cLast.setValues(name.getLastNames(true));
      cLast.setText(name.getLastName());
      cFirst.setValues(name.getFirstNames(true));
      cFirst.setText(name.getFirstName());
      tSuff.setText(name.getSuffix());
      tNick.setText(name.getNick());
    }

    cAll.setVisible(false);
    cAll.setSelected(false);

    // done
  }
 /** Calculate message for replace all last names */
 private String getReplaceAllMsg() {
   if (sameLastNames.length < 2) return null;
   // we're using getDisplayValue() here
   // because like in PropertyRelationship's case there might be more
   // in the gedcom value than what we want to display (witness@INDI:BIRT)
   return RESOURCES.getString(
       "choice.global.confirm",
       "" + sameLastNames.length,
       ((PropertyName) getProperty()).getLastName(),
       cLast.getText());
 }
  /** Finish editing a property through proxy */
  @Override
  protected void commitImpl(Property property) {

    PropertyName p = (PropertyName) property;

    // ... calc texts
    String first = cFirst.getText().trim();
    String last = cLast.getText().trim();
    String suff = tSuff.getText().trim();
    String nick = tNick.getText().trim();

    Gedcom ged = p.getGedcom();
    if (ged != null) {
      switch (Options.getInstance().correctName) {
          // John DOE
        case 2:
          last = last.toUpperCase(ged.getLocale());
          cLast.setText(last);
          // John Doe
        case 1:
          if (first.length() > 0) {
            first =
                Character.toString(first.charAt(0)).toUpperCase(ged.getLocale())
                    + first.substring(1);
            cFirst.setText(first);
          }
      }
    }

    // ... store changed value
    p.setName(first, last, suff, cAll.isSelected());
    p.setNick(nick);

    // start fresh
    setPropertyImpl(p);

    // Done
  }
  public NameBean() {

    setLayout(LAYOUT.copy());

    cLast = new ChoiceWidget();
    cLast.addChangeListener(changeSupport);
    cLast.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            String msg = getReplaceAllMsg();
            if (msg != null) {
              cAll.setVisible(true);
              cAll.setToolTipText(msg);
            }
          }
        });
    cLast.setIgnoreCase(true);
    cFirst = new ChoiceWidget();
    cFirst.addChangeListener(changeSupport);
    cFirst.setIgnoreCase(true);
    tSuff = new TextFieldWidget("", 10);
    tSuff.addChangeListener(changeSupport);
    tNick = new TextFieldWidget("", 10);
    tNick.addChangeListener(changeSupport);

    cAll = new JCheckBox();
    cAll.setBorder(new EmptyBorder(1, 1, 1, 1));
    cAll.setVisible(false);
    cAll.setRequestFocusEnabled(false);

    add(new JLabel(PropertyName.getLabelForFirstName()));
    add(cFirst);

    add(new JLabel(PropertyName.getLabelForLastName()));
    add(cLast);
    add(cAll);

    add(new JLabel(PropertyName.getLabelForSuffix()));
    add(tSuff);

    add(new JLabel(Gedcom.getName("NICK")));
    add(tNick);

    // listen to selection of global and ask for confirmation
    cAll.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String msg = getReplaceAllMsg();
            if (msg != null && cAll.isSelected()) {
              int rc =
                  DialogHelper.openDialog(
                      RESOURCES.getString("choice.global.enable"),
                      DialogHelper.QUESTION_MESSAGE,
                      msg,
                      Action2.yesNo(),
                      NameBean.this);
              cAll.setSelected(rc == 0);
            }
          }
        });

    // we're done aside from declaring the default focus
    defaultFocus = cFirst;
  }