/**
* 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.search;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MessageBox;
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.PersonChoiceShell;
/**
* Sucht alle Personen, die keine Verbindung zur aktuellen Person besitzen und
* zeigt diese eigens an.
* @author Christian Packenius, Juli 2008.
*/
public class SearchPersonsWithoutConnectionToCurrentPerson implements Listener {
/**
* Personen suchen und anzeigen.
* @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
*/
public void handleEvent(Event event) {
// Die Personen suchen, die keine Verbindung zur aktuellen Person haben.
Person[] persons = Family.instance.getPersonsArray();
List<Person> allConnections = new ArrayList<Person>();
allConnections.add(Family.instance.getCurrentPerson());
int i = 0;
while (i < allConnections.size()) {
Person person = allConnections.get(i++);
addPersonsToList(allConnections, person.getChildren());
addPersonsToList(allConnections, person.getParents());
addPersonsToList(allConnections, person.getPartner());
}
boolean bFound = false;
for (Person person : persons) {
if (!allConnections.contains(person)) {
bFound = true;
break;
}
}
if (!bFound) {
MessageBox mb = new MessageBox(GUI.instance.shell, SWT.ICON_INFORMATION | SWT.OK);
mb.setMessage("Es wurde keine Person ohne Verbindung gefunden; alle eingetragenen\r\nPersonen geh�ren der gleichen Familie an.");
mb.setText("Nicht gefunden");
mb.open();
return;
}
// Shell erzeugen und anzeigen.
PersonChoiceShell pcs = new PersonChoiceShell(GUI.instance.shell, "Personen ohne Verbindung", "Anzeigen", null, 1,
true, null, false);
for (Person person : persons) {
if (!allConnections.contains(person)) {
pcs.addPerson(person, null);
}
}
pcs.open();
if (pcs.personChoice != null) {
Family.instance.setCurrentPerson(pcs.personChoice, 2);
}
}
/**
* F�gt alle angegebenen Personen der Liste hinzu.
* @param allConnections
* @param persons
*/
private void addPersonsToList(List<Person> allConnections, Person[] persons) {
for (Person person : persons) {
if (!allConnections.contains(person)) {
allConnections.add(person);
}
}
}
}