Java Code Examples for org.pentaho.reporting.engine.classic.core.MasterReport#getParameterDefinition()

The following examples show how to use org.pentaho.reporting.engine.classic.core.MasterReport#getParameterDefinition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParameterEditUndoEntry.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void undo( final ReportDocumentContext renderContext ) {
  final AbstractReportDefinition abstractReportDefinition = renderContext.getReportDefinition();
  if ( abstractReportDefinition instanceof MasterReport == false ) {
    return;
  }
  final MasterReport report = (MasterReport) abstractReportDefinition;
  final ReportParameterDefinition definition = report.getParameterDefinition();
  if ( definition instanceof ModifiableReportParameterDefinition == false ) {
    return;
  }

  final ModifiableReportParameterDefinition mdef = (ModifiableReportParameterDefinition) definition;
  if ( newElement != null ) {
    mdef.removeParameterDefinition( position );
    clearParameterValues( report );
    report.notifyNodeChildRemoved( newElement );
  }
  if ( oldElement != null ) {
    mdef.addParameterDefinition( position, oldElement );
    clearParameterValues( report );
    report.notifyNodeChildAdded( oldElement );
  }
}
 
Example 2
Source File: PreviewParametersDialog.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static boolean process( final Window parent, final MasterReport masterReport ) {
  if ( masterReport == null ) {
    throw new NullPointerException();
  }
  final ReportParameterDefinition parameterDefinition = masterReport.getParameterDefinition();
  if ( parameterDefinition.getParameterCount() == 0 ) {
    return true;
  }

  // if all parameters are hidden, then nothing to do
  if ( isAllParametersHidden( masterReport, parameterDefinition ) ) {
    return true;
  }

  final PreviewParametersDialog parametersDialog;
  if ( parent instanceof Frame ) {
    parametersDialog = new PreviewParametersDialog( (Frame) parent, masterReport );
  } else if ( parent instanceof Dialog ) {
    parametersDialog = new PreviewParametersDialog( (Dialog) parent, masterReport );
  } else {
    parametersDialog = new PreviewParametersDialog( masterReport );
  }

  parametersDialog.setVisible( true );
  return parametersDialog.isConfirmed();
}
 
Example 3
Source File: ParameterEditUndoEntry.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void redo( final ReportDocumentContext renderContext ) {
  final AbstractReportDefinition abstractReportDefinition = renderContext.getReportDefinition();
  if ( abstractReportDefinition instanceof MasterReport == false ) {
    return;
  }
  final MasterReport report = (MasterReport) abstractReportDefinition;
  final ReportParameterDefinition definition = report.getParameterDefinition();
  if ( definition instanceof ModifiableReportParameterDefinition == false ) {
    return;
  }

  final ModifiableReportParameterDefinition mdef = (ModifiableReportParameterDefinition) definition;
  if ( oldElement != null ) {
    mdef.removeParameterDefinition( position );
    clearParameterValues( report );
    report.notifyNodeChildRemoved( oldElement );
  }
  if ( newElement != null ) {
    mdef.addParameterDefinition( position, newElement );
    clearParameterValues( report );
    report.notifyNodeChildAdded( newElement );
  }
}
 
Example 4
Source File: StateUtilities.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Computes the parameter value set for a given report. Note that this method ignores the validation result, so if the
 * specified parameter values are wrong you may end up with a bunch of default values.
 *
 * @param report
 * @return
 * @throws ReportProcessingException
 */
public static ReportParameterValues computeParameterValueSet( final MasterReport report )
  throws ReportProcessingException {

  final ReportParameterDefinition parameters = report.getParameterDefinition();
  final DefaultParameterContext parameterContext = new DefaultParameterContext( report );

  final ReportParameterValues parameterValues;
  try {
    final ReportParameterValidator reportParameterValidator = parameters.getValidator();
    final ValidationResult validationResult =
        reportParameterValidator.validate( new ValidationResult(), parameters, parameterContext );
    parameterValues = validationResult.getParameterValues();
    return computeParameterValueSet( report, parameterValues );
  } finally {
    parameterContext.close();
  }
}
 
