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-2006 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.xml.refactoring.ui;
042:
043: import java.awt.Component;
044: import java.awt.Dimension;
045: import javax.swing.JPanel;
046: import javax.swing.event.ChangeListener;
047: import org.netbeans.modules.xml.xam.Referenceable;
048: import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
049:
050: /**
051: * @author Jan Becicka
052: */
053: public class WhereUsedPanel extends JPanel implements
054: CustomRefactoringPanel {
055: public static final long serialVersionUID = 1L;
056:
057: // private final transient RefObject element;
058: //private final transient ParametersPanel parent;
059: private final transient ChangeListener parent;
060: private transient Referenceable ref;
061:
062: /** Creates new form RenamePanelName */
063: // public WhereUsedPanel(String name, RefObject e, ParametersPanel parent) {
064: // setName(NbBundle.getMessage(WhereUsedPanel.class,"LBL_WhereUsed")); // NOI18N
065: // this.element = e;
066: // this.parent = parent;
067: // initComponents();
068: // parent.setPreviewEnabled(false);
069: // }
070: public WhereUsedPanel(Referenceable ref, ChangeListener parent) {
071: this .parent = parent;
072: this .ref = ref;
073: }
074:
075: private boolean initialized = false;
076: private String methodDeclaringSuperClass = null;
077: private String methodDeclaringClass = null;
078:
079: String getMethodDeclaringClass() {
080: return isMethodFromBaseClass() ? methodDeclaringSuperClass
081: : methodDeclaringClass;
082: }
083:
084: public void initialize() {
085: // String m_isBaseClassText = null;
086: // if (initialized) return;
087: // final String labelText;
088: // int modif = 0;
089: //
090: // JavaModel.getJavaRepository().beginTrans(true);
091: // try {
092: // if (element instanceof Method) {
093: // Method method = (Method) element;
094: // JavaModel.setClassPath(method.getResource());
095: // modif = method.getModifiers();
096: // labelText = NbBundle.getMessage(WhereUsedPanel.class, "DSC_MethodUsages", getHeader(method), getSimpleName(method.getDeclaringClass())); // NOI18N
097: //
098: // methodDeclaringClass = getSimpleName(method.getDeclaringClass());
099: // Collection overridens = JavaModelUtil.getOverriddenMethods(method);
100: // if (!overridens.isEmpty()) {
101: // m_isBaseClassText =
102: // new MessageFormat(NbBundle.getMessage(WhereUsedPanel.class, "LBL_UsagesOfBaseClass")).format(
103: // new Object[] {
104: // methodDeclaringSuperClass = getSimpleName(((Method) overridens.iterator().next()).getDeclaringClass())
105: // }
106: // );
107: // }
108: // } else if (element instanceof JavaClass) {
109: // labelText = NbBundle.getMessage(WhereUsedPanel.class, "DSC_ClassUsages", ((JavaClass) element).getSimpleName()); // NOI18N
110: // } else if (element instanceof Constructor) {
111: // labelText = NbBundle.getMessage(WhereUsedPanel.class, "DSC_ConstructorUsages", getHeader((CallableFeature)element), getSimpleName(((Constructor) element).getDeclaringClass())); // NOI18N
112: // } else if (element instanceof Field) {
113: // labelText = NbBundle.getMessage(WhereUsedPanel.class, "DSC_FieldUsages", ((NamedElement) element).getName(), getSimpleName(((Field) element).getDeclaringClass())); // NOI18N
114: // } else if (element instanceof JavaPackage) {
115: // labelText = NbBundle.getMessage(WhereUsedPanel.class, "DSC_PackageUsages", ((NamedElement) element).getName()); // NOI18N
116: // } else if (element instanceof NamedElement) {
117: // labelText = NbBundle.getMessage(WhereUsedPanel.class, "DSC_VariableUsages", ((NamedElement) element).getName()); // NOI18N
118: // } else {
119: // labelText = null;
120: // }
121: // } finally {
122: // JavaModel.getJavaRepository().endTrans();
123: // }
124: //
125: // final int modifiers = modif;
126: // final String isBaseClassText = m_isBaseClassText;
127: //
128: // SwingUtilities.invokeLater(new Runnable() {
129: // public void run() {
130: // remove(classesPanel);
131: // remove(methodsPanel);
132: // label.setText(labelText);
133: // if (element instanceof Method) {
134: // add(methodsPanel, BorderLayout.CENTER);
135: // methodsPanel.setVisible(true);
136: // m_usages.setVisible(!Modifier.isStatic(modifiers));
137: // m_overriders.setVisible(! (Modifier.isFinal(modifiers) || Modifier.isStatic(modifiers) || Modifier.isPrivate(modifiers)));
138: // if (methodDeclaringSuperClass != null ) {
139: // m_isBaseClass.setVisible(true);
140: // m_isBaseClass.setSelected(true);
141: // Mnemonics.setLocalizedText(m_isBaseClass, isBaseClassText);
142: // } else {
143: // m_isBaseClass.setVisible(false);
144: // m_isBaseClass.setSelected(false);
145: // }
146: // } else if (element instanceof JavaClass) {
147: // add(classesPanel, BorderLayout.CENTER);
148: // classesPanel.setVisible(true);
149: // } else {
150: // remove(classesPanel);
151: // remove(methodsPanel);
152: // c_subclasses.setVisible(false);
153: // m_usages.setVisible(false);
154: // c_usages.setVisible(false);
155: // c_directOnly.setVisible(false);
156: // }
157: // validate();
158: // }
159: // });
160: // initialized = true;
161: }
162:
163: // private String getSimpleName(ClassDefinition clazz) {
164: // if (clazz instanceof JavaClass) {
165: // return ((JavaClass) clazz).getSimpleName();
166: // } else {
167: // return NbBundle.getMessage(WhereUsedPanel.class, "LBL_AnonymousClass"); // NOI18N
168: // }
169: // }
170: //
171: // private String getHeader(CallableFeature call) {
172: // if (((CallableFeatureImpl) call).getParser() == null) {
173: // if (call instanceof Method) {
174: // return ((Method) call).getName();
175: // } else if (call instanceof Constructor) {
176: // return getSimpleName(call.getDeclaringClass());
177: // }
178: // return "";
179: // }
180: // int s = ((MetadataElement) call).getPartStartOffset(ElementPartKindEnum.HEADER);
181: // int element = ((MetadataElement) call).getPartEndOffset(ElementPartKindEnum.HEADER);
182: // String result = call.getResource().getSourceText().substring(s,element);
183: // if (result.length() > 50) {
184: // result = result.substring(0,49) + "..."; // NOI18N
185: // }
186: // return CheckUtils.htmlize(result);
187: // }
188: //
189: // public void requestFocus() {
190: // super.requestFocus();
191: // }
192:
193: /** This method is called from within the constructor to
194: * initialize the form.
195: * WARNING: Do NOT modify this code. The content of this method is
196: * always regenerated by the Form Editor.
197: */
198: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
199: private void initComponents() {
200: java.awt.GridBagConstraints gridBagConstraints;
201:
202: buttonGroup = new javax.swing.ButtonGroup();
203: methodsPanel = new javax.swing.JPanel();
204: m_isBaseClass = new javax.swing.JCheckBox();
205: jPanel1 = new javax.swing.JPanel();
206: m_overriders = new javax.swing.JCheckBox();
207: m_usages = new javax.swing.JCheckBox();
208: classesPanel = new javax.swing.JPanel();
209: jPanel2 = new javax.swing.JPanel();
210: c_subclasses = new javax.swing.JRadioButton();
211: c_usages = new javax.swing.JRadioButton();
212: c_directOnly = new javax.swing.JRadioButton();
213: jPanel3 = new javax.swing.JPanel();
214: label = new javax.swing.JLabel();
215: searchInComments = new javax.swing.JCheckBox();
216:
217: setLayout(new java.awt.BorderLayout());
218:
219: methodsPanel.setLayout(new java.awt.GridBagLayout());
220:
221: m_isBaseClass.setSelected(true);
222: m_isBaseClass
223: .addActionListener(new java.awt.event.ActionListener() {
224: public void actionPerformed(
225: java.awt.event.ActionEvent evt) {
226: m_isBaseClassActionPerformed(evt);
227: }
228: });
229:
230: gridBagConstraints = new java.awt.GridBagConstraints();
231: gridBagConstraints.gridx = 0;
232: gridBagConstraints.gridy = 3;
233: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
234: gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0);
235: methodsPanel.add(m_isBaseClass, gridBagConstraints);
236: m_isBaseClass.getAccessibleContext().setAccessibleDescription(
237: null);
238:
239: gridBagConstraints = new java.awt.GridBagConstraints();
240: gridBagConstraints.gridx = 0;
241: gridBagConstraints.gridy = 4;
242: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
243: gridBagConstraints.weightx = 1.0;
244: gridBagConstraints.weighty = 1.0;
245: methodsPanel.add(jPanel1, gridBagConstraints);
246:
247: m_overriders
248: .addActionListener(new java.awt.event.ActionListener() {
249: public void actionPerformed(
250: java.awt.event.ActionEvent evt) {
251: m_overridersActionPerformed(evt);
252: }
253: });
254:
255: gridBagConstraints = new java.awt.GridBagConstraints();
256: gridBagConstraints.gridx = 0;
257: gridBagConstraints.gridy = 2;
258: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
259: gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0);
260: methodsPanel.add(m_overriders, gridBagConstraints);
261: m_overriders.getAccessibleContext().setAccessibleDescription(
262: null);
263:
264: m_usages.setSelected(true);
265: m_usages.setMargin(new java.awt.Insets(10, 2, 2, 2));
266: m_usages.addActionListener(new java.awt.event.ActionListener() {
267: public void actionPerformed(java.awt.event.ActionEvent evt) {
268: m_usagesActionPerformed(evt);
269: }
270: });
271:
272: gridBagConstraints = new java.awt.GridBagConstraints();
273: gridBagConstraints.gridx = 0;
274: gridBagConstraints.gridy = 1;
275: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
276: gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0);
277: methodsPanel.add(m_usages, gridBagConstraints);
278: m_usages.getAccessibleContext().setAccessibleDescription(null);
279:
280: add(methodsPanel, java.awt.BorderLayout.CENTER);
281:
282: classesPanel.setLayout(new java.awt.GridBagLayout());
283:
284: gridBagConstraints = new java.awt.GridBagConstraints();
285: gridBagConstraints.gridx = 0;
286: gridBagConstraints.gridy = 4;
287: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
288: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
289: gridBagConstraints.weightx = 1.0;
290: gridBagConstraints.weighty = 1.0;
291: classesPanel.add(jPanel2, gridBagConstraints);
292:
293: buttonGroup.add(c_subclasses);
294: gridBagConstraints = new java.awt.GridBagConstraints();
295: gridBagConstraints.gridx = 0;
296: gridBagConstraints.gridy = 2;
297: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
298: gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0);
299: classesPanel.add(c_subclasses, gridBagConstraints);
300: c_subclasses.getAccessibleContext().setAccessibleDescription(
301: null);
302:
303: buttonGroup.add(c_usages);
304: c_usages.setSelected(true);
305: c_usages.setMargin(new java.awt.Insets(4, 2, 2, 2));
306: gridBagConstraints = new java.awt.GridBagConstraints();
307: gridBagConstraints.gridx = 0;
308: gridBagConstraints.gridy = 1;
309: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
310: gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0);
311: classesPanel.add(c_usages, gridBagConstraints);
312: c_usages.getAccessibleContext().setAccessibleDescription(null);
313:
314: buttonGroup.add(c_directOnly);
315: gridBagConstraints = new java.awt.GridBagConstraints();
316: gridBagConstraints.gridx = 0;
317: gridBagConstraints.gridy = 3;
318: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
319: gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0);
320: classesPanel.add(c_directOnly, gridBagConstraints);
321: c_directOnly.getAccessibleContext().setAccessibleDescription(
322: null);
323:
324: add(classesPanel, java.awt.BorderLayout.CENTER);
325:
326: jPanel3.setLayout(new java.awt.BorderLayout());
327:
328: jPanel3.add(label, java.awt.BorderLayout.NORTH);
329:
330: searchInComments.setMargin(new java.awt.Insets(10, 14, 2, 2));
331: searchInComments
332: .addItemListener(new java.awt.event.ItemListener() {
333: public void itemStateChanged(
334: java.awt.event.ItemEvent evt) {
335: searchInCommentsItemStateChanged(evt);
336: }
337: });
338:
339: jPanel3.add(searchInComments, java.awt.BorderLayout.SOUTH);
340: searchInComments.getAccessibleContext()
341: .setAccessibleDescription(searchInComments.getText());
342:
343: add(jPanel3, java.awt.BorderLayout.NORTH);
344:
345: }// </editor-fold>//GEN-END:initComponents
346:
347: private void searchInCommentsItemStateChanged(
348: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_searchInCommentsItemStateChanged
349: // used for change default value for searchInComments check-box.
350: // The value is persisted and then used as default in next IDE run.
351: // Boolean b = evt.getStateChange() == ItemEvent.SELECTED ? Boolean.TRUE : Boolean.FALSE;
352: // RefactoringModule.setOption("searchInComments.whereUsed", b);
353: }//GEN-LAST:event_searchInCommentsItemStateChanged
354:
355: private void m_isBaseClassActionPerformed(
356: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_isBaseClassActionPerformed
357: parent.stateChanged(null);
358: }//GEN-LAST:event_m_isBaseClassActionPerformed
359:
360: private void m_overridersActionPerformed(
361: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_overridersActionPerformed
362: parent.stateChanged(null);
363: }//GEN-LAST:event_m_overridersActionPerformed
364:
365: private void m_usagesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_usagesActionPerformed
366: parent.stateChanged(null);
367: }//GEN-LAST:event_m_usagesActionPerformed
368:
369: // Variables declaration - do not modify//GEN-BEGIN:variables
370: private javax.swing.ButtonGroup buttonGroup;
371: private javax.swing.JRadioButton c_directOnly;
372: private javax.swing.JRadioButton c_subclasses;
373: private javax.swing.JRadioButton c_usages;
374: private javax.swing.JPanel classesPanel;
375: private javax.swing.JPanel jPanel1;
376: private javax.swing.JPanel jPanel2;
377: private javax.swing.JPanel jPanel3;
378: private javax.swing.JLabel label;
379: private javax.swing.JCheckBox m_isBaseClass;
380: private javax.swing.JCheckBox m_overriders;
381: private javax.swing.JCheckBox m_usages;
382: private javax.swing.JPanel methodsPanel;
383: private javax.swing.JCheckBox searchInComments;
384:
385: // End of variables declaration//GEN-END:variables
386:
387: public boolean isMethodFromBaseClass() {
388: return m_isBaseClass.isSelected();
389: }
390:
391: public boolean isMethodOverriders() {
392: return m_overriders.isSelected();
393: }
394:
395: public boolean isClassSubTypes() {
396: return c_subclasses.isSelected();
397: }
398:
399: public boolean isClassSubTypesDirectOnly() {
400: return c_directOnly.isSelected();
401: }
402:
403: public boolean isMethodFindUsages() {
404: return m_usages.isSelected();
405: }
406:
407: public boolean isClassFindUsages() {
408: return c_usages.isSelected();
409: }
410:
411: public Dimension getPreferredSize() {
412: Dimension orig = super .getPreferredSize();
413: return new Dimension(orig.width + 30, orig.height + 30);
414: }
415:
416: public boolean isSearchInComments() {
417: return searchInComments.isSelected();
418: }
419:
420: public Component getComponent() {
421: return this;
422: }
423:
424: }
|