Java 类net.sf.jasperreports.engine.design.JRDesignSubreportParameter 实例源码

项目:PDFReporter-Studio    文件:SubreportPropertyPage.java   
protected void loadSettings() {
    JRParameter[] parameters = null;
    // load settings, if available..
    if (getSettings() != null && getSettings().containsKey(NewSubreportPage.SUBREPORT_PARAMETERS)) {
        parameters = (JRParameter[]) getSettings().get(NewSubreportPage.SUBREPORT_PARAMETERS);
    }

    if (lastParameters != parameters) {
        lastParameters = parameters;
        List<JRDesignSubreportParameter> sParameters = new ArrayList<JRDesignSubreportParameter>();

        if (lastParameters != null && lastParameters.length > 0) {
            // Create an array of subreport parameters to be used in in the table model...
            for (JRParameter p : lastParameters) {
                if (!p.isSystemDefined()) {
                    JRDesignSubreportParameter sp = new JRDesignSubreportParameter();
                    sp.setName(p.getName());
                    sp.setExpression(new JRDesignExpression());
                    sParameters.add(sp);
                }
            }
        }
        setValue(sParameters.toArray(new JRDesignSubreportParameter[sParameters.size()]));
    }
}
项目:ireport-fork    文件:SubreportParametersPanel.java   
@SuppressWarnings("unchecked")
private void jButtonAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddActionPerformed

    Object pWin = SwingUtilities.getWindowAncestor(this);
    JRSubreportParameterDialog jrpd = null;
    if (pWin instanceof Dialog) jrpd = new JRSubreportParameterDialog((Dialog)pWin, getParameters());
    else jrpd = new JRSubreportParameterDialog((Frame)pWin, getParameters());

    jrpd.setExpressionContext( getExpressionContext() );
    jrpd.setVisible(true);

    if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) {

        JRDesignSubreportParameter parameter = jrpd.getParameter();
        parameters.put(parameter.getName(), parameter);

        DefaultTableModel model = (DefaultTableModel)jTable.getModel();
        model.addRow(new Object[]{parameter.getName(), 
                ((parameter.getExpression() != null && parameter.getExpression().getText() != null) ? 
                    parameter.getExpression().getText() : "")
            });
    }

}
项目:ireport-fork    文件:JRSubreportParameterDialog.java   
/** Setter for property tmpParameter.
 * @param tmpParameter New value of property tmpParameter.
 *
 */
