/** * 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); }
@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; } } } }
@Override public Object createObject(Attributes atts) { JRDesignDatasetParameter datasetParameter = new JRDesignDatasetParameter(); datasetParameter.setName(atts.getValue(JRXmlConstants.ATTRIBUTE_name)); return datasetParameter; }
public static void setupDatasetRun(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]; if (getParameter(dr, pname) != null) continue; JRDesignDatasetParameter prm = new JRDesignDatasetParameter(); prm.setName(pname); prm.setExpression(new JRDesignExpression("$P{" + pname + "}")); dr.addParameter(prm); } // cleanup? }
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(); } } }
@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(); } } }
private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed JRParameter param = (JRParameter) this.jComboBox1.getSelectedItem(); if (param == null) { javax.swing.JOptionPane.showMessageDialog(this, I18n.getString("JRDatasetParameterDialog.Message.Warning"), I18n.getString("JRDatasetParameterDialog.Message.Error"), javax.swing.JOptionPane.WARNING_MESSAGE ); return; } String newName = param.getName(); if (oldName != null && !oldName.equals(newName) && currentParameters != null && currentParameters.containsKey(newName)) { javax.swing.JOptionPane.showMessageDialog(this, I18n.getString("JRDatasetParameterDialog.Message.Warning2"), I18n.getString("JRFontPanel.Message.Error2"), javax.swing.JOptionPane.WARNING_MESSAGE ); return; } tmpParameter = new JRDesignDatasetParameter(); tmpParameter.setName(newName); JRDesignExpression exp = new JRDesignExpression(); exp.setText(this.jRTextExpressionAreaDefaultExpression.getText()); exp.setValueClassName(param.getValueClassName()); tmpParameter.setExpression(exp); setVisible(false); this.setDialogResult( javax.swing.JOptionPane.OK_OPTION); dispose(); }
/** Setter for property tmpParameter. * @param tmpParameter New value of property tmpParameter. * */ public void setParameter(JRDesignDatasetParameter tmpParameter) { for (int i=0; i<jComboBox1.getItemCount(); ++i) { JRParameter p = (JRParameter) jComboBox1.getItemAt(i); if (p.getName().equals(tmpParameter.getName())) { jComboBox1.setSelectedItem(p); break; } } //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 ); }
/** * Create the dialog. * @param parentShell */ public DatasetRunPameterDialog(JRDesignDatasetParameter datasetParameter, JRDesignDataset dataset, Shell parentShell) { super(parentShell); this.datasetParameter=datasetParameter; this.dataset=dataset; }
private void jButtonModParameterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonModParameterActionPerformed if (this.isInit()) return; if (getCurrentSelectedComponent() == null) return; int rowNumber = jTableDatasetParameters.getSelectedRow(); JRDesignDatasetParameter parameter = (JRDesignDatasetParameter)jTableDatasetParameters.getValueAt( jTableDatasetParameters.getSelectedRow(), 0); 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.setParameter( parameter ); /* if (subdatasetParameterHighlightExpression != null) { jrpd.setFocusedExpression( ((Integer)subdatasetParameterHighlightExpression[0]).intValue() ); } */ jrpd.setVisible(true); if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) { parameter.setName( jrpd.getParameter().getName() ); parameter.setExpression( jrpd.getParameter().getExpression()); javax.swing.table.DefaultTableModel dtm = (javax.swing.table.DefaultTableModel)jTableDatasetParameters.getModel(); dtm.setValueAt(parameter, rowNumber, 0); dtm.setValueAt(parameter.getExpression(), rowNumber, 1); jTableDatasetParameters.updateUI(); notifyChange(); } }
private void jButtonModParameterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonModParameterActionPerformed if (this.isInit()) return; if (getCurrentSelectedChartComponent() == null) return; int rowNumber = jTableDatasetParameters.getSelectedRow(); JRDesignDatasetParameter parameter = (JRDesignDatasetParameter)jTableDatasetParameters.getValueAt( jTableDatasetParameters.getSelectedRow(), 0); 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.setParameter( parameter ); /* if (subdatasetParameterHighlightExpression != null) { jrpd.setFocusedExpression( ((Integer)subdatasetParameterHighlightExpression[0]).intValue() ); } */ jrpd.setVisible(true); if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) { parameter.setName( jrpd.getParameter().getName() ); parameter.setExpression( jrpd.getParameter().getExpression()); javax.swing.table.DefaultTableModel dtm = (javax.swing.table.DefaultTableModel)jTableDatasetParameters.getModel(); dtm.setValueAt(parameter, rowNumber, 0); dtm.setValueAt(parameter.getExpression(), rowNumber, 1); jTableDatasetParameters.updateUI(); notifyChange(); } }
@SuppressWarnings("unchecked") private void jButtonModParameterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonModParameterActionPerformed if (this.isInit()) return; if (currentSelectedChartElement == null) return; int rowNumber = jTableDatasetParameters.getSelectedRow(); JRDesignDatasetParameter parameter = (JRDesignDatasetParameter)jTableDatasetParameters.getValueAt( jTableDatasetParameters.getSelectedRow(), 0); 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.setParameter( parameter ); /* if (subdatasetParameterHighlightExpression != null) { jrpd.setFocusedExpression( ((Integer)subdatasetParameterHighlightExpression[0]).intValue() ); } */ jrpd.setVisible(true); if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) { parameter.setName( jrpd.getParameter().getName() ); parameter.setExpression( jrpd.getParameter().getExpression()); javax.swing.table.DefaultTableModel dtm = (javax.swing.table.DefaultTableModel)jTableDatasetParameters.getModel(); dtm.setValueAt(parameter, rowNumber, 0); dtm.setValueAt(parameter.getExpression(), rowNumber, 1); jTableDatasetParameters.updateUI(); notifyChange(); } }
@SuppressWarnings("unchecked") private void jButtonModParameterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonModParameterActionPerformed if (this.isInit()) return; if (currentSelectedCrosstabElement == null) return; int rowNumber = jTableDatasetParameters.getSelectedRow(); JRDesignDatasetParameter parameter = (JRDesignDatasetParameter)jTableDatasetParameters.getValueAt( jTableDatasetParameters.getSelectedRow(), 0); 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.setParameter( parameter ); /* if (subdatasetParameterHighlightExpression != null) { jrpd.setFocusedExpression( ((Integer)subdatasetParameterHighlightExpression[0]).intValue() ); } */ jrpd.setVisible(true); if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) { parameter.setName( jrpd.getParameter().getName() ); parameter.setExpression( jrpd.getParameter().getExpression()); javax.swing.table.DefaultTableModel dtm = (javax.swing.table.DefaultTableModel)jTableDatasetParameters.getModel(); dtm.setValueAt(parameter, rowNumber, 0); dtm.setValueAt(parameter.getExpression(), rowNumber, 1); jTableDatasetParameters.updateUI(); notifyChange(); } }
/** * Gets the modified dataset parameter. * * @return the edited parameter */ public JRDesignDatasetParameter getModifiedDatasetParameter(){ return datasetParameter; }
/** Getter for property tmpParameter. * @return Value of property tmpParameter. * */ public JRDesignDatasetParameter getParameter() { return tmpParameter; }