BrightSide Workbench Full Report + Source Code
Modal.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.elephant.zkoss;
19 
20 import java.util.Map;
21 import org.turro.command.Command;
22 import org.turro.command.Context;
23 import org.zkoss.zk.ui.Component;
24 import org.zkoss.zk.ui.Executions;
25 import org.zkoss.zk.ui.UiException;
26 import org.zkoss.zk.ui.event.Event;
27 import org.zkoss.zk.ui.event.EventListener;
28 import org.zkoss.zk.ui.event.Events;
29 import org.zkoss.zul.Window;
30 
35 public class Modal {
36 
37  @Deprecated
38  public static int doModal(String file) throws InterruptedException {
39  return doModal(file, null, (Map) null);
40  }
41 
42  @Deprecated
43  public static int doModal(String file, Map arg) throws InterruptedException {
44  return doModal(file, null, arg);
45  }
46 
47  @Deprecated
48  public static int doModal(String file, Component parent, Map arg) throws InterruptedException {
49  return doModal(getModal(file, parent, arg));
50  }
51 
52  @Deprecated
53  public static int doModal(ModalWindow win) throws InterruptedException {
54  if(win.getDesktop().getWebApp().getConfiguration().isEventThreadEnabled()) {
55  try {
56  win.doModal();
57  } catch (Throwable ex) {
58  win.detach();
59  if (ex instanceof InterruptedException)
60  throw (InterruptedException)ex;
61  throw UiException.Aide.wrap(ex);
62  }
63  }
64  return win.getResult();
65  }
66 
67  @Deprecated
68  public static void doModal(Window win) throws InterruptedException {
69  if(win.getDesktop().getWebApp().getConfiguration().isEventThreadEnabled()) {
70  try {
71  win.doModal();
72  } catch (Throwable ex) {
73  win.detach();
74  if (ex instanceof InterruptedException)
75  throw (InterruptedException)ex;
76  throw UiException.Aide.wrap(ex);
77  }
78  }
79  }
80 
81  public static void doModal(String file, Command command) {
82  doModal(file, null, null, command);
83  }
84 
85  public static void doModal(String file, Map arg, Command command) throws InterruptedException {
86  doModal(file, null, arg, command);
87  }
88 
89  public static void doModal(String file, Component parent, Map arg, Command command) {
90  doModal(getModal(file, parent, arg), command);
91  }
92 
93  public static void doModal(final Window win, final Command command) {
94  win.addEventListener(Events.ON_CLOSE, new EventListener<Event>() {
95  @Override
96  public void onEvent(Event event) throws Exception {
97  if(command != null) {
98  Context ctx = new Context();
99  ctx.put("win", win);
100  command.execute(ctx);
101  }
102  win.removeEventListener(Events.ON_CLOSE, this);
103  win.detach();
104  }
105  });
106  win.doModal();
107  }
108 
109  public static ModalWindow getModal(String file) {
110  return (ModalWindow) Executions.createComponents(file, null, null);
111  }
112 
113  public static ModalWindow getModal(String file, Map arg) {
114  return (ModalWindow) Executions.createComponents(file, null, arg);
115  }
116 
117  public static ModalWindow getModal(String file, Component parent, Map arg) {
118  return (ModalWindow) Executions.createComponents(file, parent, arg);
119  }
120 
121  private Modal() {
122  }
123 }
static ModalWindow getModal(String file, Component parent, Map arg)
Definition: Modal.java:117
static int doModal(ModalWindow win)
Definition: Modal.java:53
static ModalWindow getModal(String file, Map arg)
Definition: Modal.java:113
static int doModal(String file, Component parent, Map arg)
Definition: Modal.java:48
static void doModal(String file, Map arg, Command command)
Definition: Modal.java:85
static void doModal(Window win)
Definition: Modal.java:68
static void doModal(String file, Command command)
Definition: Modal.java:81
static void doModal(final Window win, final Command command)
Definition: Modal.java:93
static int doModal(String file)
Definition: Modal.java:38
static int doModal(String file, Map arg)
Definition: Modal.java:43
static void doModal(String file, Component parent, Map arg, Command command)
Definition: Modal.java:89
static ModalWindow getModal(String file)
Definition: Modal.java:109