Skip to content

Commit

Permalink
Enhance the report designer to provide the excel emitter configuratio…
Browse files Browse the repository at this point in the history
…n directly (#1770)
  • Loading branch information
speckyspooky authored Jul 1, 2024
1 parent ea2e3a3 commit 98cc593
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*************************************************************************************
* Copyright (c) 2011, 2012, 2013 James Talbut.
* Copyright (c) 2011, 2012, 2013, 2024 James Talbut and others
* jim-emitters@spudsoft.co.uk
*
*
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
*
* SPDX-License-Identifier: EPL-2.0
*
*
* Contributors:
* James Talbut - Initial implementation.
************************************************************************************/
Expand All @@ -26,6 +26,12 @@

import uk.co.spudsoft.birt.emitters.excel.framework.ExcelEmitterPlugin;

/**
* Emitter service to handle the emitter configuration options
*
* @since 3.3
*
*/
public class EmitterServices {

/**
Expand Down Expand Up @@ -77,13 +83,27 @@ public static boolean booleanOption(ITaskOption options, IContent birtContent, S
value = options.getOption(name);
}

if (birtContent != null && birtContent.getReportContent() != null && value == null) {
value = getReportDesignConfiguration(birtContent.getReportContent(), name);
}

if (value != null) {
result = booleanOption(value, defaultValue);
}

return result;
}

/**
* Convert an Object to a boolean, with quite a few options about the class of
* the Object.
*
* @param options The task options to extract the value from.
* @param reportContent The report node to look for UserProperties
* @param name The name of the value to extract from options.
* @param defaultValue Value to return if value is null.
* @return true if value in some way represents a boolean TRUE value.
*/
public static boolean booleanOption(ITaskOption options, IReportContent reportContent, String name,
boolean defaultValue) {
boolean result = defaultValue;
Expand All @@ -108,9 +128,34 @@ public static boolean booleanOption(ITaskOption options, IReportContent reportCo
result = booleanOption(value, defaultValue);
}

if (reportContent != null && value == null) {
value = getReportDesignConfiguration(reportContent, name);
}

return result;
}

/*
* Read the configuration from the report design if no user property is set
*/
private static Object getReportDesignConfiguration(IReportContent reportContent, String name) {
Object value = null;
if (name.equalsIgnoreCase(ExcelEmitter.SINGLE_SHEET)) {
value = reportContent.getDesign().getReportDesign().getExcelSingleSheet();

} else if (name.equalsIgnoreCase(ExcelEmitter.DISABLE_GROUPING)) {
value = reportContent.getDesign().getReportDesign().getExcelDisableGrouping();

} else if (name.equalsIgnoreCase(ExcelEmitter.DISPLAYGRIDLINES_PROP)) {
value = reportContent.getDesign().getReportDesign().getExcelDisplayGridlines();

} else if (name.equalsIgnoreCase(ExcelEmitter.FORCEAUTOCOLWIDTHS_PROP)) {
value = reportContent.getDesign().getReportDesign().getExcelForceAutoColWidths();

}
return value;
}

/**
* Search for an emitter option and return it as a string
*
Expand Down Expand Up @@ -286,14 +331,15 @@ public static boolean booleanOption(Object value, boolean defaultValue) {
}

/**
* Returns the symbolic name for the plugin.
* Get the symbolic name for the plugin.
*
* @return the symbolic name for the plugin.
*/
public static String getPluginName() {
if ((ExcelEmitterPlugin.getDefault() != null) && (ExcelEmitterPlugin.getDefault().getBundle() != null)) {
return ExcelEmitterPlugin.getDefault().getBundle().getSymbolicName();
} else {
return "uk.co.spudsoft.birt.emitters.excel";
}
return "uk.co.spudsoft.birt.emitters.excel";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1429,4 +1429,79 @@ public void setLanguage(String language) throws SemanticException {
setProperty(LANGUAGE_PROP, language);
}

/**
* Get the configuration for the excel handling of forced auto column width
*
* @return the configuration of forced auto column width
*/
public boolean getExcelForceAutoColWidths() {
return getBooleanProperty(EXCEL_FORCE_AUTO_COL_WIDTHS);
}

/**
* Set the auto column width usage for the excel output
*
* @param forceAutoColWidths auto columns widths calculation to be used
* @throws SemanticException
*/
public void setExcelForceAutoColWidths(boolean forceAutoColWidths) throws SemanticException {
setBooleanProperty(EXCEL_FORCE_AUTO_COL_WIDTHS, forceAutoColWidths);
}

/**
* Get the configuration for the excel handling of single sheet result
*
* @return the configuration of single sheet result
*/
public boolean getExcelSingleSheet() {
return getBooleanProperty(EXCEL_SINGLE_SHEET);
}

/**
* Set the single sheet usage for the excel output
*
* @param singleSheet single sheet to be used
* @throws SemanticException
*/
public void setExcelSingleSheet(boolean singleSheet) throws SemanticException {
setBooleanProperty(EXCEL_SINGLE_SHEET, singleSheet);
}

/**
* Get the configuration for the excel handling of disabled grouping
*
* @return the configuration of disabled grouping
*/
public boolean getExcelDisableGrouping() {
return getBooleanProperty(EXCEL_DISABLE_GROUPING);
}

/**
* Set the deactivation of the grouping of the excel output
*
* @param disableGrouping disable grouping
* @throws SemanticException
*/
public void setExcelDisableGrouping(boolean disableGrouping) throws SemanticException {
setBooleanProperty(EXCEL_DISABLE_GROUPING, disableGrouping);
}

/**
* Get the configuration for the excel handling to display grid lines
*
* @return the configuration to display grind lines
*/
public boolean getExcelDisplayGridlines() {
return getBooleanProperty(EXCEL_DISPLAY_GRIDLINES);
}

/**
* Set the display of grid line for the excel output
*
* @param displayGridlines display grid lines
* @throws SemanticException
*/
public void setExcelDisplayGridlines(boolean displayGridlines) throws SemanticException {
setBooleanProperty(EXCEL_DISPLAY_GRIDLINES, displayGridlines);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,23 @@ public interface IInternalReportDesignModel {
*/
String LANGUAGE_PROP = "language"; //$NON-NLS-1$

/**
* Excel option, force auto column width calculation
*/
String EXCEL_FORCE_AUTO_COL_WIDTHS = "excelForceAutoColWidths"; //$NON-NLS-1$

/**
* Excel option, create only singe sheet
*/
String EXCEL_SINGLE_SHEET = "excelSingleSheet"; //$NON-NLS-1$

/**
* Excel option, disable grouping
*/
String EXCEL_DISABLE_GROUPING = "excelDisableGrouping"; //$NON-NLS-1$

/**
* Excel option, display grid lines
*/
String EXCEL_DISPLAY_GRIDLINES = "excelDisplayGridlines"; //$NON-NLS-1$
}
Original file line number Diff line number Diff line change
Expand Up @@ -1887,6 +1887,24 @@
</Property>
<Property displayNameID="Element.ReportDesign.locale" name="locale" since="2.5" type="locale" />
<Property displayNameID="Element.ReportDesign.language" name="language" since="4.3" type="string" />
<PropertyGroup displayNameID="Element.ReportDesign.Emitter.excel">
<!-- excel (spudsoft): force the column width calculation -->
<Property canInherit="false" displayNameID="Element.ReportDesign.Emitter.excel.forceAutoColWidths" name="excelForceAutoColWidths" runtimeSettable="false" since="4.17" type="boolean" >
<Default>false</Default>
</Property>
<!-- excel (spudsoft): output of table as single sheet -->
<Property canInherit="false" displayNameID="Element.ReportDesign.Emitter.excel.singleSheet" name="excelSingleSheet" runtimeSettable="false" since="4.17" type="boolean" >
<Default>false</Default>
</Property>
<!-- excel (spudsoft): disable the excel grouping -->
<Property canInherit="false" displayNameID="Element.ReportDesign.Emitter.excel.disableGrouping" name="excelDisableGrouping" runtimeSettable="false" since="4.17" type="boolean" >
<Default>false</Default>
</Property>
<!-- excel (spudsoft): show/hide the excel gridlines -->
<Property canInherit="false" displayNameID="Element.ReportDesign.Emitter.excel.displayGridlines" name="excelDisplayGridlines" runtimeSettable="false" since="4.17" type="boolean" >
<Default>true</Default>
</Property>
</PropertyGroup>
<Method context="client" displayNameID="Element.ReportDesign.clientInitialize" name="clientInitialize" since="1.0" toolTipID="Element.ReportDesign.clientInitialize.toolTip">
</Method>
<Method context="startup" displayNameID="Element.ReportDesign.initialize" name="initialize" since="1.0" toolTipID="Element.ReportDesign.initialize.toolTip">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2627,6 +2627,11 @@ Element.ReportDesign.clientInitialize.toolTip=Load the client side java script l
Element.ReportDesign.clientInitialize.this=Report design
Element.ReportDesign.language=Language
Element.ReportDesign.PDFAccessible=Accessible PDF
Element.ReportDesign.Emitter.excel=Emitter excel configuration
Element.ReportDesign.Emitter.excel.forceAutoColWidths=Force auto column width calculation
Element.ReportDesign.Emitter.excel.singleSheet=Excel output as single sheet
Element.ReportDesign.Emitter.excel.disableGrouping=Disable grouping
Element.ReportDesign.Emitter.excel.displayGridlines=Display grid lines

#2. Report Element ( Prefix = Element.ReportElement )
Element.ReportElement.displayName=Display name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ protected void writeSimpleProperties(ReportDesign obj) {
property(obj, IReportDesignModel.IMAGE_DPI_PROP);
property(obj, IReportDesignModel.LOCALE_PROP);

property(obj, IReportDesignModel.EXCEL_DISABLE_GROUPING);
property(obj, IReportDesignModel.EXCEL_FORCE_AUTO_COL_WIDTHS);
property(obj, IReportDesignModel.EXCEL_SINGLE_SHEET);
property(obj, IReportDesignModel.EXCEL_DISPLAY_GRIDLINES);

// include libraries and scripts

writeStructureList(obj, IModuleModel.LIBRARIES_PROP);
Expand Down

0 comments on commit 98cc593

Please sign in to comment.