Oliver Lambert <olambo...@gmail.com> writes: [...]
> No this isn't what I'm suggesting, I don't think MappedEnum should be made > flexible. I know this wasn't your suggestion, but any reason not to make MappedEnum flexible (if possible and backwards compatibility could be maintained) ? > I was thinking perhaps your class could work with EnumWithDescription > as shown below, which extends Enumeration#Values to include a > description. This should be simple, but see below > trait ValueWithDescription { > def description: String > def name: String > } > abstract class EnumWithDescription { > type Value = enum.Value with ValueWithDescription > > private var _values: List[Value] = Nil > def values = _values > > // possibly not a good idea using this directly > val enum = new Enumeration { > def Value(inName: String, inDescription: String): Value with > ValueWithDescription = { > new Val(nextId, inName) with ValueWithDescription { > def description = inDescription > def name = inName > } > } > } > def Value(name: String, description: String): Value = { > val value = enum.Value(name, description) > _values = _values ::: List(value) // build in order > value > } > def Value(name: String): Value = Value(name, name) > def valueOf(name: String) = values find (_.name == name) > def nameDescriptionList = values map(x => (x.name, x.description) ) > } At first I didn't understand why you don't just extend Enumeration like this: abstract class EnumWithDescription extends Enumeration { def Value(inName: String, inDescription: String): Value with ValueWithDescription = { new Val(nextId, inName) with ValueWithDescription { def description = inDescription def name = inName } } } but figure you would then have to cast all the values to ValueWithDescription. It seems Enumeration miss a type parameter to describe the types of Values in cases like this. Hmmm I see Enumerations have changed for 2.8 so maybe this is not impossible.... Back to the mapping. The way I see all these different solutions is: 1) We need to define Enumerations to get nice handling of predefined constants 2) The enumeration values need to be mapped to a database value (numeric or string) 3) The enumeration values need to be mapped to a display value (from code our property files) If the MappedEnum was parameterized on how to achieve 2+3 it seem all possibilities are open. If MappedEnum worked with ValueWithDescription values instead of Enumeration#Value, it might? be possible to define an implicit conversion from Enumeration#Value to ValueWithDescription.... I don't have much time in the days that are coming but will try to think of a solution to this. Input is welcome :-) /Jeppe --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~----------~----~----~----~------~----~------~--~---