Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / panelGroup / exceptions / PanelBaseException.java @ 40561

History | View | Annotate | Download (4.33 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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.
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.
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.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.gui.beans.panelGroup.exceptions;
25

    
26
import java.util.HashMap;
27
import java.util.Map;
28

    
29
import org.gvsig.gui.beans.Messages;
30
import org.gvsig.tools.exception.BaseException;
31

    
32
/**
33
 * <p>Adapts any <i>Java</i> exception produced working with panels to be dealed in as a {@link BaseException BaseException}.</p>
34
 * 
35
 * @version 11/12/2007
36
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es) 
37
 */
38
public class PanelBaseException extends BaseException {
39
        private static final long serialVersionUID = -5248981827020054295L;
40
        protected HashMap<String, String> values;
41
        public static final String PANEL_LABEL = "PANEL_LABEL";
42
        public static final String CAUSE_MESSAGE = "CAUSE_MESSAGE";
43

    
44
        /**
45
         * <p>Creates and initializes a new instance of <code>PanelBaseException</code>.</p>
46
         */
47
        public PanelBaseException() {
48
                super();
49
                initialize();
50
        }
51

    
52
        /**
53
         * <p>Creates and initializes a new instance of <code>PanelBaseException</code>.</p>
54
         * 
55
         * @param e the exception to be wrappered
56
         */
57
        public PanelBaseException(Exception e) {
58
                super();
59
                initialize();
60
                initCause(e);
61
        }
62

    
63
        /**
64
         * <p>Creates and initializes a new instance of <code>PanelBaseException</code>.</p>
65
         * 
66
         * @param e the exception to be wrappered
67
         * @param panelLabel label of the panel which is the source of the exception wrappered
68
         */
69
        public PanelBaseException(Exception e, String panelLabel) {
70
                super();
71
                initialize();
72
                initCause(e);
73
                setPanelLabel(panelLabel);
74
        }
75

    
76
        protected Map<String, String> values() {
77
                return values;
78
        }
79

    
80
        /**
81
         * <p>Initializes a <code>PanelBaseException</code> with the needed information.</p>
82
         */
83
        protected void initialize() {
84
                // Identifier of this kind of exception
85
                this.code = serialVersionUID;
86
                
87
                // Default text that explains this kind of exception. If there is no translation associated to the
88
                // "messageKey" of this exception, then the value shown will be the value of "formatString".
89
                this.formatString = "Error loading %(" + PANEL_LABEL + ")%(" + CAUSE_MESSAGE + ").";
90

    
91
                 // Key to the sentence that explains this exception. That key will be use for multilingual purposes.
92
                this.messageKey = "panel_base_exception";
93
                
94
                // Map with the label of the panel
95
                values = new HashMap<String, String>();
96
                values.put(PANEL_LABEL, Messages.getText("a_panel"));
97
                values.put(CAUSE_MESSAGE, "");
98
                
99
                setTranslator(new Messages());
100
        }
101

    
102
        /**
103
         * <p>Gets the label of the panel which is the source of this exception, or
104
         *  <code>null</code> if hasn't been defined.</p>
105
         * 
106
         * @return label of the panel which is the source of this exception
107
         */
108
        public String getPanelLabel() {
109
                return values.get(PANEL_LABEL);
110
        }
111

    
112
        /**
113
         * <p>Sets the label of the panel which is the source of this exception.</p>
114
         * 
115
         * @param panelLabel label of the panel which is the source of this exception
116
         */
117
        public void setPanelLabel(String panelLabel) {
118
                if ((panelLabel.equals("")) || (panelLabel == null)) {
119
                        values.put(PANEL_LABEL, Messages.getText("a_panel"));
120
                } else {
121
                        values.put(PANEL_LABEL, Messages.getText("the_panel") + " \"" + panelLabel + "\"");
122
                }
123
        }
124

    
125
        /*
126
         * (non-Javadoc)
127
         * @see java.lang.Throwable#initCause(java.lang.Throwable)
128
         */
129
        public Throwable initCause(Throwable cause) {
130
                Throwable t = super.initCause(cause);
131
                
132
                if ((cause == null) || (cause.getLocalizedMessage() == null)) {
133
                        values.put(CAUSE_MESSAGE, "");
134
                } else {
135
                        values.put(CAUSE_MESSAGE, ": " + cause.getLocalizedMessage());
136
                }
137
                
138
                return t;
139
        }
140
}