Display blanks instead of 0 or 0.0 in a BIRT report - eclipse

When using an aggregate control in some reports you would prefer to see a blank field instead of 0. There does not appear to be a way to do this automatically. Does anyone have a way that this can be done. Note, you want to maintain the '0' value for the field in cases when you export, but you want to show a blank when rendering to PDF or HTML.

There are a number of ways to solve this. The two primary are to use either visibility rules or highlights to create conditional formatting. The visibility is particularly attractive since it is easy to only apply the format rules to particular types of output (e.g. HTML).
For this particular case, there are two problems with these approaches. First, I want a general solutions where I don't have to specify the text color. In other words, when the condition is true (value of 0) then I want my text color to match the background color. In that way if someone changes the backgroundColor for the control, the code still works.
The other issue is that in this case I am using dynamic column binding which does not support value lookup.
The solution that I created was to add a JavaScript function called hideMe as shown below.
function hideText (dataControl){
if (dataControl.getValue() == 0) {
var color = dataControl.getStyle().getBackgroundColor();
var parentItem = dataControl.getParent();
do {
if (color == null && parentItem != null) {
color = parentItem.getStyle().getBackgroundColor();
parentItem = parentItem.getParent();
} else {
break;
}
} while (color == null);
dataControl.getStyle().color = color;
}
}
Once this function has been added to the report (in my case an included javascript file) I just call it from the OnCreate method of the control.
hideText(this);
This can also be done using Java Event Handlers but this method seems to be easier.

Just an FYI, after working with this for a while longer, I have found that it is just easier to use Visibility rules. The one big advantage is that you can easily configure different visibility for different output formats. So for PDF it may be best to use blanks, but for Excel you may want the 0 values.

Related

need some javascript for a pdf form

not sure if I've come to the right place or not. Any help is appreciated.
I am creating a form that will post certain air quality test results on a building. Users will insert particular numbers in the form (e.g., concentration of certain gases, etc.). If number meets acceptable standards (e.g., below acceptable maximum), then I would like a check box to turn on that says the building meets the safety standards.
let A be air quality value
let B be maximum accepted value
let C be checkbox indicating pass
So, if A is less than B, then C is ON (pass) but if A is greater than B, C is OFF (fail)
Ideally, C will be a graphic of a green check mark or a red ex.
thx
You'll need to set up a file with your field and 4 "buttons" set to read-only which are really just holders for your graphics. One is the visible button that has its image replaced by the code, three of them are hidden, the check, the X, and a clear one for when the form is reset. Then add the following code to the Custom Format script of the field. The code will use the value of the field to swap the button icons. The value of 50 is arbitrary. Set it to the number you need.
if (event.value != "") {
if (event.value <= 50) {
this.getField("graphic").buttonSetIcon(this.getField("passed").buttonGetIcon());
}
else {
this.getField("graphic").buttonSetIcon(this.getField("failed").buttonGetIcon());
}
}
else {
this.getField("graphic").buttonSetIcon(this.getField("clear").buttonGetIcon());
}
You can download a working example from here.

Best approach getting answer from multiplay text boxes

