Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

AfterScroll on ECO??

1 view
Skip to first unread message

Marcelo Siqueira

unread,
Apr 23, 2006, 9:00:40 PM4/23/06
to
I have a form with a DataGrid, an ExpressionHandle, a
CurrencyManagerHandle and a ComboBox. I need to update a value on the
ComboBox depending on the current selected object (record) on the
DataGrid, but I didnt find any AfterScroll or equivalent event on any of
the ECO components. What event ECO fires when the user moves from one
record to another on the DataGrid?

TIA,
Marcelo

Jose Maria Sanmartin

unread,
Apr 24, 2006, 5:41:26 AM4/24/06
to
Hi,

Have a look to Jan Norden' blog where you can find an example with a
DataGrid and a Combobox which changes depending of the row selected.

Hope it helps,

Jose Maria Sanmartin


"Marcelo Siqueira" <mdmsiqueira...@uol.com.br> escribió en el
mensaje news:444c...@newsgroups.borland.com...

Marcelo Siqueira

unread,
Apr 24, 2006, 12:35:47 PM4/24/06
to
Hi Jose,

Thanks for the help, but Norden's example didn't work for me. My case is
a bit different.

I have a class with an attribute of a enumerated type:

public enum DeliveryType {Normal, Fast};

public class Test : ILoopBack
{
public DeliveryType Delivery;
{
// get / set
}
{

If the CurrencyManager exposed an event like AfterScroll I would get/set
the ComboBox ItemIndex and the class properties correctly.

I just don't know what to do to get this to work right.

Marcelo

Jose Maria Sanmartin

unread,
Apr 24, 2006, 3:04:12 PM4/24/06
to
Hi,

Have a look to Attachments "ECO: Enum and ComboBox",

I have created an example which shows how to do it.

ExpressionHandle ehEnum with:
expression DeliveryType.AllInstances
Column MySelf with expression self
Column DisplayString with xpression self.asString

ComboBox1
DataSource: ehEnum
DisplayMember: DisplayString
ValueMember: MySelf

SelectedValue ehTests - Delivery

Let me know if you have any doubt.

Regards,

Jose Maria Sanmartin


Jose Maria Sanmartin

unread,
Apr 24, 2006, 3:05:49 PM4/24/06
to
Take into account that the property change in the datagrid after leaving the
comboBox.

Jose Maria Sanmartin


Marcelo Siqueira

unread,
Apr 24, 2006, 6:49:53 PM4/24/06
to
Hi Jose,

Thanks a lot! It was exactly what I needed.

Just one last question.

Let's say that I have an enum type like this:

public enum DeliveryType {dtNormal, dtFast};

I like to add this identification characters on my types, like those
"dt". But on the ComboBox I would like to show a friendly string, just
like "Normal" and "Fast". Is there a way to control the result of OCL
self.AsString, to show any string I want?

Marcelo

Erik Reischl

unread,
Apr 25, 2006, 3:40:48 AM4/25/06
to

Hi Marcelo,

Marcelo Siqueira <mdmsi...@yahoo.com.br> wrote:
>I like to add this identification characters on my types, like those
>"dt". But on the ComboBox I would like to show a friendly string, just
>like "Normal" and "Fast". Is there a way to control the result of OCL
>self.AsString, to show any string I want?

Basically, you will need to write and install a custom OCL
operation for the display of the enum, lets assume you call it
"DisplayEnum". Then, in the data grid, add additional columns with
expressions for your attribute like this:

self.Delivery.DisplayEnum

I beleive there are quite a few sources for writing your own
custom OCL operations with ECO.

HTH,

Erik

P.S.: Hey, that's the second time in my life I post into an ECO
NG without having a question myself but rather answering. I'm
getting better, eh? ;-)

Jose Maria Sanmartin

unread,
Apr 25, 2006, 10:57:13 AM4/25/06
to
What about using subString in the Ocl expression for DisplayString?
i.e. self.asString.subString(3,15)

I guess that you should do the same for the delivery attribute of the Test
class.

Regards,

Jose Maria Sanmartin

"Marcelo Siqueira" <mdmsi...@yahoo.com.br> escribió en el mensaje
news:444d5612$1...@newsgroups.borland.com...

Marcelo Siqueira

unread,
Apr 25, 2006, 1:00:17 PM4/25/06
to
Erik Reischl wrote:
> P.S.: Hey, that's the second time in my life I post into an ECO
> NG without having a question myself but rather answering. I'm
> getting better, eh? ;-)

I'm glad about that.

Soon I'm hope to be answering questions too. :)

Marcelo

Erik Reischl

unread,
Apr 25, 2006, 2:18:34 PM4/25/06
to
"Jose Maria Sanmartin" <ch...@nospamplease.com> schrieb im Newsbeitrag
news:444e38c9$1...@newsgroups.borland.com...

> What about using subString in the Ocl expression for DisplayString?
> i.e. self.asString.subString(3,15)

I wouldn't recommend this. In this particular case it's okay, of course, but
it wouldn't look too nice with other enums, especially when you need spaces
in the display string or when you want the display string in another
language than the names of the enums.

Just my two cents :-)

Erik


Marcelo Siqueira

unread,
Apr 26, 2006, 9:17:47 PM4/26/06
to
Hi Jose,

New error here:

