Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » How to add User Defined Property and Named Expression programmatically?
How to add User Defined Property and Named Expression programmatically? [message #1002521] Fri, 18 January 2013 14:02 Go to next message
Aleksey   is currently offline Aleksey
Messages: 42
Registered: April 2012
Member
hello,
we are struggling to find the right code using Design Engine API to add User Defined Property and Named Expressions to an element:
....
DataItemHandle control = (DataItemHandle) elementFactory.newDataItem("COLUMN1");
control.setResultSetColumn("COLUMN1");

control.setProperty("MyProperty", "test");
control.setExpressionProperty("MyExpression", new Expression("\"test\"", ExpressionType.JAVASCRIPT));

....


Both setProperty() and setExpressionProperty() throw exceptions that the property name is invalid. Looks like you have to add it first - I found addUserPropertyDefn() method for simple properties but even after I add the property:
UserPropertyDefn p = new UserPropertyDefn();
p.setName("MyProperty");
p.setType(new StringPropertyType());
control.addUserPropertyDefn(p);

control.setProperty("MyProperty", "test"); throws another exception saying that value type is invalid...

And I cannot find any API method that would allow you to add a NamedExpression as opposed to User Defined Property. Could somebody who knows API help with that?

Thanks,
Alexey
Re: How to add User Defined Property and Named Expression programmatically? [message #1002572 is a reply to message #1002521] Fri, 18 January 2013 16:25 Go to previous message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Try something like:

MetaDataDictionary dd = MetaDataDictionary.getInstance( );
PropertyType strType = dd.getPropertyType( PropertyType.STRING_TYPE );

UserPropertyDefn newPropDefn = new UserPropertyDefn( );
newPropDefn.setName( "myProp4" ); //$NON-NLS-1$
newPropDefn.setType( strType );

PropertyType expType = dd.getPropertyType( PropertyType.EXPRESSION_TYPE );

UserPropertyDefn newNamedDefn = new UserPropertyDefn( );
newNamedDefn.setName( "myNamedExpression" ); //$NON-NLS-1$
newNamedDefn.setType( expType );
Expression expr = new Expression("\"test\"", ExpressionType.JAVASCRIPT);
newNamedDefn.setDefault(expr);



// Add one new user-defined property definition

table.addUserPropertyDefn( newPropDefn );
table.addUserPropertyDefn( newNamedDefn );

Jason
Previous Topic:How to eliminate the outline of a meter chart?
Next Topic:crosstab dimension drilldown
Goto Forum:
  


Current Time: Fri Aug 01 07:53:26 EDT 2014

Powered by FUDForum. Page generated in 0.03753 seconds