X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-gui%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fgui%2FTable.java;h=079593c94bd247f0c80f4aabb496f6166737e53f;hb=refs%2Fchanges%2F75%2F65275%2F1;hp=6839a9ab3f19196faa285cca8393ef72ce431f30;hpb=824dc7b5fc0e1ccdf7f460479aff344727f0f01e;p=aaf%2Fauthz.git diff --git a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/Table.java b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/Table.java index 6839a9ab..079593c9 100644 --- a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/Table.java +++ b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/Table.java @@ -42,188 +42,188 @@ import org.onap.aaf.misc.xgen.html.HTMLGen; import org.onap.aaf.misc.xgen.html.State; public class Table, TRANS extends TransStore> extends NamedCode { - private final Slot ROW_MSG_SLOT, EMPTY_TABLE_SLOT; - private final String title; - private final String[] columns; - private final Rows rows; - private Code other; -// private DynamicCode prefix,postfix; + private final Slot ROW_MSG_SLOT, EMPTY_TABLE_SLOT; + private final String title; + private final String[] columns; + private final Rows rows; + private Code other; +// private DynamicCode prefix,postfix; - public Table(String title, TRANS trans, Data data, Code other, String name, String ... attrs) { - this(title,trans,data,name, attrs); - this.other = other; - } - - public Table(String title, TRANS trans, Data data, String name, String ... attrs) { - super(true,name); -// prefix=postfix=null; - for(String a : attrs) { - addAttr(false, a); - } - ROW_MSG_SLOT=trans.slot("TABLE_ROW_MSG"); - EMPTY_TABLE_SLOT=trans.slot("TABLE_EMPTY"); - this.columns = data.headers(); - boolean alt = false; - for(String s : attrs) { - if("class=std".equals(s) || "class=stdform".equals(s)) { - alt=true; - } - } - rows = new Rows(data,alt?1:0); - this.title = title; - // Derive an ID from title (from no spaces, etc), and prepend to IDAttributes (Protected from NamedCode) - addAttr(true,title(trans).replaceAll("\\s","")); - - other = null; - } + public Table(String title, TRANS trans, Data data, Code other, String name, String ... attrs) { + this(title,trans,data,name, attrs); + this.other = other; + } + + public Table(String title, TRANS trans, Data data, String name, String ... attrs) { + super(true,name); +// prefix=postfix=null; + for(String a : attrs) { + addAttr(false, a); + } + ROW_MSG_SLOT=trans.slot("TABLE_ROW_MSG"); + EMPTY_TABLE_SLOT=trans.slot("TABLE_EMPTY"); + this.columns = data.headers(); + boolean alt = false; + for(String s : attrs) { + if("class=std".equals(s) || "class=stdform".equals(s)) { + alt=true; + } + } + rows = new Rows(data,alt?1:0); + this.title = title; + // Derive an ID from title (from no spaces, etc), and prepend to IDAttributes (Protected from NamedCode) + addAttr(true,title(trans).replaceAll("\\s","")); + + other = null; + } - @Override - public void code(final Cache cache, final HTMLGen hgen) throws APIException, IOException { - cache.dynamic(hgen, new DynamicCode() { - @Override - public void code(S state, TRANS trans, Cache cache, HTMLGen xgen) throws APIException, IOException { - rows.data.prefix(state, trans, cache, xgen); - } - }); - Mark table = new Mark(); - Mark tr = new Mark(); - - hgen.incr(table,TABLE); - if(title==null) { - cache.dynamic(hgen, new DynamicCode() { - @Override - public void code(S state, TRANS trans, final Cache cache, final HTMLGen hgen) throws APIException, IOException { - hgen.leaf("caption", "class=title").text(title(trans)).end(); - } - }); - } else { - hgen.leaf("caption", "class=title").text(title).end(); - } - hgen.incr(tr,TR); - for(String column : columns) { - hgen.leaf("th").text(column).end(); - } - hgen.end(tr); - - // Load Rows Dynamically - cache.dynamic(hgen, rows); - // End Table - hgen.end(table); - - if(other!=null) { - other.code(cache,hgen); - } - - // Print Message from Row Gathering, if available - cache.dynamic(hgen, new DynamicCode() { - @Override - public void code(S state, TRANS trans, final Cache cache, final HTMLGen hgen) throws APIException, IOException { - String msg; - if((msg = trans.get(EMPTY_TABLE_SLOT, null))!=null) { - hgen.incr("style").text("#inner tr,caption,input,p.preamble {display: none;}#inner p.notfound {margin: 0px 0px 0px 20px}").end(); - hgen.incr(HTMLGen.P,"class=notfound").text(msg).end().br(); - } else if((msg=trans.get(ROW_MSG_SLOT,null))!=null) { - hgen.p(msg).br(); - } - } - }); - cache.dynamic(hgen, new DynamicCode() { - @Override - public void code(S state, TRANS trans, Cache cache, HTMLGen xgen) throws APIException, IOException { - rows.data.postfix(state, trans, cache, xgen); - } - }); + @Override + public void code(final Cache cache, final HTMLGen hgen) throws APIException, IOException { + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(S state, TRANS trans, Cache cache, HTMLGen xgen) throws APIException, IOException { + rows.data.prefix(state, trans, cache, xgen); + } + }); + Mark table = new Mark(); + Mark tr = new Mark(); + + hgen.incr(table,TABLE); + if(title==null) { + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(S state, TRANS trans, final Cache cache, final HTMLGen hgen) throws APIException, IOException { + hgen.leaf("caption", "class=title").text(title(trans)).end(); + } + }); + } else { + hgen.leaf("caption", "class=title").text(title).end(); + } + hgen.incr(tr,TR); + for(String column : columns) { + hgen.leaf("th").text(column).end(); + } + hgen.end(tr); + + // Load Rows Dynamically + cache.dynamic(hgen, rows); + // End Table + hgen.end(table); + + if(other!=null) { + other.code(cache,hgen); + } + + // Print Message from Row Gathering, if available + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(S state, TRANS trans, final Cache cache, final HTMLGen hgen) throws APIException, IOException { + String msg; + if((msg = trans.get(EMPTY_TABLE_SLOT, null))!=null) { + hgen.incr("style").text("#inner tr,caption,input,p.preamble {display: none;}#inner p.notfound {margin: 0px 0px 0px 20px}").end(); + hgen.incr(HTMLGen.P,"class=notfound").text(msg).end().br(); + } else if((msg=trans.get(ROW_MSG_SLOT,null))!=null) { + hgen.p(msg).br(); + } + } + }); + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(S state, TRANS trans, Cache cache, HTMLGen xgen) throws APIException, IOException { + rows.data.postfix(state, trans, cache, xgen); + } + }); - } + } - protected String title(TRANS trans) { - return title; - } + protected String title(TRANS trans) { + return title; + } - public static class Cells { - public static final Cells EMPTY = new Cells(); - private Cells() { - cells = new AbsCell[0][0]; - msg = "No Data Found"; - } - - public Cells(ArrayList arrayCells, String msg) { - cells = new AbsCell[arrayCells.size()][]; - arrayCells.toArray(cells); - this.msg = msg; - } - public AbsCell[][] cells; - public String msg; - - } - - public interface Data, TRANS extends Trans> { - // Note: Trans is not first to avoid Method Name Collision - public void prefix(S state, TRANS trans, final Cache cache, final HTMLGen hgen); - public Cells get(TRANS trans,S state); - public void postfix(S state, TRANS trans, final Cache cache, final HTMLGen hgen); - public String[] headers(); - } + public static class Cells { + public static final Cells EMPTY = new Cells(); + private Cells() { + cells = new AbsCell[0][0]; + msg = "No Data Found"; + } + + public Cells(ArrayList arrayCells, String msg) { + cells = new AbsCell[arrayCells.size()][]; + arrayCells.toArray(cells); + this.msg = msg; + } + public AbsCell[][] cells; + public String msg; + + } + + public interface Data, TRANS extends Trans> { + // Note: Trans is not first to avoid Method Name Collision + public void prefix(S state, TRANS trans, final Cache cache, final HTMLGen hgen); + public Cells get(TRANS trans,S state); + public void postfix(S state, TRANS trans, final Cache cache, final HTMLGen hgen); + public String[] headers(); + } - private class Rows extends DynamicCode { - private Data data; - private int alt; - - public Rows(Data data, int alt) { - this.data = data; - this.alt = alt; - } - - @Override - public void code(final S state, final TRANS trans, final Cache cache, final HTMLGen hgen) throws APIException, IOException { - Mark tr = new Mark(); - Mark td = new Mark(); - - int alt = this.alt; - Cells cells = data.get(trans,state); - if(cells.cells.length>0) { - for(AbsCell[] row : cells.cells) { - if(row.length==0) { - hgen.text("") - .hr() - .text(""); - } else { - switch(alt) { - case 1: - alt=2; - case 0: - hgen.incr(tr,TR); - break; - default: - alt=1; - hgen.incr(tr,TR,"class=alt"); - } - for(AbsCell cell :row) { - hgen.leaf(td, TD,cell.attrs()); - cell.write(hgen); - hgen.end(td); - } - hgen.end(tr); - } - } - // Pass Msg back to Table code, in order to place after Table Complete - if(cells.msg!=null) { - trans.put(ROW_MSG_SLOT,cells.msg); - } - } else { - trans.put(EMPTY_TABLE_SLOT,cells.msg); - } - } - } + private class Rows extends DynamicCode { + private Data data; + private int alt; + + public Rows(Data data, int alt) { + this.data = data; + this.alt = alt; + } + + @Override + public void code(final S state, final TRANS trans, final Cache cache, final HTMLGen hgen) throws APIException, IOException { + Mark tr = new Mark(); + Mark td = new Mark(); + + int alt = this.alt; + Cells cells = data.get(trans,state); + if(cells.cells.length>0) { + for(AbsCell[] row : cells.cells) { + if(row.length==0) { + hgen.text("
") + .hr() + .text(""); + } else { + switch(alt) { + case 1: + alt=2; + case 0: + hgen.incr(tr,TR); + break; + default: + alt=1; + hgen.incr(tr,TR,"class=alt"); + } + for(AbsCell cell :row) { + hgen.leaf(td, TD,cell.attrs()); + cell.write(hgen); + hgen.end(td); + } + hgen.end(tr); + } + } + // Pass Msg back to Table code, in order to place after Table Complete + if(cells.msg!=null) { + trans.put(ROW_MSG_SLOT,cells.msg); + } + } else { + trans.put(EMPTY_TABLE_SLOT,cells.msg); + } + } + } -// public Table setPrefix(DynamicCode dynamicCode) { -// prefix = dynamicCode; -// return this; -// } -// -// public Table setPostfix(DynamicCode dynamicCode) { -// postfix = dynamicCode; -// return this; -// } +// public Table setPrefix(DynamicCode dynamicCode) { +// prefix = dynamicCode; +// return this; +// } +// +// public Table setPostfix(DynamicCode dynamicCode) { +// postfix = dynamicCode; +// return this; +// } }