Now when I tried to create the database schema for my model I got:

Schema Generation| Unable to find a persistence mapper for
"NKModelCS.DeliveryType", please update your
SqlDatabaseConfig.PersistenceMappers

I tried to include a new item on the
persistentMapperMySQL1.PersistentMappers collecion:

Mapper = Borland.Eco.Persistence.NKModelCS.DeliveryType
Name = NKModelCS.DeliveryType

But it didn't work. The system just erased my Mapper name.

Any ideas?

Thanks,
Marcelo

I tried to put NKModelCS.DeliveryType on the

I have no idea how to update this PersistenceMapper.

Jose Maria Sanmartin

unread,
Apr 27, 2006, 1:46:27 AM4/27/06
to
Hi Marcelo,

You'll have to write a persistence mapper for the DeliveryType enum:

See how:
http://homepages.borland.com/ecoteam/pmwiki/pmwiki.php?n=Eco.PersistenceMappersForEnums

If not use a class instead of an enum.

Regards,

Jose Maria Sanmartin


"Marcelo Siqueira" <mdmsi...@yahoo.com.br> escribió en el mensaje
news:44501bbc$1...@newsgroups.borland.com...

Marcelo Siqueira

unread,
Apr 27, 2006, 8:44:36 AM4/27/06
to
Hi Jose,

Thanks again.

But I was a bit disapointed. It's a lot of code to handle just a small
enum type. I still have a lot to learn about ECO...

Marcelo

Jonas Hogstrom

unread,
May 5, 2006, 5:50:36 AM5/5/06
to
Marcelo Siqueira wrote:

> Hi Jose,
>
> New error here:
>
> Now when I tried to create the database schema for my model I got:
>
> Schema Generation| Unable to find a persistence mapper for
> "NKModelCS.DeliveryType", please update your
> SqlDatabaseConfig.PersistenceMappers


I just recently made a generic class for handling enums, you still need
to subclass and install the mapper, but most of the generic stuff is
handled in the generic class (less copy/paste if you have multiple
enums):

using System;
using System.Data;
using Borland.Eco.Persistence;
using Borland.Eco.Persistence.Default;
using Borland.Eco.Persistence.Configuration;

namespace Borland.Eco.Persistence
{
// Map to numeric value of enum
/// <summary>
/// Generic class to map an enum value to an integer
/// </summary>
/// <remarks>
/// Subclass this class and override the constructor and implement two
static private properties as in the example.
/// <example>
/// <code>
/// // the enumeration type that should be mapped
/// public enum Gender { male, female }
///
/// // the mapper class for the Gender enum type above
/// public class GenderAsInteger: GenericEnumAsInteger
/// {
/// private static Type enumType = typeof(Gender);
/// private static Type mapperType = typeof(GenderAsInteger);
///
/// // parameterless constructor that initializes the attribute mapper
with the enum type
/// public TestCaseStatusAsInteger(): base(enumType, mapperType)
/// {
/// // intentionally left blank
/// }
///
/// // This method can be used in runtime to add the attribute
/// // mapper to the attributemapper collection of a PersistenceMapper
component
/// public static void AddToPersistenceMapper(PersistenceMapperDb
pmapper)
/// {
/// GenericEnumAsInteger.AddToPersistenceMapper(pmapper,
enumType, mapperType);
/// }
/// }
/// </code>
/// </example>


public class GenericEnumAsInteger:
AbstractNumericSingleColumnAttribute, ISingleColumnAttributemapping
{
private readonly Type enumType;
private readonly Type mapperType;
protected GenericEnumAsInteger(Type enumType, Type mapperType)
{
this.enumType = enumType;
this.mapperType = mapperType;
}

public String ColumnType(int length)
{
return "INTEGER"; // do not localize
}

public void ValueToParameter(System.Object value, IDataParameter
parameter)
{
EnsureType(value, enumType);
parameter.DbType = DbType.Int32;
if (value == null)
parameter.Value = DBNull.Value;
parameter.Value = (Int32)value;
}

public void StringToParameter(string value, IDataParameter parameter)
{
if (value == null || value.Length == 0)
parameter.Value = DBNull.Value;
else
ValueToParameter(Enum.Parse(enumType, value), parameter);
}

public override System.Object ColumnToValue(System.Object columnValue)
{
EnsureType(columnValue, typeof(System.Int32));
if (DBNull.Value.Equals(columnValue))
return null;
else
{
// is there no easier way to convert an int to an enum?
Array values = Enum.GetValues(enumType);
object value = Enum.Parse(enumType,
values.GetValue((int)columnValue).ToString());
return value;
}
}

/// <summary>
/// generic method to install the attribute mapper in the attribute
mapper collection of a PersistenceMapper
/// </summary>
public static void AddToPersistenceMapper(PersistenceMapperDb
pmapper, Type enumType, Type mapperType)
{
PersistenceMapperDefinitionCollection collection =
pmapper.SqlDatabaseConfig.PersistenceMappers;
string defName = enumType.ToString();
if (collection.FindByName(defName) == null)
{
PersistenceMapperDefinition def = new PersistenceMapperDefinition();
def.Mapper = mapperType;
def.Name = defName;
collection.Add(def);
}
}
}
}

--
/Jonas, Borland Eco R&D

0 new messages