001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * JRParameterDialog.java
028: *
029: * Created on 9 maggio 2003, 17.25
030: *
031: */
032:
033: package it.businesslogic.ireport.gui;
034:
035: import it.businesslogic.ireport.util.*;
036: import it.businesslogic.ireport.*;
037: import java.util.Iterator;
038: import javax.swing.JOptionPane;
039:
040: /**
041: *
042: * @author Administrator
043: */
044: public class JRParameterDialog extends javax.swing.JDialog {
045: /** Creates new form JRParameterDialog */
046: JRParameter tmpParameter = null;
047: private SubDataset subDataset = null;
048: String originalName = null;
049:
050: private java.util.List properties = new java.util.ArrayList();
051:
052: public JRParameterDialog(java.awt.Frame parent, boolean modal) {
053:
054: super (parent, modal);
055: initComponents();
056: applyI18n();
057: this .jRTextExpressionAreaDefaultExpression.setText("");
058: setClassTypes();
059: this .jComboBoxType.setSelectedItem("java.lang.String");
060: jComboBoxType.setEditable(true);
061:
062: javax.swing.KeyStroke escape = javax.swing.KeyStroke
063: .getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0,
064: false);
065: javax.swing.Action escapeAction = new javax.swing.AbstractAction() {
066: public void actionPerformed(java.awt.event.ActionEvent e) {
067: jButtonCancelActionPerformed(e);
068: }
069: };
070:
071: getRootPane().getInputMap(
072: javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(
073: escape, "ESCAPE");
074: getRootPane().getActionMap().put("ESCAPE", escapeAction);
075:
076: //to make the default button ...
077: this .getRootPane().setDefaultButton(this .jButtonOK);
078: }
079:
080: public void setClassTypes() {
081: this .jComboBoxType.addItem("java.lang.String");
082: this .jComboBoxType.addItem("java.lang.Object");
083: this .jComboBoxType.addItem("java.lang.Boolean");
084: this .jComboBoxType.addItem("java.lang.Byte");
085: this .jComboBoxType.addItem("java.util.Date");
086: this .jComboBoxType.addItem("java.sql.Timestamp");
087: this .jComboBoxType.addItem("java.sql.Time");
088: this .jComboBoxType.addItem("java.lang.Double");
089: this .jComboBoxType.addItem("java.lang.Float");
090: this .jComboBoxType.addItem("java.lang.Integer");
091: this .jComboBoxType.addItem("java.io.InputStream");
092: this .jComboBoxType.addItem("java.lang.Long");
093: this .jComboBoxType.addItem("java.lang.Short");
094: this .jComboBoxType.addItem("java.math.BigDecimal");
095: this .jComboBoxType.addItem("java.util.Collection");
096: this .jComboBoxType
097: .addItem("net.sf.jasperreports.engine.JREmptyDataSource");
098: }
099:
100: /** This method is called from within the constructor to
101: * initialize the form.
102: * WARNING: Do NOT modify this code. The content of this method is
103: * always regenerated by the Form Editor.
104: */
105: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
106: private void initComponents() {
107: java.awt.GridBagConstraints gridBagConstraints;
108:
109: jLabel1 = new javax.swing.JLabel();
110: jTextFieldName = new javax.swing.JTextField();
111: jLabel2 = new javax.swing.JLabel();
112: jComboBoxType = new javax.swing.JComboBox();
113: jCheckBoxIsForPrompting = new javax.swing.JCheckBox();
114: jLabel3 = new javax.swing.JLabel();
115: jRTextExpressionAreaDefaultExpression = new it.businesslogic.ireport.gui.JRTextExpressionArea();
116: jLabel4 = new javax.swing.JLabel();
117: jScrollPane1 = new javax.swing.JScrollPane();
118: jTextAreaDescription = new javax.swing.JTextArea();
119: jButtonParameterProperties = new javax.swing.JButton();
120: jPanel1 = new javax.swing.JPanel();
121: jSeparator1 = new javax.swing.JSeparator();
122: jButtonOK = new javax.swing.JButton();
123: jButtonCancel = new javax.swing.JButton();
124:
125: getContentPane().setLayout(new java.awt.GridBagLayout());
126:
127: setTitle("Add/modify parameter");
128: setModal(true);
129: addWindowListener(new java.awt.event.WindowAdapter() {
130: public void windowClosing(java.awt.event.WindowEvent evt) {
131: closeDialog(evt);
132: }
133: });
134:
135: jLabel1.setText("Parameter name");
136: gridBagConstraints = new java.awt.GridBagConstraints();
137: gridBagConstraints.gridx = 0;
138: gridBagConstraints.gridy = 0;
139: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
140: gridBagConstraints.insets = new java.awt.Insets(3, 3, 0, 3);
141: getContentPane().add(jLabel1, gridBagConstraints);
142:
143: gridBagConstraints = new java.awt.GridBagConstraints();
144: gridBagConstraints.gridx = 0;
145: gridBagConstraints.gridy = 1;
146: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
147: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
148: gridBagConstraints.insets = new java.awt.Insets(0, 3, 3, 3);
149: getContentPane().add(jTextFieldName, gridBagConstraints);
150:
151: jLabel2.setText("Parameter class type");
152: gridBagConstraints = new java.awt.GridBagConstraints();
153: gridBagConstraints.gridx = 0;
154: gridBagConstraints.gridy = 2;
155: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
156: gridBagConstraints.insets = new java.awt.Insets(3, 3, 0, 3);
157: getContentPane().add(jLabel2, gridBagConstraints);
158:
159: jComboBoxType.setEditable(true);
160: gridBagConstraints = new java.awt.GridBagConstraints();
161: gridBagConstraints.gridx = 0;
162: gridBagConstraints.gridy = 3;
163: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
164: gridBagConstraints.insets = new java.awt.Insets(0, 3, 3, 3);
165: getContentPane().add(jComboBoxType, gridBagConstraints);
166:
167: jCheckBoxIsForPrompting.setText("Is for prompting");
168: jCheckBoxIsForPrompting
169: .setNextFocusableComponent(jRTextExpressionAreaDefaultExpression);
170: gridBagConstraints = new java.awt.GridBagConstraints();
171: gridBagConstraints.gridx = 0;
172: gridBagConstraints.gridy = 4;
173: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
174: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
175: getContentPane().add(jCheckBoxIsForPrompting,
176: gridBagConstraints);
177:
178: jLabel3.setText("Default value expression");
179: gridBagConstraints = new java.awt.GridBagConstraints();
180: gridBagConstraints.gridx = 0;
181: gridBagConstraints.gridy = 5;
182: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
183: gridBagConstraints.insets = new java.awt.Insets(3, 3, 0, 3);
184: getContentPane().add(jLabel3, gridBagConstraints);
185:
186: jRTextExpressionAreaDefaultExpression
187: .setBorder(javax.swing.BorderFactory
188: .createEtchedBorder());
189: jRTextExpressionAreaDefaultExpression.setCaretVisible(false);
190: jRTextExpressionAreaDefaultExpression.setElectricScroll(0);
191: jRTextExpressionAreaDefaultExpression
192: .setMinimumSize(new java.awt.Dimension(0, 60));
193: jRTextExpressionAreaDefaultExpression
194: .setPreferredSize(new java.awt.Dimension(310, 60));
195: gridBagConstraints = new java.awt.GridBagConstraints();
196: gridBagConstraints.gridx = 0;
197: gridBagConstraints.gridy = 6;
198: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
199: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
200: gridBagConstraints.weighty = 1.0;
201: gridBagConstraints.insets = new java.awt.Insets(0, 3, 3, 3);
202: getContentPane().add(jRTextExpressionAreaDefaultExpression,
203: gridBagConstraints);
204:
205: jLabel4.setText("Parameter description");
206: gridBagConstraints = new java.awt.GridBagConstraints();
207: gridBagConstraints.gridx = 0;
208: gridBagConstraints.gridy = 7;
209: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
210: gridBagConstraints.insets = new java.awt.Insets(3, 3, 0, 3);
211: getContentPane().add(jLabel4, gridBagConstraints);
212:
213: jScrollPane1.setMinimumSize(new java.awt.Dimension(22, 50));
214: jScrollPane1.setPreferredSize(new java.awt.Dimension(3, 50));
215: jTextAreaDescription.setMinimumSize(new java.awt.Dimension(0,
216: 32));
217: jScrollPane1.setViewportView(jTextAreaDescription);
218:
219: gridBagConstraints = new java.awt.GridBagConstraints();
220: gridBagConstraints.gridx = 0;
221: gridBagConstraints.gridy = 8;
222: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
223: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
224: gridBagConstraints.weighty = 1.0;
225: gridBagConstraints.insets = new java.awt.Insets(0, 3, 3, 3);
226: getContentPane().add(jScrollPane1, gridBagConstraints);
227:
228: jButtonParameterProperties
229: .setText("Edit parameter properties...");
230: jButtonParameterProperties
231: .addActionListener(new java.awt.event.ActionListener() {
232: public void actionPerformed(
233: java.awt.event.ActionEvent evt) {
234: jButtonParameterPropertiesActionPerformed(evt);
235: }
236: });
237:
238: gridBagConstraints = new java.awt.GridBagConstraints();
239: gridBagConstraints.gridx = 0;
240: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
241: gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 4);
242: getContentPane().add(jButtonParameterProperties,
243: gridBagConstraints);
244:
245: jPanel1.setLayout(new java.awt.GridBagLayout());
246:
247: jSeparator1.setMinimumSize(new java.awt.Dimension(2, 2));
248: jSeparator1.setPreferredSize(new java.awt.Dimension(2, 2));
249: gridBagConstraints = new java.awt.GridBagConstraints();
250: gridBagConstraints.gridwidth = 2;
251: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
252: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
253: gridBagConstraints.weightx = 1.0;
254: gridBagConstraints.insets = new java.awt.Insets(8, 0, 4, 0);
255: jPanel1.add(jSeparator1, gridBagConstraints);
256:
257: jButtonOK.setMnemonic('o');
258: jButtonOK.setText("OK");
259: jButtonOK
260: .addActionListener(new java.awt.event.ActionListener() {
261: public void actionPerformed(
262: java.awt.event.ActionEvent evt) {
263: jButtonOKActionPerformed(evt);
264: }
265: });
266:
267: gridBagConstraints = new java.awt.GridBagConstraints();
268: gridBagConstraints.gridy = 1;
269: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
270: gridBagConstraints.weightx = 1.0;
271: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 4);
272: jPanel1.add(jButtonOK, gridBagConstraints);
273:
274: jButtonCancel.setMnemonic('c');
275: jButtonCancel.setText("Cancel");
276: jButtonCancel
277: .addActionListener(new java.awt.event.ActionListener() {
278: public void actionPerformed(
279: java.awt.event.ActionEvent evt) {
280: jButtonCancelActionPerformed(evt);
281: }
282: });
283:
284: gridBagConstraints = new java.awt.GridBagConstraints();
285: gridBagConstraints.gridy = 1;
286: jPanel1.add(jButtonCancel, gridBagConstraints);
287:
288: gridBagConstraints = new java.awt.GridBagConstraints();
289: gridBagConstraints.gridx = 0;
290: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
291: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
292: gridBagConstraints.weightx = 1.0;
293: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
294: getContentPane().add(jPanel1, gridBagConstraints);
295:
296: pack();
297: java.awt.Dimension screenSize = java.awt.Toolkit
298: .getDefaultToolkit().getScreenSize();
299: java.awt.Dimension dialogSize = getSize();
300: setLocation((screenSize.width - dialogSize.width) / 2,
301: (screenSize.height - dialogSize.height) / 2);
302: }// </editor-fold>//GEN-END:initComponents
303:
304: private void jButtonParameterPropertiesActionPerformed(
305: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonParameterPropertiesActionPerformed
306: PropertiesDialog pd = new PropertiesDialog(this , true);
307: pd.setProperties(getProperties());
308: pd.setVisible(true);
309:
310: if (pd.getDialogResult() == JOptionPane.OK_OPTION) {
311: this .setProperties(pd.getProperties());
312: }
313: }//GEN-LAST:event_jButtonParameterPropertiesActionPerformed
314:
315: private void jButtonCancelActionPerformed(
316: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
317: setVisible(false);
318: this .setDialogResult(javax.swing.JOptionPane.CANCEL_OPTION);
319: dispose();
320: }//GEN-LAST:event_jButtonCancelActionPerformed
321:
322: private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
323: if (this .jTextFieldName.getText().trim().length() <= 0) {
324: javax.swing.JOptionPane
325: .showMessageDialog(
326: this ,
327: I18n
328: .getString(
329: "messages.jRParameterDialog.notValidParameterName",
330: "Please insert a valid parameter name!"),
331: I18n
332: .getString(
333: "messages.jRParameterDialog.notValidParameterNameCaption",
334: "Invalid parameter!"),
335: javax.swing.JOptionPane.WARNING_MESSAGE);
336: return;
337: }
338:
339: if (getSubDataset() != null) {
340: //check unique name...
341: String newName = this .jTextFieldName.getText();
342: if (originalName == null || !originalName.equals(newName)) {
343: for (int i = 0; i < getSubDataset().getParameters()
344: .size(); ++i) {
345: JRParameter f = (JRParameter) getSubDataset()
346: .getParameters().get(i);
347: if (f.getName().equals(newName)) {
348: javax.swing.JOptionPane
349: .showMessageDialog(
350: this ,
351: I18n
352: .getString(
353: "messages.jRParameterDialog.DuplicatedParameterName",
354: "A parameter with this name already exists!"),
355: I18n
356: .getString(
357: "messages.jRParameterDialog.notValidParameterNameCaption",
358: "Invalid parameter!"),
359: javax.swing.JOptionPane.WARNING_MESSAGE);
360: return;
361: }
362: }
363: }
364: }
365:
366: tmpParameter = new JRParameter(this .jTextFieldName.getText(),
367: "java.lang.String", this .jCheckBoxIsForPrompting
368: .isSelected(), this .jTextAreaDescription
369: .getText());
370: tmpParameter.setProperties(this .properties);
371: if (this .jComboBoxType.getSelectedItem().toString().trim()
372: .length() != 0) {
373: tmpParameter.setClassType(this .jComboBoxType
374: .getSelectedItem().toString().trim());
375: }
376: tmpParameter
377: .setDefaultValueExpression(jRTextExpressionAreaDefaultExpression
378: .getText());
379:
380: setVisible(false);
381: this .setDialogResult(javax.swing.JOptionPane.OK_OPTION);
382: dispose();
383: }//GEN-LAST:event_jButtonOKActionPerformed
384:
385: /** Closes the dialog */
386: private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
387: setVisible(false);
388: this .setDialogResult(javax.swing.JOptionPane.CLOSED_OPTION);
389: dispose();
390: }//GEN-LAST:event_closeDialog
391:
392: /** Getter for property tmpParameter.
393: * @return Value of property tmpParameter.
394: *
395: */
396: public it.businesslogic.ireport.JRParameter getParameter() {
397: return tmpParameter;
398: }
399:
400: /** Setter for property tmpParameter.
401: * @param tmpParameter New value of property tmpParameter.
402: *
403: */
404: public void setParameter(
405: it.businesslogic.ireport.JRParameter tmpParameter) {
406: originalName = tmpParameter.getName();
407: this .jTextFieldName.setText(new String(tmpParameter.getName()));
408: this .jComboBoxType.setSelectedItem(new String(tmpParameter
409: .getClassType()));
410: this .jCheckBoxIsForPrompting.setSelected(tmpParameter
411: .isIsForPrompting());
412: this .jTextAreaDescription.setText(new String(tmpParameter
413: .getDescription()));
414: this .jRTextExpressionAreaDefaultExpression.setText(new String(
415: tmpParameter.getDefaultValueExpression()));
416:
417: this .properties = new java.util.ArrayList();
418:
419: Iterator iter = tmpParameter.getProperties().iterator();
420: while (iter.hasNext()) {
421: JRProperty p = (JRProperty) iter.next();
422: this .properties.add(p.cloneMe());
423: }
424:
425: }
426:
427: /** Getter for property dialogResult.
428: * @return Value of property dialogResult.
429: *
430: */
431: public int getDialogResult() {
432: return dialogResult;
433: }
434:
435: /** Setter for property dialogResult.
436: * @param dialogResult New value of property dialogResult.
437: *
438: */
439: public void setDialogResult(int dialogResult) {
440: this .dialogResult = dialogResult;
441: }
442:
443: // Variables declaration - do not modify//GEN-BEGIN:variables
444: private javax.swing.JButton jButtonCancel;
445: private javax.swing.JButton jButtonOK;
446: private javax.swing.JButton jButtonParameterProperties;
447: private javax.swing.JCheckBox jCheckBoxIsForPrompting;
448: private javax.swing.JComboBox jComboBoxType;
449: private javax.swing.JLabel jLabel1;
450: private javax.swing.JLabel jLabel2;
451: private javax.swing.JLabel jLabel3;
452: private javax.swing.JLabel jLabel4;
453: private javax.swing.JPanel jPanel1;
454: private it.businesslogic.ireport.gui.JRTextExpressionArea jRTextExpressionAreaDefaultExpression;
455: private javax.swing.JScrollPane jScrollPane1;
456: private javax.swing.JSeparator jSeparator1;
457: private javax.swing.JTextArea jTextAreaDescription;
458: private javax.swing.JTextField jTextFieldName;
459: // End of variables declaration//GEN-END:variables
460:
461: private int dialogResult;
462:
463: public void setSubDataset(SubDataset subDataset) {
464:
465: this .subDataset = subDataset;
466: jRTextExpressionAreaDefaultExpression.setSubDataset(subDataset);
467: jRTextExpressionAreaDefaultExpression.getTokenMarker()
468: .setKeywordLookup(subDataset.getKeywordLookup());
469: }
470:
471: public void applyI18n() {
472: // Start autogenerated code ----------------------
473: jCheckBoxIsForPrompting.setText(I18n.getString(
474: "jRParameterDialog.checkBoxIsForPrompting",
475: "Is for prompting"));
476: // End autogenerated code ----------------------
477: // Start autogenerated code ----------------------
478: jButtonCancel.setText(I18n.getString(
479: "jRParameterDialog.buttonCancel", "Cancel"));
480: jButtonOK.setText(I18n.getString("jRParameterDialog.buttonOK",
481: "OK"));
482:
483: jButtonParameterProperties.setText(I18n.getString(
484: "jRParameterDialog.buttonParameterProperties",
485: "Edit parameter properties..."));
486:
487: jLabel1.setText(I18n.getString("jRParameterDialog.label1",
488: "Parameter name"));
489: jLabel2.setText(I18n.getString("jRParameterDialog.label2",
490: "Parameter class type"));
491: jLabel3.setText(I18n.getString("jRParameterDialog.label3",
492: "Default value expression"));
493: jLabel4.setText(I18n.getString("jRParameterDialog.label4",
494: "Parameter description"));
495: // End autogenerated code ----------------------
496: this .setTitle(I18n.getString("jRParameterDialog.title",
497: "Add/modify parameter"));
498: jButtonCancel.setMnemonic(I18n.getString(
499: "jRParameterDialog.buttonCancelMnemonic", "c")
500: .charAt(0));
501: jButtonOK.setMnemonic(I18n.getString(
502: "jRParameterDialog.buttonOKMnemonic", "o").charAt(0));
503: }
504:
505: public SubDataset getSubDataset() {
506: return subDataset;
507: }
508:
509: public static final int COMPONENT_NONE = 0;
510: public static final int COMPONENT_DEFAULT_EXPRESSION = 1;
511:
512: /**
513: * This method set the focus on a specific component.
514: * Valid constants are something like:
515: * FIELD_XXX
516: */
517: public void setFocusedExpression(int expID) {
518: switch (expID) {
519: case COMPONENT_DEFAULT_EXPRESSION:
520: Misc
521: .selectTextAndFocusArea(jRTextExpressionAreaDefaultExpression);
522: break;
523: }
524:
525: }
526:
527: public java.util.List getProperties() {
528: return properties;
529: }
530:
531: public void setProperties(java.util.List properties) {
532: this.properties = properties;
533: }
534: }
|