| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
package org.homeunix.thecave.buddi.view.panels; |
| 5 | |
|
| 6 | |
import java.awt.BorderLayout; |
| 7 | |
import java.awt.Component; |
| 8 | |
import java.awt.FlowLayout; |
| 9 | |
import java.awt.event.ActionEvent; |
| 10 | |
import java.awt.event.ActionListener; |
| 11 | |
import java.util.List; |
| 12 | |
import java.util.Vector; |
| 13 | |
|
| 14 | |
import javax.swing.BoxLayout; |
| 15 | |
import javax.swing.DefaultListCellRenderer; |
| 16 | |
import javax.swing.JComboBox; |
| 17 | |
import javax.swing.JLabel; |
| 18 | |
import javax.swing.JList; |
| 19 | |
import javax.swing.JPanel; |
| 20 | |
import javax.swing.JScrollPane; |
| 21 | |
|
| 22 | |
import org.homeunix.thecave.buddi.i18n.BuddiKeys; |
| 23 | |
import org.homeunix.thecave.buddi.i18n.keys.PluginReportDateRangeChoices; |
| 24 | |
import org.homeunix.thecave.buddi.model.Document; |
| 25 | |
import org.homeunix.thecave.buddi.model.prefs.PrefsModel; |
| 26 | |
import org.homeunix.thecave.buddi.plugin.BuddiPluginFactory; |
| 27 | |
import org.homeunix.thecave.buddi.plugin.BuddiPluginHelper; |
| 28 | |
import org.homeunix.thecave.buddi.plugin.BuddiPluginHelper.DateChoice; |
| 29 | |
import org.homeunix.thecave.buddi.plugin.api.BuddiReportPlugin; |
| 30 | |
import org.homeunix.thecave.buddi.plugin.api.util.TextFormatter; |
| 31 | |
import org.homeunix.thecave.buddi.util.InternalFormatter; |
| 32 | |
import org.homeunix.thecave.buddi.view.MainFrame; |
| 33 | |
import org.homeunix.thecave.buddi.view.dialogs.CustomDateDialog; |
| 34 | |
|
| 35 | |
import ca.digitalcave.moss.swing.MossPanel; |
| 36 | |
import ca.digitalcave.moss.swing.exception.WindowOpenException; |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | 0 | public class MyReportsPanel extends MossPanel { |
| 42 | |
public static final long serialVersionUID = 0; |
| 43 | |
|
| 44 | |
private final MainFrame parent; |
| 45 | |
|
| 46 | |
public MyReportsPanel(MainFrame parent){ |
| 47 | 3025 | super(true); |
| 48 | 3025 | this.parent = parent; |
| 49 | |
|
| 50 | 3025 | open(); |
| 51 | 3025 | } |
| 52 | |
|
| 53 | |
@SuppressWarnings("unchecked") |
| 54 | |
public void init() { |
| 55 | 3025 | super.init(); |
| 56 | |
|
| 57 | 3025 | JPanel pluginsPanel = new JPanel(); |
| 58 | 3025 | pluginsPanel.setLayout(new BoxLayout(pluginsPanel, BoxLayout.Y_AXIS)); |
| 59 | |
|
| 60 | 3025 | for (BuddiReportPlugin report : (List<BuddiReportPlugin>) BuddiPluginFactory.getPlugins(BuddiReportPlugin.class)) { |
| 61 | |
|
| 62 | |
Vector<DateChoice> dateChoices; |
| 63 | 15125 | if (report.getDateRangeChoice().equals(PluginReportDateRangeChoices.INTERVAL)) |
| 64 | 12100 | dateChoices = BuddiPluginHelper.getInterval((Document) parent.getDocument()); |
| 65 | 3025 | else if (report.getDateRangeChoice().equals(PluginReportDateRangeChoices.START_ONLY)) |
| 66 | 3025 | dateChoices = BuddiPluginHelper.getStartOnly((Document) parent.getDocument()); |
| 67 | 0 | else if (report.getDateRangeChoice().equals(PluginReportDateRangeChoices.END_ONLY)) |
| 68 | 0 | dateChoices = BuddiPluginHelper.getEndOnly((Document) parent.getDocument()); |
| 69 | |
else |
| 70 | 0 | dateChoices = new Vector<DateChoice>(); |
| 71 | |
|
| 72 | 15125 | final JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); |
| 73 | 15125 | final JLabel label = new JLabel(PrefsModel.getInstance().getTranslator().get(report.getDescription())); |
| 74 | 15125 | final JComboBox dateChooser = new JComboBox(dateChoices); |
| 75 | 15125 | dateChooser.setPreferredSize(InternalFormatter.getComboBoxSize(dateChooser)); |
| 76 | 15125 | dateChooser.setRenderer(new DefaultListCellRenderer(){ |
| 77 | |
public static final long serialVersionUID = 0; |
| 78 | |
|
| 79 | |
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
| 80 | 189895 | super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); |
| 81 | 189895 | if (value == null) |
| 82 | 16855 | this.setText("<html><font color='gray'>" + TextFormatter.getTranslation(BuddiKeys.REPORTS_SELECT_DATE_RANGE) + "</font></html>"); |
| 83 | 189895 | if (index == -1) |
| 84 | 189205 | this.setText(TextFormatter.getTranslation(BuddiKeys.REPORTS_SELECT_DATE_RANGE)); |
| 85 | 189895 | return this; |
| 86 | |
} |
| 87 | |
}); |
| 88 | |
|
| 89 | 15125 | panel.add(label); |
| 90 | 15125 | panel.add(dateChooser); |
| 91 | |
|
| 92 | 15125 | final BuddiReportPlugin finalReport = report; |
| 93 | |
|
| 94 | 15125 | dateChooser.addActionListener(new ActionListener(){ |
| 95 | |
public void actionPerformed(ActionEvent e) { |
| 96 | |
|
| 97 | 0 | Object o = dateChooser.getSelectedItem(); |
| 98 | |
|
| 99 | |
|
| 100 | 0 | if (o instanceof DateChoice){ |
| 101 | 0 | DateChoice choice = (DateChoice) o; |
| 102 | |
|
| 103 | |
|
| 104 | 0 | if (!choice.isCustom()){ |
| 105 | |
|
| 106 | 0 | BuddiPluginHelper.openReport(parent, finalReport, choice.getStartDate(), choice.getEndDate()); |
| 107 | |
} |
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
else{ |
| 112 | |
try { |
| 113 | 0 | new CustomDateDialog(parent, finalReport).openWindow(); |
| 114 | |
} |
| 115 | 0 | catch (WindowOpenException woe){} |
| 116 | |
} |
| 117 | |
} |
| 118 | |
|
| 119 | 0 | dateChooser.setSelectedItem(null); |
| 120 | 0 | } |
| 121 | |
}); |
| 122 | |
|
| 123 | 15125 | if (report.isPluginActive()) |
| 124 | 15125 | pluginsPanel.add(panel); |
| 125 | 15125 | } |
| 126 | |
|
| 127 | 3025 | JPanel panel = new JPanel(new BorderLayout()); |
| 128 | 3025 | panel.add(pluginsPanel, BorderLayout.NORTH); |
| 129 | |
|
| 130 | 3025 | JScrollPane scrollPane = new JScrollPane(panel); |
| 131 | 3025 | scrollPane.setBorder(null); |
| 132 | 3025 | scrollPane.setOpaque(false); |
| 133 | |
|
| 134 | 3025 | this.setLayout(new BorderLayout()); |
| 135 | 3025 | this.add(scrollPane, BorderLayout.CENTER); |
| 136 | 3025 | } |
| 137 | |
} |