mirror of
https://github.com/reactos/rosev_jameicaplugin.git
synced 2024-11-23 03:39:54 +00:00
Add a CSV output feature to generate donation list data for the new Hugo-based website.
This commit is contained in:
parent
e3bbde73dd
commit
3508cb36bc
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/bin/
|
BIN
src/img/x-office-spreadsheet.png
Normal file
BIN
src/img/x-office-spreadsheet.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 704 B |
@ -7,6 +7,7 @@ Anonymous=Anonym
|
||||
Close=Schließen
|
||||
Comment=Kommentar
|
||||
Copy=Kopieren
|
||||
CSV\ Output=CSV-Ausgabe
|
||||
Currency\ Code=Währungscode
|
||||
Date=Datum
|
||||
Delete=Löschen
|
||||
|
71
src/org/reactos/ev/jameicaplugin/formatter/CSVFormatter.java
Normal file
71
src/org/reactos/ev/jameicaplugin/formatter/CSVFormatter.java
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* PROJECT: ReactOS Deutschland e.V. Helper Plugin
|
||||
* LICENSE: GNU GPL v2 or any later version as published by the Free Software Foundation
|
||||
* COPYRIGHT: Copyright 2010-2018 ReactOS Deutschland e.V. <deutschland@reactos.org>
|
||||
* AUTHORS: Colin Finck <colin@reactos.org>
|
||||
*/
|
||||
|
||||
package org.reactos.ev.jameicaplugin.formatter;
|
||||
|
||||
import de.willuhn.datasource.rmi.DBIterator;
|
||||
import de.willuhn.jameica.gui.formatter.Formatter;
|
||||
import de.willuhn.logging.Logger;
|
||||
import java.rmi.RemoteException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import org.reactos.ev.jameicaplugin.JameicaPlugin;
|
||||
import org.reactos.ev.jameicaplugin.rmi.Donation;
|
||||
|
||||
public class CSVFormatter implements Formatter
|
||||
{
|
||||
private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
private int year;
|
||||
|
||||
public CSVFormatter(int year)
|
||||
{
|
||||
this.year = year;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format(Object o)
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
DBIterator<Donation> donationList = (DBIterator<Donation>) o;
|
||||
|
||||
String csv = "";
|
||||
|
||||
try
|
||||
{
|
||||
final Calendar cal = Calendar.getInstance();
|
||||
|
||||
cal.set(year, 0, 0, 0, 0, 0);
|
||||
donationList.addFilter("date >= ?", cal.getTime());
|
||||
|
||||
cal.set(year + 1, 0, 0, 0, 0, 0);
|
||||
donationList.addFilter("date < ?", cal.getTime());
|
||||
|
||||
donationList.setOrder("ORDER BY date DESC");
|
||||
|
||||
while (donationList.hasNext())
|
||||
{
|
||||
Donation d = (Donation) donationList.next();
|
||||
|
||||
if (d.isAnonymous())
|
||||
csv += "Anonymous";
|
||||
else
|
||||
csv += d.getName();
|
||||
|
||||
csv += String.format(";%s", dateFormat.format(d.getDate()));
|
||||
csv += String.format(";%s %s", d.getCurrency(), JameicaPlugin.currencyFormatUS.format(d.getAmount()));
|
||||
csv += "\n";
|
||||
}
|
||||
}
|
||||
catch (RemoteException e)
|
||||
{
|
||||
Logger.error("Error while formatting as CSV", e);
|
||||
}
|
||||
|
||||
return csv;
|
||||
}
|
||||
}
|
30
src/org/reactos/ev/jameicaplugin/gui/action/CSVOutput.java
Normal file
30
src/org/reactos/ev/jameicaplugin/gui/action/CSVOutput.java
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* PROJECT: ReactOS Deutschland e.V. Helper Plugin
|
||||
* LICENSE: GNU GPL v2 or any later version as published by the Free Software Foundation
|
||||
* COPYRIGHT: Copyright 2010-2018 ReactOS Deutschland e.V. <deutschland@reactos.org>
|
||||
* AUTHORS: Colin Finck <colin@reactos.org>
|
||||
*/
|
||||
|
||||
package org.reactos.ev.jameicaplugin.gui.action;
|
||||
|
||||
import de.willuhn.jameica.gui.Action;
|
||||
import de.willuhn.jameica.gui.dialogs.AbstractDialog;
|
||||
import de.willuhn.logging.Logger;
|
||||
import de.willuhn.util.ApplicationException;
|
||||
|
||||
public class CSVOutput implements Action
|
||||
{
|
||||
@Override
|
||||
public void handleAction(Object context) throws ApplicationException
|
||||
{
|
||||
try
|
||||
{
|
||||
new org.reactos.ev.jameicaplugin.gui.dialog.CSVOutput(
|
||||
AbstractDialog.POSITION_CENTER).open();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.error("Error while opening the CSV Output dialog", e);
|
||||
}
|
||||
}
|
||||
}
|
119
src/org/reactos/ev/jameicaplugin/gui/dialog/CSVOutput.java
Normal file
119
src/org/reactos/ev/jameicaplugin/gui/dialog/CSVOutput.java
Normal file
@ -0,0 +1,119 @@
|
||||
/*
|
||||
* PROJECT: ReactOS Deutschland e.V. Helper Plugin
|
||||
* LICENSE: GNU GPL v2 or any later version as published by the Free Software Foundation
|
||||
* COPYRIGHT: Copyright 2010-2018 ReactOS Deutschland e.V. <deutschland@reactos.org>
|
||||
* AUTHORS: Colin Finck <colin@reactos.org>
|
||||
*/
|
||||
|
||||
package org.reactos.ev.jameicaplugin.gui.dialog;
|
||||
|
||||
import de.willuhn.datasource.rmi.DBIterator;
|
||||
import de.willuhn.jameica.gui.Action;
|
||||
import de.willuhn.jameica.gui.GUI;
|
||||
import de.willuhn.jameica.gui.dialogs.AbstractDialog;
|
||||
import de.willuhn.jameica.gui.input.TextInput;
|
||||
import de.willuhn.jameica.gui.parts.ButtonArea;
|
||||
import de.willuhn.jameica.gui.util.SimpleContainer;
|
||||
import de.willuhn.util.ApplicationException;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.PrintWriter;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.Calendar;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.FileDialog;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.reactos.ev.jameicaplugin.JameicaPlugin;
|
||||
import org.reactos.ev.jameicaplugin.formatter.CSVFormatter;
|
||||
import org.reactos.ev.jameicaplugin.rmi.Donation;
|
||||
|
||||
public class CSVOutput extends AbstractDialog<Object>
|
||||
{
|
||||
public CSVOutput(int position)
|
||||
{
|
||||
super(position);
|
||||
setTitle(JameicaPlugin.i18n().tr("CSV Output"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paint(Composite parent) throws Exception
|
||||
{
|
||||
final Calendar cal = Calendar.getInstance();
|
||||
final TextInput year = new TextInput(Integer.toString(cal.get(Calendar.YEAR)));
|
||||
year.setName(JameicaPlugin.i18n().tr("Year"));
|
||||
year.addListener(new Listener()
|
||||
{
|
||||
public void handleEvent(Event event)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (((String) year.getValue()).length() != 4)
|
||||
throw new NumberFormatException();
|
||||
|
||||
Integer.parseInt((String) year.getValue());
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
year.setValue(cal.get(Calendar.YEAR));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ButtonArea buttons = new ButtonArea();
|
||||
buttons.addButton(" " + JameicaPlugin.i18n().tr("Save") + "... ", new Action()
|
||||
{
|
||||
@Override
|
||||
public void handleAction(Object context) throws ApplicationException
|
||||
{
|
||||
final FileDialog fd = new FileDialog(GUI.getShell(), SWT.SAVE);
|
||||
fd.setFileName(year.getValue() + ".csv");
|
||||
fd.setFilterExtensions(new String[]
|
||||
{ "*.csv" });
|
||||
fd.setFilterPath(System.getProperty("user.home"));
|
||||
fd.setOverwrite(false);
|
||||
final String f = fd.open();
|
||||
if (f == null || f.length() == 0)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
DBIterator<Donation> donationList = JameicaPlugin.getDBService().createList(Donation.class);
|
||||
CSVFormatter formatter = new CSVFormatter(
|
||||
Integer.parseInt((String) year.getValue()));
|
||||
|
||||
final PrintWriter pw = new PrintWriter(f);
|
||||
pw.write(formatter.format(donationList));
|
||||
pw.close();
|
||||
|
||||
close();
|
||||
}
|
||||
catch (RemoteException e)
|
||||
{
|
||||
throw new ApplicationException(e);
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
});
|
||||
buttons.addButton(" " + JameicaPlugin.i18n().tr("Close") + " ", new Action()
|
||||
{
|
||||
@Override
|
||||
public void handleAction(Object context) throws ApplicationException
|
||||
{
|
||||
close();
|
||||
}
|
||||
});
|
||||
|
||||
SimpleContainer container = new SimpleContainer(parent);
|
||||
container.addInput(year);
|
||||
container.addButtonArea(buttons);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getData() throws Exception
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ import de.willuhn.jameica.gui.AbstractView;
|
||||
import de.willuhn.jameica.gui.GUI;
|
||||
import de.willuhn.jameica.gui.parts.ButtonArea;
|
||||
import org.reactos.ev.jameicaplugin.JameicaPlugin;
|
||||
import org.reactos.ev.jameicaplugin.gui.action.CSVOutput;
|
||||
import org.reactos.ev.jameicaplugin.gui.action.HTMLOutput;
|
||||
import org.reactos.ev.jameicaplugin.gui.action.NewAdditionalDonation;
|
||||
import org.reactos.ev.jameicaplugin.gui.control.DonationControl;
|
||||
@ -29,6 +30,7 @@ public class PublicDonationList extends AbstractView
|
||||
control.getDonationList().paint(this.getParent());
|
||||
|
||||
ButtonArea buttons = new ButtonArea();
|
||||
buttons.addButton(JameicaPlugin.i18n().tr("CSV Output"), new CSVOutput(), null, false, "x-office-spreadsheet.png");
|
||||
buttons.addButton(JameicaPlugin.i18n().tr("HTML Output"), new HTMLOutput(), null, false, "text-html.png");
|
||||
buttons.addButton(JameicaPlugin.i18n().tr("New additional donation"), new NewAdditionalDonation(), null, true, "document-new.png");
|
||||
buttons.paint(this.getParent());
|
||||
|
Loading…
Reference in New Issue
Block a user