KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > refactoring > ui > j > ui > ProblemComponent


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.refactoring.ui.j.ui;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.Container JavaDoc;
24 import java.awt.Dimension JavaDoc;
25 import java.awt.event.ActionEvent JavaDoc;
26 import java.text.MessageFormat JavaDoc;
27 import javax.swing.AbstractAction JavaDoc;
28 import javax.swing.JButton JavaDoc;
29 import org.netbeans.modules.xml.refactoring.DeleteRequest;
30 import org.netbeans.modules.xml.refactoring.ErrorItem;
31 import org.netbeans.modules.xml.refactoring.ErrorItem.Level;
32 import org.netbeans.modules.xml.refactoring.UsageSet;
33 import org.netbeans.modules.xml.refactoring.ui.j.api.Problem;
34 import org.netbeans.modules.xml.refactoring.ui.j.api.ProblemDetails;
35 import org.netbeans.modules.xml.refactoring.ui.j.spi.ui.ParametersPanel;
36 import org.netbeans.modules.xml.refactoring.ui.j.spi.ui.RefactoringUI;
37 import org.netbeans.modules.xml.refactoring.ui.j.spi.ui.WhereUsedQueryUI;
38 import org.netbeans.modules.xml.refactoring.ui.views.WhereUsedView;
39 import org.netbeans.modules.xml.xam.Referenceable;
40 import org.openide.util.Cancellable;
41 import org.openide.util.NbBundle;
42
43 /**
44  *
45  * @author Jan Becicka
46  */

47 public class ProblemComponent extends javax.swing.JPanel JavaDoc {
48     
49     private static Color JavaDoc bgColor = new Color JavaDoc(240, 240, 240);
50     private ErrorItem errorItem;
51     private RefactoringUI ui;
52     private static double buttonWidth;
53 // private boolean showFindUsagesButton;
54

55     /**
56      * Creates new form ProblemComponent
57      */

58     public ProblemComponent(ErrorItem errorItem, RefactoringUI ui) {
59         initComponents();
60         this.ui = ui;
61         icon.setIcon(errorItem.getLevel()==Level.FATAL?ErrorPanel.getFatalErrorIcon():ErrorPanel.getNonfatalErrorIcon());
62         problemDescription.setText(errorItem.getMessage());
63         this.errorItem = errorItem;
64         
65         //TODO straighten out usability issue of Safe Delete whether to allow
66
// cascade delete where possible
67
if (ui.getRefactorRequest() instanceof DeleteRequest) {
68             DeleteRequest request = (DeleteRequest) ui.getRefactorRequest();
69             UsageSet usageSet = request.getUsages();
70             if (usageSet != null && ! usageSet.isEmpty()) {
71                 setLightBackground();
72                 String JavaDoc showUsagesButtonHint = NbBundle.getMessage(ProblemComponent.class, "LBL_ShowUsages"); //NOI18N
73
buttonWidth = Math.max(new JButton JavaDoc(showUsagesButtonHint).getMinimumSize().getWidth(), buttonWidth);
74                 org.openide.awt.Mnemonics.setLocalizedText(showUsages, showUsagesButtonHint);
75                 showUsages.setPreferredSize(new Dimension JavaDoc((int) buttonWidth, (int) showUsages.getMinimumSize().getHeight()));
76             } else {
77                 showUsages.setVisible(false);
78             }
79         } else {
80             showUsages.setVisible(false);
81         }
82         validate();
83     }
84     
85     static void initButtonSize(Problem problem) {
86         buttonWidth = -1.0;
87         while (problem != null) {
88             ProblemDetails pdi = problem.getDetails();
89             if (pdi != null) {
90                 buttonWidth = Math.max(new JButton JavaDoc(pdi.getDetailsHint()).getMinimumSize().getWidth(), buttonWidth);
91             }
92             problem = problem.getNext();
93         }
94         
95     }
96     
97     public void setLightBackground() {
98         setBackground(Color.WHITE);
99         problemDescription.setBackground(Color.WHITE);
100         icon.setBackground(Color.WHITE);
101         showUsages.setBackground(Color.WHITE);
102     }
103     
104     public void setDarkBackground() {
105         Color JavaDoc bgColor = new Color JavaDoc(240, 240, 240);
106         setBackground(bgColor);
107         problemDescription.setBackground(bgColor);
108         icon.setBackground(bgColor);
109         showUsages.setBackground(bgColor);
110     }
111     
112     /** This method is called from within the constructor to
113      * initialize the form.
114      * WARNING: Do NOT modify this code. The content of this method is
115      * always regenerated by the Form Editor.
116      */

117     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
118
private void initComponents() {
119         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
120
121         icon = new javax.swing.JLabel JavaDoc();
122         problemDescription = new javax.swing.JTextArea JavaDoc();
123         showUsages = new javax.swing.JButton JavaDoc();
124
125         setLayout(new java.awt.GridBagLayout JavaDoc());
126
127         setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));
128         icon.setBackground(javax.swing.UIManager.getDefaults().getColor("TextArea.background"));
129         icon.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 6, 1, 6));
130         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
131         gridBagConstraints.gridx = 0;
132         gridBagConstraints.gridy = 0;
133         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
134         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
135         add(icon, gridBagConstraints);
136
137         problemDescription.setEditable(false);
138         problemDescription.setLineWrap(true);
139         problemDescription.setWrapStyleWord(true);
140         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
141         gridBagConstraints.gridx = 1;
142         gridBagConstraints.gridy = 0;
143         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
144         gridBagConstraints.weightx = 1.0;
145         add(problemDescription, gridBagConstraints);
146         problemDescription.getAccessibleContext().setAccessibleName(null);
147         problemDescription.getAccessibleContext().setAccessibleDescription(null);
148
149         showUsages.addActionListener(new java.awt.event.ActionListener JavaDoc() {
150             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
151                 showUsagesActionPerformed(evt);
152             }
153         });
154
155         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
156         gridBagConstraints.gridx = 2;
157         gridBagConstraints.gridy = 0;
158         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
159         add(showUsages, gridBagConstraints);
160         showUsages.getAccessibleContext().setAccessibleName(showUsages.getText());
161         showUsages.getAccessibleContext().setAccessibleDescription(showUsages.getText());
162
163     }// </editor-fold>//GEN-END:initComponents
164

