Revision 41488 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.impl/src/main/java/org/gvsig/exportto/swing/impl/panel/MessagePanel.java
MessagePanel.java | ||
---|---|---|
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2007-2013 gvSIG Association. |
5 | 5 |
* |
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License
|
|
8 |
* as published by the Free Software Foundation; either version 3
|
|
9 |
* of the License, or (at your option) any later version.
|
|
6 |
* This program is free software; you can redistribute it and/or modify it under
|
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
|
9 |
* version. |
|
10 | 10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
14 |
* details. |
|
15 | 15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
20 | 19 |
* |
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
23 | 22 |
*/ |
24 | 23 |
package org.gvsig.exportto.swing.impl.panel; |
25 | 24 |
|
... | ... | |
27 | 26 |
import java.awt.Dimension; |
28 | 27 |
import java.awt.event.ActionEvent; |
29 | 28 |
import java.awt.event.ActionListener; |
30 |
import java.util.logging.Level; |
|
29 |
import java.net.UnknownHostException; |
|
30 |
import java.util.Iterator; |
|
31 | 31 |
|
32 | 32 |
import javax.swing.BorderFactory; |
33 | 33 |
import javax.swing.Box; |
... | ... | |
43 | 43 |
import org.gvsig.tools.dynform.DynFormLocator; |
44 | 44 |
import org.gvsig.tools.dynform.JDynForm; |
45 | 45 |
import org.gvsig.tools.dynobject.DynObject; |
46 |
import org.gvsig.tools.exception.BaseException; |
|
47 |
import org.gvsig.tools.exception.BaseRuntimeException; |
|
46 | 48 |
import org.gvsig.tools.i18n.I18nManager; |
47 | 49 |
import org.gvsig.tools.service.ServiceException; |
48 | 50 |
|
... | ... | |
67 | 69 |
wm.showWindow(panel, title, WindowManager.MODE.DIALOG); |
68 | 70 |
} |
69 | 71 |
|
72 |
public static void showMessage(String title, |
|
73 |
String header, Exception ex, Feature feature) { |
|
74 |
showMessage(title, header, getMessageAsHTML(ex), feature); |
|
75 |
} |
|
76 |
|
|
77 |
private static class ExceptionIterator implements Iterator { |
|
78 |
|
|
79 |
Throwable exception; |
|
80 |
|
|
81 |
ExceptionIterator(Throwable exception) { |
|
82 |
this.exception = exception; |
|
83 |
} |
|
84 |
|
|
85 |
public boolean hasNext() { |
|
86 |
return this.exception != null; |
|
87 |
} |
|
88 |
|
|
89 |
public Object next() { |
|
90 |
Throwable exception = this.exception; |
|
91 |
this.exception = exception.getCause(); |
|
92 |
return exception; |
|
93 |
} |
|
94 |
|
|
95 |
public void remove() { |
|
96 |
throw new UnsupportedOperationException(); |
|
97 |
} |
|
98 |
} |
|
99 |
|
|
100 |
private static String getMessageAsHTML(Exception ex) { |
|
101 |
Iterator exceptions = new ExceptionIterator(ex); |
|
102 |
StringBuilder html = new StringBuilder(); |
|
103 |
|
|
104 |
html.append("<ul>\n"); |
|
105 |
while (exceptions.hasNext()) { |
|
106 |
Throwable ex1 = ((Throwable) exceptions.next()); |
|
107 |
String message = null; |
|
108 |
if (ex1 instanceof UnknownHostException) { |
|
109 |
message = "Unknown Host " + ex1.getMessage(); |
|
110 |
} else { |
|
111 |
message = ex1.getMessage(); |
|
112 |
} |
|
113 |
if (message != null) { |
|
114 |
html.append("<li>"); |
|
115 |
if (message.toLowerCase().contains(" create ")) { |
|
116 |
message = message.replaceFirst(" create ", "<br>\nCREATE "); |
|
117 |
message = message.replaceAll(",", ",<br>\n"); |
|
118 |
} else if (message.toLowerCase().contains(" insert ")) { |
|
119 |
message = message.replaceFirst(" insert ", "<br>\nINSERT "); |
|
120 |
message = message.replaceAll(",", ",<br>\n"); |
|
121 |
} |
|
122 |
html.append(message); |
|
123 |
html.append("</li>\n"); |
|
124 |
} |
|
125 |
} |
|
126 |
html.append("</ul>\n"); |
|
127 |
return html.toString(); |
|
128 |
} |
|
129 |
|
|
70 | 130 |
public MessagePanel(final String header, final String html, Feature feature) { |
71 | 131 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
72 | 132 |
|
... | ... | |
89 | 149 |
scrollPane.setPreferredSize(new Dimension(500, 220)); |
90 | 150 |
|
91 | 151 |
tabs.addTab(i18nManager.getTranslation("_Problem"), scrollPane); |
92 |
if ( feature != null ) {
|
|
152 |
if (feature != null) {
|
|
93 | 153 |
try { |
94 | 154 |
DynObject data = feature.getAsDynObject(); |
95 | 155 |
JDynForm form = DynFormLocator.getDynFormManager().createJDynForm(data); |
Also available in: Unified diff