public void setParameter(JRDesignSubreportParameter tmpParameter) {
    this.jTextFieldName.setText( tmpParameter.getName() );

    oldName =tmpParameter.getName();

    String text = "";

    if (tmpParameter.getExpression() != null  &&
        tmpParameter.getExpression().getText() != null )
    {
        text = tmpParameter.getExpression().getText();
    }

    this.jRTextExpressionAreaDefaultExpression.setText( text );                       
}
项目:jasperreports    文件:JRSubreportParameterFactory.java   
@Override
public Object createObject(Attributes atts)
{
    JRDesignSubreportParameter subreportParameter = new JRDesignSubreportParameter();

    subreportParameter.setName(atts.getValue(JRXmlConstants.ATTRIBUTE_name));

    return subreportParameter;
}
项目:ireport-fork    文件:SubreportParametersPanel.java   
/**
  * This method will duplicate the map. The panel will work on a copy of the map.
  **/
 @SuppressWarnings("unchecked")
 public void setParameters(Map oldParameters) {

     this.parameters.clear();
     DefaultTableModel model = (DefaultTableModel)this.jTable.getModel();
     model.setRowCount(0);
     // Create a copy of the map content...
     Iterator iterator = oldParameters.keySet().iterator();
     while (iterator.hasNext())
     {
         Object key = iterator.next();

         JRDesignSubreportParameter oldParameter = (JRDesignSubreportParameter)oldParameters.get(key);

         JRDesignSubreportParameter parameter = new JRDesignSubreportParameter();
         parameter.setName(oldParameter.getName() );
         if (oldParameter.getExpression() != null)
         {
             JRDesignExpression exp = new JRDesignExpression();
             exp.setText(oldParameter.getExpression().getText());
             exp.setValueClassName(oldParameter.getExpression().getValueClassName());
             parameter.setExpression(exp);
         }
         parameters.put(parameter.getName(), parameter);

         model.addRow(new Object[]{parameter.getName(), 
                 ((parameter.getExpression() != null && parameter.getExpression().getText() != null) ? 
                     parameter.getExpression().getText() : "")
             });
     }
}
项目:ireport-fork    文件:SubreportParametersPanel.java   
@SuppressWarnings("unchecked")
private void jButtonModifyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonModifyActionPerformed

    DefaultTableModel model = (DefaultTableModel)jTable.getModel();

    int row = jTable.getSelectedRow();
    if (row < 0) return;

    row = ((JXTable)jTable).convertRowIndexToModel(row);

    JRDesignSubreportParameter parameter = (JRDesignSubreportParameter)parameters.get(model.getValueAt(row,0));

    String oldName = parameter.getName();

    JRSubreportParameterDialog jrpd = null;
    Window pWin = SwingUtilities.getWindowAncestor(this);
    if (pWin instanceof Dialog) jrpd = new JRSubreportParameterDialog((Dialog)pWin, getParameters());
    else if (pWin instanceof Frame) jrpd = new JRSubreportParameterDialog((Frame)pWin, getParameters());
    else jrpd = new JRSubreportParameterDialog((Dialog)null, getParameters());


    jrpd.setExpressionContext( getExpressionContext() );
    jrpd.setParameter(parameter);
    jrpd.setVisible(true);

    if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) {
        parameter = jrpd.getParameter();
        parameters.remove(oldName);
        parameters.put(parameter.getName(), parameter);
        model.setValueAt(parameter.getName(), row, 0);
        model.setValueAt(((parameter.getExpression() != null && parameter.getExpression().getText() != null) ? 
                    parameter.getExpression().getText() : ""), row, 1);

        jTable.updateUI();
    }
}
项目:ireport-fork    文件:SubreportParametersPanel.java   
@SuppressWarnings("unchecked")
private void jButtonCopyFromMasterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCopyFromMasterActionPerformed

    javax.swing.table.DefaultTableModel model = (javax.swing.table.DefaultTableModel)jTable.getModel();

    List reportParameters = IReportManager.getInstance().getActiveReport().getParametersList();

    for (int i=0; i<reportParameters.size(); ++i) {
        JRDesignParameter jrParameter = (JRDesignParameter)reportParameters.get(i);
        if (jrParameter.isSystemDefined()) continue;

        // Check if a similar parameter already exists...
        if (!parameters.containsKey(jrParameter.getName())) {
            JRDesignSubreportParameter parameter = new JRDesignSubreportParameter();
            parameter.setName(jrParameter.getName() );
            JRDesignExpression exp = new JRDesignExpression();
            exp.setText("$P{" + jrParameter.getName() + "}");
            exp.setValueClassName( jrParameter.getValueClassName() );
            parameter.setExpression(exp);
            parameters.put(parameter.getName(), parameter);
            model.addRow(new Object[]{parameter.getName(), ((parameter.getExpression() != null && parameter.getExpression().getText() != null) ? 
                    parameter.getExpression().getText() : "")});
        }
    }
    jTable.updateUI();

}
项目:ireport-fork    文件:JRSubreportParameterDialog.java   
private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed

    String newName = this.jTextFieldName.getText().trim();
    if (newName.length() <= 0)
    {
        javax.swing.JOptionPane.showMessageDialog(this,
                I18n.getString("JRSubreportParameterDialog.Message.Warning"),
                I18n.getString("JRSubreportParameterDialog.Message.Error"),
                javax.swing.JOptionPane.WARNING_MESSAGE );
        return;
    }

    if (oldName != null && 
        !oldName.equals(newName) &&
        currentParameters != null &&
        currentParameters.containsKey(newName))
    {
        javax.swing.JOptionPane.showMessageDialog(this,
                I18n.getString("JRSubreportParameterDialog.Message.Warning2"),
                I18n.getString("JRSubreportParameterDialog.Message.Error2"),
                javax.swing.JOptionPane.WARNING_MESSAGE );
        return;
    }

    tmpParameter = new JRDesignSubreportParameter();

    tmpParameter.setName(this.jTextFieldName.getText().trim());
    JRDesignExpression exp = new JRDesignExpression();
    exp.setText(this.jRTextExpressionAreaDefaultExpression.getText());
    exp.setValueClassName("java.lang.Object");
    tmpParameter.setExpression(exp);
    setVisible(false);
    this.setDialogResult( javax.swing.JOptionPane.OK_OPTION);
    dispose();
}
项目:com.opendoorlogistics    文件:SubreportsWithProviderBuilder.java   
private static void setupDatasourceParameters(JasperDesign report, boolean hasHeaderMap) {
    try {
        // ensure every subreport has the provider parameter
        for (JRBand band : report.getDetailSection().getBands()) {
            for (JRElement element : band.getElements()) {
                if (JRDesignSubreport.class.isInstance(element)) {
                    JRDesignSubreport sub = (JRDesignSubreport) element;
                    sub.removeParameter(ReportConstants.DATASOURCE_PROVIDER_PARAMETER);

                    JRDesignSubreportParameter param = new JRDesignSubreportParameter();
                    param.setName(ReportConstants.DATASOURCE_PROVIDER_PARAMETER);
                    param.setExpression(new JRDesignExpression("$P{" + ReportConstants.DATASOURCE_PROVIDER_PARAMETER + "}"));
                    sub.addParameter(param);
                }
            }
        }

        // ensure main report has correct provider parameters
        addParameter(report, ReportConstants.DATASOURCE_PROVIDER_PARAMETER);
        if (hasHeaderMap) {
            addParameter(report, ReportConstants.HEADER_MAP_PROVIDER_PARAMETER);
        }

    } catch (Throwable e) {
        throw new RuntimeException(e);
    }

}
项目:ireport-fork    文件:SubreportWizardIterator.java   
private void configureElement(JRDesignSubreport element) throws IOException, JRException
{
    Boolean useSubParam  = (Boolean)wizard.getProperty("addsubreportparameter");
        String exp = (String)wizard.getProperty("subreportexpression");
        String subreport_directory = (String)wizard.getProperty("subreport_directory");
        String con_exp = (String)wizard.getProperty("subreport_connection_expression");
        String ds_exp = (String)wizard.getProperty("subreport_datasource_expression");

        JRParameter[] sub_params = (JRParameter[])wizard.getProperty("subreport_parameters");
        String[] params_expressions = (String[])wizard.getProperty("subreport_parameters_values");

        if (useSubParam != null && useSubParam.booleanValue())
        {
            JasperDesign jd = IReportManager.getInstance().getActiveReport();

            if (!jd.getParametersMap().containsKey("SUBREPORT_DIR"))
            {
            JRDesignParameter param = new JRDesignParameter();
            param.setName("SUBREPORT_DIR");
            param.setForPrompting(false);
            // TODO: set as directory the target directory for compiled files....
            if (subreport_directory == null)
            {
                subreport_directory = Misc.getDataFolderPath( ((TemplateWizard)wizard).getTargetFolder() ) + File.separator;
            }
            subreport_directory = Misc.string_replace("\\\\","\\",subreport_directory);
            subreport_directory = "\"" + subreport_directory + "\"";
            param.setDefaultValueExpression( Misc.createExpression("java.lang.String", subreport_directory));
            param.setValueClassName("java.lang.String");

            // add the parameter to the document...
                try {
                    jd.addParameter(param);
                } catch (JRException ex)
                {}
            }
        }

        if (exp != null)
        {
            element.setExpression( Misc.createExpression("java.lang.String", exp) );
        }

        if (con_exp != null)
        {
            element.setConnectionExpression( Misc.createExpression("java.sql.Connection", con_exp) );
        }

        if (ds_exp != null)
        {
            element.setDataSourceExpression( Misc.createExpression("net.sf.jasperreports.engine.JRDataSource", ds_exp) );
        }

        if (sub_params != null && params_expressions != null)
        {
            for (int i=0; i<sub_params.length && i<params_expressions.length; ++i)
            {
                JRDesignSubreportParameter sp = new JRDesignSubreportParameter();
                sp.setName(  sub_params[i].getName() );
                sp.setExpression( Misc.createExpression(null, params_expressions[i] ) );
                element.addParameter(sp);
            }
        }
}
项目:ireport-fork    文件:JRSubreportParameterDialog.java   
/** Getter for property tmpParameter.
 * @return Value of property tmpParameter.
 *
 */
public JRDesignSubreportParameter getParameter() {
    return tmpParameter;
}