PageRenderTime 187ms CodeModel.GetById 80ms app.highlight 42ms RepoModel.GetById 59ms app.codeStats 1ms

/src/mpv5/ui/dialogs/Notificator.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 78 lines | 49 code | 8 blank | 21 comment | 9 complexity | ae7b761bad5078a1234457c278c10f12 MD5 | raw file
 1package mpv5.ui.dialogs;
 2
 3import javax.swing.SwingUtilities;
 4import mpv5.db.common.Context;
 5import mpv5.db.common.DatabaseObject;
 6import mpv5.db.common.QueryHandler;
 7import mpv5.db.objects.HistoryItem;
 8import mpv5.globals.Messages;
 9import mpv5.ui.frames.MPView;
10
11/**
12 *
13 * Use this class to pass messages to the user
14 * @author anti
15 */
16public class Notificator {
17
18    /**
19     * Raise a notification to the user
20     * @param message
21     */
22    public static void raiseNotification(final Object message) {
23        Runnable runnable = new Runnable() {
24
25            @Override
26            public void run() {
27                Popup.notice(message);
28            }
29        };
30        SwingUtilities.invokeLater(runnable);
31    }
32
33    /**
34     * Raise a notification to the user
35     * @param message
36     * @param popup 
37     */
38    public static void raiseNotification(Object message, boolean popup) {
39        if (popup) {
40            raiseNotification(message);
41        } else {
42            if (message != null) {
43                mpv5.YabsViewProxy.instance().addMessage(message.toString());
44            }
45        }
46    }
47
48    /**
49     * Raise a notification to the user
50     * @param message
51     * @param popup
52     * @param log write to log
53     * @param source  
54     */
55    public static void raiseNotification(final Object message, boolean popup, boolean log, DatabaseObject source) {
56        if (popup) {
57            raiseNotification(message);
58        } else {
59            if (message != null) {
60                mpv5.YabsViewProxy.instance().addMessage(message.toString());
61            }
62        }
63
64        if (log) {
65            final String fdbid = Messages.NOTIFICATION.getValue();
66            final int fids = source.__getIDS();
67            final int fgids = source.__getGroupsids();
68            Runnable runnable = new Runnable() {
69
70                @Override
71                public void run() {
72                    QueryHandler.instanceOf().clone(Context.getHistory()).insertHistoryItem(message.toString(), mpv5.db.objects.User.getCurrentUser().__getCname(), fdbid, fids, fgids);
73                }
74            };
75            new Thread(runnable).start();
76        }
77    }
78}