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.OperationExceptionTableModel;
045: import org.netbeans.modules.jmx.mbeanwizard.listener.AddTableRowListener;
046: import org.netbeans.modules.jmx.mbeanwizard.listener.RemTableRowListener;
047: import java.awt.BorderLayout;
048:
049: import java.awt.event.ActionEvent;
050: import java.awt.event.ActionListener;
051: import java.util.ArrayList;
052: import java.util.List;
053:
054: import javax.swing.JButton;
055: import javax.swing.JTextField;
056:
057: import org.openide.util.NbBundle;
058: import org.openide.NotifyDescriptor;
059: import org.netbeans.modules.jmx.mbeanwizard.tablemodel.MBeanOperationTableModel;
060: import org.netbeans.modules.jmx.runtime.ManagementDialogs;
061: import org.netbeans.modules.jmx.mbeanwizard.table.OperationExceptionPopupTable;
062: import javax.swing.JPanel;
063: import javax.swing.event.ChangeEvent;
064: import org.netbeans.modules.jmx.MBeanOperationException;
065:
066: /**
067: * Class implementing the exception popup window
068: *
069: */
070: public class OperationExceptionPopup extends AbstractPopup {
071:
072: protected MBeanOperationTableModel methodModel;
073: private int editedRow;
074:
075: /**
076: * Constructor
077: * @param ancestorPanel the parent panel of the popup; here the wizard
078: * @param methodModel the table model from the operation table in the wizard
079: * @param textField the textfield to fill with the popup information
080: * @param editedRow the current edited row in the wizard table
081: */
082: public OperationExceptionPopup(JPanel ancestorPanel,
083: MBeanOperationTableModel methodModel, JTextField textField,
084: int editedRow) {
085:
086: super ((java.awt.Dialog) ancestorPanel.getTopLevelAncestor());
087:
088: this .textFieldToFill = textField;
089: this .methodModel = methodModel;
090: this .editedRow = editedRow;
091:
092: setLayout(new BorderLayout());
093: initJTable();
094: initComponents();
095:
096: readSettings();
097:
098: //setDimensions(NbBundle.getMessage(OperationExceptionPopup.class,
099: // "LBL_OperationException_Popup"));// NOI18N
100: setDimensions(bundle.getString("LBL_OperationException_Popup"));// NOI18N
101: }
102:
103: protected void initJTable() {
104:
105: popupTableModel = new OperationExceptionTableModel();
106: popupTable = new OperationExceptionPopupTable(popupTableModel);
107: popupTable.setName("ExcepPopupTable");// NOI18N
108: }
109:
110: protected void initComponents() {
111: /*
112: addJButton = instanciatePopupButton(NbBundle.getMessage(OperationExceptionPopup.class,"LBL_OperationException_addException"));// NOI18N
113: removeJButton = instanciatePopupButton(NbBundle.getMessage(OperationExceptionPopup.class,"LBL_OperationException_remException"));// NOI18N
114: closeJButton = instanciatePopupButton(NbBundle.getMessage(OperationExceptionPopup.class,"LBL_OperationException_close"));// NOI18N
115:
116:
117: //Accessibility
118: removeJButton.getAccessibleContext().setAccessibleName(NbBundle.getMessage(OperationExceptionPopup.class,"ACCESS_REMOVE_EXCEPTION"));// NOI18N
119: removeJButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(OperationExceptionPopup.class,"ACCESS_REMOVE_EXCEPTION_DESCRIPTION"));// NOI18N
120: addJButton.getAccessibleContext().setAccessibleName(NbBundle.getMessage(OperationExceptionPopup.class,"ACCESS_ADD_EXCEPTION"));// NOI18N
121: addJButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(OperationExceptionPopup.class,"ACCESS_ADD_EXCEPTION_DESCRIPTION"));// NOI18N
122: closeJButton.getAccessibleContext().setAccessibleName(NbBundle.getMessage(OperationExceptionPopup.class,"ACCESS_CLOSE_EXCEPTION"));// NOI18N
123: closeJButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(OperationExceptionPopup.class,"ACCESS_CLOSE_EXCEPTION_DESCRIPTION"));// NOI18N
124: popupTable.getAccessibleContext().setAccessibleName(NbBundle.getMessage(OperationExceptionPopup.class,"ACCESS_EXCEPTION_TABLE"));// NOI18N
125: popupTable.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(OperationExceptionPopup.class,"ACCESS_EXCEPTION_TABLE_DESCRIPTION"));// NOI18N
126: */
127:
128: addJButton = instanciatePopupButton(bundle
129: .getString("LBL_OperationException_addException"));// NOI18N
130: removeJButton = instanciatePopupButton(bundle
131: .getString("LBL_OperationException_remException"));// NOI18N
132: closeJButton = instanciatePopupButton(bundle
133: .getString("LBL_OperationException_close"));// NOI18N
134:
135: //Accessibility
136: removeJButton.getAccessibleContext().setAccessibleName(
137: bundle.getString("ACCESS_REMOVE_EXCEPTION"));// NOI18N
138: removeJButton
139: .getAccessibleContext()
140: .setAccessibleDescription(
141: bundle
142: .getString("ACCESS_REMOVE_EXCEPTION_DESCRIPTION"));// NOI18N
143: addJButton.getAccessibleContext().setAccessibleName(
144: bundle.getString("ACCESS_ADD_EXCEPTION"));// NOI18N
145: addJButton.getAccessibleContext().setAccessibleDescription(
146: bundle.getString("ACCESS_ADD_EXCEPTION_DESCRIPTION"));// NOI18N
147: closeJButton.getAccessibleContext().setAccessibleName(
148: bundle.getString("ACCESS_CLOSE_EXCEPTION"));// NOI18N
149: closeJButton.getAccessibleContext().setAccessibleDescription(
150: bundle.getString("ACCESS_CLOSE_EXCEPTION_DESCRIPTION"));// NOI18N
151: popupTable.getAccessibleContext().setAccessibleName(
152: bundle.getString("ACCESS_EXCEPTION_TABLE"));// NOI18N
153: popupTable.getAccessibleContext().setAccessibleDescription(
154: bundle.getString("ACCESS_EXCEPTION_TABLE_DESCRIPTION"));// NOI18N
155:
156: addJButton.setName("addExceptionJButton");// NOI18N
157: removeJButton.setName("remExceptionJButton");// NOI18N
158: closeJButton.setName("closeJButton");// NOI18N
159:
160: //remove button should first be remove
161: removeJButton.setEnabled(false);
162:
163: addJButton.addActionListener(new AddTableRowListener(
164: popupTable, popupTableModel, removeJButton));
165: removeJButton.addActionListener(new RemTableRowListener(
166: popupTable, popupTableModel, removeJButton));
167:
168: closeJButton.addActionListener(new ActionListener() {
169: public void actionPerformed(ActionEvent evt) {
170: if (existsSameException()) {
171: ManagementDialogs
172: .getDefault()
173: .notify(
174: //new NotifyDescriptor.Message(NbBundle.getMessage(OperationExceptionPopup.class, "ERR_InheritanceConflict"), // NOI18N
175: // NotifyDescriptor.ERROR_MESSAGE));
176: new NotifyDescriptor.Message(
177: bundle
178: .getString("ERR_InheritanceConflict"), // NOI18N
179: NotifyDescriptor.ERROR_MESSAGE));
180: } else {
181: textFieldToFill.setText(storeSettings());
182: dispose();
183: }
184: }
185: });
186:
187: definePanels(getUsedButtons(), popupTable, bundle
188: .getString("LBL_OP_EXCEPTIONS_POPUP_TABLE")); // NOI18N
189: }
190:
191: protected JButton[] getUsedButtons() {
192: return new JButton[] { addJButton, removeJButton, closeJButton };
193: }
194:
195: protected void readSettings() {
196:
197: if (methodModel.size() != 0) {
198: //get the exception list of the current operation
199: List<MBeanOperationException> panelExcepts = methodModel
200: .getOperation(editedRow).getExceptionsList();
201:
202: for (int i = 0; i < panelExcepts.size(); i++) {
203:
204: popupTableModel.addRow();
205: //copy the exceptions from the panel model to the popup model
206: ((OperationExceptionTableModel) popupTableModel)
207: .setException(i, panelExcepts.get(i));
208: }
209: removeJButton.setEnabled(popupTableModel.getRowCount() > 0);
210: }
211: }
212:
213: /**
214: * Inherited method from superclass
215: */
216: public String storeSettings() {
217:
218: //stores all values from the table in the model even with keyboard navigation
219: popupTable.editingStopped(new ChangeEvent(this ));
220:
221: String excepString = "";// NOI18N
222: String excepName = "";// NOI18N
223: String excepDescription = "";// NOI18N
224: // create a new list of exceptions to fill
225: ArrayList<MBeanOperationException> mboe = new ArrayList<MBeanOperationException>();
226:
227: for (int i = 0; i < popupTableModel.size(); i++) {
228: //get the current exception in the popup model
229: MBeanOperationException popupEx = ((OperationExceptionTableModel) popupTableModel)
230: .getException(i);
231: excepName = popupEx.getExceptionClass();
232: excepDescription = popupEx.getExceptionDescription();
233:
234: if (excepName != "")// NOI18N
235: excepString += excepName;
236:
237: if (i < popupTableModel.size() - 1)
238: excepString += ",";// NOI18N
239:
240: // fills the arraylist with the exceptions to store
241: mboe.add(popupEx);
242: }
243:
244: //copy back the exceptions from the popup to the panel model
245: methodModel.getOperation(editedRow).setExceptionsList(mboe);
246:
247: return excepString;
248: }
249:
250: private boolean existsSameException() {
251: // prevents from having two or more exception with the same name
252: String excepName = "";// NOI18N
253: String excepString = "";// NOI18N
254:
255: for (int i = 0; i < popupTableModel.size(); i++) {
256: //excepName = (String)popupTableModel.getValueAt(i,
257: // OperationExceptionTableModel.IDX_EXCEPTION_NAME);
258: excepName = ((OperationExceptionTableModel) popupTableModel)
259: .getException(i).getExceptionClass();
260: if (excepString.contains(excepName))
261: return true;
262: else {
263: if (excepName != "")// NOI18N
264: excepString += excepName;
265: }
266: }
267: return false;
268: }
269: }
|