001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.visualweb.designer.jsf.ui;
042:
043: import com.sun.rave.designtime.markup.MarkupDesignBean;
044: import org.netbeans.modules.visualweb.insync.models.FacesModel;
045: import java.awt.Color;
046: import java.awt.Font;
047: import java.awt.event.ActionEvent;
048: import java.awt.event.ActionListener;
049: import java.io.PrintWriter;
050: import java.io.StringWriter;
051: import javax.swing.JPanel;
052: import javax.swing.UIManager;
053: import org.netbeans.modules.visualweb.designer.jsf.JsfForm;
054: import org.openide.util.NbBundle;
055:
056: // XXX Moved from designer/RenderErrorPanel.
057:
058: // XXX Moved from designer/RenderErrorPanel.
059: /**
060: * Panel which shows an error label, and a listbox containing errors
061: *
062: * @todo Unify this code with the code in ImportPagePanel such that JSP tag
063: * handling etc. is handled correctly in both places. There's already some
064: * deviation in what these do.
065: * @todo Trap the case where conversion fails, and tell the user that it failed,
066: * in addition to graying out the buttons.
067: *
068: * @author Tor Norbye
069: */
070: public class RenderErrorPanelImpl extends JPanel implements
071: ActionListener, JsfForm.ErrorPanel {
072: // private WebForm webform;
073: // private final FacesModel facesModel;
074: private final JsfForm jsfForm;
075: private final JsfForm.ErrorPanelCallback errorPanelCallback;
076: private final RenderFailureProvider renderFailureProvider;
077:
078: // Variables declaration - do not modify//GEN-BEGIN:variables
079: private javax.swing.JButton continueButton;
080: private javax.swing.JTextArea exceptions;
081: private javax.swing.JLabel jLabel3;
082: private javax.swing.JPanel jPanel1;
083: private javax.swing.JPanel jPanel2;
084: private javax.swing.JScrollPane jScrollPane1;
085: private javax.swing.JTextArea textArea;
086:
087: // End of variables declaration//GEN-END:variables
088:
089: /** Creates new form ErrorPanel */
090: public RenderErrorPanelImpl(/*WebForm webform*/JsfForm jsfForm,
091: JsfForm.ErrorPanelCallback errorPanelCallback,
092: RenderFailureProvider renderFailureProvider) {
093: // this.webform = webform;
094: // this.facesModel = facesModel;
095: this .jsfForm = jsfForm;
096: this .errorPanelCallback = errorPanelCallback;
097: this .renderFailureProvider = renderFailureProvider;
098:
099: initComponents();
100: updateErrors();
101:
102: // XXX #100175 Do not hardcode font sizes.
103: // But how to provide larger font nicely?
104: Font titleFont = jLabel3.getFont();
105: if (titleFont != null) {
106: int size = titleFont.getSize();
107: float newSize = 2 * size;
108: Font newFont = titleFont.deriveFont(newSize);
109: jLabel3.setFont(newFont);
110: }
111:
112: continueButton.addActionListener(this );
113: textArea.setEnabled(false);
114:
115: //textArea.setColor(Color.BLACK);
116: textArea.setDisabledTextColor(Color.BLACK);
117: textArea.setFont((Font) UIManager.getDefaults().get(
118: "Label.font")); // NOI18N
119:
120: // webform.setRenderFailureShown(true);
121: errorPanelCallback.setRenderFailureShown(true);
122: }
123:
124: public void updateErrors() {
125: // boolean missingBodyElement = webform.getHtmlBody(false) == null;
126: boolean missingBodyElement = jsfForm.getHtmlBody(false) == null;
127: if (missingBodyElement) {
128: jLabel3.setText(NbBundle.getMessage(
129: RenderErrorPanelImpl.class,
130: "LBL_MissingBodyElement"));
131: textArea.setText(NbBundle.getMessage(
132: RenderErrorPanelImpl.class,
133: "TXT_MissingBodyElement"));
134: // XXX
135: continueButton.setVisible(false);
136: jScrollPane1.setVisible(false);
137: } else {
138: jLabel3.setText(NbBundle.getMessage(
139: RenderErrorPanelImpl.class, "CompRenderError"));
140:
141: // Exception e = webform.getRenderFailure();
142: // MarkupDesignBean bean = webform.getRenderFailureComponent();
143: // Exception e = errorPanelCallback.getRenderFailure();
144: // MarkupDesignBean bean = errorPanelCallback.getRenderFailureComponent();
145: Exception e = renderFailureProvider
146: .getRenderFailureException();
147: MarkupDesignBean bean = renderFailureProvider
148: .getRenderFailureComponent();
149:
150: StringWriter sw = new StringWriter();
151: e.printStackTrace(new PrintWriter(sw));
152: String trace = sw.toString();
153: // XXX #6416590 Very suspicious potentionaly dangerous code.
154: // Why to hide the internals from stack, if they might be cause of the issue??
155: // // Chop off Creator internals
156: // while (true) {
157: // int insync = trace.indexOf("org.netbeans.modules.visualweb.insync"); // NOI18N
158: // if (insync != -1) {
159: // int cause = trace.indexOf("Caused"); // NOI18N
160: // if (cause == -1) {
161: // trace = trace.substring(0, insync-3);
162: // } else {
163: // trace = trace.substring(0, insync-3) + "\n" + trace.substring(cause);
164: // }
165: // } else {
166: // break;
167: // }
168: // }
169: exceptions.setText(trace);
170: String instanceName = bean.getInstanceName();
171: textArea.setText(NbBundle.getMessage(
172: RenderErrorPanelImpl.class, "CompErrorDescription",
173: instanceName, e.toString()));
174:
175: continueButton.setVisible(true);
176: jScrollPane1.setVisible(true);
177: }
178: }
179:
180: public void actionPerformed(ActionEvent e) {
181: // // Continue from the error panel to the designview
182: // webform.getTopComponent().showErrors(webform.getModel().isBusted());
183: // // 6274302: See if the user has cleared the error
184: //// webform.refresh(true);
185: // webform.refreshModel(true);
186: // errorPanelCallback.handleRefresh(jsfForm.getFacesModel().isBusted());
187: errorPanelCallback.handleRefresh(jsfForm.isModelBusted());
188: }
189:
190: /** This method is called from within the constructor to
191: * initialize the form.
192: * WARNING: Do NOT modify this code. The content of this method is
193: * always regenerated by the NetBeans Form Editor.
194: */
195: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
196: private void initComponents() {
197: java.awt.GridBagConstraints gridBagConstraints;
198:
199: jPanel2 = new javax.swing.JPanel();
200: jLabel3 = new javax.swing.JLabel();
201: textArea = new javax.swing.JTextArea();
202: continueButton = new javax.swing.JButton();
203: jPanel1 = new javax.swing.JPanel();
204: jScrollPane1 = new javax.swing.JScrollPane();
205: exceptions = new javax.swing.JTextArea();
206:
207: setBackground(javax.swing.UIManager.getDefaults().getColor(
208: "TextArea.background"));
209: setLayout(new java.awt.GridBagLayout());
210:
211: jPanel2.setBackground(java.awt.Color.red);
212:
213: jLabel3.setForeground(java.awt.Color.white);
214: jLabel3.setText(NbBundle.getMessage(RenderErrorPanelImpl.class,
215: "CompRenderError")); // NOI18N
216: jPanel2.add(jLabel3);
217:
218: gridBagConstraints = new java.awt.GridBagConstraints();
219: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
220: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
221: gridBagConstraints.weightx = 1.0;
222: add(jPanel2, gridBagConstraints);
223:
224: textArea.setLineWrap(true);
225: textArea.setWrapStyleWord(true);
226: gridBagConstraints = new java.awt.GridBagConstraints();
227: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
228: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
229: gridBagConstraints.weightx = 1.0;
230: gridBagConstraints.insets = new java.awt.Insets(12, 12, 11, 11);
231: add(textArea, gridBagConstraints);
232:
233: continueButton.setText(org.openide.util.NbBundle.getBundle(
234: RenderErrorPanelImpl.class).getString("Continue")); // NOI18N
235: gridBagConstraints = new java.awt.GridBagConstraints();
236: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
237: gridBagConstraints.insets = new java.awt.Insets(0, 12, 12, 11);
238: add(continueButton, gridBagConstraints);
239:
240: jPanel1.setBackground(java.awt.Color.white);
241: gridBagConstraints = new java.awt.GridBagConstraints();
242: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
243: gridBagConstraints.weighty = 1.0;
244: add(jPanel1, gridBagConstraints);
245:
246: jScrollPane1.setViewportView(exceptions);
247:
248: gridBagConstraints = new java.awt.GridBagConstraints();
249: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
250: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
251: gridBagConstraints.weightx = 1.0;
252: gridBagConstraints.weighty = 1.0;
253: gridBagConstraints.insets = new java.awt.Insets(0, 12, 11, 11);
254: add(jScrollPane1, gridBagConstraints);
255: }// </editor-fold>//GEN-END:initComponents
256:
257: // XXX
258: public interface RenderFailureProvider {
259: public Exception getRenderFailureException();
260:
261: public MarkupDesignBean getRenderFailureComponent();
262: } // End of RenderFailureProvider
263:
264: }
|