// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
// Source File Name: TableCtrl.java
package com.cyt.commons.sortTable;
import com.cyt.commons.webservice.PageCtrlInfo;
import cyt.core.InvokeKit;
import java.io.PrintStream;
import java.util.*;
// Referenced classes of package com.cyt.commons.sortTable:
// LinkInfo, LinkImage, ExtAttr, tableField,
// LinkBase
public class TableCtrl
{
public TableCtrl()
{
tableCss = "topTab";
checkBoxAttr = null;
voList = null;
pageCtrl = null;
headerList = null;
linkList = null;
tableId = "dfTableId";
headerList = new ArrayList();
sortTable = true;
align = "left";
width = "100%";
HeaderBgColor = "#74AEEC";
rowColor1 = "#48D1CC";
rowColor2 = "#AFEEEE";
bShowIndex = false;
showFieldAtrr = false;
}
public void clearLinks()
{
if(linkList != null)
linkList.clear();
}
public int AddLink(String linkName, String link, String linkField, String linkEndWith, String tip)
{
if(linkList == null)
linkList = new ArrayList();
linkList.add(new LinkInfo(linkName, link, linkField, linkEndWith, tip));
return linkList.size() - 1;
}
public int AddLink(String linkName, String link, String linkField, String linkEndWith, String tip, String btnCss)
{
if(linkList == null)
linkList = new ArrayList();
linkList.add(new LinkInfo(linkName, link, linkField, linkEndWith, tip, btnCss));
return linkList.size() - 1;
}
public int AddImgLink(String imgPath, String link, String linkField, String linkEndWith, String tip)
{
if(linkList == null)
linkList = new ArrayList();
linkList.add(new LinkImage(imgPath, link, linkField, linkEndWith, tip));
return linkList.size() - 1;
}
public void AddCheckBoxAttr(String name, String value)
{
if(checkBoxAttr == null)
checkBoxAttr = new ArrayList();
checkBoxAttr.add(new ExtAttr(name, value));
}
public void setVOList(ArrayList volist)
{
voList = volist;
}
public String getHeaderNameJsArray()
{
String headerNamejs = "headerName = Array(";
if(isHasSubTable())
headerNamejs = (new StringBuilder(String.valueOf(headerNamejs))).append("'',").toString();
else
headerNamejs = (new StringBuilder(String.valueOf(headerNamejs))).append("'',").toString();
if(hasCheckBox)
headerNamejs = (new StringBuilder(String.valueOf(headerNamejs))).append("'',").toString();
for(int i = 0; i < headerList.size(); i++)
{
Set mapset = ((Map)headerList.get(i)).entrySet();
java.util.Map.Entry m = (java.util.Map.Entry)mapset.toArray()[0];
tableField field = (tableField)m.getValue();
headerNamejs = (new StringBuilder(String.valueOf(headerNamejs))).append("\"").append(field.getHeaderName()).append("\"").toString();
if(i < headerList.size() - 1)
headerNamejs = (new StringBuilder(String.valueOf(headerNamejs))).append(",").toString();
}
headerNamejs = (new StringBuilder(String.valueOf(headerNamejs))).append(");").toString();
return headerNamejs;
}
public String getsortFields()
{
String sortFields = "sortFields = Array(";
if(isHasSubTable())
sortFields = (new StringBuilder(String.valueOf(sortFields))).append("'',").toString();
else
sortFields = (new StringBuilder(String.valueOf(sortFields))).append("'',").toString();
if(hasCheckBox)
sortFields = (new StringBuilder(String.valueOf(sortFields))).append("'',").toString();
for(int i = 0; i < headerList.size(); i++)
{
Set mapset = ((Map)headerList.get(i)).entrySet();
java.util.Map.Entry m = (java.util.Map.Entry)mapset.toArray()[0];
sortFields = (new StringBuilder(String.valueOf(sortFields))).append("\"").append((String)m.getKey()).append("\"").toString();
if(i < headerList.size() - 1)
sortFields = (new StringBuilder(String.valueOf(sortFields))).append(",").toString();
}
sortFields = (new StringBuilder(String.valueOf(sortFields))).append(");").toString();
return sortFields;
}
public String getTableHtml()
{
InvokeKit kit = new InvokeKit();
String table = (new StringBuilder("\r\n\r\n\r\n<TABLE id=")).append(tableId).toString();
if(tableCss.length() > 0)
table = (new StringBuilder(String.valueOf(table))).append(" class=").append(tableCss).toString();
table = (new StringBuilder(String.valueOf(table))).append(" width='").append(width).append("' align=").append(align).append(">\r\n").toString();
String hBgColor = "bgColor=";
if(HeaderBgColor.indexOf("#") < 0)
hBgColor = (new StringBuilder(String.valueOf(hBgColor))).append("#").toString();
hBgColor = (new StringBuilder(String.valueOf(hBgColor))).append(HeaderBgColor).toString();
table = (new StringBuilder(String.valueOf(table))).append("<thead>\r\n<TR ").append(hBgColor).append(" class=topTab_thead_tr>\r\n").toString();
if(bShowIndex && hasCheckBox || bShowIndex && isHasSubTable())
table = (new StringBuilder(String.valueOf(table))).append("<th align='center' width='40px'>").toString();
else
table = (new StringBuilder(String.valueOf(table))).append("<th align='center' width='12px'>").toString();
int n = 1;
if(hasCheckBox)
table = (new StringBuilder(String.valueOf(table))).append("<INPUT name=cbAll onclick='checkTabAll(0);' title=\u9009\u4E2D\u6216\u6E05\u9664\u9009\u4E2D\u6240\u6709\u7684\u9879\u76EE type=checkbox>").toString();
else
table = (new StringBuilder(String.valueOf(table))).append(" ").toString();
table = (new StringBuilder(String.valueOf(table))).append("</th>\r\n").toString();
for(int i = 0; i < headerList.size(); i++)
{
Set mapset = ((Map)headerList.get(i)).entrySet();
java.util.Map.Entry m = (java.util.Map.Entry)mapset.toArray()[0];
table = (new StringBuilder(String.valueOf(table))).append("<th align=center id=h").append(n).toString();
if(isSortTable())
table = (new StringBuilder(String.valueOf(table))).append(" style='cursor:pointer;' onClick='javascript:sortTable(\"").append(tableId).append("\", ").append(n).append(");'").toString();
if(showFieldAtrr)
table = (new StringBuilder(String.valueOf(table))).append(" f='").append(((tableField)m.getValue()).getFieldName()).append("' ").toString();
if(showTitleAtrr)
table = (new StringBuilder(String.valueOf(table))).append(" h='").append(((tableField)m.getValue()).getHeaderName()).append("' ").toString();
table = (new StringBuilder(String.valueOf(table))).append(">").append(((tableField)m.getValue()).getHeaderName()).append("</th>\r\n").toString();
n++;
}
int colCount = headerList.size() + 1;
if(linkList != null && linkList.size() > 0)
{
table = (new StringBuilder(String.valueOf(table))).append("<th id=h").append(n).append(" align='center'>\u64CD\u4F5C</th>\r\n").toString();
colCount++;
}
table = (new StringBuilder(String.valueOf(table))).append("</TR>\r\n</thead>\r\n<tbody>\r\n").toString();
for(int k = 0; k < voList.size(); k++)
try
{
Object vo = voList.get(k);
String key = kit.GetValue(vo, keyField).toString();
if(k % 2 == 1)
table = (new StringBuilder(String.valueOf(table))).append("<TR id='").append(tableId).append("_Tr_").append(key).append("' bgColor=").append(rowColor1).append(">\r\n<TD>").toString();
else
if(isHasSubTable())
table = (new StringBuilder(String.valueOf(table))).append("<TR id='").append(tableId).append("_Tr_").append(key).append("' bgColor=").append(rowColor2).append(">\r\n<TD>").toString();
else
table = (new StringBuilder(String.valueOf(table))).append("<TR id='").append(tableId).append("_Tr_").append(key).append("' bgColor=#FFFFFF>\r\n<TD>").toString();
if(bShowIndex)
table = (new StringBuilder(String.valueOf(table))).append(k + 1).append(" ").toString();
if(isHasSubTable())
table = (new StringBuilder(String.valueOf(table))).append("<img src='/Images/_plus.gif' style='cursor:pointer;' id=img").append(key).append(" title='\u663E\u793A\u8BE6\u7EC6' onclick=\"showDetail('").append(key).append("')\">").toString();
if(hasCheckBox)
{
table = (new StringBuilder(String.valueOf(table))).append("<INPUT id=").append(keyField).append(" name=").append(keyField).toString();
if(checkBoxAttr != null)
{
table = (new StringBuilder(String.valueOf(table))).append(" ").toString();
for(int c = 0; c < checkBoxAttr.size(); c++)
{
ExtAttr attr = (ExtAttr)checkBoxAttr.get(c);
table = (new StringBuilder(String.valueOf(table))).append(attr.getName()).append("='").toString();
table = (new StringBuilder(String.valueOf(table))).append(kit.GetValue(vo, attr.getFieldName()).toString()).append("' ").toString();
}
}
table = (new StringBuilder(String.valueOf(table))).append(" onclick='CCA(this)' type='checkbox' value ='").append(key).append("'>").toString();
}
table = (new StringBuilder(String.valueOf(table))).append(" </TD>\r\n").toString();
for(int i = 0; i < headerList.size(); i++)
{
Set mapset = ((Map)headerList.get(i)).entrySet();
java.util.Map.Entry m = (java.util.Map.Entry)mapset.toArray()[0];
Object obj = kit.GetValue(vo, (String)m.getKey());
String str = obj != null ? obj.toString() : "";
ArrayList extList = ((tableField)m.getValue()).getExtAttrList();
if(extList == null || extList.size() == 0)
{
table = (new StringBuilder(String.valueOf(table))).append("<TD>").toString();
} else
{
table = (new StringBuilder(String.valueOf(table))).append("<TD ").toString();
for(int e = 0; e < extList.size(); e++)
{
ExtAttr ext = (ExtAttr)extList.get(e);
table = (new StringBuilder(String.valueOf(table))).append(ext.getName()).append("='").toString();
table = (new StringBuilder(String.valueOf(table))).append(kit.GetStrValue(vo, ext.getFieldName())).toString();
table = (new StringBuilder(String.valueOf(table))).append("'").toString();
}
table = (new StringBuilder(String.valueOf(table))).append(">").toString();
}
if(!((tableField)m.getValue()).getLink().isEmpty())
{
table = (new StringBuilder(String.valueOf(table))).append("<a href=\"").append(((tableField)m.getValue()).getLink()).toString();
if(!((tableField)m.getValue()).getLinkField().isEmpty())
{
String linkFields = ((tableField)m.getValue()).getLinkField();
String fieds[] = linkFields.split(",");
for(int f = 0; f < fieds.length; f++)
{
String fieldValue = kit.GetStrValue(vo, fieds[f]);
if(f > 0)
table = (new StringBuilder(String.valueOf(table))).append("&").append(fieds[f]).append("=").toString();
table = (new StringBuilder(String.valueOf(table))).append(fieldValue).toString();
}
}
if(!((tableField)m.getValue()).getLinkEndWith().isEmpty())
table = (new StringBuilder(String.valueOf(table))).append(((tableField)m.getValue()).getLinkEndWith()).toString();
table = (new StringBuilder(String.valueOf(table))).append("\">").append(str).append("</a>").toString();
} else
{
table = (new StringBuilder(String.valueOf(table))).append(str).toString();
}
table = (new StringBuilder(String.valueOf(table))).append(" </TD>\r\n").toString();
}
if(linkList != null && linkList.size() > 0)
{
table = (new StringBuilder(String.valueOf(table))).append("<TD align=center>").toString();
for(int i = 0; i < linkList.size(); i++)
{
LinkBase lnk = (LinkBase)linkList.get(i);
table = (new StringBuilder(String.valueOf(table))).append(lnk.getLinkHtml(vo)).toString();
}
table = (new StringBuilder(String.valueOf(table))).append("</TD>\r\n").toString();
}
table = (new StringBuilder(String.valueOf(table))).append("</TR>\r\n").toString();
if(isHasSubTable())
table = (new StringBuilder(String.valueOf(table))).append("<tr id='dtTr_").append(key).append("' style='display:none' ><td id=dtTd_").append(key).append(" colspan=").append(colCount).append("></td></tr>\r\n").toString();
}
catch(Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}
table = (new StringBuilder(String.valueOf(table))).append("<tbody></TABLE>\r\n").toString();
if(pageCtrl != null)
{
table = (new StringBuilder(String.valueOf(table))).append("<TABLE border=0 cellPadding=3 cellSpacing=1 >\r\n").toString();
table = (new StringBuilder(String.valueOf(table))).append("<TR>\r\n").toString();
table = (new StringBuilder(String.valueOf(table))).append("<TD align=left>").append(pageCtrl.getPageLinks()).append("</TD>\r\n").toString();
table = (new StringBuilder(String.valueOf(table))).append("</TR>\r\n</TABLE>\r\n\r\n").toString();
}
return table;
}
public void addHeaderField(String fieldName, tableField field)
{
Map map = new HashMap();
map.put(fieldName, field);
headerList.add(map);
}
public void addHeaderField(String fieldName, String headerName)
{
Map map = new HashMap();
tableField field = new tableField();
field.setFieldName(fieldName);
field.setHeaderName(headerName);
map.put(fieldName, field);
headerList.add(map);
}
public void addHeaderField(String fieldName, String headerName, ArrayList tdAtrrList)
{
Map map = new HashMap();
tableField field = new tableField();
field.setFieldName(fieldName);
field.setHeaderName(headerName);
field.setExtAttrList(tdAtrrList);
map.put(fieldName, field);
headerList.add(map);
}
public void addHeaderField(String fieldName, String headerName, ExtAttr tdExtAtrr)
{
Map map = new HashMap();
tableField field = new tableField();
field.setFieldName(fieldName);
field.setHeaderName(headerName);
field.AddExtAttr(tdExtAtrr.getName(), tdExtAtrr.getFieldName());
map.put(fieldName, field);
headerList.add(map);
}
public void addHeaderField(String fieldName, String headerName, String link, String linkFields, String linkEndWith, String tip)
{
Map map = new HashMap();
tableField field = new tableField();
field.setFieldName(fieldName);
field.setHeaderName(headerName);
field.setLink(link);
field.setLinkField(linkFields);
field.setLinkEndWith(linkEndWith);
field.setLinkTitle(tip);
map.put(fieldName, field);
headerList.add(map);
}
public void addHeaderField(String fieldName, String headerName, String link, String linkFields, String linkEndWith, String tip, ArrayList tdAtrrList)
{
Map map = new HashMap();
tableField field = new tableField();
field.setFieldName(fieldName);
field.setHeaderName(headerName);
field.setLink(link);
field.setLinkField(linkFields);
field.setLinkEndWith(linkEndWith);
field.setLinkTitle(tip);
field.setExtAttrList(tdAtrrList);
map.put(fieldName, field);
headerList.add(map);
}
public String getOnSearch()
{
return onSearch;
}
public void setOnSearch(String onSearch)
{
this.onSearch = onSearch;
}
public List getHeaderList()
{
return headerList;
}
public void setHeaderList(List headerList)
{
this.headerList = headerList;
}
public String getTableId()
{
return tableId;
}
public void setTableId(String tableId)
{
this.tableId = tableId;
}
public String getWidth()
{
return width;
}
public void setWidth(String width)
{
this.width = width;
}
public String getTableCss()
{
return tableCss;
}
public void setTableCss(String tableCss)
{
this.tableCss = tableCss;
}
public String getOnAdd()
{
return onAdd;
}
public void setOnAdd(String onAdd)
{
this.onAdd = onAdd;
}
public String getOnEdit()
{
return onEdit;
}
public void setOnEdit(String onEdit)
{
this.onEdit = onEdit;
}
public String getOnDelete()
{
return onDelete;
}
public void setOnDelete(String onDelete)
{
this.onDelete = onDelete;
}
public boolean isHasCheckBox()
{
return hasCheckBox;
}
public void setHasCheckBox(boolean hasCheckBox)
{
this.hasCheckBox = hasCheckBox;
}
public String getKeyField()
{
return keyField;
}
public void setKeyField(String keyField)
{
this.keyField = keyField;
}
public ArrayList getVoList()
{
return voList;
}
public void setVoList(ArrayList voList)
{
this.voList = voList;
}
public PageCtrlInfo getPageCtrl()
{
return pageCtrl;
}
public void setPageCtrl(PageCtrlInfo pageCtrl)
{
this.pageCtrl = pageCtrl;
}
public boolean isHasSubTable()
{
return hasSubTable;
}
public void setHasSubTable(boolean hasSubTable)
{
this.hasSubTable = hasSubTable;
if(hasSubTable)
sortTable = false;
}
public boolean isSortTable()
{
return sortTable;
}
public void setSortTable(boolean sortTable)
{
this.sortTable = sortTable;
if(hasSubTable)
this.sortTable = false;
}
public String getAlign()
{
return align;
}
public void setAlign(String align)
{
this.align = align;
}
public boolean isBShowIndex()
{
return bShowIndex;
}
public void setBShowIndex(boolean showIndex)
{
bShowIndex = showIndex;
}
public String getHeaderBgColor()
{
return HeaderBgColor;
}
public void setHeaderBgColor(String headerBgColor)
{
HeaderBgColor = headerBgColor;
}
public String getRowColor1()
{
return rowColor1;
}
public void setRowColor1(String rowColor1)
{
this.rowColor1 = rowColor1;
}
public String getRowColor2()
{
return rowColor2;
}
public void setRowColor2(String rowColor2)
{
this.rowColor2 = rowColor2;
}
public boolean isShowFieldAtrr()
{
return showFieldAtrr;
}
public void setShowFieldAtrr(boolean showFieldName)
{
showFieldAtrr = showFieldName;
}
public boolean isShowTitleAtrr()
{
return showTitleAtrr;
}
public void setShowTitleAtrr(boolean showTitleAtrr)
{
this.showTitleAtrr = showTitleAtrr;
}
private String tableId;
private String width;
private String tableCss;
private String onAdd;
private String onEdit;
private String onDelete;
private String onSearch;
private boolean hasCheckBox;
private boolean hasSubTable;
private boolean sortTable;
private String keyField;
private boolean bShowIndex;
private String align;
private String HeaderBgColor;
private boolean showFieldAtrr;
private boolean showTitleAtrr;
private String rowColor1;
private String rowColor2;
private ArrayList checkBoxAttr;
private ArrayList voList;
private PageCtrlInfo pageCtrl;
private List headerList;
private List linkList;
}