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.mbeanwizard.popup;
043:
044: import org.netbeans.modules.jmx.mbeanwizard.tablemodel.MBeanOperationTableModel;
045: import org.netbeans.modules.jmx.mbeanwizard.tablemodel.OperationParameterTableModel;
046: import org.netbeans.modules.jmx.mbeanwizard.listener.AddTableRowListener;
047: import org.netbeans.modules.jmx.mbeanwizard.listener.RemTableRowListener;
048: import java.awt.BorderLayout;
049:
050: import javax.swing.JButton;
051: import javax.swing.JTextField;
052:
053: import org.openide.util.NbBundle;
054: import org.netbeans.modules.jmx.mbeanwizard.table.OperationParameterPopupTable;
055: import java.awt.event.ActionEvent;
056: import java.awt.event.ActionListener;
057: import java.util.ArrayList;
058: import java.util.List;
059: import javax.swing.JPanel;
060: import javax.swing.event.ChangeEvent;
061: import org.netbeans.modules.jmx.FireEvent;
062: import org.netbeans.modules.jmx.MBeanOperationParameter;
063:
064: /**
065: * Class implementing the parameter popup window
066: *
067: */
068: public class OperationParameterPopup extends AbstractPopup {
069:
070: private FireEvent wiz = null;
071: private MBeanOperationTableModel methodModel = null;
072: private int editedRow = 0;
073:
074: /**
075: * Constructor
076: * @param ancestorPanel the parent panel of the popup; here the wizard
077: * @param textField the text field to fill with the popup information
078: * @param result the intermediate structure which storespopup information
079: * @param wiz the parent-window's wizard panel
080: */
081: public OperationParameterPopup(JPanel ancestorPanel,
082: MBeanOperationTableModel model, JTextField textField,
083: int editedRow, FireEvent wiz) {
084:
085: super ((java.awt.Dialog) ancestorPanel.getTopLevelAncestor());
086:
087: this .methodModel = model;
088: this .textFieldToFill = textField;
089: this .editedRow = editedRow;
090: this .wiz = wiz;
091:
092: setLayout(new BorderLayout());
093: initComponents();
094:
095: readSettings();
096:
097: //setDimensions(NbBundle.getMessage(OperationParameterPopup.class,"LBL_OperationParameter_Popup"));// NOI18N
098: setDimensions(bundle.getString("LBL_OperationParameter_Popup"));// NOI18N
099: }
100:
101: protected void initJTable() {
102:
103: popupTableModel = new OperationParameterTableModel();
104: popupTable = new OperationParameterPopupTable(popupTableModel);
105: popupTable.setName("ParamPopupTable");// NOI18N
106: }
107:
108: protected void initComponents() {
109: initJTable();
110: /*
111: addJButton = instanciatePopupButton(NbBundle.getMessage(OperationExceptionPopup.class,"LBL_OperationParameter_addParam"));// NOI18N
112: removeJButton = instanciatePopupButton(NbBundle.getMessage(OperationExceptionPopup.class,"LBL_OperationParameter_remParam"));// NOI18N
113: closeJButton = instanciatePopupButton(NbBundle.getMessage(OperationExceptionPopup.class,"LBL_OperationParameter_close"));// NOI18N
114:
115: //Accessibility
116: removeJButton.getAccessibleContext().setAccessibleName(NbBundle.getMessage(OperationParameterPopup.class,"ACCESS_REMOVE_PARAMETER"));// NOI18N
117: removeJButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(OperationParameterPopup.class,"ACCESS_REMOVE_PARAMETER_DESCRIPTION"));// NOI18N
118: addJButton.getAccessibleContext().setAccessibleName(NbBundle.getMessage(OperationParameterPopup.class,"ACCESS_ADD_PARAMETER"));// NOI18N
119: addJButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(OperationParameterPopup.class,"ACCESS_ADD_PARAMETER_DESCRIPTION"));// NOI18N
120: closeJButton.getAccessibleContext().setAccessibleName(NbBundle.getMessage(OperationParameterPopup.class,"ACCESS_CLOSE_PARAMETER"));// NOI18N
121: closeJButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(OperationParameterPopup.class,"ACCESS_CLOSE_PARAMETER_DESCRIPTION"));// NOI18N
122: popupTable.getAccessibleContext().setAccessibleName(NbBundle.getMessage(OperationParameterPopup.class,"ACCESS_PARAMETER_TABLE"));// NOI18N
123: popupTable.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(OperationParameterPopup.class,"ACCESS_PARAMETER_TABLE_DESCRIPTION"));// NOI18N
124: */
125:
126: addJButton = instanciatePopupButton(bundle
127: .getString("LBL_OperationParameter_addParam"));// NOI18N
128: removeJButton = instanciatePopupButton(bundle
129: .getString("LBL_OperationParameter_remParam"));// NOI18N
130: closeJButton = instanciatePopupButton(bundle
131: .getString("LBL_OperationParameter_close"));// NOI18N
132:
133: //Accessibility
134: removeJButton.getAccessibleContext().setAccessibleName(
135: bundle.getString("ACCESS_REMOVE_PARAMETER"));// NOI18N
136: removeJButton
137: .getAccessibleContext()
138: .setAccessibleDescription(
139: bundle
140: .getString("ACCESS_REMOVE_PARAMETER_DESCRIPTION"));// NOI18N
141: addJButton.getAccessibleContext().setAccessibleName(
142: bundle.getString("ACCESS_ADD_PARAMETER"));// NOI18N
143: addJButton.getAccessibleContext().setAccessibleDescription(
144: bundle.getString("ACCESS_ADD_PARAMETER_DESCRIPTION"));// NOI18N
145: closeJButton.getAccessibleContext().setAccessibleName(
146: bundle.getString("ACCESS_CLOSE_PARAMETER"));// NOI18N
147: closeJButton.getAccessibleContext().setAccessibleDescription(
148: bundle.getString("ACCESS_CLOSE_PARAMETER_DESCRIPTION"));// NOI18N
149: popupTable.getAccessibleContext().setAccessibleName(
150: bundle.getString("ACCESS_PARAMETER_TABLE"));// NOI18N
151: popupTable.getAccessibleContext().setAccessibleDescription(
152: bundle.getString("ACCESS_PARAMETER_TABLE_DESCRIPTION"));// NOI18N
153:
154: addJButton.setName("addParamJButton");// NOI18N
155: removeJButton.setName("remParamJButton");// NOI18N
156: closeJButton.setName("closeJButton");// NOI18N
157: //cancelJButton.setName("cancelJButton");// NOI18N
158:
159: //remove button should first be disabled
160: removeJButton.setEnabled(false);
161:
162: addJButton.addActionListener(new AddTableRowListener(
163: popupTable, popupTableModel, removeJButton));
164: removeJButton.addActionListener(new RemTableRowListener(
165: popupTable, popupTableModel, removeJButton));
166:
167: //TODO factorise the listeners; this is a copy paste of
168: //ClosePopupButtonListener a little modified
169: //closeJButton.addActionListener(
170: //new ClosePopupButtonListener(this,textFieldToFill));
171: final OperationParameterPopup opParamPopup = this ;
172: closeJButton.addActionListener(new ActionListener() {
173: public void actionPerformed(ActionEvent evt) {
174:
175: textFieldToFill.setText(opParamPopup.storeSettings());
176: opParamPopup.dispose();
177:
178: wiz.event();
179: }
180: });
181:
182: definePanels(getUsedButtons(), popupTable, bundle
183: .getString("LBL_OP_PARAMETERS_POPUP_TABLE")); // NOI18N
184: }
185:
186: protected JButton[] getUsedButtons() {
187: return new JButton[] { addJButton, removeJButton, closeJButton };
188: }
189:
190: protected void readSettings() {
191: if (methodModel.size() != 0) {
192: //gets the current parameter list from the current operation
193: List<MBeanOperationParameter> opParam = methodModel
194: .getOperation(editedRow).getParametersList();
195:
196: for (int i = 0; i < opParam.size(); i++) {
197: popupTableModel.addRow();
198: //copy the current parameter from the panel model to the popup
199: //model
200: ((OperationParameterTableModel) popupTableModel)
201: .setParameter(i, opParam.get(i));
202: }
203: removeJButton.setEnabled(popupTableModel.getRowCount() > 0);
204: }
205: }
206:
207: /**
208: * Method which stores the information from the popup window in the
209: * intermediate structure
210: * and returns a String containing all couples parameter types and names
211: * seperated by a ','
212: * @return String contains the couples parameter types and names of the
213: * popup window
214: */
215: public String storeSettings() {
216:
217: //stores all values from the table in the model even with
218: //keyboard navigation
219: popupTable.editingStopped(new ChangeEvent(this ));
220:
221: String paramString = "";// NOI18N
222: String paramName = "";// NOI18N
223: String paramType = "";// NOI18N
224: String paramDescr = "";// NOI18N
225: List<MBeanOperationParameter> mbop = new ArrayList<MBeanOperationParameter>();
226:
227: for (int i = 0; i < popupTableModel.size(); i++) {
228: //get the current parameter in the popup
229: MBeanOperationParameter popupParam = ((OperationParameterTableModel) popupTableModel)
230: .getParameter(i);
231: paramName = popupParam.getParamName();
232: paramType = popupParam.getParamType();
233: paramDescr = popupParam.getParamDescription();
234:
235: if ((paramName != "") && (paramType != ""))// NOI18N
236: paramString += paramType + " " + paramName;// NOI18N
237:
238: if (i < popupTableModel.size() - 1)
239: paramString += ",";// NOI18N
240:
241: // fills the arraylist with the exceptions to store
242: mbop.add(popupParam);
243: }
244:
245: //copy back the parameters from the popup to the panel model
246: methodModel.getOperation(editedRow).setParametersList(mbop);
247:
248: return paramString;
249: }
250: }
|