Example 5
Source File: Prd4579IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testParameterLoadSave() throws Exception {
  DefaultListParameter param =
      new DefaultListParameter( "dummy-query", "", "", "parameter", false, false, String.class );
  DefaultParameterDefinition pdef = new DefaultParameterDefinition();
  pdef.addParameterDefinition( param );

  MasterReport report = new MasterReport();
  report.setParameterDefinition( pdef );
  MasterReport result = ReportWritingUtil.saveAndLoad( report );
  ReportParameterDefinition parameterDefinition = result.getParameterDefinition();
  assertEquals( 1, parameterDefinition.getParameterCount() );

  ParameterDefinitionEntry resultParam = parameterDefinition.getParameterDefinition( 0 );
  assertTrue( resultParam instanceof DefaultListParameter );
  DefaultListParameter lp = (DefaultListParameter) resultParam;
  assertEquals( "", lp.getKeyColumn() );
  assertEquals( "", lp.getTextColumn() );
  assertEquals( "dummy-query", lp.getQueryName() );
}
 
Example 6
Source File: LayerDownAction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected UndoEntry moveParameters( final AbstractReportDefinition report, final Object element ) {
  if ( report instanceof MasterReport == false ) {
    return null;
  }
  final MasterReport mr = (MasterReport) report;
  final ReportParameterDefinition definition = mr.getParameterDefinition();
  if ( definition instanceof ModifiableReportParameterDefinition == false ) {
    return null;
  }

  final ModifiableReportParameterDefinition dpd = (ModifiableReportParameterDefinition) definition;
  final ParameterDefinitionEntry[] entries = dpd.getParameterDefinitions();
  for ( int i = 0; i < entries.length; i++ ) {
    final ParameterDefinitionEntry entry = entries[ i ];
    if ( element == entry ) {
      if ( dpd.getParameterCount() > i + 1 ) {
        dpd.removeParameterDefinition( i );
        dpd.addParameterDefinition( i + 1, entry );
        report.fireModelLayoutChanged( report, ReportModelEvent.NODE_STRUCTURE_CHANGED, entry );
        return new CompoundUndoEntry
          ( new ParameterEditUndoEntry( i, entry, null ), new ParameterEditUndoEntry( i + 1, null, entry ) );
      }
    }
  }
  return null;
}
 
Example 7
Source File: InsertationUtil.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static Object insertParameter( final AbstractReportDefinition report,
                                       final ParameterDefinitionEntry fromClipboard ) {
  if ( ( report instanceof MasterReport ) == false ) {
    return null;
  }

  final MasterReport masterReportElement = (MasterReport) report;
  final ParameterDefinitionEntry pe = (ParameterDefinitionEntry) fromClipboard;
  try {
    final ModifiableReportParameterDefinition definition =
      (ModifiableReportParameterDefinition) masterReportElement.getParameterDefinition();
    final ParameterDefinitionEntry definitionEntry = (ParameterDefinitionEntry) pe.clone();
    definition.addParameterDefinition( definitionEntry );
    report.notifyNodeChildAdded( definitionEntry );
    return definitionEntry;
  } catch ( CloneNotSupportedException e1 ) {
    // ignore ..
    UncaughtExceptionsModel.getInstance().addException( e1 );
    return null;
  }
}
 
