BrightSide Workbench Full Report + Source Code
Messages.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 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 
19 package org.turro.elephant.util;
20 
21 import org.turro.string.Phrases;
22 import org.turro.i18n.I_;
23 import org.zkoss.zk.ui.event.Event;
24 import org.zkoss.zul.Messagebox;
25 
30 public class Messages {
31 
32  public void show() {
33  Messagebox.show(phrases.newLine("\n").toString(), title,
34  Messagebox.OK, type, 0, null);
35  }
36 
37  public void show(Runnable onOk) {
38  Messagebox.show(phrases.newLine("\n").toString(), title,
39  Messagebox.OK | Messagebox.CANCEL, type, (Event event) -> {
40  switch ((Integer) event.getData()) {
41  case Messagebox.OK -> onOk.run();
42  }
43  });
44  }
45 
46  /* Phrases */
47 
48  private final Phrases phrases = Phrases.start();
49 
50  public Messages add(String word) {
51  phrases.add(word);
52  return this;
53  }
54 
55  public Messages add(String word, boolean withSpace) {
56  phrases.add(word, withSpace);
57  return this;
58  }
59 
60  public Messages add(String word, String enclose) {
61  phrases.add(word, enclose);
62  return this;
63  }
64 
65  public Messages add(String value, String enclose, boolean withSpace) {
66  phrases.add(value, enclose, withSpace);
67  return this;
68  }
69 
70  public Messages format(String word, Object... args) {
71  phrases.format(word, args);
72  return this;
73  }
74 
75  public Messages line() {
76  phrases.line();
77  return this;
78  }
79 
80  public Messages paragraph() {
81  phrases.paragraph();
82  return this;
83  }
84 
85  /* Factory */
86 
87  public static Messages confirmDeletion() {
88  return question().add(I_.get("Confirm element deletion")).line();
89  }
90 
91  public static Messages confirmCutting() {
92  return question().add(I_.get("Confirm element cut")).line();
93  }
94 
95  public static Messages confirmProcess() {
96  return question().add(I_.get("Confirm process")).line();
97  }
98 
99  public static Messages confirmMove() {
100  return question().add(I_.get("Confirm element move")).line();
101  }
102 
103  public static Messages confirmAcceptation() {
104  return question().add(I_.get("Confirm acceptation")).line();
105  }
106 
107  public static Messages info() {
108  return info(I_.get("Information"));
109  }
110 
111  public static Messages info(String title) {
112  return new Messages(Messagebox.INFORMATION, title);
113  }
114 
115  public static Messages question() {
116  return question(I_.get("Question"));
117  }
118 
119  public static Messages question(String title) {
120  return new Messages(Messagebox.QUESTION, title);
121  }
122 
123  public static Messages error() {
124  return error(I_.get("Error"));
125  }
126 
127  public static Messages error(String title) {
128  return new Messages(Messagebox.ERROR, title);
129  }
130 
131  private final String type, title;
132 
133  private Messages(String type, String title) {
134  this.type = type;
135  this.title = title;
136  }
137 
138 }
Messages add(String word, boolean withSpace)
Definition: Messages.java:55
static Messages error(String title)
Definition: Messages.java:127
static Messages confirmCutting()
Definition: Messages.java:91
void show(Runnable onOk)
Definition: Messages.java:37
Messages add(String word, String enclose)
Definition: Messages.java:60
static Messages question(String title)
Definition: Messages.java:119
Messages add(String value, String enclose, boolean withSpace)
Definition: Messages.java:65
Messages format(String word, Object... args)
Definition: Messages.java:70
static Messages info(String title)
Definition: Messages.java:111
static Messages confirmDeletion()
Definition: Messages.java:87
static Messages confirmProcess()
Definition: Messages.java:95
static Messages confirmMove()
Definition: Messages.java:99
static Messages confirmAcceptation()
Definition: Messages.java:103
Messages add(String word)
Definition: Messages.java:50
static String get(String msg)
Definition: I_.java:41