cancel
Showing results for 
Search instead for 
Did you mean: 

change dynamically color of table cell

Former Member
0 Kudos

Hallo,

I want to change dynamically the color of a cell table depending to a service response.

But no color change happen.

Context node is:

phase_subphase_table >> color_cell_subphase of type com.sap.ide.webdynpro.uielementdefinitions.TableCellDesign

The code is the following:

if(status.equals(DAConst.STATUS_RUNNING)){

wdContext.currentPhase_subphase_tableElement().setColor_cell_subphase(WDTableCellDesign.CRITICALVALUE_LIGHT);

}else if(status.equals(DAConst.STATUS_NOTIFY)){

wdContext.currentPhase_subphase_tableElement().setColor_cell_subphase(WDTableCellDesign.BADVALUE_LIGHT);

}else if(status.equals(DAConst.STATUS_COMPLETED)){

wdContext.currentPhase_subphase_tableElement().setColor_cell_subphase(WDTableCellDesign.GOODVALUE_MEDIUM);

}else if(status.equals(DAConst.STATUS_ABORTED)){

msg.reportSuccess("status aborted");

wdContext.currentPhase_subphase_tableElement().setColor_cell_subphase(WDTableCellDesign.BADVALUE_DARK);

}else{

wdContext.currentPhase_subphase_tableElement().setColor_cell_subphase(WDTableCellDesign.KEY_MEDIUM);

}

After refreshes I call the web service and get the status.

The table cell is colored the first time but never more change.

Could anybody help me please?

Thanks,

Andrea

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Use a calculated attribute or call this code every time the table data change.

Armin

Former Member
0 Kudos

I call this method every time but no color change.

With debug I see that the color is set into node attribute but the layout of cell doesn't change.

Former Member
0 Kudos

Are the Table/TableColumn and editors changed programmatically? Is the data binding changed programmatically?

Armin

Former Member
0 Kudos

Just the table rows and the color of cell are set runtime...

Former Member
0 Kudos

Is the table data source node invalidated after calling the Web service?

Armin

Former Member
0 Kudos

I make wdContext.nodePhase_subphase_table().invalidate(); at the begin of my method,,,

Former Member
0 Kudos

If you add a table column with a TextView as editor which is bound to the status value, what do you see? Is the status that determines the cell color correct at each row?

Armin

Former Member
0 Kudos

I have modified the code adding into the" if" the msg areas for debug:

