How to set default value of variable in live template in Intellij IDEA? - intellij-idea

There could be a little misunterstanding in live templates in Intellij IDEA. I mean default values for variables in templates.
Suppose we have this live template
What I expect here, that when calling this template (type jqon and press TAB) I will see default values already typed which I can change or leave as it is. Like this
But no. I have empty strings instead of default values
Why?

I was wrong about Default value field. I don't need this in my case. I need to fill Expression field.
If I want just paste some string as default value I should put this string in quote in Expression. So now my variable settings look this way
And everything works how I want!

If you want a hardcoded string as the default value field (in the edit variables dialog), it needs to be in double quotes ("ii"). Putting a string there with no quotes (ii) does not result in an error, but also does not work.

Related

Bug in Google Sheets Formatting

I believe I may have found a bug in Google Sheets formatting or else my preferred option is I'm doing something wrong! * Brief rant - I find GridRange a PITBS!! Rant over.
I'm simply trying to format a cell and make the text bold. I send the following JSON request:
{"requests":[{"repeatCell":{"range":{"startRowIndex":1,"endRowIndex":"2","startColumnIndex":1,"endColumnIndex"
:2,"sheetId":0},"cell":{"effectiveFormat":{"textFormat":{"bold":"true"}}},"fields":"*"}},{"repeatCell"
:{"range":{"startRowIndex":7,"endRowIndex":"8","startColumnIndex":1,"endColumnIndex":7,"sheetId":0},"cell"
:{"effectiveFormat":{"textFormat":{"bold":"true"}}},"fields":"*"}}]}
And the values in the cells disappear?? I know the values are there because if I omit this styling code then nothing is altered and the values remain. What am I doing wrong? (For ref the fields here are B2:B2 and B8:G8). Any help gratefully appreciated.
I am sending this through the JS API but believe I have seen the same through the PHP too.
You are setting the fields parameter to *, which means, "I want to set every field.". Since you don't supply a value but said you want to set each field, the values are being reset to their defaults (which is empty).
If you only want to apply formatting, you need to set the fields parameter to just the format fields, e.g userEnteredFormat. See the documentation on field masks for more info.
Note also that you're attempting to set effectiveFormat, but per the reference docs that field is read-only.

Get Text Symbol Programmatically With ID

Is there any way of programmatically getting the value of a Text Symbol at runtime?
The scenario is that I have a simple report that calls a function module. I receive an exported parameter in variable LV_MSG of type CHAR1. This indicates a certain status message created in the program, for instance F (Fail), X (Match) or E (Error). I currently use a CASE statement to switch on LV_MSG and fill another variable with a short description of the message. These descriptions are maintained as text symbols that I retrieve at compile time with text-MS# where # is the same as the possible returns of LV_MSG, for instance text-MSX has the value "Exact Match Found".
Now it seems to me that the entire CASE statement is unnecessary as I could just assign to my description variable the value of the text symbol with ID 'MS' + LV_MSG (pseudocode, would use CONCATENATE). Now my issue is how I can find a text symbol based on the String representation of its ID at runtime. Is this even possible?
If it is, my code would look cleaner and I wouldn't have to update my actual code when new messages are added in the function module, as I would simply have to add a new text symbol. But would this approach be any faster or would it in fact degrade the report's performance?
Personally, I would probably define a domain and use the fixed values of the domain to represent the values. This way, you would even get around the string concatenation. You can use the function module DD_DOMVALUE_TEXT_GET to easily access the language-dependent text of a domain value.
To access the text elements of a program, use a function module like READ_TEXT_ELEMENTS.
Be aware that generic programming like this will definitely slow down your program. Whether it would make your code look cleaner is in the eye of the beholder - if the values change rarely, I don't see why a simple CASE statement should be inferior to some generic text access.
Hope I understand you correctly but here goes. This is possible with a little trickery, all the text symbols in a report are defined as variables in the program (with the name text-abc where abc is the text ID). So you can use the following:
data: lt_all_text type standard table of textpool with default key,
lsr_text type ref to textpool.
"Load texts - you will only want to do this once
read textpool sy-repid into lt_all_text language sy-langu.
sort lt_all_Text by entry.
"Find a text, the field KEY is the text ID without TEXT-
read table lt_all_text with key entry = i_wanted_text
reference into lsr_text binary search.
If you want the address you can add:
field-symbols: <l_text> type any.
data l_name type string.
data lr_address type ref to data.
concatenate 'TEXT-' lsr_text->key into l_name.
assign (l_name) to <l_text>.
if sy-subrc = 0.
get reference of <l_text> into lr_address.
endif.
As vwegert pointed out this is probably not the best solution, for error handling rather use message classes or exception objects. This is useful in other cases though so now you know how.