I've created multiple text fields where each text field accepts only 1 character and then moves to the next box. I would like to check users answer when all the text fields are filled but I'm a bit confused as to how to do so.
My first approach was to create an answer String and every time textFieldDidChange is called I add to the String the textfield.text but how can I know when all the boxes been filled and call the checkAnswer function another issue is that if the user decides to fill the boxes in a different order then when I compare the user answer to the correct answer it obviously comes incorrect as the order is different.
[here's a pic of the boxes every game round it generates a different number of boxes depending on the answer
If you know how many number of textFields you have then, you can add a property observer to yourAnswerString and as soon as the value of yourAnswerString becomes equal to numberOfTextFields, it will call the check Answer function automatically.
var yourAnswerString = "" {
didSet {
if yourAnswerString.count == numberOfTextFields {
self.checkAnswer()
}
}
}

How to gray selection highlight when NatTable not in focus

Some lists and tables gray out their selection when they lose keyboard focus.
In the presence of multiple lists/tables, this helps communicate to the user which selection is active.
Is there an easy way to do this with NatTable?
The best I've come up with so far is to flip between different attributes for DisplayMode.SELECT as focus comes and goes -- but I'm not sure I can do that after NatTable.configure() has been called.
Yes you can change configuration attributes dynamically after NatTable#configure() has been called. That is a common approach for dynamic changes. Another approach would be to configure a selection style for a special label and apply that label only in case the table is active. This approach can be seen in this example.
https://github.com/eclipse/nebula.widgets.nattable/blob/master/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/_500_Layers/_505_Selection/_5054_SelectionProviderExample.java
I have this working, after #DirkFauth's answer. This answer includes some specifics.
After the table has been configured with NatTable.configure(), you can modify the configuration not with NatTable.addConfiguration(IConfiguration), but instead by calling IConfiguration.configureRegistry(IConfigRegistry). For example:
myConfiguration.configureRegistry( myTable.getConfigRegistry() )
Within that implementation of configureRegistry(), you can set the style for selected and anchor cells:
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE,
selectedStyle, DisplayMode.SELECT, GridRegion.BODY);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE,
anchorStyle, DisplayMode.SELECT,
SelectionStyleLabels.SELECTION_ANCHOR_STYLE);
When the table is inactive, selectedStyle and anchorStyle can be modified clones of their usual setting. For example:
private static Color myInactiveColor = ...;
public static Style makeInactiveBodyCellStyleFrom(#Nonnull Style style) {
Style rv = style.clone();
rv.setAttributeValue( CellStyleAttributes.BACKGROUND_COLOR,
myInactiveColor );
return rv;
}
Similar work can be done for the styles of selected row and column headers.

cannot find css element in protractor

How do I locate the element with the following html, I have 4 Start buttons each in different color. I tried using css by class and is not working. There are no unique ids as well. Pls help
Start
As Ben Mohorc points out, you really need to give us a bit more to go on. But if you are saying there are multiple start buttons, but only one of each color, it ought to look like this. For now I assume all they say is "Start". If that is only part of what they say, use partial buttontext.If it is background color that differs, you may need to adapt that, too.
var coloredButton = element.all(by.buttonText('Start')).filter(function(elem) {
return elem.getCssValue('color').then(function(color) {
return (color == '#00ff00')//fill in the desired color here, in this format
})
});
Then do your stuff on coloredButton.first(), which will be the only one, according to what you are saying.
For more on the format to expect from the color, see http://www.protractortest.org/#/api?view=webdriver.WebElement.prototype.getCssValue

Using Jasper ContitionalStyles with named style references

I've got a situation where I create a report based on jrxml-files generated programmaitically and a style template with a given name and given style names. This works fine up to the point where there are conditional styles. Every example I found just uses ConditionalStyles to change some value like setting a different backcolor for specific situations. This can't be done here since there is no way of knowing what separates an even row style from an odd row style. Like wheter an odd row will get a gray background or an even row will get a green foreground and a black bottom pen.
What I tried or looked at:
Using Conditional Styles - There seems to be no way of defining a style reference just to change style values
Using a Variable for the style name - The variable didn't get evaluated
Creating a style with 2 ConditionalStyles using even and odd styles as parent styles - these were ignored when creating the jrtx-file
So... is there a way to create alternate styled rows using style references? If yes how it is done?
As there seems no solution to this, we had to change the structure of the style-files to include the conditional style instead of doing this in the document.
When walking this path and trying to change or create these style-files programmatically, be aware that in the JRXmlTemplateWriter that comes with Jasper, the method toWriteConditionalStyles is implemented as:
protected boolean toWriteConditionalStyles() {
return false;
}
Which is unfortunate. You'll have to use your own Exporter that changes this behavior.
Simply the way of knowing what separates an even row style from an odd row style.
Even row will satisfy the condition
(($V{REPORT_COUNT}%2) == 0)
Odd row will satisfy the condition
(($V{REPORT_COUNT}%2) != 0)
Then you can use a Conditional Styles with above conditions