else if(status.equals(DAConst.STATUS_ABORTED)){

msg.reportSuccess("status aborted");

wdContext.currentPhase_subphase_tableElement().setColor_cell_subphase(WDTableCellDesign.BADVALUE_DARK);

msg.reportSuccess("color: "+wdContext.currentPhase_subphase_tableElement().getColor_cell_subphase().toString());

n++;

msg.reportSuccess(Integer.toString(n));

The getColor returns the right color, but in the table the color doesn't change,it is always the same...

Former Member
0 Kudos

This is the entire method:

public void retrieveProcess( com.sap.tc.webdynpro.progmodel.api.IWDView view )

{

//@@begin retrieveProcess()

IWDMessageManager msg = wdComponentAPI.getMessageManager();

//msg.reportSuccess("RoadMapView.retrieveProcess");

logger.infoT("RoadMapView.retrieveProcess", "" + Calendar.getInstance().getTime());

category.log(Severity.INFO,logger, "RoadMapView.createRoadMap" + " - " + Calendar.getInstance().getTime());

wdContext.getContext().reset(false);

wdContext.currentContextElement().setVisibility_completed(WDVisibility.NONE);

wdContext.currentContextElement().setVisibility_running(WDVisibility.NONE);

wdContext.currentContextElement().setVisibility_notify(WDVisibility.NONE);

wdContext.currentContextElement().setVisibility_aborted(WDVisibility.NONE);

wdContext.currentContextElement().setUrl("");

wdContext.nodePhase_subphase_table().invalidate();

//se si tratta di un refresh successivo, ripulisco il container dai nodi creati in precedenza

try {

ProcessInquiryT processInquiryT = new ProcessInquiryT();

PrincipalT principalT = new PrincipalT();

principalT.setPrincipal(wdContext.currentContextElement().getIUserID());

processInquiryT.setIUser(principalT);

ApplicationContextT context = new ApplicationContextT();

context.setApplicationId(wdContext.currentContextElement().getApplicationID());

context.setEntityType(wdContext.currentContextElement().getEntityType());

processInquiryT.setContext(context);

String [] processID = {wdContext.currentContextElement().getProcessID()};

processInquiryT.setProcess(processID);

/*

msg.reportSuccess("RoadMapView.retrieveProcess: User=" + wdContext.currentContextElement().getIUserID()

+ ", ApplicationID=" + wdContext.currentContextElement().getApplicationID()

+ ", Entity Type=" + wdContext.currentContextElement().getEntityType()

+ ", ProcessID=" + wdContext.currentContextElement().getProcessID());

*/

TLManagementPpt port = wdThis.wdGetDA_compController().getTLManagementPpt();

SystemT[] arrSystemT = port.retrieveProcess(processInquiryT);

if (arrSystemT == null)

{

//msg.reportSuccess("RoadMapView.retrieveProcess: arrSystemT = null");

}

else

{

//c'è un solo sistema

SystemT systemT = arrSystemT[0];

String system_id = systemT.getSequenceGroup1().getSystemId();

String system_desc = systemT.getSequenceGroup1().getSystemDesc();

//per ogni sistema c'è un solo flusso

FlowT flowT = systemT.getSequenceGroup1().getFlowList().getSequenceGroup1().getFlow()[0];

String flow_id = flowT.getSequenceGroup1().getFlowId();

String flow_desc = flowT.getSequenceGroup1().getFlowDesc();

//per ogni flusso un solo process

ProcessT processT = flowT.getSequenceGroup1().getProcessList().getSequenceGroup1().getProcess()[0];

String process_id = processT.getSequenceGroup1().getProcessId();

String process_desc = processT.getSequenceGroup1().getProcessId();

//per ogni process un solo filepackage

FileT fileT = processT.getSequenceGroup1().getFileLIst().getSequenceGroup1().getFilePackage()[0];

String file_id = fileT.getSequenceGroup1().getId();

String file_desc = fileT.getSequenceGroup1().getDescription();

//imposto i dati mappati sulla view

wdContext.nodeDati_retrieve_process().currentDati_retrieve_processElement().setSystem_desc(system_desc);

wdContext.nodeDati_retrieve_process().currentDati_retrieve_processElement().setSystem_id(system_id);

wdContext.nodeDati_retrieve_process().currentDati_retrieve_processElement().setFlow_desc(flow_desc);

wdContext.nodeDati_retrieve_process().currentDati_retrieve_processElement().setFlow_id(flow_id);

wdContext.nodeDati_retrieve_process().currentDati_retrieve_processElement().setProcess_desc(process_desc);

wdContext.nodeDati_retrieve_process().currentDati_retrieve_processElement().setProcess_id(process_id);

wdContext.nodeDati_retrieve_process().currentDati_retrieve_processElement().setFilepackage_desc(file_desc);

wdContext.nodeDati_retrieve_process().currentDati_retrieve_processElement().setFilepackage_id(file_id);

int phaseSize = processT.getSequenceGroup1().getPhaseList().getSequenceGroup1().getPhase().length;

String currentStatus = "";

String currentPhaseId = "";

String currentSubphaseId = "";

String currentNotifyId = "";

String lastStatus = "";

for (int i = 0; i < phaseSize; i++)
{
PhaseT phaseT = processT.getSequenceGroup1().getPhaseList().getSequenceGroup1().getPhase();

String phaseDesc=phaseT.getSequenceGroup1().getPhaseDesc();

String phaseId=phaseT.getSequenceGroup1().getPhaseId();

int subPhaseSize = phaseT.getSequenceGroup1().getSubPhaseList().getSequenceGroup1().getSubPhase().length;

for(int j = 0; j< subPhaseSize; j++)

{

SubPhaseT subPhaseT = phaseT.getSequenceGroup1().getSubPhaseList().getSequenceGroup1().getSubPhase()[j];

String status = subPhaseT.getSequenceGroup1().getStatus();

IPrivateRoadMapVIew.IPhase_subphase_tableElement tableElement = wdContext.nodePhase_subphase_table().createPhase_subphase_tableElement();

tableElement.setSubphase_desc(subPhaseT.getSequenceGroup1().getSubPhaseDesc());

tableElement.setSubphase_id(subPhaseT.getSequenceGroup1().getSubPhaseId());

tableElement.setPhase_desc(phaseDesc);

tableElement.setPhase_id(phaseId);

wdContext.nodePhase_subphase_table().addElement(tableElement);

lastStatus = status;

//le fasi/sotofasi sono ordinate perciò la corrente è l'ultima con uno status valido

if (status != null && !status.equals(""))

{

currentStatus = status;

currentPhaseId = phaseT.getSequenceGroup1().getPhaseId();

currentSubphaseId = subPhaseT.getSequenceGroup1().getSubPhaseId();

if (status.equals(DAConst.STATUS_NOTIFY))

{

//currentNotifyId = "notifyId"; //subPhaseT.getSequenceGroup1().getNotifyId();

currentNotifyId = subPhaseT.getSequenceGroup1().getNotifyId();

}

}

if(status.equals(DAConst.STATUS_RUNNING)){

wdContext.currentPhase_subphase_tableElement().setColor_cell_subphase(WDTableCellDesign.CRITICALVALUE_LIGHT);

}else if(status.equals(DAConst.STATUS_NOTIFY)){

wdContext.currentPhase_subphase_tableElement().setColor_cell_subphase(WDTableCellDesign.BADVALUE_LIGHT);

}else if(status.equals(DAConst.STATUS_COMPLETED)){

wdContext.currentPhase_subphase_tableElement().setColor_cell_subphase(WDTableCellDesign.GOODVALUE_MEDIUM);

}else if(status.equals(DAConst.STATUS_ABORTED)){

msg.reportSuccess("status aborted");

wdContext.currentPhase_subphase_tableElement().setColor_cell_subphase(WDTableCellDesign.BADVALUE_DARK);

msg.reportSuccess("color: "+wdContext.currentPhase_subphase_tableElement().getColor_cell_subphase().toString());

n++;

msg.reportSuccess(Integer.toString(n));

}else{

wdContext.currentPhase_subphase_tableElement().setColor_cell_subphase(WDTableCellDesign.KEY_MEDIUM);

}

}

}

/*

msg.reportSuccess("RoadMapView.retrieveProcess: currentPhaseId=" + currentPhaseId);

msg.reportSuccess("RoadMapView.retrieveProcess: currentSubphaseId=" + currentSubphaseId);

msg.reportSuccess("RoadMapView.retrieveProcess: currentStatus=" + currentStatus);

*/

if (currentStatus.equals(DAConst.STATUS_COMPLETED))

{

if(lastStatus.equals(DAConst.STATUS_COMPLETED))

{

//il processo è completed

wdContext.currentContextElement().setVisibility_completed(WDVisibility.VISIBLE);

//fermare il refresh

wdContext.currentContextElement().setEnabled_pollingProcess(false);

}

else

{

//ci sono ancora fasi con status non completato perciò considero il processo

//come running (lastStatus = "")

wdContext.currentContextElement().setVisibility_running(WDVisibility.VISIBLE);

// msg.reportSuccess("currData= "+wdContext.currentContextElement().getCurrData());

//msg.reportSuccess("currState= "process_id"_"currentPhaseId"_"currentSubphaseId"_"+currentNotifyId);

}

}

else if (currentStatus.equals(DAConst.STATUS_ABORTED))

{

wdContext.currentContextElement().setVisibility_aborted(WDVisibility.VISIBLE);

}

else if (currentStatus.equals(DAConst.STATUS_RUNNING))

{

wdContext.currentContextElement().setVisibility_running(WDVisibility.VISIBLE);

// msg.reportSuccess("currData= "+wdContext.currentContextElement().getCurrData());

// msg.reportSuccess("currState= "process_id"_"currentPhaseId"_"+currentSubphaseId);

}

else if (currentStatus.equals(DAConst.STATUS_NOTIFY))

{

//fermare il refresh

wdContext.currentContextElement().setEnabled_pollingProcess(false);

wdContext.currentContextElement().setVisibility_notify(WDVisibility.VISIBLE);

//ricavare l'url dal file di properties

String currentFlow = flow_id.substring(0, 3);

//msg.reportSuccess("url=" + DAProperties.URL_NOTIFY + currentFlow + "." + currentPhaseId + "." + currentSubphaseId + "." + currentNotifyId);

String url = wdThis.wdGetDA_compController().getPropertyValue(DAProperties.URL_NOTIFY + "." + currentFlow + "." + currentPhaseId + "." + currentSubphaseId + "." + currentNotifyId);

//url = url.replaceAll("%processId",wdContext.currentContextElement().getProcessID());

wdContext.currentContextElement().setUrl(url);

msg.reportWarning("RoadMapView.retrieveProcess: URL=" + url);

//msg.reportSuccess("currData= "+wdContext.currentContextElement().getCurrData());

//msg.reportSuccess("currState= "process_id"_"currentPhaseId"_"currentSubphaseId"_"+currentNotifyId);

//msg.reportSuccess("notifyID= "+currentNotifyId);

}

else

{

//non è ancora stata avviata alcuna fase di workflow: considerare lo stato Running

wdContext.currentContextElement().setVisibility_running(WDVisibility.VISIBLE);

}

}

String refreshAt = wdContext.currentLabelsElement().getMsgRefreshAt().replaceAll("%1", Utils.getCurrentDate());

wdContext.currentContextElement().setRefreshAt(refreshAt);

} catch (RemoteException e) {

// TODO: handle exception

msgReportException("retrieveProcess", e);

logger.throwing("RoadMapView.retrieveProcess",e);

} catch (Exception e) {

// TODO: handle exception

logger.throwing("RoadMapView.retrieveProcess",e);

e.printStackTrace();

StringWriter sw = new StringWriter();

PrintWriter pw = new PrintWriter(sw);

e.printStackTrace(pw);

sw.flush();

StringBuffer exc = sw.getBuffer();

msgReportException("retrieveProcess "exc.toString()" ", e);

}

//@@end

}

Former Member
0 Kudos

Any help is welcome...

Former Member
0 Kudos

I'm not 100% sure why your code doesn't work, I just know that I did a working implementation of this with calculated fields, and it worked like a charm.

It seems like you are doing a lot of things in your retrieveProcess, and mixing business logic and UI logic is never really a good thing. If the status your retrieving in the for-loop doesn't reflect on your context, would it not be better to have a field in the context that is just Status, that can be either STATUS_RUNNING, STATUS_NOTIFY, STATUS_COMPLETED or STATUS_ABORTED (can be set with a SimpleValue if you want to). You set this in the same place in the code as you set the color. You then change the color_cell_subphase to be a calculated value (set it to readonly, so you don't have to worry about the set-method), and code the getColor_cell_subphase to something like this:

