BrightSide Workbench Full Report + Source Code
ZkossUtils.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.util;
19 
20 import org.amic.util.string.Strings;
21 import org.turro.command.Command;
22 import org.turro.command.Context;
23 import org.turro.i18n.I_;
24 import org.turro.reflection.ReflectionUtil;
25 import org.turro.util.PhraseBuilder;
26 import org.zkoss.zk.ui.Component;
27 import org.zkoss.zk.ui.Page;
28 import org.zkoss.zk.ui.event.Event;
29 import org.zkoss.zk.ui.event.EventListener;
30 import org.zkoss.zk.ui.impl.PageImpl;
31 import org.zkoss.zul.Messagebox;
32 
37 public class ZkossUtils {
38 
39  public static Component getParent(Page page, Class jClass) {
40  if(page instanceof PageImpl) {
41  return getParent(((PageImpl) page).getOwner(), jClass);
42  }
43  return null;
44  }
45 
46  public static Component getParent(Component component, Class jClass) {
47  if(component != null) {
48  Component p = component;
49  while((p = p.getParent()) != null) {
50  if(ReflectionUtil.representsClass(p.getClass(), jClass)) {
51  return p;
52  }
53  }
54  }
55  return null;
56  }
57 
58  public static void confirmDeletion(String message, Command command) {
59  PhraseBuilder pb = new PhraseBuilder(I_.get("Confirm element deletion"));
60  if(!Strings.isEmpty(message)) {
61  pb.addWord(message);
62  }
63  confirmMessage(pb.toString(), command);
64  }
65 
66  public static void confirmCutting(String message, Command command) {
67  PhraseBuilder pb = new PhraseBuilder(I_.get("Confirm element cut"));
68  if(!Strings.isEmpty(message)) {
69  pb.addWord(message);
70  }
71  confirmMessage(pb.toString(), command);
72  }
73 
74  public static void confirmProcess(String message, Command command) {
75  PhraseBuilder pb = new PhraseBuilder(I_.get("Confirm process"));
76  if(!Strings.isEmpty(message)) {
77  pb.addWord(message);
78  }
79  confirmMessage(pb.toString(), command);
80  }
81 
82  public static void confirmMove(String message, Command command) {
83  PhraseBuilder pb = new PhraseBuilder(I_.get("Confirm element move"));
84  if(!Strings.isEmpty(message)) {
85  pb.addWord(message);
86  }
87  confirmMessage(pb.toString(), command);
88  }
89 
90  public static void confirmAcceptation(String message, Command command) {
91  PhraseBuilder pb = new PhraseBuilder(I_.get("Confirm acceptation"));
92  if(!Strings.isEmpty(message)) {
93  pb.addWord(message);
94  }
95  confirmMessage(pb.toString(), command);
96  }
97 
98  public static void confirmMessage(String message, final Command command) {
99  Messagebox.show(message, I_.get("Question"),
100  Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION,
101  new EventListener<Event>() {
102  @Override
103  public void onEvent(Event event) throws Exception {
104  Context ctx = new Context();
105  switch ((Integer) event.getData()) {
106  case Messagebox.OK: command.execute(ctx); break;
107  }
108  }
109  });
110  }
111 
112  public static void showMessage(String title, String message) {
113  Messagebox.show(message, title, Messagebox.OK, Messagebox.INFORMATION, 0, null);
114  }
115 
116  private ZkossUtils() {
117  }
118 }
static Component getParent(Component component, Class jClass)
Definition: ZkossUtils.java:46
static Component getParent(Page page, Class jClass)
Definition: ZkossUtils.java:39
static void confirmMessage(String message, final Command command)
Definition: ZkossUtils.java:98
static void confirmAcceptation(String message, Command command)
Definition: ZkossUtils.java:90
static void confirmProcess(String message, Command command)
Definition: ZkossUtils.java:74
static void confirmMove(String message, Command command)
Definition: ZkossUtils.java:82
static void confirmCutting(String message, Command command)
Definition: ZkossUtils.java:66
static void confirmDeletion(String message, Command command)
Definition: ZkossUtils.java:58
static void showMessage(String title, String message)
static String get(String msg)
Definition: I_.java:41