Example 8
Source File: JdbcQueryDesignerDialog.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void actionPerformed( final ActionEvent arg0 ) {
  try {
    final String query = getQuery();
    final DataPreviewDialog dialog = new DataPreviewDialog( JdbcQueryDesignerDialog.this );

    MasterReport report = (MasterReport) designTimeContext.getReport();
    ReportParameterDefinition parameters = null;

    if ( report != null ) {
      parameters = report.getParameterDefinition();
    }

    dialog.showData( new JdbcPreviewWorker( new SimpleSQLReportDataFactory( getConnectionDefinition() ), query, 0, 0, parameters ) );
  } catch ( Exception e ) {
    log.warn( "QueryPanel.actionPerformed ", e );
    if ( designTimeContext != null ) {
      designTimeContext.userError( e );
    }
  }
}
 
Example 9
Source File: ParameterUtils.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Enriches the parameter values with computed default values. Warning: This is a dangerous thing as this may use
 * untrusted input for the default value computation.
 *
 * @param report
 * @param context
 * @return
 * @throws ReportDataFactoryException
 * @deprecated
 */
public static ReportParameterValues
  initializeDefaultValues( final MasterReport report, final ParameterContext context )
    throws ReportDataFactoryException {
  if ( report == null ) {
    throw new NullPointerException();
  }
  if ( context == null ) {
    throw new NullPointerException();
  }

  final ReportParameterDefinition definition = report.getParameterDefinition();
  final ReportParameterValues parameters = new ReportParameterValues( report.getParameterValues() );
  final ParameterContextWrapper wrapper = new ParameterContextWrapper( context, parameters );
  final ParameterDefinitionEntry[] entries = definition.getParameterDefinitions();
  for ( int i = 0; i < entries.length; i++ ) {
    final ParameterDefinitionEntry entry = entries[i];
    final Object oldValue = parameters.get( entry.getName() );
    if ( oldValue == null ) {
      parameters.put( entry.getName(), entry.getDefaultValue( wrapper ) );
    }
  }
  return parameters;
}
 
Example 10
Source File: LayerBottomAction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected UndoEntry moveParameters( final AbstractReportDefinition report, final Object element ) {
  if ( report instanceof MasterReport == false ) {
    return null;
  }
  final MasterReport mr = (MasterReport) report;
  final ReportParameterDefinition definition = mr.getParameterDefinition();
  if ( definition instanceof ModifiableReportParameterDefinition == false ) {
    return null;
  }

  final ModifiableReportParameterDefinition dpd = (ModifiableReportParameterDefinition) definition;
  final ParameterDefinitionEntry[] entries = dpd.getParameterDefinitions();
  for ( int i = 0; i < entries.length - 1; i++ ) {
    final ParameterDefinitionEntry entry = entries[ i ];
    if ( element == entry ) {
      dpd.removeParameterDefinition( i );
      dpd.addParameterDefinition( entry );
      report.fireModelLayoutChanged( report, ReportModelEvent.NODE_STRUCTURE_CHANGED, entry );
      return new CompoundUndoEntry
        ( new ParameterEditUndoEntry( i, entry, null ),
          new ParameterEditUndoEntry( dpd.getParameterDefinitions().length - 1, null, entry ) );
    }
  }
  return null;
}
 
Example 11
Source File: LayerTopAction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected UndoEntry moveParameters( final AbstractReportDefinition report, final Object element ) {
  if ( report instanceof MasterReport == false ) {
    return null;
  }
  final MasterReport mr = (MasterReport) report;
  final ReportParameterDefinition definition = mr.getParameterDefinition();
  if ( definition instanceof ModifiableReportParameterDefinition == false ) {
    return null;
  }

  final ModifiableReportParameterDefinition dpd = (ModifiableReportParameterDefinition) definition;
  final ParameterDefinitionEntry[] entries = dpd.getParameterDefinitions();
  for ( int i = 1; i < entries.length; i++ ) {
    final ParameterDefinitionEntry entry = entries[ i ];
    if ( element == entry ) {
      dpd.removeParameterDefinition( i );
      dpd.addParameterDefinition( 0, entry );
      report.fireModelLayoutChanged( report, ReportModelEvent.NODE_STRUCTURE_CHANGED, entry );
      return new CompoundUndoEntry
        ( new ParameterEditUndoEntry( i, entry, null ), new ParameterEditUndoEntry( 0, null, entry ) );
    }
  }
  return null;
}
 