public WDTableCellDesign getColor_cell_subphase(IPrivateStep1.IColorElement){

String status = wdContext.currentPhase_subphase_tableElement().getStatus();

//if you want to do it fancy you can do a switch case here, but a few chained if-s works aswell

if(status.equals(DAConst.STATUS_RUNNING)){

return WDTableCellDesign.CRITICALVALUE_LIGHT;

}else if(status.equals(DAConst.STATUS_NOTIFY)){

return WDTableCellDesign.BADVALUE_LIGHT;

}else if(status.equals(DAConst.STATUS_COMPLETED)){

return WDTableCellDesign.GOODVALUE_MEDIUM;

}else if(status.equals(DAConst.STATUS_ABORTED)){

return WDTableCellDesign.BADVALUE_DARK;

}else{

return WDTableCellDesign.KEY_MEDIUM;

}

}

/Best regards, Björn Bergenheim

Former Member
0 Kudos

Thanks Björn,

with your help now it works almost well:

At the beginning, when the table is displayed the first time, no color is into cell table.

The color comes and change just after the first refresh...

How can I set the color for the first time?

Thanks,

Andrea

Former Member
0 Kudos

I'm not sure, and I realised that there might be a potential nullpointerException in the code I written.

If the String status gets returned as null, things will go bad. You might want to check for that, and if its null, set it do the default / start value you want.