How to format numeric field using dutch format in extjs?

i want to format number entered by user in dutch format. ie. use decimal Separator as , and thousand seperator as .
blur: function () {
Ext.util.Format.number(this.value, '000,000.00')
}
I want to format my numeric field on blur, the above code works fine, but
my requirement is to get a format like this- '000000.000,00'.
How to do this in extjs?
Quick and dirty, just set the thousandSeparator and decimalSeparator. It should work:
//Set these once, right after Ext.onReady
Ext.util.Format.thousandSeparator = '.';
Ext.util.Format.decimalSeparator = ',';
//Then this should work:
Ext.util.Format.number(12345.67, '0,000.00'); //output 12.345,67
Or even better, use the localization, so formats can be changed according to language requirement.
Side note:
The documentation wrote:
To allow specification of the formatting string using UK/US grouping characters (,) and decimal (.) for international numbers, add /i to the end. For example: 0.000,00/i
And from the comments in the source code
// The "/i" suffix allows caller to use a locale-specific formatting string.
// Clean the format string by removing all but numerals and the decimal separator.
// Then split the format string into pre and post decimal segments according to *what* the
// decimal separator is. If they are specifying "/i", they are using the local convention in the format string.
To me, it seems that it means a developer can use a specific format string "0.000,00" to format a given number, and not to mean a developer can use this specific format string to format a number into the format they want. They will still need to change the default separator setting.
Edit
Demo link: http://jsfiddle.net/chaoszcat/nbWwN/
I have this working for user entered values in a numberfield now.
As lionel pointed out, this is needed:
// set this once after Ext.onReady
Ext.util.Format.thousandSeparator = '.';
Ext.util.Format.decimalSeparator = ',';
Then change your handler to this:
blur: function(field) {
field.setRawValue(Ext.util.Format.number(field.getValue(), '0.000,00/i'));
}
You should also include this config on your numberfield:
decimalSeperator: ','
It will allow users to type in their own decimal symbols.
Working Example
Here is a working fiddle of this, using a numberfield.
A word of warning
Ext.form.field.Number does not support formatting, the blur handler I gave above will work totally fine if the user edits the field and then does not go back into it to edit it again, if he refocuses the field it will validate and try to correct the thousands markers into decimals.
If you are using this field to post data back to the server it will send it back in the format that is displayed (with thousand seperators), I don't know if that was what you were going for.
If you simply want formatted numbers you should do what you're trying to do above but with a textfield. That way it won't reconfigure your thousands as decimals.
If you want all the functionality of a numberfield (spinners, min/max validation, step increments, etc) you will have to take a look at extending the numberfield class, here is a user extension that already exists and which is almost exactly what you needed, but it includes a currency symbol, it would fairly easy to take that out.

Formatting a variable in iReport according to specified pattern

I'm trying to build a report with iReport. I have defined the a variable named: totalCosts. This variable is based on this expression:
$V{costs}.multiply(new java.math.BigDecimal($F{numberOfItems}.intValue()))
I want to format this variable by the following pattern:
#,##0
What I tried before asking this question:
I tried to use the following variable expression but no success:
new java.math.BigDecimal(new java.text.DecimalFormat("#,##0").format($V{costs}.multiply(new java.math.BigDecimal($F{numberOfItems}.intValue()))))
My variable is a java.math.BigDecimal.
Thank you.
If you are trying to display the variable in a report, then normally you should just have a Text Field with a value of "$V{MyVariable}" (without the quotes). Set the pattern for that Text Field as you like. It saves you all of the trouble of formatting things yourself.

How to test for blank text field when using robotframework-selenium?

How can I specify blank/empty value for a text field when using the robotframework-seleniumlibrary with a TSV file? For example, I have the following:
Textfield Value Should Be identifier=name1 Chris
Textfield Value Should Be identifier=name2
I want to test that name2 is blank. I have tried leaving it blank (which returns a message about an incorrect number of arguments. I have tried "", which looks for a pair of quotes, and '' which enters a single quote, and selenium seems to look for that
You can use either a single backslash \ or special variable ${EMPTY} to create an empty string in the test data. User guide has the details: Robot Framework User Guide.
Yes, ${EMPTY} is a built in variable.
There are many examples, see an example here
${EMPTY} is good for a blank value but, surprisingly, it didn't work for an empty value.
I found what I was looking for. The field I was verifying had no value in its value attribute and I wanted to verify it. It was returning '' as the value and when using ${EMPTY} it couldn't find '''' instead. Such a minor thing but ended up solving what I needed, so it depends what you're seeking to verify.