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 2004-2005 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:
042: package org.netbeans.modules.jmx.actions.dialog;
043:
044: import java.awt.event.ActionListener;
045: import java.text.MessageFormat;
046: import java.util.ResourceBundle;
047: import javax.swing.JButton;
048: import org.netbeans.modules.jmx.MBeanAttribute;
049: import org.netbeans.modules.jmx.actions.AddAttrAction;
050: import org.openide.DialogDescriptor;
051: import org.openide.DialogDisplayer;
052: import org.openide.util.HelpCtx;
053: import org.openide.util.NbBundle;
054:
055: /**
056: * Class responsible for the warning message shown when you use Add Attributes...
057: * popup action in the contextual management menu and there is already an
058: * existing implementation of a specified attribute.
059: * @author tl156378
060: */
061: public class AddAttributesInfoPanel extends javax.swing.JPanel {
062:
063: private ResourceBundle bundle;
064: private String title;
065: private JButton btnOK;
066:
067: /**
068: * Creates new form Panel.
069: */
070: public AddAttributesInfoPanel(String itfName,
071: String mbeanClassName, MBeanAttribute[] attributes) {
072: bundle = NbBundle.getBundle(AddAttributesInfoPanel.class);
073:
074: // init tags
075:
076: initComponents();
077:
078: //init labels
079: StringBuffer methodsList = new StringBuffer();
080: for (int i = 0; i < attributes.length; i++) {
081: if (attributes[i].getIsMethodExits())
082: methodsList.append(" - is" + attributes[i].getName()
083: + "\n"); // NOI18N
084: else if (attributes[i].getGetMethodExits())
085: methodsList.append(" - get" + attributes[i].getName()
086: + "\n"); // NOI18N
087:
088: if (attributes[i].getSetMethodExits()
089: && attributes[i].isWritable())
090: methodsList.append(" - set" + attributes[i].getName()
091: + "\n"); // NOI18N
092: }
093:
094: MessageFormat formAttribute = new MessageFormat(bundle
095: .getString("LBL_AttrMethodsAlreadyExist")); // NOI18N
096: Object[] args = { mbeanClassName, mbeanClassName,
097: mbeanClassName, methodsList.toString() };
098: String msg = formAttribute.format(args);
099:
100: formAttribute = new MessageFormat(bundle
101: .getString("LBL_AddAttributesAction.Title")); // NOI18N
102: Object[] args2 = { itfName };
103: title = formAttribute.format(args2);
104:
105: infoTextArea.setText(msg);
106: getAccessibleContext().setAccessibleDescription(
107: bundle.getString("ACCESS_PANEL"));// NOI18N
108: }
109:
110: public boolean isAcceptable() {
111: return true;
112: }
113:
114: /**
115: * Displays a configuration dialog and updates Register MBean options
116: * according to the user's settings.
117: * @return <CODE>boolean</CODE> true only if user clicks on Ok button.
118: */
119: public boolean configure() {
120:
121: // create and display the dialog
122:
123: btnOK = new JButton(bundle.getString("LBL_OK")); // NOI18N
124: btnOK.setEnabled(isAcceptable());
125: btnOK.getAccessibleContext().setAccessibleDescription(
126: bundle.getString("ACCESS_OK_DESCRIPTION")); // NOI18N
127:
128: Object returned = DialogDisplayer.getDefault().notify(
129: new DialogDescriptor(this ,
130: title,
131: true, //modal
132: new Object[] { btnOK,
133: DialogDescriptor.CANCEL_OPTION },
134: btnOK, //initial value
135: DialogDescriptor.DEFAULT_ALIGN, new HelpCtx(
136: AddAttrAction.class),
137: (ActionListener) null));
138:
139: if (returned == btnOK) {
140: return true;
141: }
142: return false;
143: }
144:
145: /** This method is called from within the constructor to
146: * initialize the form.
147: * WARNING: Do NOT modify this code. The content of this method is
148: * always regenerated by the Form Editor.
149: */
150: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
151: private void initComponents() {
152: java.awt.GridBagConstraints gridBagConstraints;
153:
154: infoTextArea = new javax.swing.JTextArea();
155:
156: setLayout(new java.awt.GridBagLayout());
157:
158: infoTextArea.setBackground(javax.swing.UIManager.getDefaults()
159: .getColor("Panel.background"));
160: infoTextArea.setEditable(false);
161: infoTextArea.setFont(new java.awt.Font("Arial", 0, 12));
162: infoTextArea.setBorder(null);
163: infoTextArea.setFocusable(false);
164: infoTextArea.setName("infoTextArea");
165: infoTextArea.setSelectionColor(javax.swing.UIManager
166: .getDefaults().getColor("textText"));
167: gridBagConstraints = new java.awt.GridBagConstraints();
168: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
169: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
170: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
171: gridBagConstraints.weightx = 1.0;
172: gridBagConstraints.weighty = 1.0;
173: gridBagConstraints.insets = new java.awt.Insets(12, 12, 11, 12);
174: add(infoTextArea, gridBagConstraints);
175:
176: }
177:
178: // </editor-fold>//GEN-END:initComponents
179:
180: // Variables declaration - do not modify//GEN-BEGIN:variables
181: private javax.swing.JTextArea infoTextArea;
182: // End of variables declaration//GEN-END:variables
183:
184: }
|