Package de.chris_soft.fyllgen.menu.edit

Source Code of de.chris_soft.fyllgen.menu.edit.InsertParentPerson

/**
* FyLLGen - A Java based tool for collecting and distributing family data
*
* Copyright (C) 2007-2011 Christian Packenius
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package de.chris_soft.fyllgen.menu.edit;

import java.util.List;

import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

import de.chris_soft.fyllgen.GUI;
import de.chris_soft.fyllgen.data.Family;
import de.chris_soft.fyllgen.data.Person;
import de.chris_soft.fyllgen.widget.dialog.MultiPersonChoiceShell;
import de.chris_soft.fyllgen.widget.dialog.PersonChoiceShell;

/**
* Selection-Listener f�r das Erzeugen eines Elternteils der aktuellen Person.
* @author Christian Packenius, Juni 2008.
*/
public class InsertParentPerson implements Listener {
  /**
   * Event-Handler f�r Erzeugung eines Elternteils.
   * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
   */
  public void handleEvent(Event event) {
    // Aktuelle Person merken.
    Person child = Family.instance.getCurrentPerson();

    PersonChoiceShell pcs = new PersonChoiceShell(GUI.instance.shell, "Elternteil hinzuf�gen",
        "Als Elternteil eintragen", "Neues Elternteil erzeugen", 2, false, null, false);

    // Verschiedene Personen raus nehmen.
    pcs.removePerson(child);
    for (Person person : child.getChildren()) {
      pcs.removePerson(person);
    }
    for (Person person : child.getParents()) {
      pcs.removePerson(person);
    }

    pcs.open();

    // Erzeugtes oder vorhandenes und nun eingetragenes Elternteil.
    Person parent = null;

    if (pcs.personChoice != null) {
      // Es wurde eine vorhandene Person angew�hlt.
      Family.instance.getCurrentPerson().addParent(pcs.personChoice);
      Family.instance.review();
      parent = pcs.personChoice;
    }
    else if (pcs.newPersonName != null) {
      parent = new Person();
      parent.setValue(Person.NAME, pcs.newPersonName);
      Family.instance.addNewPerson(parent);
      Family.instance.getCurrentPerson().addParent(parent);
      Family.instance.setCurrentPerson(parent, 2);
    }
    else {
      return;
    }

    // Da nun ein Elternteil eingetragen wurde, auch f�r jeden Partner einzeln
    // nachfragen, ob es dessen Kind ist.
    String msgText = "Bei welchen der folgenden Personen soll <" + parent.getValueView(Person.NAME)
        + "> noch zus�tzlich als Elternteil eingetragen werden?";
    MultiPersonChoiceShell mpcs = new MultiPersonChoiceShell(GUI.instance.shell, "Elternteil hinzuf�gen", msgText);

    // Alle Partner der aktuellen Person angeben.
    Person[] siblings = child.getSiblings();
    for (Person person : siblings) {
      if (!parent.hasParent(person)) {
        mpcs.add(person, null, true, false);
      }
    }

    // Dialog �ffnen.
    mpcs.open();

    // Hat der User den Dialog �ber den OK-Button verlassen?
    if (mpcs.bPressedOkay) {
      // Ja, also hier bei allen angeklickten Personen ebenfalls
      // parent-child-Beziehung eintragen.
      List<Person> list = mpcs.getCheckedPersons();
      for (Person person : list) {
        person.addParent(parent);
      }
      Family.instance.review();
    }
  }
}
TOP

Related Classes of de.chris_soft.fyllgen.menu.edit.InsertParentPerson

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.