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 java.text.MessageFormat;
046: import javax.swing.JPanel;
047: import javax.swing.SwingUtilities;
048: import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
049: import org.netbeans.modules.xml.xam.NamedReferenceable;
050: import org.openide.util.NbBundle;
051:
052: /**
053: * Subclass of CustomRefactoringPanel representing the
054: * Safe Delete refactoring UI
055: * @author Bharath Ravikumar
056: */
057: public class SafeDeletePanel extends JPanel implements
058: CustomRefactoringPanel {
059:
060: private final transient NamedReferenceable target;
061:
062: /**
063: * Creates new form RenamePanelName
064: * @param refactoring The SafeDelete refactoring used by this panel
065: * @param selectedElements A Collection of selected elements
066: */
067: public SafeDeletePanel(NamedReferenceable target) {
068: assert target != null : "Nameable target required.";
069: setName(NbBundle.getMessage(SafeDeletePanel.class,
070: "LBL_SafeDel")); // NOI18N
071: this .target = target;
072: initComponents();
073: }
074:
075: private boolean initialized = false;
076:
077: /**
078: * Initialization method. Creates appropriate labels in the panel.
079: */
080: public void initialize() {
081:
082: if (initialized)
083: return;
084: final String labelText;
085:
086: SwingUtilities.invokeLater(new Runnable() {
087: public void run() {
088: // System.out.println("INIT CALLED");
089: label.setText(MessageFormat.format(NbBundle.getMessage(
090: SafeDeletePanel.class, "LBL_Delete_BOLD"),
091: new Object[] { target.getName() }));
092: validate();
093: }
094: });
095: initialized = true;
096: }
097:
098: public void requestFocus() {
099: super .requestFocus();
100: }
101:
102: /** This method is called from within the constructor to
103: * initialize the form.
104: * WARNING: Do NOT modify this code. The content of this method is
105: * always regenerated by the Form Editor.
106: */
107: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
108: private void initComponents() {
109: buttonGroup = new javax.swing.ButtonGroup();
110: jPanel3 = new javax.swing.JPanel();
111: label = new javax.swing.JLabel();
112:
113: setLayout(new java.awt.BorderLayout());
114:
115: jPanel3.setLayout(new java.awt.BorderLayout());
116:
117: org.openide.awt.Mnemonics.setLocalizedText(label,
118: "Delete myGlobalComponent");
119: jPanel3.add(label, java.awt.BorderLayout.NORTH);
120:
121: add(jPanel3, java.awt.BorderLayout.NORTH);
122:
123: }// </editor-fold>//GEN-END:initComponents
124:
125: // Variables declaration - do not modify//GEN-BEGIN:variables
126: private javax.swing.ButtonGroup buttonGroup;
127: private javax.swing.JPanel jPanel3;
128: private javax.swing.JLabel label;
129:
130: // End of variables declaration//GEN-END:variables
131:
132: public Dimension getPreferredSize() {
133: Dimension orig = super .getPreferredSize();
134: return new Dimension(orig.width + 30, orig.height + 30);
135: }
136:
137: //--public utility methods--
138:
139: //This method has been made public so that another class might be able to reuse this.
140: //This should be moved to a common utility class.
141: /**
142: * Returns the formatted string corresponding to the declaration
143: * of a CallableFeature(a {@link org.netbeans.jmi.javamodel.Method}
144: * or a {@link org.netbeans.jmi.javamodel.Constructor})
145: * Copied from {@link org.netbeans.modules.refactoring.ui.WhereUsedPanel}
146: */
147: // public String getHeader(CallableFeature call) {
148: // if (((CallableFeatureImpl) call).getParser() == null) {
149: // if (call instanceof Method) {
150: // return ((Method) call).getName();
151: // } else if (call instanceof Constructor) {
152: // return getSimpleName(call.getDeclaringClass());
153: // }
154: // return "";
155: // }
156: // int s = ((MetadataElement) call).getPartStartOffset(ElementPartKindEnum.HEADER);
157: // int element = ((MetadataElement) call).getPartEndOffset(ElementPartKindEnum.HEADER);
158: // String result = call.getResource().getSourceText().substring(s,element);
159: // if (result.length() > 50) {
160: // result = result.substring(0,49) + "..."; // NOI18N
161: // }
162: // return CheckUtils.htmlize(result);
163: // }
164:
165: public Component getComponent() {
166: return this;
167: }
168:
169: }
|