package com.vci.client.uif.engine.client.tableArea;
|
|
import java.awt.BorderLayout;
|
import java.awt.Component;
|
import java.awt.GridBagConstraints;
|
import java.awt.GridBagLayout;
|
import java.awt.Insets;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.util.HashMap;
|
import java.util.Iterator;
|
import java.util.Map;
|
import javax.swing.ComboBoxModel;
|
import javax.swing.JPanel;
|
import javax.swing.text.JTextComponent;
|
|
import com.vci.client.portal.utility.DataModelFactory;
|
import com.vci.client.portal.utility.PLDefination;
|
import com.vci.client.portal.utility.PRM;
|
import com.vci.client.portal.utility.PRMItem;
|
import com.vci.client.portal.utility.UITools;
|
import com.vci.client.ui.swing.VCISwingUtil;
|
import com.vci.client.ui.swing.components.VCIJButton;
|
import com.vci.client.ui.swing.components.VCIJComboBox;
|
import com.vci.client.ui.swing.components.VCIJLabel;
|
import com.vci.client.ui.swing.components.VCIJPanel;
|
import com.vci.client.ui.swing.components.VCIJScrollPane;
|
import com.vci.client.ui.swing.components.VCIJTextField;
|
import com.vci.client.uif.engine.client.controls.ControlFactory;
|
import com.vci.client.uif.engine.client.controls.DateControl;
|
import com.vci.client.uif.engine.client.controls.DateTimeControl;
|
import com.vci.client.uif.engine.client.controls.ICustomControl;
|
import com.vci.client.uif.engine.client.controls.TimeControl;
|
import com.vci.client.uif.engine.client.controls.VCIJComboBoxModelValueObject;
|
import com.vci.corba.portal.data.PortalVI;
|
import com.vci.mw.ClientContextVariable;
|
|
public class TablePanelSearchAreaPanel extends JPanel implements ActionListener{
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = -980328802916633426L;
|
|
private String type = "";
|
private String context = "";
|
private PLDefination defination = null;
|
private DataModelFactory factory = null;
|
private TablePanel tablePanel = null;
|
|
private PortalVI tableDef = null;
|
private PRM tablePrm = null;
|
private PortalVI formView = null;
|
private PRM formPrm = null;
|
|
private VCIJButton btnSearch = VCISwingUtil.createVCIJButton("search", "查询", "查询", "search.png", this);
|
private VCIJButton btnSearchAdvance = VCISwingUtil.createVCIJButton("search_advance", "高级查询", "点击开始高级查询", "search_advance.png", this);
|
private VCIJButton btnClear = VCISwingUtil.createVCIJButton("clear_search", "清空条件", "清空条件", "clear.gif", this);
|
private VCIJButton btnClearaAndReload = VCISwingUtil.createVCIJButton("clear_search_reload", "清空条件并重新加载", "清空后重新加载", "pagination_refresh.png", this);
|
|
private HashMap<String, VCIJLabel> ctlLblMap = new HashMap<String, VCIJLabel>();
|
private HashMap<String, Component> ctlComptMap = new HashMap<String, Component>();
|
|
private boolean hasNormatSearchAttrs = true;
|
private boolean hasAdvanceSearchAttrs = false;
|
|
public TablePanelSearchAreaPanel(String type, String context,
|
PLDefination defination, DataModelFactory factory,
|
TablePanel tablePanel) {
|
|
super();
|
|
this.type = type;
|
this.context = context;
|
this.defination = defination;
|
|
this.factory = factory;
|
this.tablePanel = tablePanel;
|
}
|
|
public void init(){
|
setLayout(new BorderLayout());
|
try{
|
add(new VCIJScrollPane(getSearchFormPanel()), BorderLayout.CENTER);
|
} catch (Throwable e) {
|
e.printStackTrace();
|
}
|
add(getSouthButtonPanel(), BorderLayout.SOUTH);
|
}
|
|
|
private VCIJPanel getSearchFormPanel() throws Throwable{
|
VCIJPanel pal = new VCIJPanel(new GridBagLayout());
|
|
tableDef = getPortalDefination();
|
tablePrm = UITools.getPRM(tableDef.prm);
|
boolean bShowSearch = tablePrm.getPrmItemList().get(0).getItemIsNavigatorExpand().equalsIgnoreCase("true");
|
|
tablePanel.setExpandSearchArea(bShowSearch);
|
|
formView = factory.getFormViewById(tablePrm.getPrmItemList().get(0).getItemInObj());
|
formPrm = UITools.getPRM(formView.prm);
|
boolean hasNormanSearchAttrs = hasNormalSearchAttrs();
|
boolean hasAdvanceSearchAttrs = hasAdvanceSearchAttrs();
|
setHasNormatSearchAttrs(hasNormanSearchAttrs);
|
setHasAdvanceSearchAttrs(hasAdvanceSearchAttrs);
|
if(!hasNormanSearchAttrs) return pal;
|
|
String[] queryCols = tablePrm.getPrmItemList().get(0).getItemKeyFields().split(",");
|
if (queryCols.length == 0) {
|
return pal;
|
}
|
int gridx = 0;
|
int gridy = 0;
|
int gridwidth = 1;
|
|
for (int i = 0; i < queryCols.length; i++) {
|
for (int j = 0; j < formPrm.getPrmItemList().size(); j++) {
|
PRMItem prmItem = formPrm.getPrmItemList().get(j);
|
String field = prmItem.getItemField();
|
String name = prmItem.getItemName();
|
|
if (!queryCols[i].equalsIgnoreCase(field)) {
|
continue;
|
}
|
|
VCIJLabel attarLabel = new VCIJLabel(name + ":");
|
attarLabel.setObj(prmItem);
|
|
Component compt = ControlFactory.createControlForSearch(prmItem);
|
if (compt == null)
|
continue;
|
|
if(ControlFactory.isLCStatusAttr(field) && compt instanceof VCIJComboBox){
|
String btmType = defination.getShowType();
|
((VCIJComboBox)compt).setModel(ControlFactory.getLCStatusComboboxModel(prmItem, btmType));
|
}
|
Component comptToAdd = compt;
|
if(compt instanceof VCIJTextField){
|
VCIJTextField txt = ((VCIJTextField)compt);
|
txt.setRequired(false);
|
txt.setEditable(true);
|
}
|
|
String key = field;
|
ctlLblMap.put(key, attarLabel);
|
ctlComptMap.put(key, compt);
|
|
pal.add(attarLabel,
|
getGBC(gridx, gridy, 1, 1, 0.0, 0.0,
|
GridBagConstraints.NORTHEAST,
|
GridBagConstraints.NONE));
|
gridx++;
|
|
if (gridx == 3) {
|
gridwidth = GridBagConstraints.REMAINDER;
|
}
|
|
pal.add(
|
comptToAdd,
|
getGBC(gridx, gridy, gridwidth, 1,
|
1.0, 0.0, GridBagConstraints.NORTHWEST,
|
GridBagConstraints.BOTH));
|
gridx++;
|
if (gridx > 3) {
|
gridx = 0;
|
gridy += 1;
|
gridwidth = 1;
|
}
|
|
}
|
}
|
return pal;
|
}
|
|
private GridBagConstraints getGBC(int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty, int anchor, int fill) {
|
int padxy = 2;
|
return new GridBagConstraints(gridx, gridy, gridwidth, gridheight, weightx, weighty, anchor, fill, new Insets(padxy, padxy, padxy, padxy), padxy, padxy);
|
}
|
private PortalVI getPortalDefination() throws Throwable{
|
if(tableDef != null) return tableDef;
|
if(defination.getLinkType() != null && !"".equals(defination.getLinkType())) {
|
tableDef = factory.getTableDefinationByTypeAndTableName(defination.getLinkType(), defination.getTemplateId());
|
} else {
|
tableDef = factory.getTableDefinationByTypeAndTableName(defination.getShowType(), defination.getTemplateId());
|
}
|
return tableDef;
|
}
|
|
private VCIJPanel getSouthButtonPanel(){
|
VCIJPanel pal = new VCIJPanel();
|
boolean hasNormanSearchAttrs = isHasNormatSearchAttrs();
|
boolean hasAdvanceSearhAttrs = isHasAdvanceSearchAttrs();
|
if(hasNormanSearchAttrs){
|
pal.add(btnSearch);
|
}
|
if(hasAdvanceSearhAttrs){
|
pal.add(btnSearchAdvance);
|
}
|
if(hasNormanSearchAttrs || hasAdvanceSearhAttrs){
|
pal.add(btnClear);
|
pal.add(btnClearaAndReload);
|
}
|
return pal;
|
}
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
String actionCommand = e.getActionCommand();
|
if(actionCommand.equals(btnSearch.getActionCommand())) search();
|
else if(actionCommand.equals(btnSearchAdvance.getActionCommand())) searchAdvance();
|
else if(actionCommand.equals(btnClear.getActionCommand())) clear(false);
|
else if(actionCommand.equals(btnClearaAndReload.getActionCommand())) clear(true);
|
}
|
|
private void search(){
|
this.tablePanel.getDataTablePanel().setPageIndex(1);
|
tablePanel.getDataProvider().setLoadByCondition(true);
|
tablePanel.getDataProvider().setNormalSearchFilterMap(getSearchConditionMap(false));
|
tablePanel.getDataTablePanel().refreshTableData();
|
}
|
|
private void searchAdvance(){
|
TablePanalAdvanceSearchDialog ad = new TablePanalAdvanceSearchDialog(type, context, defination, factory, tablePanel);
|
ad.init();
|
ad.setSize(600, 400);
|
ad.setLocationRelativeTo(ClientContextVariable.getFrame());
|
ad.setVisible(true);
|
}
|
|
private void clear(boolean reload){
|
// if(ctlComptMap.size() == 0) return;
|
|
getSearchConditionMap(true);
|
|
tablePanel.getDataProvider().setLoadByCondition(false);
|
tablePanel.getDataProvider().getNormalSearchFilterMap().clear();
|
|
if(reload){
|
tablePanel.getDataTablePanel().refreshTableData();
|
}
|
}
|
private HashMap<String, String> getSearchConditionMap(boolean isClearn){
|
HashMap<String, String> map = new HashMap<String, String>();
|
Iterator<String> keys = ctlComptMap.keySet().iterator();
|
while(keys.hasNext()){
|
String key = keys.next();
|
Component compt = ctlComptMap.get(key);
|
String value = "";
|
if(JTextComponent.class.isAssignableFrom(compt.getClass())){
|
JTextComponent txtCompt = (JTextComponent)compt;
|
String text = txtCompt.getText();
|
if(isClearn){
|
text = "";
|
}
|
txtCompt.setText(text);
|
|
if(text.contains("%")){
|
text = text.replace("%", "*");
|
}
|
// if(text.contains("*")){
|
// if(!text.startsWith("*")){
|
// text = "*" + text;
|
// }
|
// if(!text.endsWith("*")){
|
// text = text + "*";
|
// }
|
// }
|
value = text;
|
} else if(compt instanceof VCIJComboBox){
|
VCIJComboBox cbx = (VCIJComboBox)compt;
|
ComboBoxModel model = cbx.getModel();
|
Object selectObj = model.getSelectedItem();
|
if(selectObj instanceof VCIJComboBoxModelValueObject){
|
VCIJComboBoxModelValueObject vo = (VCIJComboBoxModelValueObject) selectObj;
|
value = vo.getValue();
|
if(isClearn) {
|
try {
|
cbx.setSelectedIndex(0);
|
} catch (Exception e){
|
e.printStackTrace();
|
}
|
}
|
}
|
}else if(compt instanceof ICustomControl){
|
ICustomControl ctrl = (ICustomControl)compt;
|
value = ctrl.getValue();
|
if(!"".equals(value) && isDateTimeControl(compt)){
|
//modify by songyf 2014.09.05 修改tabel中使用时间作为查询条件异常
|
// 不需要再此处转换,后台自动判断
|
//value = "to_date('" + value + "','YYYY-MM-dd HH24:mi:ss')";
|
//end
|
if(isClearn){
|
((DateTimeControl)compt).clearValue();
|
}
|
}
|
}
|
if(isClearn){
|
value = "";
|
}
|
map.put(key, value);
|
}
|
return map;
|
}
|
|
private boolean isDateTimeControl(Component compt){
|
boolean res = false;
|
if(compt instanceof DateControl || compt instanceof TimeControl || compt instanceof DateTimeControl){
|
res = true;
|
}
|
return res;
|
}
|
|
|
/**
|
* 返回 table 是否定义了一般查询属性
|
* @return
|
*/
|
private boolean hasNormalSearchAttrs(){
|
boolean res = true;
|
String[] queryCols = tablePrm.getPrmItemList().get(0).getItemKeyFields().split(",");
|
int len = queryCols.length;
|
if(len <= 0) return false;
|
res = false;
|
for(String queryCol : queryCols){
|
if(queryCol != null && !"".equals(queryCol)){
|
res = true;
|
}
|
if(res){
|
break;
|
}
|
}
|
return res;
|
}
|
|
/**
|
* 返回 table 是否定义了高级查询属性
|
* @return
|
*/
|
private boolean hasAdvanceSearchAttrs(){
|
boolean res = true;
|
if(tableDef != null){
|
PRM tablePrm = UITools.getPRM(tableDef.prm);
|
if(tablePrm != null){
|
Map<String, Integer> asvMap = tablePrm.getPrmItemList().get(0).getColAndUseCountMap();
|
if(asvMap == null || asvMap.size() < 1) return false;
|
// 先置为false
|
res = false;
|
// 实际上只需要判断 asvMap.size() 是否大于0即可,
|
// 但由于定义时偶尔会出现一条空数据问题,因此增加下面的判断
|
// 只有有一个有效的高级查询属性定义,则返回true
|
Iterator<String> its = asvMap.keySet().iterator();
|
while(its.hasNext()){
|
String key = its.next();
|
if(key != null && !"".equals(key)){
|
res = true;
|
}
|
if(res){
|
break;
|
}
|
}
|
}
|
}
|
return res;
|
}
|
|
public boolean isHasNormatSearchAttrs() {
|
return hasNormatSearchAttrs;
|
}
|
|
public void setHasNormatSearchAttrs(boolean hasNormatSearchAttrs) {
|
this.hasNormatSearchAttrs = hasNormatSearchAttrs;
|
}
|
|
public boolean isHasAdvanceSearchAttrs() {
|
return hasAdvanceSearchAttrs;
|
}
|
|
public void setHasAdvanceSearchAttrs(boolean hasAdvanceSearchAttrs) {
|
this.hasAdvanceSearchAttrs = hasAdvanceSearchAttrs;
|
}
|
|
|
}
|