You might want to try to add debug-out-messages in the getColor_cell_subphase to see that its called even for the first time, and if so, on what statement it returns (and what it returns). Should point you in the right direction.

Glad you got some of it working atleast!

/Björn

Former Member
0 Kudos

New problem afte test.

My table is like a roadmap. I want color the cells depending by a response of the web service.

For example status running blue, status completed green ecc

So first cell blue>...>green

second cell blue>...>green

ecc

My proble is that just and always the first cell changes color...

for (int i = 0; i < phaseSize; i++)

{

PhaseT phaseT = processT.getSequenceGroup1().getPhaseList().getSequenceGroup1().getPhase()<i>;

String phaseDesc=phaseT.getSequenceGroup1().getPhaseDesc();

String phaseId=phaseT.getSequenceGroup1().getPhaseId();

int subPhaseSize = phaseT.getSequenceGroup1().getSubPhaseList().getSequenceGroup1().getSubPhase().length;

for(int j = 0; j< subPhaseSize; j++)

{

SubPhaseT subPhaseT = phaseT.getSequenceGroup1().getSubPhaseList().getSequenceGroup1().getSubPhase()[j];

String status = subPhaseT.getSequenceGroup1().getStatus();

wdContext.currentContextElement().setStatus(status);

msg.reportSuccess("status: "+status);

IPrivateRoadMapVIew.IPhase_subphase_tableElement tableElement = wdContext.nodePhase_subphase_table().createPhase_subphase_tableElement();

tableElement.setSubphase_desc(subPhaseT.getSequenceGroup1().getSubPhaseDesc());

tableElement.setSubphase_id(subPhaseT.getSequenceGroup1().getSubPhaseId());

tableElement.setPhase_desc(phaseDesc);

tableElement.setPhase_id(phaseId);

lastStatus = status;

if (status != null && !status.equals(""))

{

// wdContext.currentContextElement().setStatus(status);

currentStatus = status;

currentPhaseId = phaseT.getSequenceGroup1().getPhaseId();

currentSubphaseId = subPhaseT.getSequenceGroup1().getSubPhaseId();

if (status.equals(DAConst.STATUS_NOTIFY))

{

//currentNotifyId = "notifyId"; //subPhaseT.getSequenceGroup1().getNotifyId();

currentNotifyId = subPhaseT.getSequenceGroup1().getNotifyId();

msg.reportSuccess("notifyId: "+currentNotifyId);

}

tableElement.setColor_cell_subphase(getColor_cell_subphase());

(getColor_cell_subphase());

wdContext.nodePhase_subphase_table().addElement(tableElement);

}

Former Member
0 Kudos

Looks like you are calling the method getColor_cell_subphase() yourself. This is something you should not do. Set the variable the cells are reading its color from (say color_cell_subphase) to be calculated = true. (this is done in the context tab, then properties). The framework then calls this method (the method itself gets created in the sourcefile automatic, when setting the variable to calculated=true) whenever it feels necessary, and you don't have to worry about it. Just how to set up the colors should be described in several blogs (there are some tricks how to get the right selected element).

Hope you can solve your problem.

/Björn

Former Member
0 Kudos

Thanks, now I have to go , tomorrow I will try and tell you.

Do you know one or two of these tricks? We are not able to surf out of sdn.sap.com

Have a good evening,

Andrea

Former Member
0 Kudos

HAllo Björn,

I have followed your instructions.

I set color attribute whit calculated=true and readonly=true.

In the method I put:

public com.sap.tc.webdynpro.clientserver.uielib.standard.api.WDTableCellDesign getPhase_subphase_tableColor_cell_subphase(IPrivateRoadMapVIew.IPhase_subphase_tableElement element)

{

//@@begin getPhase_subphase_tableColor_cell_subphase(IPrivateRoadMapVIew.IPhase_subphase_tableElement)

if(wdContext.currentContextElement().getStatus().equals(DAConst.STATUS_RUNNING)){

return WDTableCellDesign.CRITICALVALUE_LIGHT;

}else if(wdContext.currentContextElement().getStatus().equals(DAConst.STATUS_NOTIFY)){

return WDTableCellDesign.BADVALUE_LIGHT;

}else if(wdContext.currentContextElement().getStatus().equals(DAConst.STATUS_COMPLETED)){

return WDTableCellDesign.GOODVALUE_MEDIUM;

}else if(wdContext.currentContextElement().getStatus().equals(DAConst.STATUS_ABORTED)){

return WDTableCellDesign.BADVALUE_DARK;

}else{

return WDTableCellDesign.KEY_MEDIUM;

}

//@@end

}

Now the problem is that at the beginning all the cells are colored togheter with the same color...

My web service returns n phases. Into each phases there are m subphases. table rows number=number of all subphases.

Each subphases change status from running to completed.

Web services return all future subphases but the present subphases has a status !=null

I want set and change color of past and present subphases.

PHASE | SUBPHASE

Acquisition Phase | Loading

Profile Phase | Notify acquisition

Profile phase |

Share phase |

The first subphase (Loading) has status=completed (color blue).

The status of second subphase in the last valid status, so this is the current subphase. In this case status= notify (color orange).

The other cells of subphase are not yet colored.

Thanks,

Andrea

Edited by: Andrea Mucelli on Mar 18, 2009 11:23 AM

Former Member
0 Kudos

Right.

When I did this, I had the attribute that controlled the color as an extra 1-1 cardinality Value node (mainly because the node I was working with was based on a Structure, that I couldn't add a extra attribute to). So in the get_nameOfYourAttribute -method, I had to back up one step to get to the node I was interested in.

IRowsElement row = (IRowsElement) element.node().getParentElement();

Seems like you don't have this problem.

You do however need to get the element your working with, and you do this by instead of getting the current element, get the element thats provided in the getPhase_subphase_tableColor_cell_subphase()-call.

If the attribute is added to the IPhase_subphase_tableElement, then you should be able to get the status by calling

String status = element.getStatus();

I'm not sure how your context look like, so there might be other errors here, but I hope I pointed you in the right direction.

/Björn

Former Member
0 Kudos

With a risk of sounding like a someone who only trolls these forums looking for points...

there are a few links you might want to read too, that discus this issue

https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/creatingaColorLegendinaTableinWeb+Dynpro

/Björn

Former Member
0 Kudos

Thanks for your help Björn, now it works!

You are very kind, your explanation about calculated node is helpfull, I did not known this argument!

Have a nice day!

Kind regards,

Andrea

Answers (0)