KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > customizers > common > CustomizerErrorPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * CustomizerErrorPanel.java
21  *
22  * Created on March 1, 2004, 12:22 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.common;
26
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.ResourceBundle JavaDoc;
30
31 import java.text.MessageFormat JavaDoc;
32
33 import java.awt.Color JavaDoc;
34 import java.awt.Container JavaDoc;
35 import java.awt.GridBagConstraints JavaDoc;
36 import java.awt.Insets JavaDoc;
37 import javax.swing.JLabel JavaDoc;
38 import javax.swing.JPanel JavaDoc;
39
40 import org.netbeans.modules.j2ee.sun.share.configbean.Base;
41 import org.netbeans.modules.j2ee.sun.share.configbean.ErrorMessageDB;
42 import org.netbeans.modules.j2ee.sun.share.configbean.ValidationError;
43
44 /**
45  *
46  * @author Peter Williams
47  */

48 public class CustomizerErrorPanel extends JPanel JavaDoc {
49     
50     private static final ResourceBundle JavaDoc bundle = ResourceBundle.getBundle(
51         "org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.Bundle"); // NOI18N
52

53     private ErrorClient errorClient;
54     
55     /** Creates new form CustomizerErrorPanel
56      *
57      * @param client The error support client, typically the customizer instance.
58      */

59     public CustomizerErrorPanel(ErrorClient client) {
60         errorClient = client;
61         
62         initComponents();
63         initUserComponents();
64     }
65     
66     public GridBagConstraints JavaDoc getConstraints() {
67         GridBagConstraints JavaDoc constraints = new GridBagConstraints JavaDoc();
68         constraints.gridwidth = GridBagConstraints.REMAINDER;
69         constraints.fill = GridBagConstraints.HORIZONTAL;
70         constraints.weightx = 1.0;
71         constraints.insets = new Insets JavaDoc(6,12,11,11);
72         
73         return constraints;
74     }
75     
76     /** This method is called from within the constructor to
77      * initialize the form.
78      * WARNING: Do NOT modify this code. The content of this method is
79      * always regenerated by the Form Editor.
80      */

81     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
82
private void initComponents() {
83
84         setLayout(new java.awt.GridBagLayout JavaDoc());
85
86         getAccessibleContext().setAccessibleName(bundle.getString("ACSN_ErrorTextArea"));
87         getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_ErrorTextArea"));
88     }// </editor-fold>//GEN-END:initComponents
89

90     
91     // Variables declaration - do not modify//GEN-BEGIN:variables
92
// End of variables declaration//GEN-END:variables
93

94     
95     private void initUserComponents() {
96     }
97     
98     /** Shows the errors at the top of dialog panel.
99      * Set focus to the focused component.
100      */

101     public void showErrors(Base bean) {
102         String JavaDoc errorString;
103         List JavaDoc errorList = null;
104         
105         removeAll();
106         
107         // Get error list, if any,
108
ErrorMessageDB messageDB = ErrorMessageDB.getMessageDB(bean);
109         if(messageDB != null) {
110             ValidationError.Partition visiblePartition = errorClient.getPartition();
111             errorList = messageDB.getErrors(visiblePartition);
112         }
113         
114         if(errorList != null && errorList.size() > 0) {
115             Object JavaDoc [] args = new Object JavaDoc[2];
116             
117             for(Iterator JavaDoc iter = errorList.iterator(); iter.hasNext();) {
118                 ValidationError error = (ValidationError) iter.next();
119
120                 args[0] = error.getFieldId();
121                 args[1] = error.getMessage();
122                 
123                 String JavaDoc message = MessageFormat.format(bundle.getString("MSG_ErrorDisplayFormat"), args); // NOI18N
124

125                 // Add error message
126
JLabel JavaDoc label = new JLabel JavaDoc();
127                 label.setIcon(BaseCustomizer.errorMessageIcon);
128                 label.setText(message); // NOI18N
129
label.getAccessibleContext().setAccessibleName(bundle.getString("ASCN_ErrorMessage")); // NOI18N
130
label.getAccessibleContext().setAccessibleDescription(message);
131                 label.setForeground(errorClient.getErrorMessageForegroundColor());
132
133                 GridBagConstraints JavaDoc constraints = new GridBagConstraints JavaDoc();
134                 constraints.gridwidth = GridBagConstraints.REMAINDER;
135                 constraints.fill = GridBagConstraints.HORIZONTAL;
136                 constraints.weightx = 1.0;
137                 add(label, constraints);
138             }
139         }
140
141         Container JavaDoc parent = getParent();
142         if(parent != null) {
143             parent.validate();
144         }
145     }
146
147     
148     /** Interface to allow customization of error panel by owner.
149      */

150     public static interface ErrorClient {
151         
152         /** Foreground color to use with error messages.
153          *
154          * @return Foreground color for error messages.
155          */

156         public Color JavaDoc getErrorMessageForegroundColor();
157         
158 // /** Foreground color to use with warning messages.
159
// *
160
// * @return Foreground color for warning messages.
161
// */
162
// public Color getWarningMessageForegroundColor();
163

164         /** Gets the current panel descriptor.
165          *
166          * @return Current panel descriptor.
167          */

168         public ValidationError.Partition getPartition();
169         
170     }
171 }
172
173
Popular Tags