📄 reportquerydialog.java
字号:
row.addElement(field.getDescription());
dtm.addRow(row);
}
}
*/
} catch (ClassNotFoundException cnf)
{
javax.swing.JOptionPane.showMessageDialog(this, "Class not found!\nCheck your classpath and retry.","Error",javax.swing.JOptionPane.ERROR_MESSAGE);
return;
} catch (Exception ex)
{
ex.printStackTrace();
javax.swing.JOptionPane.showMessageDialog(this, ex.getMessage() ,"Error",javax.swing.JOptionPane.ERROR_MESSAGE);
return;
}
}//GEN-LAST:event_jButtonReadBeanAttributesActionPerformed
private String getJRFieldType(String type)
{
if (type == null) return "java.lang.Object";
if (type.equals("java.lang.Boolean") || type.equals("boolean")) return "java.lang.Boolean";
if (type.equals("java.lang.Byte") || type.equals("byte")) return "java.lang.Byte";
if (type.equals("java.lang.Integer") || type.equals("int")) return "java.lang.Integer";
if (type.equals("java.lang.Long") || type.equals("long")) return "java.lang.Long";
if (type.equals("java.lang.Double") || type.equals("double")) return "java.lang.Double";
if (type.equals("java.lang.Float") || type.equals("float")) return "java.lang.Float";
if (type.equals("java.lang.Short") || type.equals("short")) return "java.lang.Short";
if (type.equals("java.util.Date") ||
type.equals("java.sql.Timestamp") ||
type.equals("java.io.InputStream") ||
type.equals("java.math.BigDecimal") ||
type.equals("java.lang.String") ||
type.equals("java.sql.Time")) return type;
return "java.lang.Object";
}
/** Closes the dialog */
private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
setVisible(false);
dispose();
}//GEN-LAST:event_closeDialog
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new ReportQueryDialog(new javax.swing.JFrame(), true).show();
}
/** Getter for property jReportFrame.
* @return Value of property jReportFrame.
*
*/
public it.businesslogic.ireport.gui.JReportFrame getJReportFrame() {
return jReportFrame;
}
/** Setter for property jReportFrame.
* @param jReportFrame New value of property jReportFrame.
*
*/
public void setJReportFrame(it.businesslogic.ireport.gui.JReportFrame jReportFrame) {
this.jReportFrame = jReportFrame;
DefaultTableModel dtm = (DefaultTableModel)jTableFields.getModel();
dtm.setRowCount(0);
// Load query...
if (jReportFrame == null)
this.jRSQLExpressionArea1.setText("");
else
{
// Use query, and use existing field list. ie Dont load from DB
isSettingSQLExpression = true;
this.jRSQLExpressionArea1.setText( this.jReportFrame.getReport().getQuery() );
isSettingSQLExpression = false;
List columns = new ArrayList();
Iterator i = jReportFrame.getReport().getFields().iterator();
while( i.hasNext() ) {
it.businesslogic.ireport.JRField field = (it.businesslogic.ireport.JRField)i.next();
columns.add( new Object[]{field, field.getClassType()} );
}
setColumns( columns );
}
}
Map parameterNameToExpressionID = null;
/**
* Create an expression evaluator for report parameters.
*
*/
private Interpreter prepareExpressionEvaluator() throws net.sf.jasperreports.engine.JRException, bsh.EvalError {
JasperDesign jd = new JasperDesign();
parameterNameToExpressionID = new HashMap();
Enumeration enumParams = getJReportFrame().getReport().getParameters().elements();
while( enumParams.hasMoreElements() ) {
it.businesslogic.ireport.JRParameter parameter = (it.businesslogic.ireport.JRParameter)enumParams.nextElement();
if( parameter.getDefaultValueExpression().length()==0 ) {
// no default value for this param
continue;
}
Class c = classStringToClass( parameter.getClassType() );
JRDesignParameter p = new JRDesignParameter();
//JRDesignExpression exp = parameter.getDefaultValueExpression();
JRDesignExpression exp = new JRDesignExpression();
if (c==null) c = java.lang.Object.class;
exp.setValueClass( c );
exp.setName("parameterDefaultValue_" + parameter.getName() );
exp.setText( parameter.getDefaultValueExpression() );
p.setName( parameter.getName() );
p.setValueClass( c );
p.setForPrompting( false );
p.setDefaultValueExpression( exp );
jd.addParameter( p );
parameterNameToExpressionID.put( parameter.getName(), new Integer(exp.getId()) );
}
String bshScript = JRBshGenerator.generateScript( jd );
Interpreter interpreter = new Interpreter();
interpreter.setClassLoader(interpreter.getClass().getClassLoader());
interpreter.eval(new StringReader(bshScript));
interpreter.eval("bshCalculator = createBshCalculator()");
return interpreter;
}
/**
* Convert a class name string into its class object.
* There must be a function in JasperReports that does this somewhere.
*
*
*/
private Class classStringToClass(String classType) {
Class c = null;
if ( classType.equals("java.lang.String") ) {
c = java.lang.String.class;
} else if ( classType.equals("java.lang.Integer") ) {
c = java.lang.Integer.class;
} else if ( classType.equals("java.lang.Boolean") ) {
c = java.lang.Boolean.class;
} else if ( classType.equals("java.lang.Byte") ) {
c = java.lang.Byte.class;
} else if ( classType.equals("java.util.Date") ) {
c = java.util.Date.class;
} else if ( classType.equals("java.sql.Timestamp") ) {
c = java.sql.Timestamp.class;
} else if ( classType.equals("java.sql.Time") ) {
c = java.sql.Time.class;
} else if ( classType.equals("java.lang.Double") ) {
c = java.lang.Double.class;
} else if ( classType.equals("java.lang.Float") ) {
c = java.lang.Float.class;
} else if ( classType.equals("java.lang.Long") ) {
c = java.lang.Long.class;
} else if ( classType.equals("java.lang.Short") ) {
c = java.lang.Short.class;
} else if ( classType.equals("java.math.BigDecimal") ) {
c = java.math.BigDecimal.class;
}
return c;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JCheckBox automaticlyReadFieldsCheckBox;
private javax.swing.JButton cancelButton;
private javax.swing.JLabel columnsErrorMsgLabel;
private javax.swing.JScrollPane columnsErrorScrollPane;
private javax.swing.JScrollPane columnsScrollPane;
private javax.swing.JButton exportQueryButton;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButtonReadBeanAttributes;
private javax.swing.JButton jButtonReadBeanAttributes3;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel10;
private javax.swing.JPanel jPanel11;
private javax.swing.JPanel jPanel12;
private javax.swing.JPanel jPanel13;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JPanel jPanel7;
private javax.swing.JPanel jPanel8;
private javax.swing.JPanel jPanel9;
private javax.swing.JPanel jPanelSQL;
private it.businesslogic.ireport.gui.JRSQLExpressionArea jRSQLExpressionArea1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSplitPane jSplitPane1;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JTable jTableFields;
private javax.swing.JTextField jTextFieldBeanClass;
private javax.swing.JTextField jTextFieldBeanClass1;
private javax.swing.JTree jTree1;
private javax.swing.JButton okButton;
private javax.swing.JButton readFieldsButton;
// End of variables declaration//GEN-END:variables
private JReportFrame jReportFrame;
private boolean isSettingSQLExpression = false;
public void exploreBean(DefaultMutableTreeNode root, String classname, String parentPath)
{
try {
root.removeAllChildren();
if (parentPath.length() > 0) parentPath += ".";
java.lang.reflect.Method[] methods = Class.forName(classname).getMethods();
java.lang.reflect.Field[] fields = Class.forName(classname).getFields();
// for any method, looking for get<FieldName> ....
for (int i=0; i<methods.length; ++i)
{
//System.out.println( methods[i].getName());
if ( java.lang.reflect.Modifier.isPublic( methods[i].getModifiers() ) &&
methods[i].getDeclaringClass().getName().equals(classname) &&
!java.lang.reflect.Modifier.isNative( methods[i].getModifiers() )
&& methods[i].getName().startsWith("get")
&& !methods[i].getReturnType().isPrimitive()
&& !methods[i].getReturnType().isArray())
{
String fieldName = methods[i].getName().substring(3);
if (fieldName.length() == 0) continue;
// Looking for the field...
for (int f=0; f<fields.length; ++f)
{
if (fields[f].getName().equalsIgnoreCase( fieldName ))
{
fieldName = fields[f].getName();
break;
}
}
String returnType = methods[i].getReturnType().getName();
it.businesslogic.ireport.JRField field = new it.businesslogic.ireport.JRField(fieldName, returnType);
field.setDescription(parentPath + fieldName);
TreeJRField jtf = new TreeJRField();
jtf.setField( field );
jtf.setObj( methods[i].getReturnType() );
boolean bChildrens = true;
if (methods[i].getReturnType().getName().startsWith("java.lang."))
{
bChildrens = false;
}
root.add(new DefaultMutableTreeNode(jtf, bChildrens));
}
}
jTree1.expandPath( new TreePath(root.getPath()) );
jTree1.updateUI();
} catch (ClassNotFoundException cnf)
{
javax.swing.JOptionPane.showMessageDialog(this, "Class not found!\nCheck your classpath and retry.","Error",javax.swing.JOptionPane.ERROR_MESSAGE);
return;
} catch (Exception ex)
{
javax.swing.JOptionPane.showMessageDialog(this, ex.getMessage() ,"Error",javax.swing.JOptionPane.ERROR_MESSAGE);
return;
}
}
public void lostOwnership (Clipboard parClipboard, Transferable parTransferable) { }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -