OpenXava how to populate dropdown/combobox with my own values - properties

Hello thanks that code works very well; but in my case i want to display different time for example "07:00","08:00" and so on. is there a way for that to happen?

To have a dropdown in OpenXava you can:
Define your property as a JPA #ManyToOne relationship annotated with #DescriptionsList.
#ManyToOne
#DescriptionsList
Hour hours;
You have an entity Hour that maps a table HOUR in your database, a combo box with all the value is shown.
Other option is to define a regular Java enum property:
public enum Color { UNSPECIFIED, RED, YELLOW, WHITE, BLACK }
Color color;
It will show a combo with the four values of the enum.
Finally, you can add the values programmatically, usind add/removeValidValue of View class.
For example, for a simple property like this:
String color;
You can add a combo programmatically in this way:
getView().addValidValue("color", "wht", "White");
getView().addValidValue("color", "blk", "Black");
Look at:
https://openxava.org/OpenXavaDoc/docs/view_en.html#View-Property%20customization-Dynamic%20combos%20%28new%20in%20v5.8%29

Related

Anylogic: How to link a radio button to a variable with type double?

I'd like to use radio buttons in my Anylogic model to make it easier to change values before a simulation. I am running different szenarios (szenario A: electricity price Winter (Strompreis Winter); szenario B: electricity price Summer (Strompreis Sommer), szenario C: electrity price Fall (Strompreis Übergang) and I don't want to change all the formulas in my model when using another electricity price. Instead, I would like to just use the variable "electricityprice" in my formulas and then change the value(s) of that variable by using the radio button.
I tried to use a radio button to set the value of the variable "electricityprice" (Strompreis) / link it to the variable "electricityprice" (Strompreis). This is because I have hourly electricity prices for several type weeks (e.g. electricityprice winter) which are shown by dynamic variable who read them from an excel file.
Anylogic screenshot
excel file
In the field Action of the radio button I typed:
if (value==0) {
Strompreis = StrompreisWinter;
}
else if (value==1) {
Strompreis = StrompreisSommer;
}
else if (value==2) {
Strompreis = StrompreisÜbergang;
}
However, the electricity prices are of type double (e.g. 4.45€). It's only possible to link the radio buttons to a variable of type int. Any idea how I could solve that problem? Thank you!
Several things are "off" here:
When AnyLogic says you can only use Int values for radio buttons, they mean this: the value relates to the user choice made. Your radio button has 3 choices in your example so the value can only be 0, 1 or 2. Nothing else. How you map them to any action is your business.
Next: Your issue should be solved differently. Either, you want to dynamically change a variable value over the course of a year (case 1). Or you want the user to change a variable value during runtime (case 2).
Case 1: dynamically change variable value
Several ways to do this: if you only have 4 seasons, probably easiest to use a simple mapping function "getCurrentElecPrice" that returns a different dbase value based on the current season:
Case 2: let user change value
You can always change a variable directly at runtime: click on it and then on the value to edit it, see below:
More elegantly, you might want to use a slider or editbox. Or a radio button with limited options, but you wouldn't use that for a price, like in your case.
hope that helps
Here is an example model that does what you want, hope this helps :-)
download

How to specify different editor widgets for the same column in Dojo DataGrid

I am wondering, is there an official way to specify a different widget editor for the same column in a DataGrid (different rows)?
I found dojox.grid.cells._MultipleEditor, but it is quite complicated and not officially supported.
This is for creating things like a property sheet with DataGrid.
EDIT: People seem to suggest using dgrid. However, I am not sure if dgrid has this feature. Also, unfortunately, ... drum roll... horror music... I must support IE6.
Well, there seems to be a way to do it. Doesn't seem to show much negative side effects (so far)...
Create one column for each value type, one after the other.
Tag each column with a CSS class to indicate its value type (via classes). For example: classes="multivalue int"
For each column, tag it with the correct editor widget and the appropriate constraint & options.
Put styles on each row (with onStyleRow) that correspond to each type. For example, add a type-int class to the row that has an int type.
Put in a CSS style that initially hides all the multi-valued cells:
.dojoxGridCell.multivalue { display:none; }
Un-hide all the cells with the correct type:
.dojoxGridRow.type-int .dojoxGridCell.multivalue.int
{
display:table-cell;
*display:block; /* For IE6/7 */
}
For this to work, obviously, each row must match exactly one column.
Obviously, you must set all these fields to the same property name. DataGrid allows you to do that.
Put display:none (via CSS etc.) on all the header cells of multi-valued columns except the first one. Otherwise, you'll end up with too many header cells.

Displaying dynamic kanban colors according to record state in OpenERP 7

could someone tell me in what way I can display the items in a view kanban with a specific color according to the state that is the record.
I'm trying something like this
<div t-attf-class="#{record.state=='scheduled' ? oe_kanban_color_#{kanban_getcolor(1)} : oe_kanban_color_#{kanban_getcolor(0)}">
but I looked ALL elements and not only those who are in the "scheduled".
Thanks :)
If you have copy/pasted exactly what you typed in the view definition, then your t-attf- class attribute is malformed, and all record will have the following class:
class="#{record.state=='scheduled' ? oe_kanban_color_1 : oe_kanban_color_0"
which, due to CSS class precedence, will cause them all to have the oe_kanban_color_1 style.
A few hints:
To avoid coloring some records, you can omit the oe_kanban_color_X entirely in some cases
You can use a t-att-class attribute to allow arbitrary Javascript expressions, depending on what you want to do. In contrast, t-attf-class only allows replacing placeholders.
When comparing field values with Javascript operators you normally want to use the value or raw_value of the field, rather that the Field object itself. value will only differ from raw_value when the value needs specific rendering, such as dates, numbers, etc.
The kanban_getcolor() function accepts any integer or string and returns one of the 10 default kanban color indexes.
Based on the above, the following might be closer to what you tried to do (note the t-att-class attribute:
<div t-att-class="record.state.value == 'scheduled' ?
'oe_kanban_color_1' :
'oe_kanban_color_0' ">
Alternatively, you could use t-attf-class and let kanban_getcolor() pick a color based on the state string:
<div t-attf-class="oe_kanban_color_#{kanban_getcolor(record.state.value)}">
That last example is similar to what is done in many default kanban views in the official OpenERP distribution.

NHibernate - how to achieve this n:m relation?

I have two objects: Color and Palette. Each palette can get a range of colors assigned. That is what I am able to configure out with Fluent NHibernate without any problem.
But: the assignment of colors is only a constraint. If no color is assigned the palette should have every color which is available in the database.
My approach would be to check if Palette.Colors.Count() is 0, and if so, to fetch all the colors by ColorRepository.GetAllColors() and assign them manually to the palette.
Is there another "built-in" way?
It will be difficult (read: impossible) for NHibernate to map something that the database does not reflect.
You would get a huge headache if you assigned all available colors to the palette if no color is assigned. Before persisting you would have to empty the list, so that you do not end up with all those colors in the PaletteColorAssociation table.
The way I understand you, I see two options here:
1) Turn the whole thing around. What I mean is, do not save the colors that are assigned but those that are not assigned. Make that a PaletteColorExclusion table. Of course there are drawbacks to this: 1) If you add a new color to your Colors table, then that color will implicitly be part of every palette and 2) If your general rule is to only have a fraction of the available colors assigned to a palette, you will end up with more rows in the table that you would need.
I do not recommend that approach. It is only meant to show a way how to reflect that logic in the DB.
2) A modification of your apporach seems like the better idea: Do not put that logic within the Palette class but in your business logic classes. Example:
public ReadOnlyCollection<Color> GetColorsForPalette(Palette p)
{
if (p.Colors.Count() != 0)
{
return new ReadOnlyCollection<Color>(p.Colors);
}
else
{
return new ReadOnlyCollection<Color>(ColorRepository.GetAllColors());
}
}
I did not test that code and I put ReadOnlyCollection there to avoid the temptation of altering the collection, since it may not be the palette's colors.

How to use a single NSValueTransformer subclass to toggle the titles of multiple menu items

I would like to make some bindings that toggle item titles in a popup menu based on a single numerical value in a text field. Let me explain:
This is my UI:
I want my menu items to automatically adjust to singular or plural based on the number in the text field. For example, when I type "1" in the box, I want the menu items to be labeled "minute", "hour" and "day". When I type "4", I want the menu items to be labeled "minutes", "hours" and "days".
What I did to date:
I bound the three menu item's labels to the same key path as the text field's value.
I created an NSValueTransformer subclass to interpret the value in the text field and return singular or plural to be used as item titles.
I applied this value transformer to the three bindings.
The issue:
My value transformer can either return singular or plural but it can't set the appropriate string based on the menu item it's applied to.
It looks to me like a value transformer is generic and can't return different values for different destinations. That would mean that to have the three titles change automatically, I would need to have three different value transformers that return the appropriate string for each menu item. That doesn't seem optimal at all.
Ideally I would be able to combine a string stored in the destination menu item (let's say in the item's tag property) with an "s" in the value transformer when the text field's value is larger than one, or something similar that would enable me to use a single value transformer for all the menu items.
Is there something I missed? What would be an ideal solution?
Okay, this is probably not an ideal solution, but something you could consider: if you set your value transformers from your code (and not in IB), you could instantiate 3 different transformers of the same class. You could give your value transformer an ivar NSString *unit (and add something like [[MyValueTransformer alloc] initWithUnit:]) to allow each to return their own string, but you still have to write the value transformer's code only once.
(Also, if you're ever going to consider making your application localizable, simply appending an "s" to create the plurals is not going to work. You could of course add ivars for both NSString *singular and NSString *plural to do that.)
Edit: Wait, I just realized you can register value transformers! If you register them as MyValueTransformerHours and MyValueTransformerMinutes (by manually allocating and initializing them in your code), you can use them from Interface Builder. See also https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ValueTransformers/Concepts/Registration.html#//apple_ref/doc/uid/20002166-BAJEAIEE.