[GWT] OpenerEvents
Google/GWT / 2008. 11. 23. 18:21
원래 GWT 가 팝업된 윈도우와의 이벤트는 고려를 하지 않고 만들어졌기 때문에 팝업을 주로 사용하는 시스템에서는 팝업 윈도우와 원래 윈도우간의 커뮤니케이션 수단이 필요합니다.
OpenerCommand.java
1 | package com.idstrust.wiseone.ui.common.client.popup; |
2 |
3 | public interface OpenerCommand { |
4 |
5 | void execute(); |
6 | |
7 | } |
OpenerCommandCollection.java
01 | package com.idstrust.wiseone.ui.common.client.popup; |
02 |
03 | import java.util.ArrayList; |
04 |
05 | @SuppressWarnings ( "serial" ) |
06 | public class OpenerCommandCollection extends ArrayList<OpenerCommand> { |
07 | |
08 | public void fireExecute() { |
09 | for (OpenerCommand command : this ) { |
10 | command.execute(); |
11 | } |
12 | } |
13 |
14 | } |
OpenerEvents.java
01 | package com.idstrust.wiseone.ui.common.client.popup; |
02 |
03 | import java.util.HashMap; |
04 | import java.util.Map; |
05 |
06 | public class OpenerEvents { |
07 | |
08 | private static Map<String, OpenerCommandCollection> openerCommandsMap; |
09 | |
10 | static { |
11 | install(); |
12 | openerCommandsMap = new HashMap<String, OpenerCommandCollection>(); |
13 | } |
14 | |
15 | /** |
16 | * 팝업창 리스너 핸들러를 초기화합니다. |
17 | */ |
18 | private native static void install() /*-{ |
19 | $wnd['__openerEventsHandler'] = function(type) { |
20 | @com.idstrust.wiseone.ui.common.client.popup.OpenerEvents::fireExecute(Ljava/lang/String;)(type); |
21 | }; |
22 | }-*/; |
23 |
24 | /** |
25 | * OpenerCommand 를 추가합니다. |
26 | * @param type |
27 | * @param command |
28 | */ |
29 | public static void addOpenerCommand(String type, OpenerCommand command) { |
30 | OpenerCommandCollection openerCommands = openerCommandsMap.get(type); |
31 | if (openerCommands == null) { |
32 | openerCommands = new OpenerCommandCollection(); |
33 | openerCommandsMap.put(type, openerCommands); |
34 | } |
35 | openerCommands.add(command); |
36 | } |
37 | |
38 | /** |
39 | * OpenerCommand 를 제거합니다. |
40 | * @param type |
41 | * @param command |
42 | */ |
43 | public static void removeOpenerCommand(String type, OpenerCommand command) { |
44 | OpenerCommandCollection openerCommands = openerCommandsMap.get(type); |
45 | if (openerCommands != null) { |
46 | openerCommands.remove(command); |
47 | } |
48 | } |
49 | |
50 | /** |
51 | * OpenerCommand 의 이벤트를 실행시킵니다. |
52 | * @param type |
53 | */ |
54 | protected static void fireExecute(String type) { |
55 | OpenerCommandCollection openerCommands = openerCommandsMap.get(type); |
56 | if (openerCommands != null) { |
57 | openerCommands.fireExecute(); |
58 | } |
59 | } |
60 | |
61 | /** |
62 | * 팝업 윈도우에서 부모창의 이벤트를 실행시킵니다. |
63 | * @param type |
64 | */ |
65 | public static native void fireOpenerEvents(String type) /*-{ |
66 | if ($wnd.opener && $wnd.opener['__openerEventsHandler']) { |
67 | $wnd.opener['__openerEventsHandler'](type); |
68 | } |
69 | }-*/ ; |
70 | } |
실제 사용 예...
Opener 윈도우
1 | OpenerEvents.addOpenerCommand( "refresh" , new OpenerCommand() { |
2 | public void execute() { |
3 | // TODO 이벤트를 처리합니다. |
4 | } |
5 | }); |
Popup 윈도우
1 | OpenerEvents.fireOpenerEvents( "refresh" ); |
Opener 윈도우에 이벤트 처리 핸들러를 등록해놓고, Popup 윈도우에서 이벤트를 실행시키는 형식입니다.
Posted by
자수씨