Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
UrumaMessageDialog |
|
| 1.1666666666666667;1.167 |
1 | /* | |
2 | * Copyright 2004-2008 the Seasar Foundation and the Others. | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | |
13 | * either express or implied. See the License for the specific language | |
14 | * governing permissions and limitations under the License. | |
15 | */ | |
16 | package org.seasar.uruma.ui.dialogs; | |
17 | ||
18 | import org.eclipse.jface.dialogs.InputDialog; | |
19 | import org.eclipse.jface.dialogs.MessageDialog; | |
20 | import org.eclipse.jface.window.Window; | |
21 | import org.seasar.uruma.core.UrumaConstants; | |
22 | import org.seasar.uruma.util.MessageUtil; | |
23 | import org.seasar.uruma.util.ShellUtil; | |
24 | ||
25 | /** | |
26 | * メッセージダイアログを表示するためのユーティリティクラスです。<br /> | |
27 | * 各ダイアログで表示するメッセージは {@link UrumaConstants#USER_MESSAGE_BASE} リソースバンドルから取得します。<br /> | |
28 | * その際、タイトルは、<i>リソースキー</i><code>_TITLE</code> から、メッセージは <i>リソースキー</i><code>_MSG</code> | |
29 | * から取得します。<br /> | |
30 | * | |
31 | * @author y-komori | |
32 | */ | |
33 | public class UrumaMessageDialog { | |
34 | private static final String TITLE_SUFFIX = "_TITLE"; | |
35 | ||
36 | private static final String MESSAGE_SUFFIX = "_MSG"; | |
37 | ||
38 | 0 | private UrumaMessageDialog() { |
39 | ||
40 | 0 | } |
41 | ||
42 | /** | |
43 | * インフォメーションダイアログを表示します。<br /> | |
44 | * | |
45 | * @param title | |
46 | * タイトル | |
47 | * @param msg | |
48 | * メッセージ | |
49 | */ | |
50 | public static final void openInformation(final String title, | |
51 | final String msg) { | |
52 | 0 | MessageDialog.openInformation(ShellUtil.getShell(), title, msg); |
53 | 0 | } |
54 | ||
55 | /** | |
56 | * インフォメーションダイアログを表示します。<br /> | |
57 | * | |
58 | * @param key | |
59 | * リソースキー | |
60 | */ | |
61 | public static final void openInformation(final String key) { | |
62 | 0 | openInformation(getTitle(key), getMessage(key)); |
63 | 0 | } |
64 | ||
65 | /** | |
66 | * エラーダイアログを表示します。<br /> | |
67 | * | |
68 | * @param title | |
69 | * タイトル | |
70 | * @param msg | |
71 | * メッセージ | |
72 | */ | |
73 | public static final void openError(final String title, final String msg) { | |
74 | 0 | MessageDialog.openError(ShellUtil.getShell(), title, msg); |
75 | 0 | } |
76 | ||
77 | /** | |
78 | * エラーダイアログを表示します。<br /> | |
79 | * | |
80 | * @param key | |
81 | * リソースキー | |
82 | */ | |
83 | public static final void openError(final String key) { | |
84 | 0 | openError(getTitle(key), getMessage(key)); |
85 | 0 | } |
86 | ||
87 | /** | |
88 | * 確認ダイアログを表示します。<br /> | |
89 | * | |
90 | * @param title | |
91 | * タイトル | |
92 | * @param msg | |
93 | * メッセージ | |
94 | * @return OKボタンが押された場合、<code>true</code>。キャンセルボタンが押された場合、<code>false</code> | |
95 | */ | |
96 | public static final boolean openConfirm(final String title, final String msg) { | |
97 | 0 | return MessageDialog.openConfirm(ShellUtil.getShell(), title, msg); |
98 | } | |
99 | ||
100 | /** | |
101 | * 確認ダイアログを表示します。<br /> | |
102 | * | |
103 | * @param key | |
104 | * リソースキー | |
105 | * @return OKボタンが押された場合、<code>true</code>。キャンセルボタンが押された場合、<code>false</code> | |
106 | */ | |
107 | public static final boolean openConfirm(final String key) { | |
108 | 0 | return openConfirm(getTitle(key), getMessage(key)); |
109 | } | |
110 | ||
111 | /** | |
112 | * 入力ダイアログを表示します。<br /> | |
113 | * | |
114 | * @param title | |
115 | * タイトル | |
116 | * @param msg | |
117 | * メッセージ | |
118 | * @param initialText | |
119 | * 初期表示文字列 | |
120 | * @return 入力結果。キャンセルされた場合は <code>null</code> | |
121 | */ | |
122 | public static String openInput(final String title, final String msg, | |
123 | final String initialText) { | |
124 | 0 | InputDialog dialog = new InputDialog(ShellUtil.getShell(), title, msg, |
125 | initialText, null); | |
126 | 0 | if (dialog.open() == Window.OK) { |
127 | 0 | return dialog.getValue(); |
128 | } else { | |
129 | 0 | return null; |
130 | } | |
131 | } | |
132 | ||
133 | /** | |
134 | * 入力ダイアログを表示します。<br /> | |
135 | * | |
136 | * @param key | |
137 | * リソースキー | |
138 | * @param initialText | |
139 | * 初期表示文字列 | |
140 | * @return 入力結果。キャンセルされた場合は <code>null</code> | |
141 | */ | |
142 | public static String openInput(final String key, final String initialText) { | |
143 | 0 | return openInput(getTitle(key), getMessage(key), initialText); |
144 | } | |
145 | ||
146 | /** | |
147 | * 入力ダイアログを表示します。<br /> | |
148 | * | |
149 | * @param key | |
150 | * リソースキー | |
151 | * @return 入力結果。キャンセルされた場合は <code>null</code> | |
152 | */ | |
153 | public static String openInput(final String key) { | |
154 | 0 | return openInput(getTitle(key), getMessage(key), |
155 | UrumaConstants.NULL_STRING); | |
156 | } | |
157 | ||
158 | protected static String getTitle(final String bundleKey) { | |
159 | 0 | return MessageUtil.getMessage(bundleKey + TITLE_SUFFIX); |
160 | } | |
161 | ||
162 | protected static String getMessage(final String bundleKey) { | |
163 | 0 | return MessageUtil.getMessage(bundleKey + MESSAGE_SUFFIX); |
164 | } | |
165 | } |