cancel
Showing results for 
Search instead for 
Did you mean: 

Setting TextViewSemanticColor on runtime

Rodrigo-Giner
Active Contributor
0 Kudos

I dont have NV04s , so I know that the only way to change the color in a table is trought the property SemanticColor.

I want to set this property depending the value that is in the table.

I created a Value Attribute in the context with type:

com.sap.tc.webdynpro.clientserver.uielib.standard.api.WDTextViewSemanticColor

I wanna bind the semanticColor property to this value Atrribute and change his value in the wdDoModifyView depening a certain conditions. But when I hit the "..." button I found that the value attribute that I created is not compatible.

what is wrong ?

BTW, some1 could tell me some links to also change the cells design in xml format (I export this table to Excel 2003 using the method of XML-Binary cache)

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Use DDIC type com.sap.ide.webdynpro.uielementdefinitions.TextViewSemanticColor at designtime for the context attribute, not the Java native type.

Bind the "semanticColor" property of the TextView (table cell editor) to your context attribute.

Then you can control the editor color by setting the attribute value. Do it from inside event handler methods, not from wdDoModifyView().

If you want to calculate the color from another context attribute's value, a calculated context attribute is useful.

Armin

Rodrigo-Giner
Active Contributor
0 Kudos

Done, thx Armin

now what I need is a big help with the code _ Im a humble ABAPer, Im very new in all this webdynpro and java code.

1- Some1 could tell me how to run trought the entire table and only trought the column that I want to set the color change depending a condition like < 0.

2- To set the value in the Value Attribute I do:

wdContext.currentContextElement().setCellColor( ??? );

The setCellColor method ask me a WDTextViewSemanticColor value parameter, How do I do to pass to the method for example a NEGATIVE value.

Thx for your help and your pacience 😃

Former Member
0 Kudos

You don't need to "run through the table" etc.

Example: Say you have a context node "Stock" with an attribute "Available" of type "integer", and you want to mark a stock item with a red color if there are less than 3 available.

Define a new context attribute "Color" of type TextViewSemanticColor (as I wrote before) under the node "Stock", set readOnly=true, calculated=true.

Then there will appear a new method

WDTextViewSemanticColor getColor(IPrivate<View>.IStockElement element)

in the view controller.

Write the following code inside the //@@begin ... //@@end block (aka. user coding area):


return element.getAvailable() < 3
  ? WDTextViewSemanticColor.CRITICAL
  : WDTextViewSemanticColor.STANDARD;

If you bind the cell editor's "semanticColor" property to attribute "Color", exactly those cells will be red, where the available stock is less than 3.

Armin

Message was edited by: Armin Reichert

Rodrigo-Giner
Active Contributor
0 Kudos

Hi Armin.

I try to adapt what u said to me, in my program but without success.

could u tell me the code, just like u did, but with this scenary:

- In my context I have a Model Nodel so I cant create a value Attribute inside of this node.

- All the data is bringed in String format, so I would use a "match" condition.

Thx u very much.

Former Member
0 Kudos

Rodrigo,

You can use a helper node to achieve this. Under the Model Node, create a Value Node, say <i>VN1</i> (Cardinality - <i>1:1</i>, Singleton - <i>false</i>, Selection - <i>1:1</i>). Create a value attribute (i.e the attribute "<i>Available</i>" in Armin's post) under this Value Node VN1.

Then follow all the steps prescribed my Armin. You will definitely get to see the results.

Good luck,

Bala

Rodrigo-Giner
Active Contributor
0 Kudos

Bala sorry but I get so loss. I will go to documentation to know about modyfing context and UI at runtime 'cuase Im simply not getting this, I tought that this would be easier.

BTW Armir, do u erase a line of code ?

I know that is stupid that some1 that doesnt know java get involved in this, but well I have to do it for my work, so slowly and by the hard way Im learning, so dont be afraid to treat me like a Noob.

Former Member
0 Kudos

In the context editor, add a subnode (value node) to the model node exactly as Bala described.

Then follow the steps from my post. No need to add additional runtime code.

As a valuable source of information, I recommend the book "Inside Web Dynpro for Java" by Chris Whealy.

Yes, I removed a line of code because it was obsolete (parameter of get-method is already strongly typed).

Armin

Rodrigo-Giner
Active Contributor
0 Kudos

So, my context should look like this ? right ?

-Table_user (model node)

.|-VN1 (value node)

...|-Available (Vale Attribute)

.|-(my models attributes that I bring)

-Color (value attribute)

or not ? ^^

my question are:

1- What properties should I set in the Available attribute that I created.

2-

return element.getAvailable() < 3

? WDTextViewSemanticColor.CRITICAL

: WDTextViewSemanticColor.STANDARD;

a- what I have to put in "element" ?

b- getAvailable() reffers to the Model Attribute or to the Value attribute inside Value node?

3- My field wich I wanna check isnt a Integer is a String so, how would it be the code to acomplish this ?

4- What does the property "calculated" ?

Thx

Former Member
0 Kudos

Not exactly.

In my example, the "Available" attribute would probably come from the model and the "Color" attribute would be added to the value node "Additional".

So the context would look like this:

"Stock" (model node)

++ "Available" (attribute)

++ "Additional" (value node, singleton=false, card=1:1, selection=1:1

++++ "Color" (attribute, calculated=true, readOnly=true)

The values of "Available" for the "Stock" elements would come from the backend.

For each "Stock" element, there will exist a separate "Additonal" node (because singleton=false).

The get-method for the calculated attribute "Color" computes the color for each "Stock" element from the "Available" attribute value.

Armin

Rodrigo-Giner
Active Contributor
0 Kudos

Thx Armin, now Im seeing the light _

I hope that this will be the last question, now I get it the why of the value node creation.

This code will work if Im not working with Model nodel:

return element.getAvailable() < 3

? WDTextViewSemanticColor.CRITICAL

: WDTextViewSemanticColor.STANDARD;

But 'cuase Im using Model node,I have to create the value node with cardinality 1:1, and singleton false, an inside an attribute of type TextViewSemanticColor and calculated, when I go to implementation.

now "element" is pointing to the Value Node, instead of the Model node, so that's why:

return element.<u>getAvailable</u>() < 3

? WDTextViewSemanticColor.CRITICAL

: WDTextViewSemanticColor.STANDARD;

doesnt work 'cause getAttribute is in the Model node Scope, right ?

But how do I fix this ?

I tried this:

String cod = wdContext.currentTable_userElement().getCodcivil();

if (cod.matches("01"))

return WDTextViewSemanticColor.CRITICAL;

else

return WDTextViewSemanticColor.STANDARD;

but... Im seeing all the column in CRITICAL not only the fields with "01"

What is wrong?

Former Member
0 Kudos

Try this:

ITable_userElement parentElement = (ITable_userElement) element.node().getParentElement();
String cod = parentElement.getCodcivil();
if (cod.matches("01"))
  return WDTextViewSemanticColor.CRITICAL;
else
  return WDTextViewSemanticColor.STANDARD;

Armin

Former Member
0 Kudos

Armin,

If my brains serve me well (it is 01:11 Thu the code

if (cod.matches("01"))

is very same (in given context) as

if (cod.equals("01"))

(but cheaper in terms of performance)

Thoughts?

VS

Former Member
0 Kudos

Honestly, I didn't spend any thoughts on this one, I just concentrated on explaining the non-singleton value node part.

You are most probably correct on this one.

Armin

Answers (0)