Example 12
Source File: SelfDrillDownController.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void requestParameterRefresh( final DrillDownParameterRefreshEvent event ) {
  final HashMap<String, DrillDownParameter> entries = new HashMap<String, DrillDownParameter>();
  final DrillDownParameter[] originalParams = event.getParameter();
  for ( int i = 0; i < originalParams.length; i++ ) {
    final DrillDownParameter param = originalParams[ i ];
    param.setType( DrillDownParameter.Type.MANUAL );
    entries.put( param.getName(), param );
  }

  final ReportDocumentContext activeContext = getReportDesignerContext().getActiveContext();
  final MasterReport masterReportElement = activeContext.getContextRoot();
  final ReportParameterDefinition reportParams = masterReportElement.getParameterDefinition();
  final ParameterDefinitionEntry[] parameterDefinitionEntries = reportParams.getParameterDefinitions();

  for ( int i = 0; i < parameterDefinitionEntries.length; i++ ) {
    final ParameterDefinitionEntry entry = parameterDefinitionEntries[ i ];
    if ( entries.containsKey( entry.getName() ) == false ) {
      entries.put( entry.getName(),
        new DrillDownParameter( entry.getName(), null, DrillDownParameter.Type.PREDEFINED, false, false ) );
    } else {
      final DrillDownParameter parameter = entries.get( entry.getName() );
      parameter.setType( DrillDownParameter.Type.PREDEFINED );
    }
  }

  final DrillDownParameter[] parameters = entries.values().toArray( new DrillDownParameter[ entries.size() ] );
  getWrapper().setDrillDownParameter( parameters );
  getTable().setDrillDownParameter( parameters );
}
 
Example 13
Source File: SwingGenericUrlDrillDownUi.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void requestParameterRefresh( final DrillDownParameterRefreshEvent event ) {
  final HashMap<String, DrillDownParameter> entries = new HashMap<String, DrillDownParameter>();
  final DrillDownParameter[] originalParams = event.getParameter();
  for ( int i = 0; i < originalParams.length; i++ ) {
    final DrillDownParameter param = originalParams[ i ];
    param.setType( DrillDownParameter.Type.MANUAL );
    entries.put( param.getName(), param );
  }

  final ReportDocumentContext activeContext = getReportDesignerContext().getActiveContext();
  final MasterReport masterReportElement = activeContext.getContextRoot();
  final ReportParameterDefinition reportParams = masterReportElement.getParameterDefinition();
  final ParameterDefinitionEntry[] parameterDefinitionEntries = reportParams.getParameterDefinitions();

  for ( int i = 0; i < parameterDefinitionEntries.length; i++ ) {
    final ParameterDefinitionEntry entry = parameterDefinitionEntries[i];
    if ( entries.containsKey( entry.getName() ) == false ) {
      entries.put( entry.getName(),
              new DrillDownParameter( entry.getName(), null, DrillDownParameter.Type.PREDEFINED, false, false ) );
    } else {
      final DrillDownParameter parameter = entries.get( entry.getName() );
      parameter.setType( DrillDownParameter.Type.PREDEFINED );
    }
  }

  final DrillDownParameter[] parameters = entries.values().toArray( new DrillDownParameter[ entries.size() ] );
  getWrapper().setDrillDownParameter( parameters );
  getTable().setDrillDownParameter( parameters );
}
 
