1 /********************************************************************************
2 * InternetCafe is a software solution that helps the management of Cybercafes
3 * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4 * Copyright (C) 2006 Guido Angelo Ingenito
5
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *******************************************************************************/
20 package ui.command.information;
21
22 import java.util.Date;
23
24 import ui.Messages;
25 import ui.command.Command;
26 import ui.table.model.SessionTableModel;
27 import ui.util.SortStrategy;
28 import base.InternetCafe;
29 import base.InternetCafeManager;
30 import base.session.Session;
31
32 public class SearchSessionCommand extends Command {
33
34 private final SessionTableModel sessionTableModel;
35
36 private final String text;
37
38 private final Date date;
39
40 /***
41 * @param sessionTableModel
42 * @param text
43 * @param date
44 */
45 public SearchSessionCommand(SessionTableModel sessionTableModel,
46 String text, Date date) {
47 super();
48
49 this.sessionTableModel = sessionTableModel;
50 this.text = text;
51 this.date = date;
52 }
53
54
55
56
57
58
59 @Override
60 protected void prologo() {
61 String message = (text != null && date == null) ? Messages.getString("command.searchsessioncommand.search.byspecifiedtext")
62 : (text == null && date != null) ? Messages.getString("command.searchsessioncommand.search.byspecifieddateascending")
63 : Messages.getString("command.searchsessioncommand.search.byspecifiedtextanddateascending");
64 InternetCafe
65 .setStatusBarMessage(Messages.getString("command.searchsessioncommand.searchingsession") + message + "...");
66 setStatus(EXECUTE_STATUS);
67 }
68
69
70
71
72
73
74 @Override
75 protected void execution() throws Exception {
76 switch (getStatus()) {
77 case ABORT_STATUS:
78 break;
79 case VETOED_STATUS:
80 break;
81 case EXECUTE_STATUS:
82 if (text != null && date == null) {
83 sessionTableModel.setData(SortStrategy.searchSessionByText(
84 text, InternetCafeManager.getInstance().getSession()));
85 sessionTableModel.fireTableDataChanged();
86 } else if (text == null && date != null) {
87 sessionTableModel.setData(SortStrategy.searchSessionByDate(
88 date, InternetCafeManager.getInstance().getSession()));
89 sessionTableModel.fireTableDataChanged();
90 } else if (text != null && date != null) {
91 Session[] sByText = SortStrategy.searchSessionByText(text,
92 InternetCafeManager.getInstance().getSession());
93 sessionTableModel.setData(SortStrategy.searchSessionByDate(
94 date, sByText));
95 sessionTableModel.fireTableDataChanged();
96 }
97 setStatus(SUCCESS_STATUS);
98 break;
99 }
100 }
101 }