* falls sie nicht schon existieren.
* @see de.willuhn.jameica.gui.Action#handleAction(java.lang.Object)
*/
public void handleAction(Object context) throws ApplicationException
{
I18N i18n = Application.getPluginLoader().getPlugin(HBCI.class).getResources().getI18N();
if (context == null)
throw new ApplicationException(i18n.tr("Bitte w�hlen Sie ein oder mehrere Auftr�ge aus"));
if (!(context instanceof Transfer) &&
!(context instanceof Transfer[]) &&
!(context instanceof Address) &&
!(context instanceof Address[]) &&
!(context instanceof Umsatz) &&
!(context instanceof Umsatz[]))
throw new ApplicationException(i18n.tr("Bitte w�hlen Sie ein oder mehrere Auftr�ge aus"));
List<HibiscusAddress> items = new ArrayList<HibiscusAddress>();
try {
///////////////////////////////////////////////////////////////
// Transfers
if (context instanceof Transfer)
{
Transfer t = (Transfer) context;
items.add(create(t.getGegenkontoName(),t.getGegenkontoNummer(),t.getGegenkontoBLZ()));
}
else if (context instanceof Transfer[])
{
Transfer[] list = (Transfer[]) context;
for (int i=0;i<list.length;++i)
{
Transfer t = list[i];
items.add(create(t.getGegenkontoName(),t.getGegenkontoNummer(),t.getGegenkontoBLZ()));
}
}
///////////////////////////////////////////////////////////////
// Hibiscus-Adressen
else if (context instanceof HibiscusAddress)
{
items.add((HibiscusAddress)context);
}
else if (context instanceof HibiscusAddress[])
{
HibiscusAddress[] list = (HibiscusAddress[]) context;
for (int i=0;i<list.length;++i)
{
items.add(list[i]);
}
}
///////////////////////////////////////////////////////////////
// Address
else if (context instanceof Address)
{
Address a = (Address) context;
items.add(create(a.getName(),a.getKontonummer(),a.getBlz()));
}
else if (context instanceof Address[])
{
Address[] list = (Address[]) context;
for (int i=0;i<list.length;++i)
{
Address a = list[i];
items.add(create(a.getName(),a.getKontonummer(),a.getBlz()));
}
}
///////////////////////////////////////////////////////////////
if (items.size() == 0)
return;
// Falls mehrere Eintraege markiert sind, kann es sein, dass einige
// davon doppelt da sind, die fischen wir raus.
HashMap seen = new HashMap();
AddressbookService book = (AddressbookService) Application.getServiceFactory().lookup(HBCI.class,"addressbook");
String q1 = i18n.tr("Eine Adresse mit dem Namen {0} (Kto. {1}, BLZ {2}) existiert bereits im Adressbuch.\n" +
"M�chten Sie die Adresse dennoch hinzuf�gen?");
String q2 = i18n.tr("Eine Adresse mit dem Namen {0} (IBAN {1}) existiert bereits im Adressbuch.\n" +
"M�chten Sie die Adresse dennoch hinzuf�gen?");
int count = 0;
for (int i=0;i<items.size();++i)
{
// wir checken erstmal, ob wir den schon haben.
HibiscusAddress e = items.get(i);
if (e.getName() == null || e.getName().length() == 0)
{
Logger.warn("address [kto. " + e.getKontonummer() + ", blz " + e.getBlz() + " has no name, skipping");
continue;
}
String key = e.getName() + "-" + e.getKontonummer() + "-" + e.getBlz() + "-" + e.getIban();
if (seen.get(key) != null)
continue; // den hatten wir schonmal. Und wir wollen den User doch nicht immer wieder fragen
seen.put(key,e);
if (book.contains(e) != null)
{
if (StringUtils.trimToNull(e.getKontonummer()) != null)
{
if (!Application.getCallback().askUser(q1,new String[]{e.getName(),e.getKontonummer(),e.getBlz()}))
continue;
}
else
{
if (!Application.getCallback().askUser(q2,new String[]{e.getName(),e.getIban()}))
continue;
}
}
// OK, speichern
e.store();
count++;
}
if (count > 0)
Application.getMessagingFactory().sendMessage(new StatusBarMessage(i18n.tr("Adresse{0} gespeichert",(count > 1 ? "n" : "")), StatusBarMessage.TYPE_SUCCESS));
}
catch (ApplicationException ae)
{
throw ae;
}
catch (Exception e)
{
Logger.error("error while storing empfaenger",e);
GUI.getStatusBar().setErrorText(i18n.tr("Fehler beim Speichern des Empf�ngers"));
}
}