protected JRBaseDatasetParameter getDatasetParameter(JRDatasetParameter datasetParameter) { JRBaseDatasetParameter baseSubreportParameter = null; if (datasetParameter != null) { baseSubreportParameter = (JRBaseDatasetParameter) get(datasetParameter); if (baseSubreportParameter == null) { baseSubreportParameter = new JRBaseDatasetParameter(datasetParameter, this); put(datasetParameter, baseSubreportParameter); } } return baseSubreportParameter; }
/** * Adds a parameter value. * * @param parameter the parameter value * @throws JRException * @see net.sf.jasperreports.engine.JRDatasetRun#getParameters() */ public void addParameter(JRDatasetParameter parameter) throws JRException { if (parametersMap.containsKey(parameter.getName())) { throw new JRException( EXCEPTION_MESSAGE_KEY_DUPLICATE_PARAMETER, new Object[]{parameter.getName()}); } parametersMap.put(parameter.getName(), parameter); parametersList.add(parameter); getEventSupport().fireCollectionElementAddedEvent(PROPERTY_PARAMETERS, parameter, parametersList.size() - 1); }
/** * Removes a parameter value. * * @param parameterName the parameter name * @return the removed parameter value */ public JRDatasetParameter removeParameter(String parameterName) { JRDatasetParameter param = parametersMap.remove(parameterName); if (param != null) { int idx = parametersList.indexOf(param); if (idx >= 0) { parametersList.remove(idx); } getEventSupport().fireCollectionElementRemovedEvent(PROPERTY_PARAMETERS, param, idx); } return param; }
/** * Set the input of the table and of the combo viewer. On the table will be available a number of * rows equals to the number of parameters that the user can select * * @param table the table */ private void fillTable(Table table) { List<JRDatasetParameter> lst = new ArrayList<JRDatasetParameter>(Arrays.asList(value.getValue())); input = new ArrayList<JRDatasetParameter>(); for(JRDatasetParameter param : lst){ JRDesignDatasetParameter newParam = new JRDesignDatasetParameter(); newParam.setExpression(param.getExpression() != null ? (JRExpression)param.getExpression().clone() : null); newParam.setName(param.getName()); input.add(newParam); } Collections.sort(input, new Comparator<JRDatasetParameter>() { @Override public int compare(JRDatasetParameter o1, JRDatasetParameter o2) { return o1.getName().compareTo(o2.getName()); } }); tableViewer.setInput(input); }
private void fixDSParametersList() { JRDatasetParameter[] currParams = (JRDatasetParameter[]) tableViewerDatasetRunParams.getInput(); String datasetName = ""; JRDatasetRun jrDatasetRun = datasetRunInstance.getJRDatasetRun(); if(jrDatasetRun!=null) { datasetName = jrDatasetRun.getDatasetName(); List<JRParameter> parameters4Datasource = ModelUtils.getParameters4Datasource(datasetRunInstance.getEditableDataset().getJasperDesign(), datasetName); if(currParams!=null) { for(JRDatasetParameter p1 : currParams) { for(JRParameter p2 : parameters4Datasource) { if(p2.getName().equals(p1.getName())){ datasetRunInstance.addParameter((JRDatasetParameter) p1.clone()); break; } } } } tableViewerDatasetRunParams.setInput(datasetRunInstance.getJRDatasetRun().getParameters()); } else { // switching to main one tableViewerDatasetRunParams.getTable().clearAll(); } }
@Override public void execute() { ParameterDTO parameters = (ParameterDTO) element.getPropertyValue(JRDesignDatasetRun.PROPERTY_PARAMETERS); List<JRDatasetParameter> lst = new ArrayList<JRDatasetParameter>(Arrays.asList(parameters.getValue())); for (JRDatasetParameter param : lst) { if (param.getName() != null && param.getName().equals(oldName)) { try { // The parameter is removed and readded to have JR to update its internal structure (list and map) element.getValue().removeParameter(param); ((JRDesignDatasetParameter) param).setName(newName); element.getValue().addParameter(param); parameterFound = true; } catch (JRException e) { e.printStackTrace(); } // element.setPropertyValue(JRDesignDatasetRun.PROPERTY_PARAMETERS, parameters); // The parameter was found, i mark the flag to support the undo and exit the cycle when the parameter is found // since the aren't two parameters with the same name break; } } }
@Override public void undo() { if (parameterFound) { ParameterDTO parameters = (ParameterDTO) element.getPropertyValue(JRDesignDatasetRun.PROPERTY_PARAMETERS); List<JRDatasetParameter> lst = new ArrayList<JRDatasetParameter>(Arrays.asList(parameters.getValue())); for (JRDatasetParameter param : lst) { if (param.getName() != null && param.getName().equals(newName)) { try { // The parameter is removed and readded to have JR to update its internal structure (list and map) element.getValue().removeParameter(param); ((JRDesignDatasetParameter) param).setName(oldName); element.getValue().addParameter(param); } catch (JRException e) { e.printStackTrace(); } parameterFound = false; break; } } } }
private void jButtonRemParameterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRemParameterActionPerformed if (this.isInit()) return; if (getCurrentSelectedComponent() == null) return; javax.swing.table.DefaultTableModel dtm = (javax.swing.table.DefaultTableModel)jTableDatasetParameters.getModel(); JRDesignDatasetRun datasetRun = (JRDesignDatasetRun)getDesignDataset().getDatasetRun(); while (jTableDatasetParameters.getSelectedRowCount() > 0) { int i=jTableDatasetParameters.getSelectedRow(); datasetRun.removeParameter( ((JRDatasetParameter)jTableDatasetParameters.getValueAt( i, 0)).getName() ); dtm.removeRow(i); } notifyChange(); }
private void jButtonRemParameterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRemParameterActionPerformed if (this.isInit()) return; if (getCurrentSelectedChartComponent() == null) return; javax.swing.table.DefaultTableModel dtm = (javax.swing.table.DefaultTableModel)jTableDatasetParameters.getModel(); JRDesignDatasetRun datasetRun = (JRDesignDatasetRun)getCurrentSelectedChartComponent().getDataset().getDatasetRun(); while (jTableDatasetParameters.getSelectedRowCount() > 0) { int i=jTableDatasetParameters.getSelectedRow(); datasetRun.removeParameter( ((JRDatasetParameter)jTableDatasetParameters.getValueAt( i, 0)).getName() ); dtm.removeRow(i); } notifyChange(); }
private void jButtonRemParameterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRemParameterActionPerformed if (this.isInit()) return; if (currentSelectedChartElement == null) return; javax.swing.table.DefaultTableModel dtm = (javax.swing.table.DefaultTableModel)jTableDatasetParameters.getModel(); JRDesignDatasetRun datasetRun = (JRDesignDatasetRun)currentSelectedChartElement.getDataset().getDatasetRun(); while (jTableDatasetParameters.getSelectedRowCount() > 0) { int i=jTableDatasetParameters.getSelectedRow(); datasetRun.removeParameter( ((JRDatasetParameter)jTableDatasetParameters.getValueAt( i, 0)).getName() ); dtm.removeRow(i); } notifyChange(); }
private void jButtonRemParameterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRemParameterActionPerformed if (this.isInit()) return; if (currentSelectedCrosstabElement == null) return; javax.swing.table.DefaultTableModel dtm = (javax.swing.table.DefaultTableModel)jTableDatasetParameters.getModel(); JRDesignDatasetRun datasetRun = (JRDesignDatasetRun)currentSelectedCrosstabElement.getDataset().getDatasetRun(); while (jTableDatasetParameters.getSelectedRowCount() > 0) { int i=jTableDatasetParameters.getSelectedRow(); datasetRun.removeParameter( ((JRDatasetParameter)jTableDatasetParameters.getValueAt( i, 0)).getName() ); dtm.removeRow(i); } notifyChange(); }
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus,row, column); setIcon(null); if (value instanceof JRDatasetParameter && value != null) { setText( ((JRDatasetParameter)value).getName() ); } else if (value instanceof JRExpression) { JRExpression exp = (JRExpression)value; if (exp == null) setText(""); else if (exp.getText() == null) setText(""); else setText(exp.getText()); } return this; }
/** * */ protected JRBaseDatasetParameter(JRDatasetParameter datasetParameter, JRBaseObjectFactory factory) { factory.put(datasetParameter, this); name = datasetParameter.getName(); expression = factory.getExpression(datasetParameter.getExpression()); }
/** * Creates a copy of a dataset instantiation. * * @param datasetRun the dataset instantiation * @param factory the base object factory */ protected JRBaseDatasetRun(JRDatasetRun datasetRun, JRBaseObjectFactory factory) { factory.put(datasetRun, this); uuid = datasetRun.getUUID(); datasetName = datasetRun.getDatasetName(); parametersMapExpression = factory.getExpression(datasetRun.getParametersMapExpression()); connectionExpression = factory.getExpression(datasetRun.getConnectionExpression()); dataSourceExpression = factory.getExpression(datasetRun.getDataSourceExpression()); propertiesMap = JRPropertiesMap.getPropertiesClone(datasetRun); JRDatasetParameter[] datasetParams = datasetRun.getParameters(); if (datasetParams != null && datasetParams.length > 0) { parameters = new JRBaseDatasetParameter[datasetParams.length]; for (int i = 0; i < parameters.length; i++) { parameters[i] = factory.getDatasetParameter(datasetParams[i]); } } List<ReturnValue> datesetReturnValues = datasetRun.getReturnValues(); if (datesetReturnValues != null && !datesetReturnValues.isEmpty()) { this.returnValues = new ArrayList<ReturnValue>(datesetReturnValues.size()); for (ReturnValue datasetReturnValue : datesetReturnValues) { BaseReturnValue returnValue = factory.getReturnValue(datasetReturnValue); this.returnValues.add(returnValue); } } }
private static void addDatasetRules(Digester digester) { String subDatasetPattern = "jasperReport/" + JRXmlConstants.ELEMENT_subDataset; digester.addFactoryCreate(subDatasetPattern, JRDatasetFactory.class.getName()); digester.addSetNext(subDatasetPattern, "addDataset", JRDesignDataset.class.getName()); String datasetRunPattern = "*/" + JRXmlConstants.ELEMENT_datasetRun; digester.addFactoryCreate(datasetRunPattern, JRDatasetRunFactory.class.getName()); digester.addSetNext(datasetRunPattern, "setDatasetRun", JRDatasetRun.class.getName()); String datasetParamPattern = datasetRunPattern + "/" + JRXmlConstants.ELEMENT_datasetParameter; digester.addFactoryCreate(datasetParamPattern, JRDatasetRunParameterFactory.class.getName()); digester.addSetNext(datasetParamPattern, "addParameter", JRDatasetParameter.class.getName()); String datasetParamExprPattern = datasetParamPattern + "/" + JRXmlConstants.ELEMENT_datasetParameterExpression; digester.addFactoryCreate(datasetParamExprPattern, JRExpressionFactory.class.getName()); digester.addSetNext(datasetParamExprPattern, "setExpression", JRExpression.class.getName()); digester.addCallMethod(datasetParamExprPattern, "setText", 0); String returnValuePattern = datasetRunPattern + "/" + JRXmlConstants.ELEMENT_returnValue; digester.addObjectCreate(returnValuePattern, DesignReturnValue.class.getName()); digester.addSetProperties(returnValuePattern, new String[]{JRXmlConstants.ATTRIBUTE_incrementerFactoryClass, JRXmlConstants.ATTRIBUTE_calculation}, new String[]{"incrementerFactoryClassName"}); digester.addRule(returnValuePattern, new XmlConstantPropertyRule( JRXmlConstants.ATTRIBUTE_calculation, CalculationEnum.values())); digester.addSetNext(returnValuePattern, "addReturnValue"); }
private void writeDatasetParameter(JRDatasetParameter datasetParameter) throws IOException { writer.startElement(JRXmlConstants.ELEMENT_datasetParameter); writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_name, datasetParameter.getName()); writeExpression(JRXmlConstants.ELEMENT_datasetParameterExpression, datasetParameter.getExpression(), false); writer.closeElement(); }
/** * */ private void writeDatasetParameter( JRDatasetParameter datasetParameter, String runName, String datasetParameterName) { if(datasetParameter != null) { write( "JRDesignDatasetParameter " + datasetParameterName + " = new JRDesignSubreportParameter();\n"); write( datasetParameterName + ".setName(\"{0}\");\n", JRStringUtil.escapeJavaStringLiteral(datasetParameter.getName())); writeExpression( datasetParameter.getExpression(), datasetParameterName, "Expression"); write( runName + ".addParameter(" + datasetParameterName + ");\n"); flush(); } }
/** * Outputs the XML representation of a subdataset run object. * * @param datasetRun the subdataset run */ public void writeDatasetRun( JRDatasetRun datasetRun, String parentName) { if(datasetRun != null) { String runName = parentName + "Run"; write( "JRDesignDatasetRun " + runName + " = new JRDesignDatasetRun();\n"); write( runName + ".setDatasetName(\"{0}\");\n", JRStringUtil.escapeJavaStringLiteral(datasetRun.getDatasetName())); writeExpression( datasetRun.getParametersMapExpression(), runName, "ParametersMapExpression"); JRDatasetParameter[] parameters = datasetRun.getParameters(); if (parameters != null && parameters.length > 0) { for(int i = 0; i < parameters.length; i++) { writeDatasetParameter( parameters[i], runName, runName + "Parameter" + i); } } writeExpression( datasetRun.getConnectionExpression(), runName, "ConnectionExpression"); writeExpression( datasetRun.getDataSourceExpression(), runName, "DataSourceExpression"); List<ReturnValue> returnValues = datasetRun.getReturnValues(); if (returnValues != null && !returnValues.isEmpty()) { for (ListIterator<ReturnValue> it = returnValues.listIterator(); it.hasNext();) { ReturnValue returnValue = it.next(); String returnValueVarName = runName + "ReturnValue" + it.previousIndex(); writeReturnValue(returnValue, returnValueVarName); write(runName + ".addReturnValue(" + returnValueVarName + ");\n"); } } write( parentName + ".setDatasetRun(" + runName + ");\n"); flush(); } }
/** * Creates an empty dataset instantiation. */ public JRDesignDatasetRun() { parametersMap = new HashMap<String, JRDatasetParameter>(); parametersList = new ArrayList<JRDatasetParameter>(); returnValues = new ArrayList<ReturnValue>(2); }
@Override public JRDatasetParameter[] getParameters() { JRDatasetParameter[] params = new JRDatasetParameter[parametersList.size()]; parametersList.toArray(params); return params; }
/** * Utility method used for constructing a parameter values map for subreports, sub datasets and crosstabs. * * @param filler report filler * @param parametersMapExpression expression that yields bulk parameter values map * @param subreportParameters list of individual parameter values * @param evaluation evaluation type * @param ignoreNullExpressions whether to ignore individual parameter value expressions * @param removeResourceBundle whether to remove the {@link JRParameter#REPORT_RESOURCE_BUNDLE REPORT_RESOURCE_BUNDLE} * value from the bulk values map * @return the parameter values map * @throws JRException */ public static Map<String, Object> getParameterValues( BaseReportFiller filler, JRExpression parametersMapExpression, JRDatasetParameter[] subreportParameters, byte evaluation, boolean ignoreNullExpressions, boolean removeResourceBundle, boolean removeFormatFactory ) throws JRException { return getParameterValues(filler, filler.getExpressionEvaluator(), parametersMapExpression, subreportParameters, evaluation, ignoreNullExpressions, removeResourceBundle, removeFormatFactory); }
public TableSubreport(JRDatasetRun datasetRun, JRComponentElement componentElement) { super(componentElement); this.datasetRun = datasetRun; JRDatasetParameter[] datasetParameters = datasetRun.getParameters(); if (datasetParameters == null) { this.parameters = null; } else { this.parameters = new JRSubreportParameter[datasetParameters.length]; for (int i = 0; i < datasetParameters.length; i++) { JRDatasetParameter datasetParameter = datasetParameters[i]; TableSubreportParameter subreportParameter = new TableSubreportParameter(datasetParameter); this.parameters[i] = subreportParameter; } } List<ReturnValue> datasetReturnValues = datasetRun.getReturnValues(); if (datasetReturnValues == null || datasetReturnValues.isEmpty()) { returnValues = null; } else { returnValues = new JRSubreportReturnValue[datasetReturnValues.size()]; for (ListIterator<ReturnValue> it = datasetReturnValues.listIterator(); it.hasNext();) { ReturnValue returnValue = it.next(); returnValues[it.previousIndex()] = new SubreportReturnValueAdapter(returnValue); } } }
/** * Return the list (not null) of parameters that need to be added to the passed dataset run * * @param the dataset run to check * @return a not null list of string, representing the missing parameters name */ private List<String> getMissingParameterOnDatasetRun(MDatasetRun datasetRun){ List<String> result = new ArrayList<String>(); JRDatasetParameter[] parameters = datasetRun.getValue().getParameters(); HashSet<String> definedParameters = new HashSet<String>(); for(JRDatasetParameter parameter : parameters){ definedParameters.add(parameter.getName()); } for(String neededParameter : NEDDED_PARAMETERS){ if (!definedParameters.contains(neededParameter)) result.add(neededParameter); } return result; }
public String getColumnText(Object element, int columnIndex) { switch (columnIndex) { case 0: return ((JRDatasetParameter) element).getName(); case 1: JRDatasetParameter value2 = (JRDatasetParameter) element; if (value2 != null && value2.getExpression() != null) return value2.getExpression().getText(); } return ""; //$NON-NLS-1$ }
@Override public void dispose() { // clear all properties List<JRDatasetParameter> props = (List<JRDatasetParameter>) tableViewer.getInput(); value = new ParameterDTO(); value.setValue(props.toArray(new JRDatasetParameter[props.size()])); super.dispose(); }
/** * When the dialog is disposed the return value is update */ @Override public void dispose() { value = new ParameterDTO(); value.setJasperDesign(value.getJasperDesign()); List<JRDatasetParameter> returnValues = new ArrayList<JRDatasetParameter>(); for(JRDatasetParameter param : input){ if (param.getName() != null && !param.getName().isEmpty()) returnValues.add(param); } value.setValue(returnValues.toArray(new JRDatasetParameter[returnValues.size()])); super.dispose(); }
@Override public String getText(Object element) { if (element!=null){ return ((JRDatasetParameter)element).getName(); } return null; }
@Override public String getText(Object element) { if (element!=null){ JRExpression expression = ((JRDatasetParameter)element).getExpression(); if (expression!=null){ return expression.getText(); } } return null; }
public static void cleanDatasetRun(Object[] bprms, JRDesignDatasetRun dr) throws JRException { if (dr.getDataSourceExpression() != null) return; for (int i = 0; i < bprms.length; i += 2) { String pname = (String) bprms[i]; JRDatasetParameter p = getParameter(dr, pname); if (p.getExpression() != null && p.getExpression().getText() != null && p.getExpression().getText().equals("$P{" + pname + "}")) dr.removeParameter(p); } }
public void addParameter(JRDatasetParameter newParameter) { if (!useReportMainDataset()){ try { datasetRun.addParameter(newParameter); } catch (JRException e) { UIUtils.showError(e); } } }
private void jButtonAddParameterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddParameterActionPerformed if (this.isInit()) return; if (getCurrentSelectedComponent() == null) return; // Set the new value for all selected elements... java.util.HashMap map = new java.util.HashMap(); java.util.List<JRDatasetParameter> params = Arrays.asList(getDesignDataset().getDatasetRun().getParameters()); for (JRDatasetParameter p : params) { map.put(p.getName(), p); } Object pWin = SwingUtilities.windowForComponent(this); JRDatasetParameterDialog jrpd = null; if (pWin instanceof Dialog) jrpd = new JRDatasetParameterDialog((Dialog)pWin,map, (JRDesignDataset)getJasperDesign().getDatasetMap().get(getDesignDataset().getDatasetRun().getDatasetName())); else jrpd = new JRDatasetParameterDialog((Frame)pWin,map, (JRDesignDataset)getJasperDesign().getDatasetMap().get(getDesignDataset().getDatasetRun().getDatasetName())); ExpressionContext docEc = new ExpressionContext( getJasperDesign().getMainDesignDataset() ); jrpd.setExpressionContext(docEc); jrpd.setVisible(true); if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) { JRDesignDatasetParameter parameter = jrpd.getParameter(); try { ((JRDesignDatasetRun)getDesignDataset().getDatasetRun()).addParameter( parameter ); javax.swing.table.DefaultTableModel dtm = (javax.swing.table.DefaultTableModel)jTableDatasetParameters.getModel(); dtm.addRow(new Object[]{parameter, parameter.getExpression()}); notifyChange(); } catch (Exception ex) { ex.printStackTrace(); } } }
private void jButtonAddParameterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddParameterActionPerformed if (this.isInit()) return; if (getCurrentSelectedChartComponent() == null) return; // Set the new value for all selected elements... java.util.HashMap map = new java.util.HashMap(); java.util.List<JRDatasetParameter> params = Arrays.asList(getCurrentSelectedChartComponent().getDataset().getDatasetRun().getParameters()); for (JRDatasetParameter p : params) { map.put(p.getName(), p); } Object pWin = SwingUtilities.windowForComponent(this); JRDatasetParameterDialog jrpd = null; if (pWin instanceof Dialog) jrpd = new JRDatasetParameterDialog((Dialog)pWin,map, (JRDesignDataset)getJasperDesign().getDatasetMap().get(getCurrentSelectedChartComponent().getDataset().getDatasetRun().getDatasetName())); else jrpd = new JRDatasetParameterDialog((Frame)pWin,map, (JRDesignDataset)getJasperDesign().getDatasetMap().get(getCurrentSelectedChartComponent().getDataset().getDatasetRun().getDatasetName())); ExpressionContext docEc = new ExpressionContext( getJasperDesign().getMainDesignDataset() ); jrpd.setExpressionContext(docEc); jrpd.setVisible(true); if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) { JRDesignDatasetParameter parameter = jrpd.getParameter(); try { ((JRDesignDatasetRun)getCurrentSelectedChartComponent().getDataset().getDatasetRun()).addParameter( parameter ); javax.swing.table.DefaultTableModel dtm = (javax.swing.table.DefaultTableModel)jTableDatasetParameters.getModel(); dtm.addRow(new Object[]{parameter, parameter.getExpression()}); notifyChange(); } catch (Exception ex) { ex.printStackTrace(); } } }
private void jButtonAddParameterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddParameterActionPerformed if (this.isInit() || datasetRun == null) return; // Set the new value for all selected elements... java.util.HashMap map = new java.util.HashMap(); java.util.List<JRDatasetParameter> params = Arrays.asList(datasetRun.getParameters()); for (JRDatasetParameter p : params) { map.put(p.getName(), p); } Object pWin = SwingUtilities.windowForComponent(this); JRDatasetParameterDialog jrpd = null; if (pWin instanceof Dialog) jrpd = new JRDatasetParameterDialog((Dialog)pWin,map, (JRDesignDataset)getJasperDesign().getDatasetMap().get(datasetRun.getDatasetName())); else jrpd = new JRDatasetParameterDialog((Frame)pWin,map, (JRDesignDataset)getJasperDesign().getDatasetMap().get(datasetRun.getDatasetName())); ExpressionContext docEc = new ExpressionContext( getJasperDesign().getMainDesignDataset() ); jrpd.setExpressionContext(docEc); jrpd.setVisible(true); if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) { JRDesignDatasetParameter parameter = jrpd.getParameter(); try { datasetRun.addParameter( parameter ); javax.swing.table.DefaultTableModel dtm = (javax.swing.table.DefaultTableModel)jTableDatasetParameters.getModel(); dtm.addRow(new Object[]{parameter, parameter.getExpression()}); } catch (Exception ex) { ex.printStackTrace(); } } }
private void jButtonRemParameterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRemParameterActionPerformed if (this.isInit() || datasetRun == null) return; javax.swing.table.DefaultTableModel dtm = (javax.swing.table.DefaultTableModel)jTableDatasetParameters.getModel(); while (jTableDatasetParameters.getSelectedRowCount() > 0) { int i=jTableDatasetParameters.getSelectedRow(); datasetRun.removeParameter( ((JRDatasetParameter)jTableDatasetParameters.getValueAt( i, 0)).getName() ); dtm.removeRow(i); } }
@SuppressWarnings("unchecked") private void jButtonAddParameterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddParameterActionPerformed if (this.isInit()) return; if (currentSelectedChartElement == null) return; // Set the new value for all selected elements... java.util.HashMap map = new java.util.HashMap(); java.util.List<JRDatasetParameter> params = Arrays.asList(currentSelectedChartElement.getDataset().getDatasetRun().getParameters()); for (JRDatasetParameter p : params) { map.put(p.getName(), p); } Object pWin = SwingUtilities.windowForComponent(this); JRDatasetParameterDialog jrpd = null; if (pWin instanceof Dialog) jrpd = new JRDatasetParameterDialog((Dialog)pWin,map, (JRDesignDataset)getJasperDesign().getDatasetMap().get(currentSelectedChartElement.getDataset().getDatasetRun().getDatasetName())); else jrpd = new JRDatasetParameterDialog((Frame)pWin,map, (JRDesignDataset)getJasperDesign().getDatasetMap().get(currentSelectedChartElement.getDataset().getDatasetRun().getDatasetName())); ExpressionContext docEc = new ExpressionContext( getJasperDesign().getMainDesignDataset() ); jrpd.setExpressionContext(docEc); jrpd.setVisible(true); if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) { JRDesignDatasetParameter parameter = jrpd.getParameter(); try { ((JRDesignDatasetRun)currentSelectedChartElement.getDataset().getDatasetRun()).addParameter( parameter ); javax.swing.table.DefaultTableModel dtm = (javax.swing.table.DefaultTableModel)jTableDatasetParameters.getModel(); dtm.addRow(new Object[]{parameter, parameter.getExpression()}); notifyChange(); } catch (Exception ex) { ex.printStackTrace(); } } }
@SuppressWarnings("unchecked") private void jButtonAddParameterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddParameterActionPerformed if (this.isInit()) return; if (currentSelectedCrosstabElement == null) return; // Set the new value for all selected elements... java.util.HashMap map = new java.util.HashMap(); java.util.List<JRDatasetParameter> params = Arrays.asList(currentSelectedCrosstabElement.getDataset().getDatasetRun().getParameters()); for (JRDatasetParameter p : params) { map.put(p.getName(), p); } Object pWin = SwingUtilities.windowForComponent(this); JRDatasetParameterDialog jrpd = null; if (pWin instanceof Dialog) jrpd = new JRDatasetParameterDialog((Dialog)pWin,map, (JRDesignDataset)getJasperDesign().getDatasetMap().get(currentSelectedCrosstabElement.getDataset().getDatasetRun().getDatasetName())); else jrpd = new JRDatasetParameterDialog((Frame)pWin,map, (JRDesignDataset)getJasperDesign().getDatasetMap().get(currentSelectedCrosstabElement.getDataset().getDatasetRun().getDatasetName())); ExpressionContext docEc = new ExpressionContext( getJasperDesign().getMainDesignDataset() ); jrpd.setExpressionContext(docEc); jrpd.setVisible(true); if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) { JRDesignDatasetParameter parameter = jrpd.getParameter(); try { ((JRDesignDatasetRun)currentSelectedCrosstabElement.getDataset().getDatasetRun()).addParameter( parameter ); javax.swing.table.DefaultTableModel dtm = (javax.swing.table.DefaultTableModel)jTableDatasetParameters.getModel(); dtm.addRow(new Object[]{parameter, parameter.getExpression()}); notifyChange(); } catch (Exception ex) { ex.printStackTrace(); } } }
@Override public JRDatasetParameter[] getParameters() { return parameters; }
/** * Outputs the XML representation of a subdataset run object. * * @param datasetRun the subdataset run * @throws IOException */ public void writeDatasetRun(JRDatasetRun datasetRun) throws IOException { writer.startElement(JRXmlConstants.ELEMENT_datasetRun, getNamespace()); writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_subDataset, datasetRun.getDatasetName()); if (isNewerVersionOrEqual(JRConstants.VERSION_4_6_0)) { if (!isExcludeUuids()) { writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_uuid, datasetRun.getUUID().toString()); } writeProperties(datasetRun); } writeExpression(JRXmlConstants.ELEMENT_parametersMapExpression, datasetRun.getParametersMapExpression(), false); /* */ JRDatasetParameter[] parameters = datasetRun.getParameters(); if (parameters != null && parameters.length > 0) { for(int i = 0; i < parameters.length; i++) { writeDatasetParameter(parameters[i]); } } writeExpression(JRXmlConstants.ELEMENT_connectionExpression, datasetRun.getConnectionExpression(), false); writeExpression(JRXmlConstants.ELEMENT_dataSourceExpression, datasetRun.getDataSourceExpression(), false); List<ReturnValue> returnValues = datasetRun.getReturnValues(); if (returnValues != null && !returnValues.isEmpty()) { for (ReturnValue returnValue : returnValues) { writeReturnValue(returnValue); } } writer.closeElement(); }
/** * Verifies a subdataset run object. * * @param datasetRun the subdataset run */ public void verifyDatasetRun(JRDatasetRun datasetRun) { JRDesignDataset dataset = null; String datasetName = datasetRun.getDatasetName(); if (datasetName == null || datasetName.length() == 0) { addBrokenRule("Dataset name is missing for dataset run.", datasetRun); } else { dataset = (JRDesignDataset) jasperDesign.getDatasetMap().get(datasetName); if (dataset == null) { addBrokenRule("Unknown dataset name " + datasetName + ".", datasetRun); } } JRDatasetParameter[] parameters = datasetRun.getParameters(); if (parameters != null && parameters.length > 0) { for(int index = 0; index < parameters.length; index++) { JRDatasetParameter parameter = parameters[index]; String paramName = parameter.getName(); if (paramName == null || paramName.trim().length() == 0) { addBrokenRule("Dataset " + datasetName + " parameter name missing.", parameter); } JRParameter datasetParam = null; if (dataset != null) { datasetParam = dataset.getParametersMap().get(paramName); if (datasetParam == null) { addBrokenRule("Unknown parameter " + paramName + " in dataset " + datasetName + ".", parameter); } } } } JRExpression connectionExpression = datasetRun.getConnectionExpression(); JRExpression dataSourceExpression = datasetRun.getDataSourceExpression(); if (connectionExpression != null && dataSourceExpression != null) { addBrokenRule("Dataset " + datasetName + " cannot have both connection expresion and data source expression.", datasetRun); } List<ReturnValue> returnValues = datasetRun.getReturnValues(); if (returnValues != null && !returnValues.isEmpty()) { for (ReturnValue returnValue : returnValues) { verifyReturnValue(returnValue); } } }