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: package org.netbeans.modules.jmx.configwizard;
042:
043: import java.awt.Component;
044: import java.util.ResourceBundle;
045: import javax.swing.event.*;
046:
047: import org.netbeans.spi.project.ui.templates.support.Templates;
048: import org.openide.loaders.TemplateWizard;
049: import org.openide.WizardDescriptor;
050: import org.openide.util.HelpCtx;
051: import org.openide.util.NbBundle;
052: import org.openide.awt.Mnemonics;
053:
054: import org.netbeans.modules.jmx.WizardConstants;
055: import org.netbeans.modules.jmx.GenericWizardPanel;
056: import org.netbeans.modules.jmx.WizardHelpers;
057: import java.awt.Container;
058: import java.io.File;
059: import javax.swing.JTextField;
060: import org.netbeans.api.project.Project;
061: import org.netbeans.api.project.ProjectUtils;
062:
063: /**
064: *
065: * Class handling the graphical part of the standard Agent wizard panel
066: *
067: */
068: public class ConfigPanel extends javax.swing.JPanel {
069: private ConfigWizardPanel wiz;
070: private ResourceBundle bundle;
071:
072: /**
073: * Create the wizard panel component and set up some basic properties.
074: * @param wiz <CODE>WizardDescriptor</CODE> the wizard
075: */
076: public ConfigPanel(ConfigWizardPanel wiz) {
077: this .wiz = wiz;
078: bundle = NbBundle.getBundle(ConfigPanel.class);
079: initComponents();
080:
081: Mnemonics.setLocalizedText(rmiAccessFileJLabel, bundle
082: .getString("LBL_RMI_Access_File"));//NOI18N
083: Mnemonics.setLocalizedText(rmiPasswordFileJLabel, bundle
084: .getString("LBL_RMI_Password_File"));//NOI18N
085:
086: Mnemonics.setLocalizedText(threadContentionJCheckBox, bundle
087: .getString("LBL_ThreadContention"));//NOI18N
088:
089: //Set tooltips
090: threadContentionJCheckBox.setToolTipText(bundle
091: .getString("TLTP_Thread_Contention"));//NOI18N
092:
093: // Provide a name in the title bar.
094: setName(bundle.getString("LBL_Config_Panel")); // NOI18N
095:
096: //Accessibility
097: threadContentionJCheckBox.getAccessibleContext()
098: .setAccessibleName(
099: bundle.getString("ACCESS_OTHER_CONTENTION")); // NOI18N
100: threadContentionJCheckBox
101: .getAccessibleContext()
102: .setAccessibleDescription(
103: bundle
104: .getString("ACCESS_OTHER_CONTENTION_DESCRIPTION"));// NOI18N
105:
106: rmiAccessFileJTextField.getAccessibleContext()
107: .setAccessibleName(
108: bundle.getString("ACCESS_RMI_ACCESS_FILE")); // NOI18N
109: rmiAccessFileJTextField
110: .getAccessibleContext()
111: .setAccessibleDescription(
112: bundle
113: .getString("ACCESS_RMI_ACCESS_FILE_DESCRIPTION"));// NOI18N
114:
115: rmiPasswordFileJTextField.getAccessibleContext()
116: .setAccessibleName(
117: bundle.getString("ACCESS_RMI_PASSWORD_FILE"));// NOI18N
118: rmiPasswordFileJTextField
119: .getAccessibleContext()
120: .setAccessibleDescription(
121: bundle
122: .getString("ACCESS_RMI_PASSWORD_FILE_DESCRIPTION"));// NOI18N
123:
124: getAccessibleContext().setAccessibleDescription(
125: bundle.getString("ACCESS_PANEL"));// NOI18N
126: }
127:
128: /** This method is called from within the constructor to
129: * initialize the form.
130: * WARNING: Do NOT modify this code. The content of this method is
131: * always regenerated by the Form Editor.
132: */
133: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
134: private void initComponents() {
135: java.awt.GridBagConstraints gridBagConstraints;
136:
137: northPanel = new javax.swing.JPanel();
138: northWestCenterPanel = new javax.swing.JPanel();
139: rmiAccessFileJLabel = new javax.swing.JLabel();
140: rmiPasswordFileJLabel = new javax.swing.JLabel();
141: rmiAccessFileJTextField = new javax.swing.JTextField();
142: rmiPasswordFileJTextField = new javax.swing.JTextField();
143: threadContentionJCheckBox = new javax.swing.JCheckBox();
144:
145: setLayout(new java.awt.BorderLayout());
146:
147: northPanel.setLayout(new java.awt.BorderLayout());
148:
149: northWestCenterPanel.setLayout(new java.awt.GridBagLayout());
150:
151: rmiAccessFileJLabel
152: .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
153: rmiAccessFileJLabel.setLabelFor(rmiAccessFileJTextField);
154: gridBagConstraints = new java.awt.GridBagConstraints();
155: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
156: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
157: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12);
158: northWestCenterPanel.add(rmiAccessFileJLabel,
159: gridBagConstraints);
160:
161: rmiPasswordFileJLabel
162: .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
163: rmiPasswordFileJLabel.setLabelFor(rmiPasswordFileJTextField);
164: rmiPasswordFileJLabel.setAlignmentX(0.5F);
165: gridBagConstraints = new java.awt.GridBagConstraints();
166: gridBagConstraints.gridx = 0;
167: gridBagConstraints.gridy = 1;
168: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
169: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
170: gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 12);
171: northWestCenterPanel.add(rmiPasswordFileJLabel,
172: gridBagConstraints);
173:
174: rmiAccessFileJTextField.setEditable(false);
175: rmiAccessFileJTextField.setName("rmiAccessFileJTextField");
176: gridBagConstraints = new java.awt.GridBagConstraints();
177: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
178: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
179: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
180: northWestCenterPanel.add(rmiAccessFileJTextField,
181: gridBagConstraints);
182:
183: rmiPasswordFileJTextField.setEditable(false);
184: rmiPasswordFileJTextField.setName("rmiPasswordFileJTextField");
185: gridBagConstraints = new java.awt.GridBagConstraints();
186: gridBagConstraints.gridx = 1;
187: gridBagConstraints.gridy = 1;
188: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
189: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
190: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
191: gridBagConstraints.weightx = 1.0;
192: gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
193: northWestCenterPanel.add(rmiPasswordFileJTextField,
194: gridBagConstraints);
195:
196: threadContentionJCheckBox.setText("jCheckBox1");
197: threadContentionJCheckBox.setBorder(javax.swing.BorderFactory
198: .createEmptyBorder(0, 0, 0, 0));
199: threadContentionJCheckBox.setMargin(new java.awt.Insets(0, 0,
200: 0, 0));
201: threadContentionJCheckBox.setName("threadContentionJCheckBox");
202: gridBagConstraints = new java.awt.GridBagConstraints();
203: gridBagConstraints.gridx = 0;
204: gridBagConstraints.gridy = 2;
205: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
206: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
207: gridBagConstraints.insets = new java.awt.Insets(13, 0, 0, 0);
208: northWestCenterPanel.add(threadContentionJCheckBox,
209: gridBagConstraints);
210:
211: northPanel.add(northWestCenterPanel,
212: java.awt.BorderLayout.CENTER);
213:
214: add(northPanel, java.awt.BorderLayout.NORTH);
215:
216: }// </editor-fold>//GEN-END:initComponents
217:
218: // Variables declaration - do not modify//GEN-BEGIN:variables
219: private javax.swing.JPanel northPanel;
220: private javax.swing.JPanel northWestCenterPanel;
221: private javax.swing.JLabel rmiAccessFileJLabel;
222: private javax.swing.JTextField rmiAccessFileJTextField;
223: private javax.swing.JLabel rmiPasswordFileJLabel;
224: private javax.swing.JTextField rmiPasswordFileJTextField;
225: private javax.swing.JCheckBox threadContentionJCheckBox;
226:
227: // End of variables declaration//GEN-END:variables
228:
229: /**
230: *
231: * Class handling the standard Agent wizard panel
232: *
233: */
234: public static class ConfigWizardPanel extends GenericWizardPanel
235: implements org.openide.WizardDescriptor.FinishablePanel {
236: private ConfigPanel panel = null;
237: private String projectLocation = null;
238: private TemplateWizard templateWiz = null;
239: private WizardDescriptor.Panel targetWiz = null;
240: private JTextField createdFileTextField = null;
241: private JTextField projectTextField = null;
242: private JTextField nameTextField = null;
243: private transient ResourceBundle bundle;
244:
245: public Component getComponent() {
246: return getPanel();
247: }
248:
249: /**
250: * Returns the project location path.
251: * @return <CODE>String</CODE> project location path
252: */
253: public String getProjectLocation() {
254: return projectLocation;
255: }
256:
257: private ConfigPanel getPanel() {
258: if (panel == null) {
259: panel = new ConfigPanel(this );
260: }
261: return panel;
262: }
263:
264: //implementation of the FinishablePanel Interface
265: //provides the Finish Button to be always enabled
266: public boolean isFinishPanel() {
267: return false;
268: }
269:
270: public boolean isValid() {
271: if (WizardHelpers
272: .fileExists(getPanel().rmiAccessFileJTextField
273: .getText())) {
274: setErrorMsg("The file "
275: + // NOI18N
276: WizardHelpers
277: .getFileName(getPanel().rmiAccessFileJTextField
278: .getText())
279: + " already exists.");// NOI18N
280: return false;
281: } else if (WizardHelpers
282: .fileExists(getPanel().rmiPasswordFileJTextField
283: .getText())) {
284: setErrorMsg("The file "
285: + // NOI18N
286: WizardHelpers
287: .getFileName(getPanel().rmiPasswordFileJTextField
288: .getText())
289: + " already exists.");// NOI18N
290: return false;
291: }
292: setErrorMsg("");// NOI18N
293: return true;
294: }
295:
296: /**
297: * Fire a change event (designed to be used from out of this class).
298: */
299: public void fireEvent() {
300: fireChangeEvent();
301: }
302:
303: private String getProjectDisplayedName() {
304: Project project = Templates.getProject(templateWiz);
305: return ProjectUtils.getInformation(project)
306: .getDisplayName();
307: }
308:
309: private void initTargetComponentDef(Component root) {
310: if (root.getClass().equals(JTextField.class)) {
311: JTextField rootTextField = (JTextField) root;
312: if (rootTextField.isEditable()) {
313: if (nameTextField == null) {
314: nameTextField = ((JTextField) root);
315: }
316: } else if (!rootTextField.getText().equals(
317: getProjectDisplayedName())) {
318: if (projectTextField != null) {
319: createdFileTextField = ((JTextField) root);
320: }
321: } else {
322: projectTextField = ((JTextField) root);
323: }
324: } else if ((root instanceof Container)
325: && (root != getComponent())) {
326: Component[] components = ((Container) root)
327: .getComponents();
328: for (int i = 0; i < components.length; i++) {
329: initTargetComponentDef(components[i]);
330: }
331: }
332: }
333:
334: /**
335: * Displays the given message in the wizard's message area.
336: *
337: * @param message message to be displayed, or <code>null</code>
338: * if the message area should be cleared
339: */
340: private void setErrorMsg(String message) {
341: if (templateWiz != null) {
342: templateWiz.putProperty(
343: WizardConstants.WIZARD_ERROR_MESSAGE, message);
344: }
345: }
346:
347: /**
348: * Add a changeListener on the targetWiz which each time that a change
349: * event happens, store and reload the optionsWiz.
350: * @param targetWiz <CODE>Panel</CODE>
351: * @param optionsWiz <CODE>Panel</CODE>
352: * @param wizard <CODE>WizardDescriptor</CODE> a wizard
353: */
354: public void setListenerEnabled(
355: final WizardDescriptor.Panel targetWiz,
356: final WizardDescriptor.Panel optionsWiz,
357: final TemplateWizard wizard) {
358: bundle = NbBundle.getBundle(JMXConfigWizardIterator.class);
359: templateWiz = wizard;
360: this .targetWiz = targetWiz;
361: initTargetComponentDef(targetWiz.getComponent());
362: targetWiz.addChangeListener(new ChangeListener() {
363: public void stateChanged(ChangeEvent evt) {
364: optionsWiz.storeSettings(wizard);
365: optionsWiz.readSettings(wizard);
366: }
367: });
368: }
369:
370: //=====================================================================
371: // Called to read information from the wizard map in order to populate
372: // the GUI correctly.
373: //=====================================================================
374: public void readSettings(Object settings) {
375: templateWiz = (TemplateWizard) settings;
376: String filePath = (String) templateWiz
377: .getProperty(WizardConstants.PROP_CONFIG_FILE_PATH);
378: String targetName = templateWiz.getTargetName();
379: String rmiAccessFileName = "";// NOI18N
380: String rmiPasswordFileName = "";// NOI18N
381: if ((targetName != null) && (filePath != null)) {
382: rmiAccessFileName = filePath + File.separator
383: + targetName + "." + WizardConstants.ACCESS_EXT;// NOI18N
384: rmiPasswordFileName = filePath + File.separator
385: + targetName + "."
386: + WizardConstants.PASSWORD_EXT;// NOI18N
387: }
388: getPanel().rmiAccessFileJTextField
389: .setText(rmiAccessFileName);
390: getPanel().rmiPasswordFileJTextField
391: .setText(rmiPasswordFileName);
392: Boolean threadContention = (Boolean) templateWiz
393: .getProperty(WizardConstants.THREAD_CONTENTION_MONITOR);
394: if (threadContention != null)
395: getPanel().threadContentionJCheckBox
396: .setSelected(threadContention);
397: }
398:
399: public void storeSettings(Object settings) {
400: templateWiz = (TemplateWizard) settings;
401: if (createdFileTextField != null) {
402: String filePath = WizardHelpers
403: .getFolderPath(createdFileTextField.getText());
404: templateWiz
405: .putProperty(
406: WizardConstants.PROP_CONFIG_FILE_PATH,
407: filePath);
408: }
409: if (nameTextField != null) {
410: Templates.setTargetName(templateWiz, nameTextField
411: .getText());
412: }
413: Boolean threadContention = getPanel().threadContentionJCheckBox
414: .isSelected();
415: templateWiz.putProperty(
416: WizardConstants.THREAD_CONTENTION_MONITOR,
417: threadContention);
418: }
419:
420: public HelpCtx getHelp() {
421: return new HelpCtx("mgt_properties"); // NOI18N
422: }
423:
424: }
425:
426: }
|