1 | |
|
2 | |
|
3 | |
|
4 | |
package org.homeunix.thecave.buddi.view.dialogs; |
5 | |
|
6 | |
import java.awt.BorderLayout; |
7 | |
import java.awt.CardLayout; |
8 | |
import java.awt.Dimension; |
9 | |
import java.awt.FlowLayout; |
10 | |
import java.awt.GridLayout; |
11 | |
import java.awt.event.ActionEvent; |
12 | |
import java.awt.event.ActionListener; |
13 | |
import java.awt.event.ItemEvent; |
14 | |
import java.awt.event.ItemListener; |
15 | |
import java.text.SimpleDateFormat; |
16 | |
import java.util.Date; |
17 | |
import java.util.HashMap; |
18 | |
import java.util.Map; |
19 | |
import java.util.logging.Level; |
20 | |
import java.util.logging.Logger; |
21 | |
|
22 | |
import javax.swing.BorderFactory; |
23 | |
import javax.swing.JButton; |
24 | |
import javax.swing.JCheckBox; |
25 | |
import javax.swing.JFormattedTextField; |
26 | |
import javax.swing.JLabel; |
27 | |
import javax.swing.JOptionPane; |
28 | |
import javax.swing.JPanel; |
29 | |
import javax.swing.JScrollPane; |
30 | |
|
31 | |
import org.homeunix.thecave.buddi.Const; |
32 | |
import org.homeunix.thecave.buddi.i18n.BuddiKeys; |
33 | |
import org.homeunix.thecave.buddi.i18n.keys.ButtonKeys; |
34 | |
import org.homeunix.thecave.buddi.i18n.keys.ScheduleFrequency; |
35 | |
import org.homeunix.thecave.buddi.model.Document; |
36 | |
import org.homeunix.thecave.buddi.model.ScheduledTransaction; |
37 | |
import org.homeunix.thecave.buddi.model.Transaction; |
38 | |
import org.homeunix.thecave.buddi.model.impl.ModelFactory; |
39 | |
import org.homeunix.thecave.buddi.model.prefs.PrefsModel; |
40 | |
import org.homeunix.thecave.buddi.plugin.api.exception.ModelException; |
41 | |
import org.homeunix.thecave.buddi.plugin.api.util.TextFormatter; |
42 | |
import org.homeunix.thecave.buddi.util.InternalFormatter; |
43 | |
import org.homeunix.thecave.buddi.view.dialogs.schedule.BiWeeklyCard; |
44 | |
import org.homeunix.thecave.buddi.view.dialogs.schedule.DailyCard; |
45 | |
import org.homeunix.thecave.buddi.view.dialogs.schedule.EveryXDaysCard; |
46 | |
import org.homeunix.thecave.buddi.view.dialogs.schedule.MonthlyByDateCard; |
47 | |
import org.homeunix.thecave.buddi.view.dialogs.schedule.MultipleMonthsEachYearCard; |
48 | |
import org.homeunix.thecave.buddi.view.dialogs.schedule.MultipleWeeksEachMonthCard; |
49 | |
import org.homeunix.thecave.buddi.view.dialogs.schedule.OneDayEveryMonthCard; |
50 | |
import org.homeunix.thecave.buddi.view.dialogs.schedule.ScheduleCard; |
51 | |
import org.homeunix.thecave.buddi.view.dialogs.schedule.WeekdayCard; |
52 | |
import org.homeunix.thecave.buddi.view.dialogs.schedule.WeeklyCard; |
53 | |
import org.homeunix.thecave.buddi.view.panels.TransactionEditorPanel; |
54 | |
import org.homeunix.thecave.buddi.view.swing.TranslatorListCellRenderer; |
55 | |
import org.jdesktop.swingx.JXDatePicker; |
56 | |
|
57 | |
import ca.digitalcave.moss.common.DateUtil; |
58 | |
import ca.digitalcave.moss.common.OperatingSystemUtil; |
59 | |
import ca.digitalcave.moss.swing.MossDialog; |
60 | |
import ca.digitalcave.moss.swing.MossDocumentFrame; |
61 | |
import ca.digitalcave.moss.swing.MossHintTextArea; |
62 | |
import ca.digitalcave.moss.swing.MossHintTextField; |
63 | |
import ca.digitalcave.moss.swing.MossScrollingComboBox; |
64 | |
|
65 | 137 | public class ScheduledTransactionEditorDialog extends MossDialog implements ActionListener { |
66 | |
public static final long serialVersionUID = 0; |
67 | |
|
68 | |
private final JButton okButton; |
69 | |
private final JButton cancelButton; |
70 | |
|
71 | |
private final ScheduledTransaction schedule; |
72 | |
|
73 | |
private final MossHintTextField scheduleName; |
74 | |
private final MossHintTextArea message; |
75 | |
private final MossScrollingComboBox frequencyPulldown; |
76 | |
private final JXDatePicker startDateChooser; |
77 | |
private final JXDatePicker endDateChooser; |
78 | |
private final JCheckBox endDateChooserEnabled; |
79 | |
private final TransactionEditorPanel transactionEditor; |
80 | |
|
81 | |
|
82 | |
private final MonthlyByDateCard monthly; |
83 | |
private final OneDayEveryMonthCard oneDayMonthly; |
84 | |
private final WeeklyCard weekly; |
85 | |
private final BiWeeklyCard biWeekly; |
86 | |
private final WeekdayCard everyWeekday; |
87 | |
private final DailyCard everyDay; |
88 | |
private final EveryXDaysCard everyXDays; |
89 | |
private final MultipleWeeksEachMonthCard multipleWeeksMonthly; |
90 | |
private final MultipleMonthsEachYearCard multipleMonthsYearly; |
91 | |
|
92 | 1165 | private final Map<String, ScheduleCard> cardMap = new HashMap<String, ScheduleCard>(); |
93 | |
|
94 | |
private final CardLayout cardLayout; |
95 | |
private final JPanel cardHolder; |
96 | |
|
97 | |
private final Document model; |
98 | |
|
99 | |
public ScheduledTransactionEditorDialog(MossDocumentFrame parentFrame, ScheduledTransaction scheduleToEdit){ |
100 | 1165 | super(parentFrame); |
101 | |
|
102 | 1165 | this.model = (Document) parentFrame.getDocument(); |
103 | |
|
104 | 1165 | this.schedule = scheduleToEdit; |
105 | |
|
106 | 1165 | okButton = new JButton(TextFormatter.getTranslation(ButtonKeys.BUTTON_OK)); |
107 | 1165 | cancelButton = new JButton(TextFormatter.getTranslation(ButtonKeys.BUTTON_CANCEL)); |
108 | |
|
109 | 1165 | startDateChooser = new JXDatePicker(); |
110 | 1165 | endDateChooser = new JXDatePicker(); |
111 | 1165 | endDateChooserEnabled = new JCheckBox(TextFormatter.getTranslation(BuddiKeys.ENDING_ON)); |
112 | 1165 | transactionEditor = new TransactionEditorPanel(null, (Document) parentFrame.getDocument(), null, true); |
113 | |
|
114 | 1165 | scheduleName = new MossHintTextField(TextFormatter.getTranslation(BuddiKeys.HINT_SCHEDULED_TRANSACTION_NAME)); |
115 | |
|
116 | 1165 | message = new MossHintTextArea(TextFormatter.getTranslation(BuddiKeys.HINT_MESSAGE)); |
117 | |
|
118 | |
|
119 | 1165 | frequencyPulldown = new MossScrollingComboBox(ScheduleFrequency.values()); |
120 | |
|
121 | |
|
122 | 1165 | monthly = new MonthlyByDateCard(); |
123 | 1165 | oneDayMonthly = new OneDayEveryMonthCard(); |
124 | 1165 | weekly = new WeeklyCard(); |
125 | 1165 | biWeekly = new BiWeeklyCard(); |
126 | 1165 | everyWeekday = new WeekdayCard(); |
127 | 1165 | everyDay = new DailyCard(); |
128 | 1165 | everyXDays = new EveryXDaysCard(); |
129 | 1165 | multipleWeeksMonthly = new MultipleWeeksEachMonthCard(); |
130 | 1165 | multipleMonthsYearly = new MultipleMonthsEachYearCard(); |
131 | |
|
132 | 1165 | cardLayout = new CardLayout(); |
133 | 1165 | cardHolder = new JPanel(cardLayout); |
134 | 1165 | } |
135 | |
|
136 | |
protected String getType(){ |
137 | 0 | return TextFormatter.getTranslation(BuddiKeys.ACCOUNT); |
138 | |
} |
139 | |
|
140 | |
public void init() { |
141 | 1165 | if (PrefsModel.getInstance().isShowTooltips()) |
142 | 1165 | message.setToolTipText(TextFormatter.getTranslation(BuddiKeys.TOOLTIP_SCHEDULED_MESSAGE)); |
143 | |
|
144 | 1165 | okButton.setPreferredSize(InternalFormatter.getButtonSize(okButton)); |
145 | 1165 | cancelButton.setPreferredSize(InternalFormatter.getButtonSize(cancelButton)); |
146 | |
|
147 | 1165 | okButton.addActionListener(this); |
148 | 1165 | cancelButton.addActionListener(this); |
149 | |
|
150 | 1165 | JScrollPane messageScroller = new JScrollPane(message); |
151 | 1165 | messageScroller.setPreferredSize(new Dimension(200, 100)); |
152 | |
|
153 | 1165 | endDateChooserEnabled.setSelected(true); |
154 | |
|
155 | 1165 | startDateChooser.setEditor(new JFormattedTextField(new SimpleDateFormat(PrefsModel.getInstance().getDateFormat()))); |
156 | 1165 | startDateChooser.setDate(new Date()); |
157 | |
|
158 | 1165 | endDateChooser.setEditor(new JFormattedTextField(new SimpleDateFormat(PrefsModel.getInstance().getDateFormat()))); |
159 | 1165 | endDateChooser.setDate(DateUtil.addYears(new Date(), 1)); |
160 | |
|
161 | 1165 | Dimension textSize = new Dimension(Math.max(250, scheduleName.getPreferredSize().width), scheduleName.getPreferredSize().height); |
162 | 1165 | startDateChooser.setPreferredSize(textSize); |
163 | 1165 | endDateChooser.setPreferredSize(textSize); |
164 | 1165 | scheduleName.setPreferredSize(textSize); |
165 | |
|
166 | 1165 | transactionEditor.setPreferredSize(new Dimension(10, transactionEditor.getPreferredSize().height)); |
167 | |
|
168 | |
|
169 | |
|
170 | 1165 | JLabel intro = new JLabel(TextFormatter.getTranslation(BuddiKeys.REPEAT_THIS_ACTION)); |
171 | 1165 | JPanel introHolder = new JPanel(new FlowLayout(FlowLayout.RIGHT)); |
172 | 1165 | introHolder.add(intro); |
173 | 1165 | introHolder.add(frequencyPulldown); |
174 | |
|
175 | |
|
176 | 1165 | JPanel startDatePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); |
177 | 1165 | startDatePanel.add(new JLabel(TextFormatter.getTranslation(BuddiKeys.STARTING_ON))); |
178 | 1165 | startDatePanel.add(startDateChooser); |
179 | |
|
180 | |
|
181 | 1165 | JPanel endDatePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); |
182 | 1165 | endDatePanel.add(endDateChooserEnabled); |
183 | 1165 | endDatePanel.add(endDateChooser); |
184 | |
|
185 | 1165 | JPanel middlePanel = new JPanel(new GridLayout(0, 1)); |
186 | 1165 | middlePanel.add(startDatePanel); |
187 | 1165 | middlePanel.add(endDatePanel); |
188 | |
|
189 | 1165 | JPanel cardHolderPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); |
190 | 1165 | cardHolderPanel.add(cardHolder); |
191 | |
|
192 | |
|
193 | |
|
194 | 1165 | JPanel scheduleDetailsPanel = new JPanel(new BorderLayout()); |
195 | 1165 | scheduleDetailsPanel.add(introHolder, BorderLayout.NORTH); |
196 | 1165 | scheduleDetailsPanel.add(middlePanel, BorderLayout.CENTER); |
197 | 1165 | scheduleDetailsPanel.add(cardHolderPanel, BorderLayout.SOUTH); |
198 | |
|
199 | 1165 | JPanel scheduleNamePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); |
200 | 1165 | scheduleNamePanel.add(new JLabel(TextFormatter.getTranslation(BuddiKeys.SCHEDULED_TRANSACTION_NAME))); |
201 | 1165 | scheduleNamePanel.add(scheduleName); |
202 | |
|
203 | |
|
204 | 1165 | JPanel entireSchedulePanel = new JPanel(new BorderLayout()); |
205 | 1165 | entireSchedulePanel.setBorder(BorderFactory.createTitledBorder((String) null)); |
206 | 1165 | entireSchedulePanel.add(scheduleNamePanel, BorderLayout.NORTH); |
207 | 1165 | entireSchedulePanel.add(scheduleDetailsPanel, BorderLayout.CENTER); |
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | 1165 | cardMap.put(ScheduleFrequency.SCHEDULE_FREQUENCY_MONTHLY_BY_DATE.toString(), monthly); |
214 | 1165 | cardMap.put(ScheduleFrequency.SCHEDULE_FREQUENCY_MONTHLY_BY_DAY_OF_WEEK.toString(), oneDayMonthly); |
215 | 1165 | cardMap.put(ScheduleFrequency.SCHEDULE_FREQUENCY_WEEKLY.toString(), weekly); |
216 | 1165 | cardMap.put(ScheduleFrequency.SCHEDULE_FREQUENCY_BIWEEKLY.toString(), biWeekly); |
217 | 1165 | cardMap.put(ScheduleFrequency.SCHEDULE_FREQUENCY_EVERY_WEEKDAY.toString(), everyWeekday); |
218 | 1165 | cardMap.put(ScheduleFrequency.SCHEDULE_FREQUENCY_EVERY_DAY.toString(), everyDay); |
219 | 1165 | cardMap.put(ScheduleFrequency.SCHEDULE_FREQUENCY_EVERY_X_DAYS.toString(), everyXDays); |
220 | 1165 | cardMap.put(ScheduleFrequency.SCHEDULE_FREQUENCY_MULTIPLE_WEEKS_EVERY_MONTH.toString(), multipleWeeksMonthly); |
221 | 1165 | cardMap.put(ScheduleFrequency.SCHEDULE_FREQUENCY_MULTIPLE_MONTHS_EVERY_YEAR.toString(), multipleMonthsYearly); |
222 | |
|
223 | 1165 | cardHolder.add(monthly, ScheduleFrequency.SCHEDULE_FREQUENCY_MONTHLY_BY_DATE.toString()); |
224 | 1165 | cardHolder.add(oneDayMonthly, ScheduleFrequency.SCHEDULE_FREQUENCY_MONTHLY_BY_DAY_OF_WEEK.toString()); |
225 | 1165 | cardHolder.add(weekly, ScheduleFrequency.SCHEDULE_FREQUENCY_WEEKLY.toString()); |
226 | 1165 | cardHolder.add(biWeekly, ScheduleFrequency.SCHEDULE_FREQUENCY_BIWEEKLY.toString()); |
227 | 1165 | cardHolder.add(new JPanel(), ScheduleFrequency.SCHEDULE_FREQUENCY_EVERY_WEEKDAY.toString()); |
228 | 1165 | cardHolder.add(new JPanel(), ScheduleFrequency.SCHEDULE_FREQUENCY_EVERY_DAY.toString()); |
229 | 1165 | cardHolder.add(everyXDays, ScheduleFrequency.SCHEDULE_FREQUENCY_EVERY_X_DAYS.toString()); |
230 | 1165 | cardHolder.add(multipleWeeksMonthly, ScheduleFrequency.SCHEDULE_FREQUENCY_MULTIPLE_WEEKS_EVERY_MONTH.toString()); |
231 | 1165 | cardHolder.add(multipleMonthsYearly, ScheduleFrequency.SCHEDULE_FREQUENCY_MULTIPLE_MONTHS_EVERY_YEAR.toString()); |
232 | |
|
233 | |
|
234 | 1165 | JPanel scheduleAndMessagePanel = new JPanel(new BorderLayout()); |
235 | 1165 | scheduleAndMessagePanel.add(entireSchedulePanel, BorderLayout.CENTER); |
236 | 1165 | scheduleAndMessagePanel.add(messageScroller, BorderLayout.EAST); |
237 | |
|
238 | 1165 | JPanel mainPanel = new JPanel(new BorderLayout()); |
239 | 1165 | mainPanel.add(scheduleAndMessagePanel, BorderLayout.CENTER); |
240 | 1165 | mainPanel.add(transactionEditor, BorderLayout.SOUTH); |
241 | |
|
242 | 1165 | JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); |
243 | 1165 | buttonPanel.add(cancelButton); |
244 | 1165 | buttonPanel.add(okButton); |
245 | |
|
246 | 1165 | this.setTitle(TextFormatter.getTranslation(BuddiKeys.SCHEDULED_TRANSACTION)); |
247 | 1165 | this.getRootPane().setDefaultButton(okButton); |
248 | 1165 | this.setLayout(new BorderLayout()); |
249 | 1165 | this.add(mainPanel, BorderLayout.CENTER); |
250 | 1165 | this.add(buttonPanel, BorderLayout.SOUTH); |
251 | |
|
252 | 1165 | if (OperatingSystemUtil.isMac()){ |
253 | 0 | messageScroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); |
254 | 0 | messageScroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); |
255 | |
} |
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | 1165 | startDateChooser.setEnabled(schedule == null); |
261 | 1165 | endDateChooser.setEnabled(schedule == null); |
262 | 1165 | endDateChooserEnabled.setEnabled(schedule == null); |
263 | 1165 | frequencyPulldown.setEnabled(schedule == null); |
264 | 1165 | monthly.setEnabled(schedule == null); |
265 | 1165 | oneDayMonthly.setEnabled(schedule == null); |
266 | 1165 | weekly.setEnabled(schedule == null); |
267 | 1165 | biWeekly.setEnabled(schedule == null); |
268 | 1165 | everyWeekday.setEnabled(schedule == null); |
269 | 1165 | everyDay.setEnabled(schedule == null); |
270 | 1165 | everyXDays.setEnabled(schedule == null); |
271 | 1165 | multipleWeeksMonthly.setEnabled(schedule == null); |
272 | 1165 | multipleMonthsYearly.setEnabled(schedule == null); |
273 | |
|
274 | 1165 | updateSchedulePulldown(); |
275 | |
|
276 | 1165 | if (schedule == null){ |
277 | 1165 | endDateChooserEnabled.addActionListener(new ActionListener(){ |
278 | |
public void actionPerformed(ActionEvent e) { |
279 | 68 | endDateChooser.setEnabled(endDateChooserEnabled.isSelected() && schedule == null); |
280 | 68 | } |
281 | |
}); |
282 | |
} |
283 | |
|
284 | 1165 | frequencyPulldown.setRenderer(new TranslatorListCellRenderer()); |
285 | 1165 | frequencyPulldown.addItemListener(new ItemListener(){ |
286 | |
public void itemStateChanged(ItemEvent e) { |
287 | 0 | ScheduledTransactionEditorDialog.this.updateSchedulePulldown(); |
288 | 0 | } |
289 | |
}); |
290 | |
|
291 | 1165 | loadSchedule(); |
292 | 1165 | } |
293 | |
|
294 | |
private void updateSchedulePulldown(){ |
295 | 1165 | if (frequencyPulldown.getSelectedItem() != null) { |
296 | 1165 | cardLayout.show(cardHolder, frequencyPulldown.getSelectedItem().toString()); |
297 | |
|
298 | 1165 | Logger.getLogger(this.getClass().getName()).info("Showing card " + frequencyPulldown.getSelectedItem().toString()); |
299 | |
} |
300 | 1165 | } |
301 | |
|
302 | |
|
303 | |
|
304 | |
|
305 | |
|
306 | |
|
307 | |
|
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
|
317 | |
|
318 | |
|
319 | |
|
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | |
|
325 | |
|
326 | |
|
327 | |
|
328 | |
|
329 | |
|
330 | |
|
331 | |
|
332 | |
|
333 | |
|
334 | |
|
335 | |
|
336 | |
|
337 | |
|
338 | |
|
339 | |
|
340 | |
private boolean saveScheduledTransaction(){ |
341 | |
try { |
342 | |
ScheduledTransaction s; |
343 | |
final boolean needToAdd; |
344 | |
|
345 | 44 | model.startBatchChange(); |
346 | |
|
347 | |
|
348 | |
|
349 | 44 | if (schedule == null) { |
350 | 44 | Transaction t = transactionEditor.getTransactionNew(); |
351 | 0 | s = ModelFactory.createScheduledTransaction( |
352 | |
this.scheduleName.getText(), |
353 | |
this.message.getText(), |
354 | |
|
355 | |
startDateChooser.getDate(), |
356 | |
(endDateChooserEnabled.isSelected() ? endDateChooser.getDate() : null), |
357 | |
frequencyPulldown.getSelectedItem().toString(), |
358 | |
getSelectedCard().getScheduleDay(), |
359 | |
getSelectedCard().getScheduleWeek(), |
360 | |
getSelectedCard().getScheduleMonth(), |
361 | |
|
362 | |
t.getDescription(), |
363 | |
t.getAmount(), |
364 | |
t.getFrom(), |
365 | |
t.getTo()); |
366 | 0 | needToAdd = true; |
367 | 0 | } |
368 | |
else { |
369 | 0 | Transaction t = transactionEditor.getTransactionUpdated(); |
370 | 0 | s = schedule; |
371 | |
|
372 | 0 | s.setScheduleName(this.scheduleName.getText()); |
373 | 0 | s.setMessage(this.message.getText()); |
374 | 0 | s.setAmount(t.getAmount()); |
375 | 0 | s.setDescription(t.getDescription()); |
376 | 0 | s.setNumber(t.getNumber()); |
377 | 0 | s.setTo(t.getTo()); |
378 | 0 | s.setFrom(t.getFrom()); |
379 | 0 | s.setMemo(t.getMemo()); |
380 | 0 | needToAdd = false; |
381 | |
} |
382 | |
|
383 | 0 | if (transactionEditor.isTransactionValid()){ |
384 | 0 | String[] options = new String[2]; |
385 | 0 | options[0] = TextFormatter.getTranslation(ButtonKeys.BUTTON_OK); |
386 | 0 | options[1] = TextFormatter.getTranslation(ButtonKeys.BUTTON_CANCEL); |
387 | |
|
388 | |
|
389 | 0 | for (ScheduledTransaction existingSched : model.getScheduledTransactions()) { |
390 | 0 | if (existingSched.getScheduleName().equalsIgnoreCase(s.getScheduleName())){ |
391 | 0 | String[] errorOptions = new String[1]; |
392 | 0 | errorOptions[0] = TextFormatter.getTranslation(ButtonKeys.BUTTON_OK); |
393 | |
|
394 | 0 | JOptionPane.showOptionDialog(ScheduledTransactionEditorDialog.this, |
395 | |
TextFormatter.getTranslation(BuddiKeys.SCHEDULED_DUPLICATE_NAME), |
396 | |
TextFormatter.getTranslation(BuddiKeys.SCHEDULED_DUPLICATE_NAME_TITLE), |
397 | |
JOptionPane.DEFAULT_OPTION, |
398 | |
JOptionPane.ERROR_MESSAGE, |
399 | |
null, |
400 | |
errorOptions, |
401 | |
errorOptions[0]); |
402 | |
|
403 | 0 | model.finishBatchChange(); |
404 | 0 | return false; |
405 | |
} |
406 | |
} |
407 | |
|
408 | |
|
409 | 0 | if (!ScheduledTransactionEditorDialog.this.startDateChooser.getDate().before(new Date()) |
410 | |
|| schedule != null |
411 | |
|| JOptionPane.showOptionDialog(ScheduledTransactionEditorDialog.this, |
412 | |
TextFormatter.getTranslation(BuddiKeys.START_DATE_IN_THE_PAST), |
413 | |
TextFormatter.getTranslation(BuddiKeys.START_DATE_IN_THE_PAST_TITLE), |
414 | |
JOptionPane.OK_CANCEL_OPTION, |
415 | |
JOptionPane.PLAIN_MESSAGE, |
416 | |
null, |
417 | |
options, |
418 | |
options[0]) == JOptionPane.OK_OPTION){ |
419 | |
|
420 | |
|
421 | |
|
422 | |
|
423 | |
|
424 | |
|
425 | |
|
426 | |
|
427 | |
|
428 | |
|
429 | |
|
430 | |
|
431 | 0 | if (needToAdd) |
432 | 0 | model.addScheduledTransaction(s); |
433 | |
|
434 | 0 | model.finishBatchChange(); |
435 | 0 | return true; |
436 | |
} |
437 | |
else |
438 | 0 | if (Const.DEVEL) Logger.getLogger(this.getClass().getName()).finest("Cancelled from either start date in the past, or info not correct"); |
439 | 0 | } |
440 | |
else { |
441 | 0 | String[] options = new String[1]; |
442 | 0 | options[0] = TextFormatter.getTranslation(ButtonKeys.BUTTON_OK); |
443 | |
|
444 | 0 | JOptionPane.showOptionDialog(ScheduledTransactionEditorDialog.this, |
445 | |
TextFormatter.getTranslation(BuddiKeys.SCHEDULED_NOT_ENOUGH_INFO), |
446 | |
TextFormatter.getTranslation(BuddiKeys.SCHEDULED_NOT_ENOUGH_INFO_TITLE), |
447 | |
JOptionPane.DEFAULT_OPTION, |
448 | |
JOptionPane.ERROR_MESSAGE, |
449 | |
null, |
450 | |
options, |
451 | |
options[0]); |
452 | |
} |
453 | |
} |
454 | 44 | catch (ModelException me){ |
455 | 44 | String[] errorOptions = new String[1]; |
456 | 44 | errorOptions[0] = TextFormatter.getTranslation(ButtonKeys.BUTTON_OK); |
457 | |
|
458 | 44 | JOptionPane.showOptionDialog(ScheduledTransactionEditorDialog.this, |
459 | |
TextFormatter.getTranslation(BuddiKeys.SCHEDULED_UNHANDLED_EXCEPTION) + "\n\n" + me.getLocalizedMessage(), |
460 | |
TextFormatter.getTranslation(BuddiKeys.SCHEDULED_UNHANDLED_EXCEPTION_TITLE), |
461 | |
JOptionPane.DEFAULT_OPTION, |
462 | |
JOptionPane.ERROR_MESSAGE, |
463 | |
null, |
464 | |
errorOptions, |
465 | |
errorOptions[0]); |
466 | |
|
467 | 1 | Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Error when saving scheduled transaction", me); |
468 | 0 | } |
469 | |
|
470 | 1 | model.finishBatchChange(); |
471 | 1 | return false; |
472 | |
} |
473 | |
|
474 | |
private ScheduleCard getSelectedCard(){ |
475 | 0 | if (frequencyPulldown.getSelectedItem() == null) |
476 | 0 | return null; |
477 | 0 | return cardMap.get(frequencyPulldown.getSelectedItem().toString()); |
478 | |
} |
479 | |
|
480 | |
private void loadSchedule(){ |
481 | 1165 | if (schedule != null){ |
482 | 0 | transactionEditor.updateContent(); |
483 | 0 | updateSchedulePulldown(); |
484 | |
|
485 | |
|
486 | 0 | scheduleName.setText(schedule.getScheduleName()); |
487 | 0 | message.setText(schedule.getMessage()); |
488 | 0 | transactionEditor.setTransaction(schedule, true, okButton); |
489 | |
|
490 | |
|
491 | |
|
492 | 0 | startDateChooser.setDate(schedule.getStartDate()); |
493 | 0 | if (schedule.getEndDate() != null){ |
494 | 0 | endDateChooser.setDate(schedule.getEndDate()); |
495 | 0 | endDateChooserEnabled.setSelected(true); |
496 | |
} |
497 | |
else { |
498 | 0 | endDateChooserEnabled.setSelected(false); |
499 | 0 | endDateChooser.setDate(null); |
500 | |
} |
501 | 0 | if (schedule.getFrequencyType() != null) |
502 | 0 | frequencyPulldown.setSelectedItem(ScheduleFrequency.valueOf(schedule.getFrequencyType())); |
503 | |
|
504 | 0 | updateSchedulePulldown(); |
505 | |
|
506 | |
|
507 | 0 | if (getSelectedCard() != null) |
508 | 0 | getSelectedCard().loadSchedule(schedule); |
509 | |
} |
510 | 1165 | } |
511 | |
|
512 | |
|
513 | |
public void actionPerformed(ActionEvent e) { |
514 | 88 | if (e.getSource().equals(okButton)){ |
515 | 44 | if (saveScheduledTransaction()){ |
516 | 0 | model.updateScheduledTransactions(); |
517 | 0 | model.updateAllBalances(); |
518 | 0 | this.closeWindow(); |
519 | |
} |
520 | |
} |
521 | 44 | else if (e.getSource().equals(cancelButton)){ |
522 | 44 | this.closeWindow(); |
523 | |
} |
524 | 45 | } |
525 | |
|
526 | |
|
527 | |
|
528 | |
|
529 | |
|
530 | |
|
531 | |
|
532 | |
|
533 | |
|
534 | |
|
535 | |
|
536 | |
|
537 | |
|
538 | |
|
539 | |
|
540 | |
|
541 | |
|
542 | |
|
543 | |
|
544 | |
|
545 | |
|
546 | |
|
547 | |
|
548 | |
|
549 | |
} |