Example 14
Source File: Prd4579IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testStaticLoadSave() throws Exception {
  StaticListParameter param = new StaticListParameter( "parameter", false, false, String.class );
  DefaultParameterDefinition pdef = new DefaultParameterDefinition();
  pdef.addParameterDefinition( param );

  MasterReport report = new MasterReport();
  report.setParameterDefinition( pdef );
  MasterReport result = ReportWritingUtil.saveAndLoad( report );
  ReportParameterDefinition parameterDefinition = result.getParameterDefinition();
  assertEquals( 1, parameterDefinition.getParameterCount() );

  ParameterDefinitionEntry resultParam = parameterDefinition.getParameterDefinition( 0 );
  assertTrue( resultParam instanceof StaticListParameter );
}
 
Example 15
Source File: AbstractStructureVisitor.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void inspect( final AbstractReportDefinition reportDefinition ) {
  if ( reportDefinition instanceof MasterReport ) {
    final MasterReport mr = (MasterReport) reportDefinition;
    final ReportParameterDefinition parameters = mr.getParameterDefinition();
    final ParameterDefinitionEntry[] entries = parameters.getParameterDefinitions();
    for ( int i = 0; i < entries.length; i++ ) {
      final ParameterDefinitionEntry entry = entries[i];
      inspectParameter( reportDefinition, parameters, entry );
    }
  }

  final CompoundDataFactory dataFactory = CompoundDataFactory.normalize( reportDefinition.getDataFactory(), false );
  final int size = dataFactory.size();
  for ( int i = 0; i < size; i++ ) {
    inspectDataSource( reportDefinition, dataFactory.getReference( i ) );
  }

  final ExpressionCollection expressions = reportDefinition.getExpressions();
  final Expression[] expressionsArray = expressions.getExpressions();
  for ( int i = 0; i < expressionsArray.length; i++ ) {
    final Expression expression = expressionsArray[i];
    inspectExpression( reportDefinition, expression );
  }

  inspectElement( reportDefinition );
  traverseSection( reportDefinition );
}
 
Example 16
Source File: ParameterReportController.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the graphical representation of the controller. This component will be added between the menu bar and the
 * toolbar.
 * <p/>
 * Changes to this property are not detected automatically, you have to call "refreshController" whenever you want to
 * display a completely new control panel.
 *
 * @return the controller component.
 */
public JComponent getControlPanel() {
  final MasterReport report = controllerPane.getReport();
  if ( report == null ) {
    return null;
  }
  final ReportParameterDefinition definition = report.getParameterDefinition();
  if ( definition == null ) {
    return null;
  }
  if ( definition.getParameterCount() == 0 ) {
    return null;
  }
  return controllerPane;
}
 
Example 17
Source File: SwingRemoteDrillDownController.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void requestParameterRefresh( final DrillDownParameterRefreshEvent event ) {
  final HashMap<String, DrillDownParameter> entries = new HashMap<String, DrillDownParameter>();
  final DrillDownParameter[] originalParams = event.getParameter();
  for ( int i = 0; i < originalParams.length; i++ ) {
    final DrillDownParameter param = originalParams[ i ];
    param.setType( DrillDownParameter.Type.MANUAL );
    entries.put( param.getName(), param );
  }

  final ReportDocumentContext activeContext = reportDesignerContext.getActiveContext();
  final MasterReport masterReportElement = activeContext.getContextRoot();
  final ReportParameterDefinition reportParams = masterReportElement.getParameterDefinition();
  final ParameterDefinitionEntry[] parameterDefinitionEntries = reportParams.getParameterDefinitions();

  for ( int i = 0; i < parameterDefinitionEntries.length; i++ ) {
    final ParameterDefinitionEntry entry = parameterDefinitionEntries[i];
    if ( entries.containsKey( entry.getName() ) == false ) {
      entries.put( entry.getName(),
              new DrillDownParameter( entry.getName(), null, DrillDownParameter.Type.PREDEFINED, false, false ) );
    } else {
      final DrillDownParameter parameter = entries.get( entry.getName() );
      parameter.setType( DrillDownParameter.Type.PREDEFINED );
    }
  }

  final DrillDownParameter[] parameters = entries.values().toArray( new DrillDownParameter[ entries.size() ] );
  modelWrapper.setDrillDownParameter( parameters );
  ( drillDownUi.<DrillDownParameterTable>getComponent(
      SwingRemoteDrillDownUi.ComponentLookup.PARAMETER_TABLE
  ) ).setDrillDownParameter( parameters );
}
 