165     private void showUsagesActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_showUsagesActionPerformed
166
Container JavaDoc c = this;
167          while (!(c instanceof ParametersPanel)) {
168              c = c.getParent();
169          }
170          final ParametersPanel parametersPanel = (ParametersPanel) c;
171          Cancellable doCloseParent = new Cancellable() {
172              public boolean cancel() {
173                  parametersPanel.cancel.doClick();
174                  return true;
175              }
176          };
177          
178         // showUsages
179
Referenceable ref = ui.getRefactorRequest().getTarget();
180         WhereUsedView wuv = new WhereUsedView(ref);
181         WhereUsedQueryUI queryUI = new WhereUsedQueryUI(wuv, ref);
182         doCloseParent.cancel();
183         //new RefactoringPanel(queryUI, new CallbackAction(ui)).setVisible(true);
184
}//GEN-LAST:event_showUsagesActionPerformed
185

186     
187     // Variables declaration - do not modify//GEN-BEGIN:variables
188
private javax.swing.JLabel JavaDoc icon;
189     private javax.swing.JTextArea JavaDoc problemDescription;
190     private javax.swing.JButton JavaDoc showUsages;
191     // End of variables declaration//GEN-END:variables
192

193     private class CallbackAction extends AbstractAction JavaDoc {
194         RefactoringUI ui;
195         
196         public CallbackAction(RefactoringUI ui) {
197             super(MessageFormat.format(NbBundle.getMessage(ProblemComponent.class, "LBL_Rerun"), new Object JavaDoc[]{ui.getName()}));
198             this.ui = ui;
199         }
200         
201         public void actionPerformed(ActionEvent JavaDoc event) {
202             ui.getRefactorRequest().setUsages(null);
203             new RefactoringPanel(ui).setVisible(true);
204         }
205     }
206 }
207
Popular Tags