1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
package org.directdemocracyportal.democracy.web.actionlistener; |
6 | |
|
7 | |
import org.apache.commons.logging.Log; |
8 | |
import org.apache.commons.logging.LogFactory; |
9 | |
import org.directdemocracyportal.democracy.web.ApplicationMessageHolder; |
10 | |
import org.directdemocracyportal.democracy.web.ImageConstants; |
11 | |
import org.directdemocracyportal.democracy.web.ApplicationMessageHolder.MessageConstans; |
12 | |
import org.directdemocracyportal.democracy.web.action.ControllerAction; |
13 | |
import org.directdemocracyportal.democracy.web.controller.Controller; |
14 | |
|
15 | |
import thinwire.ui.Button; |
16 | |
import thinwire.ui.Frame; |
17 | |
import thinwire.ui.Hyperlink; |
18 | |
import thinwire.ui.Menu; |
19 | |
import thinwire.ui.MessageBox; |
20 | |
import thinwire.ui.GridBox.Range; |
21 | |
import thinwire.ui.event.ActionEvent; |
22 | |
import thinwire.ui.event.ActionListener; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
public class ApplicationActionListener implements ActionListener |
36 | |
{ |
37 | |
|
38 | |
|
39 | 1 | private static Log log = LogFactory.getLog(ApplicationActionListener.class); |
40 | |
|
41 | |
|
42 | |
private final Controller controller; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
public ApplicationActionListener(Controller controller) { |
50 | 1 | super(); |
51 | 1 | this.controller = controller; |
52 | 1 | } |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
public void actionPerformed(ActionEvent ev) { |
60 | 0 | Object source = ev.getSource(); |
61 | 0 | Object userObject = null; |
62 | |
|
63 | 0 | if (source instanceof Button) { |
64 | 0 | userObject = ((Button) source).getUserObject(); |
65 | 0 | } else if (source instanceof Hyperlink) { |
66 | 0 | userObject = ((Hyperlink) source).getUserObject(); |
67 | 0 | } else if (source instanceof Range) { |
68 | 0 | userObject = ((Range)source).getRow().getUserObject(); |
69 | 0 | } else if (source instanceof Menu.Item) { |
70 | 0 | if (((Menu.Item) source).isEnabled()) { |
71 | 0 | userObject = ((Menu.Item) source).getUserObject(); |
72 | |
} |
73 | 0 | } else if (source instanceof Frame) { |
74 | 0 | userObject = ((Frame)source).getUserObject(); |
75 | |
} |
76 | |
|
77 | 0 | if (userObject != null) { |
78 | |
try { |
79 | 0 | controller.handleAction((ControllerAction) userObject); |
80 | 0 | } catch (Exception e) { |
81 | 0 | log.error("Should have done rollback, unexpected error", e); |
82 | 0 | MessageBox.confirm(ImageConstants.ACTION_ERROR, ApplicationMessageHolder |
83 | |
.getMessage(MessageConstans.ERROR_MESSAGE), |
84 | |
ApplicationMessageHolder |
85 | |
.getMessage(MessageConstans.ERROR_MESSAGE) + " " + e.getMessage()); |
86 | 0 | } |
87 | |
} |
88 | 0 | } |
89 | |
} |