Example 18
Source File: JdbcDataSourceDialog.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void actionPerformed( final ActionEvent evt ) {
  final NamedDataSourceDialogModel dialogModel = getDialogModel();
  final JdbcConnectionDefinition connectionDefinition = (JdbcConnectionDefinition) dialogModel.getConnections().getSelectedItem();
  if ( connectionDefinition == null ) {
    return;
  }

  try {
    final String query = getQueryName();
    final DataPreviewDialog dialog = new DataPreviewDialog( JdbcDataSourceDialog.this );
    Integer maxRows = 0;
    if ( maxPreviewRowsSpinner.isEnabled() ) {
      maxRows = (Integer) maxPreviewRowsSpinner.getValue();
    }
    if ( maxRows == null ) {
      maxRows = 0;
    }
    final SQLReportDataFactory dataFactory = createDataFactory( connectionDefinition );
    DataFactoryEditorSupport.configureDataFactoryForPreview( dataFactory, designTimeContext );

    MasterReport report = (MasterReport) designTimeContext.getReport();
    ReportParameterDefinition parameters = null;

    if ( report != null ) {
      parameters = report.getParameterDefinition();
    }

    final JdbcPreviewWorker previewWorker = new JdbcPreviewWorker( dataFactory, query, 0, maxRows, parameters );
    dialog.showData( previewWorker );

    final ReportDataFactoryException theException = previewWorker.getException();
    if ( theException != null ) {
      ExceptionDialog.showExceptionDialog( JdbcDataSourceDialog.this,
          Messages.getString( "PreviewDialog.PreviewError.Title" ),
          Messages.getString( "PreviewDialog.PreviewError.Message" ), theException );
    }
  } catch ( Exception e ) {
    logger.warn( "Preview failed:", e );
    if ( designTimeContext != null ) {
      designTimeContext.userError( e );
    }
  }

}
 
Example 19
Source File: PasteAction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Object normalizeElements( final Object element ) {
  if ( element instanceof MasterReport ) {
    final MasterReport rawMasterReport = (MasterReport) element;
    final MasterReport masterReport = (MasterReport) rawMasterReport.derive();

    final int result = JOptionPane.showOptionDialog( getReportDesignerContext().getView().getParent(),
      Messages.getString( "SubreportReportElementDragHandler.BandedOrInlineSubreportQuestion" ),
      Messages.getString( "SubreportReportElementDragHandler.InsertSubreport" ),
      JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null,
      new String[] { Messages.getString( "SubreportReportElementDragHandler.Inline" ),
        Messages.getString( "SubreportReportElementDragHandler.Banded" ),
        Messages.getString( "SubreportReportElementDragHandler.Cancel" ) },
      Messages.getString( "SubreportReportElementDragHandler.Inline" )
    );
    if ( result == JOptionPane.CLOSED_OPTION || result == 2 ) {
      return null;
    }

    final SubReport subReport = new SubReport();
    subReport.setRootGroup( (Group) masterReport.getRootGroup().derive() );
    subReport.setReportFooter( (ReportFooter) masterReport.getReportFooter().derive() );
    subReport.setReportHeader( (ReportHeader) masterReport.getReportHeader().derive() );
    subReport.setPageFooter( (PageFooter) masterReport.getPageFooter().derive() );
    subReport.setPageHeader( (PageHeader) masterReport.getPageHeader().derive() );
    subReport.setWatermark( (Watermark) masterReport.getWatermark().derive() );
    subReport.setDataFactory( masterReport.getDataFactory().derive() );
    masterReport.copyInto( subReport );

    final ReportParameterDefinition parameterDefinition = masterReport.getParameterDefinition();
    for ( final ParameterDefinitionEntry entry : parameterDefinition.getParameterDefinitions() ) {
      subReport.addInputParameter( entry.getName(), entry.getName() );
    }
    if ( subReport.getInputMappings().length == 0 ) {
      subReport.addInputParameter( "*", "*" );
    }

    subReport.setElementType( SubReportType.INSTANCE );
    if ( result == 0 ) {
      // inline
      subReport.setAttribute
        ( ReportDesignerBoot.DESIGNER_NAMESPACE, InsertationUtil.SUBREPORT_BANDED_HINT, Boolean.FALSE );
    } else if ( result == 1 ) {
      // banded
      subReport.setAttribute
        ( ReportDesignerBoot.DESIGNER_NAMESPACE, InsertationUtil.SUBREPORT_BANDED_HINT, Boolean.TRUE );
    }
    return subReport;
  }

  return element;
}
 
Example 20
Source File: EditParametersAction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void performEditMasterReportParameters( final ReportDesignerContext context,
                                                      final ParameterDefinitionEntry parameter )
  throws ReportDataFactoryException {
  final ReportDocumentContext activeContext = context.getActiveContext();
  if ( activeContext == null ) {
    return;
  }

  final Component theParent = context.getView().getParent();
  final Window theWindow = LibSwingUtil.getWindowAncestor( theParent );
  final ParameterDialog parameterDialog;
  if ( theWindow instanceof JDialog ) {
    parameterDialog = new ParameterDialog( (JDialog) theWindow, context );
  } else if ( theWindow instanceof JFrame ) {
    parameterDialog = new ParameterDialog( (JFrame) theWindow, context );
  } else {
    parameterDialog = new ParameterDialog( context );
  }

  final MasterReport masterReport = activeContext.getContextRoot();
  final ModifiableReportParameterDefinition parameterDefinition =
    (ModifiableReportParameterDefinition) masterReport.getParameterDefinition();
  int index = -1;
  for ( int i = 0; i < parameterDefinition.getParameterCount(); i++ ) {
    final ParameterDefinitionEntry definition = parameterDefinition.getParameterDefinition( i );
    if ( definition == parameter ) {
      index = i;
      break;
    }
  }
  if ( index == -1 ) {
    if ( parameter == null ) {
      index = parameterDefinition.getParameterCount();
    } else {
      throw new IndexOutOfBoundsException( "This parameter is not part of the existing parameter collection" );
    }
  }

  final ParameterDialog.ParameterEditResult definitionEntry = parameterDialog.performEditParameter
    ( context, masterReport, parameter );
  if ( definitionEntry != null ) {
    final ParameterEditUndoEntry parameterEditUndoEntry =
      new ParameterEditUndoEntry( index, parameter, definitionEntry.getParameter() );
    final ArrayList<UndoEntry> undos = new ArrayList<UndoEntry>();
    undos.add( parameterEditUndoEntry );
    final DataFactoryWrapper[] dataFactoryWrappers = definitionEntry.getWrappers();
    for ( int i = 0; i < dataFactoryWrappers.length; i++ ) {
      final DataFactoryWrapper dataFactoryWrapper = dataFactoryWrappers[ i ];
      if ( dataFactoryWrapper.getOriginalDataFactory() != dataFactoryWrapper.getEditedDataFactory() ) {
        undos.add( new DataSourceEditUndoEntry( i, dataFactoryWrapper.getOriginalDataFactory(),
          dataFactoryWrapper.getEditedDataFactory() ) );
      }
    }

    final CompoundUndoEntry undoEntry = new CompoundUndoEntry( undos.toArray( new UndoEntry[ undos.size() ] ) );
    undoEntry.redo( activeContext );
    activeContext.getUndo()
      .addChange( ActionMessages.getString( "EditParametersAction.MasterReport.Text" ), undoEntry );
  }
}