package com.vci.client.oq.ui;
|
|
import java.awt.BorderLayout;
|
import java.awt.Component;
|
import java.awt.Dimension;
|
import java.awt.FlowLayout;
|
import java.awt.GridBagConstraints;
|
import java.awt.GridBagLayout;
|
import java.awt.Insets;
|
import java.awt.datatransfer.DataFlavor;
|
import java.awt.datatransfer.Transferable;
|
import java.awt.datatransfer.UnsupportedFlavorException;
|
import java.awt.dnd.DnDConstants;
|
import java.awt.dnd.DragGestureEvent;
|
import java.awt.dnd.DragGestureListener;
|
import java.awt.dnd.DragSource;
|
import java.awt.dnd.DragSourceDragEvent;
|
import java.awt.dnd.DragSourceDropEvent;
|
import java.awt.dnd.DragSourceEvent;
|
import java.awt.dnd.DragSourceListener;
|
import java.awt.dnd.DropTarget;
|
import java.awt.dnd.DropTargetDragEvent;
|
import java.awt.dnd.DropTargetDropEvent;
|
import java.awt.dnd.DropTargetEvent;
|
import java.awt.dnd.DropTargetListener;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.awt.event.ItemEvent;
|
import java.awt.event.ItemListener;
|
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseListener;
|
import java.io.IOException;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.Enumeration;
|
import java.util.HashMap;
|
import java.util.Iterator;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.swing.BorderFactory;
|
import javax.swing.ButtonGroup;
|
import javax.swing.JButton;
|
import javax.swing.JComboBox;
|
import javax.swing.JLabel;
|
import javax.swing.JOptionPane;
|
import javax.swing.JPanel;
|
import javax.swing.JRadioButton;
|
import javax.swing.JScrollPane;
|
import javax.swing.JTextField;
|
import javax.swing.JTree;
|
import javax.swing.tree.DefaultMutableTreeNode;
|
import javax.swing.tree.TreeSelectionModel;
|
|
import org.dom4j.Document;
|
import org.dom4j.DocumentException;
|
import org.dom4j.DocumentHelper;
|
import org.jdesktop.swingx.JXDatePicker;
|
|
import com.vci.corba.omd.atm.AttribItem;
|
import com.vci.corba.omd.data.LinkObject;
|
import com.vci.corba.omd.qtm.QTD;
|
import com.vci.corba.omd.qtm.QTInfo;
|
import com.vci.omd.objects.OtherInfo;
|
import com.vci.client.common.oq.OQTool;
|
import com.vci.client.omd.provider.ApProvider;
|
import com.vci.client.oq.QTClient;
|
import com.vci.client.oq.QTDClient;
|
import com.vci.client.oq.wrapper.QTDWrapper;
|
import com.vci.common.qt.object.ChildrenInfo;
|
import com.vci.common.qt.object.Condition;
|
import com.vci.common.qt.object.ConditionItem;
|
import com.vci.common.qt.object.Connector;
|
import com.vci.common.qt.object.LeafInfo;
|
import com.vci.common.qt.object.LeafValue;
|
import com.vci.common.qt.object.Operator;
|
import com.vci.common.qt.object.QTConstants;
|
import com.vci.common.qt.object.QueryTemplate;
|
import com.vci.corba.common.VCIError;
|
|
public class ConditionPanelForLink extends JPanel implements DropTargetListener, DragGestureListener, DragSourceListener{
|
private static final long serialVersionUID = -3154410049944995334L;
|
private JPanel westPanel, centerPanel;
|
private JPanel wp_northPanel;
|
private JPanel wp_centerPanel;
|
private JComboBox combLinkQTD;
|
private JPanel cp_northPanel;
|
private JPanel cp_centerPanel;
|
private JPanel cp_southPanel;
|
private DragSource dragSource;
|
private JRadioButton rdGeneral;
|
private JRadioButton rdSenior;
|
private JButton btnClear;
|
private JButton panelClear;
|
private ButtonGroup btnGroup;
|
private JButton btnQuery;
|
private JButton btnCancel;
|
private QTDTree linkQtdTree;
|
private String linkTypeName = null;
|
private String btmName = null;
|
/**
|
* Senior Level Tree
|
*/
|
private JTree seniorTree;
|
private DefaultMutableTreeNode seniorRoot;
|
private final String EQUAL = "=";
|
private final String UNEQUAL = "!=";
|
private final String CONTAINS = "包含";
|
private final String IN = "in";
|
private final String NOTIN = "not in";
|
private final String GT = ">";
|
private final String GTE = ">=";
|
private final String LT = "<";
|
private final String LTE = "<=";
|
private final String AND = "并且";
|
private final String OR = "或者";
|
private JButton btnAdd, btnDelete, btnModify;
|
private JRadioButton rdBtm;
|
private JRadioButton rdLinkType;
|
private JPanel eastPanel;
|
private JPanel ep_northPanel;
|
private JPanel ep_centerPanel;
|
private JComboBox combBtmQTD;
|
private QTDTree btmQtdTree;
|
private String direction = null;
|
|
public ConditionPanelForLink(String linkTypeName_, String btmName_, String direction){
|
this.linkTypeName = linkTypeName_;
|
this.btmName = btmName_;
|
this.direction = direction;
|
initUI();
|
initLinkCombQTD();
|
initBtmCombQTD();
|
initLinkQTDAbTree();
|
initBtmQTDAbTree();
|
initCP_centerPanel();
|
addListener();
|
}
|
|
public void updateUI(String linkTypeName_, String btmName, String direction){
|
this.linkTypeName = linkTypeName_;
|
this.btmName = btmName;
|
this.direction = direction;
|
initLinkCombQTD();
|
initBtmCombQTD();
|
initLinkQTDAbTree();
|
initBtmQTDAbTree();
|
}
|
private void initUI(){
|
this.setLayout(new BorderLayout());
|
westPanel = new JPanel();
|
eastPanel = new JPanel();
|
centerPanel = new JPanel();
|
// JScrollPane wpSP = new JScrollPane();
|
// wpSP.setViewportView(westPanel);
|
// JScrollPane epSP = new JScrollPane();
|
// epSP.setViewportView(eastPanel);
|
// JScrollPane cpSP = new JScrollPane();
|
// cpSP.setViewportView(centerPanel);
|
this.add(westPanel, BorderLayout.WEST);
|
this.add(eastPanel, BorderLayout.EAST);
|
this.add(centerPanel, BorderLayout.CENTER);
|
|
//链接类型候选查询条件
|
westPanel.setBorder(BorderFactory.createTitledBorder("链接类型候选条件"));
|
wp_northPanel = new JPanel();
|
wp_centerPanel = new JPanel();
|
westPanel.setLayout(new BorderLayout());
|
westPanel.add(wp_northPanel, BorderLayout.NORTH);
|
westPanel.add(wp_centerPanel, BorderLayout.CENTER);
|
|
wp_northPanel.setLayout(new GridBagLayout());
|
GridBagConstraints g = new GridBagConstraints();
|
g.anchor = GridBagConstraints.WEST;
|
g.gridx = 0;
|
g.gridy = 0;
|
g.weightx = 0.0;
|
g.fill = GridBagConstraints.BOTH;
|
combLinkQTD = new JComboBox();
|
combLinkQTD.setPreferredSize(new Dimension(200, 23));
|
wp_northPanel.add(new JLabel("查询模板定义"), g);
|
g.gridx = 1;
|
g.weightx = 1.0;
|
wp_northPanel.add(combLinkQTD, g);
|
|
wp_centerPanel.setLayout(new GridBagLayout());
|
|
//链接类型候选查询条件
|
eastPanel.setBorder(BorderFactory.createTitledBorder("业务类型候选条件"));
|
ep_northPanel = new JPanel();
|
ep_centerPanel = new JPanel();
|
eastPanel.setLayout(new BorderLayout());
|
eastPanel.add(ep_northPanel, BorderLayout.NORTH);
|
eastPanel.add(ep_centerPanel, BorderLayout.CENTER);
|
|
ep_northPanel.setLayout(new GridBagLayout());
|
GridBagConstraints gep = new GridBagConstraints();
|
gep.anchor = GridBagConstraints.WEST;
|
gep.gridx = 0;
|
gep.gridy = 0;
|
gep.weightx = 0.0;
|
gep.fill = GridBagConstraints.BOTH;
|
combBtmQTD = new JComboBox();
|
combBtmQTD.setPreferredSize(new Dimension(200, 23));
|
ep_northPanel.add(new JLabel("查询模板定义"), gep);
|
gep.gridx = 1;
|
gep.weightx = 1.0;
|
ep_northPanel.add(combBtmQTD, gep);
|
|
ep_centerPanel.setLayout(new GridBagLayout());
|
|
//查询条件
|
centerPanel.setBorder(BorderFactory.createTitledBorder("查询条件"));
|
centerPanel.setLayout(new BorderLayout());
|
cp_northPanel = new JPanel();
|
cp_centerPanel = new JPanel();
|
cp_southPanel = new JPanel();
|
|
//拖拽到cpmcpcp_centerPanel
|
dragSource = DragSource.getDefaultDragSource();
|
dragSource.createDefaultDragGestureRecognizer(this,
|
DnDConstants.ACTION_COPY_OR_MOVE,
|
this);
|
new DropTarget(cp_centerPanel, DnDConstants.ACTION_COPY_OR_MOVE, this);
|
|
centerPanel.add(cp_northPanel, BorderLayout.NORTH);
|
centerPanel.add(cp_centerPanel, BorderLayout.CENTER);
|
centerPanel.add(cp_southPanel, BorderLayout.SOUTH);
|
cp_northPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
|
rdGeneral = new JRadioButton("普通");
|
rdSenior = new JRadioButton("高级");
|
btnClear = new JButton("清空值");
|
panelClear = new JButton("删除全部条件");
|
cp_northPanel.add(rdGeneral);
|
cp_northPanel.add(rdSenior);
|
cp_northPanel.add(btnClear);
|
cp_northPanel.add(panelClear);
|
|
btnGroup = new ButtonGroup();
|
btnGroup.add(rdGeneral);
|
btnGroup.add(rdSenior);
|
rdGeneral.setSelected(true);
|
|
cp_southPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
btnAdd = new JButton("增加逻辑");
|
btnModify = new JButton("修改条件");
|
btnDelete = new JButton("删除");
|
btnAdd.setVisible(false);
|
btnModify.setVisible(false);
|
btnDelete.setVisible(false);
|
btnQuery = new JButton("查询");
|
btnCancel = new JButton("取消");
|
cp_southPanel.add(btnAdd);
|
cp_southPanel.add(btnModify);
|
cp_southPanel.add(btnDelete);
|
cp_southPanel.add(btnQuery);
|
cp_southPanel.add(btnCancel);
|
}
|
|
private void addListener(){
|
combLinkQTD.addItemListener(new ItemListener() {
|
|
@Override
|
public void itemStateChanged(ItemEvent e) {
|
initLinkQTDAbTree();
|
initCP_centerPanel();
|
cp_centerPanel.removeAll();
|
}
|
});
|
combBtmQTD.addItemListener(new ItemListener() {
|
|
@Override
|
public void itemStateChanged(ItemEvent e) {
|
initBtmQTDAbTree();
|
}
|
});
|
|
btnQuery.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
queryAction();
|
}
|
});
|
|
rdGeneral.addItemListener(new ItemListener() {
|
|
@Override
|
public void itemStateChanged(ItemEvent e) {
|
btnAdd.setVisible(false);
|
btnModify.setVisible(false);
|
btnDelete.setVisible(false);
|
// initCP_centerPanel();
|
}
|
});
|
|
rdSenior.addItemListener(new ItemListener() {
|
|
@Override
|
public void itemStateChanged(ItemEvent e) {
|
btnAdd.setVisible(true);
|
btnModify.setVisible(true);
|
btnDelete.setVisible(true);
|
initCP_centerPanel();
|
}
|
});
|
|
btnClear.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
clearValue();
|
}
|
});
|
panelClear.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
cp_centerPanel.removeAll();
|
cp_centerPanel.updateUI();
|
}
|
});
|
|
/**
|
* 增加逻辑条件
|
*/
|
btnAdd.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
addCondition();
|
}
|
});
|
|
/**
|
* 修改条件项或逻辑条件
|
*/
|
btnModify.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
modifyCondition();
|
}
|
});
|
/**
|
* 删除逻辑条件或者条件项
|
*/
|
btnDelete.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
deleteCondition();
|
}
|
});
|
}
|
|
/**
|
* 设置当前链接类型下的模板定义列表
|
*/
|
public void initLinkCombQTD(){
|
combLinkQTD.removeAllItems();
|
if(linkTypeName == null){
|
return;
|
}
|
String typeName = linkTypeName;
|
if(typeName == null || typeName.equals("")){
|
return;
|
}
|
QTD[] qtdArray = null;
|
try {
|
qtdArray = QTDClient.getService().getLinkTypeQTDs(typeName);
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
|
if(qtdArray == null){
|
return;
|
}
|
for(int i = 0; i < qtdArray.length; i++){
|
combLinkQTD.addItem(new QTDWrapper(qtdArray[i]));
|
}
|
}
|
|
/**
|
* 设置当前业务类型下的模板定义列表
|
*/
|
public void initBtmCombQTD(){
|
combBtmQTD.removeAllItems();
|
if(btmName == null){
|
return;
|
}
|
String typeName = btmName;
|
if(typeName == null || typeName.equals("")){
|
return;
|
}
|
QTD[] qtdArray = null;
|
try {
|
qtdArray = QTDClient.getService().getBizTypeQTDs(typeName);
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
|
if(qtdArray == null){
|
return;
|
}
|
for(int i = 0; i < qtdArray.length; i++){
|
combBtmQTD.addItem(new QTDWrapper(qtdArray[i]));
|
}
|
}
|
|
/**
|
* 设置候选条件中查询模板的属性树
|
*/
|
private void initLinkQTDAbTree(){
|
QTDWrapper qtdWrapper = (QTDWrapper)combLinkQTD.getSelectedItem();
|
wp_centerPanel.removeAll();
|
wp_centerPanel.updateUI();
|
if(qtdWrapper == null){
|
return;
|
}
|
QTD qtd = qtdWrapper.qtd;
|
GridBagConstraints g1 = new GridBagConstraints();
|
g1.gridx = 0;
|
g1.gridy = 0;
|
g1.weightx = 1.0;
|
g1.weighty = 1.0;
|
g1.fill = GridBagConstraints.BOTH;
|
linkQtdTree = new QTDTree(qtd, null);
|
linkQtdTree.setAutoscrolls(true);
|
linkQtdTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
|
JScrollPane jScrollPane = new JScrollPane();
|
jScrollPane.getViewport().add(linkQtdTree, null);
|
|
wp_centerPanel.add(jScrollPane, g1);
|
}
|
|
/**
|
* 设置候选条件中查询模板的属性树
|
*/
|
private void initBtmQTDAbTree(){
|
QTDWrapper qtdWrapper = (QTDWrapper)combBtmQTD.getSelectedItem();
|
ep_centerPanel.removeAll();
|
ep_centerPanel.updateUI();
|
if(qtdWrapper == null){
|
return;
|
}
|
QTD qtd = qtdWrapper.qtd;
|
GridBagConstraints g1 = new GridBagConstraints();
|
g1.gridx = 0;
|
g1.gridy = 0;
|
g1.weightx = 1.0;
|
g1.weighty = 1.0;
|
g1.fill = GridBagConstraints.BOTH;
|
btmQtdTree = new QTDTree(qtd, direction);
|
btmQtdTree.setAutoscrolls(true);
|
btmQtdTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
|
JScrollPane jScrollPane = new JScrollPane();
|
jScrollPane.getViewport().add(btmQtdTree, null);
|
|
ep_centerPanel.add(jScrollPane, g1);
|
}
|
|
/**
|
* 查询条件中的查询条件
|
*/
|
private void initCP_centerPanel(){
|
QTDWrapper qtdWrapper = (QTDWrapper)combLinkQTD.getSelectedItem();
|
cp_centerPanel.removeAll();
|
cp_centerPanel.updateUI();
|
cp_centerPanel.setAutoscrolls(true);
|
if(qtdWrapper == null){
|
return;
|
}
|
QTD qtd = qtdWrapper.qtd;
|
cp_centerPanel.setLayout(new GridBagLayout());
|
String[] abNames = qtd.abNames;
|
if(rdGeneral.isSelected()){
|
for(int i = 0; i < abNames.length; i++){
|
GridBagConstraints g = new GridBagConstraints();
|
g.anchor = GridBagConstraints.WEST;
|
g.gridx = 0;
|
g.gridy = i;
|
g.insets = new Insets(1, 1, 1, 1);
|
final JButton btnRemove = new JButton("x");
|
cp_centerPanel.add(btnRemove, g);
|
final JLabel labName = new JLabel(abNames[i]);
|
g.gridx = 1;
|
cp_centerPanel.add(labName, g);
|
g.gridx = 2;
|
final JComboBox combCons = new JComboBox();
|
combCons.setPreferredSize(new Dimension(80, 20));
|
String attName = abNames[i];
|
if(attName.contains(".")){
|
attName = attName.substring(attName.lastIndexOf(".") + 1, attName.length());
|
}
|
String attType = ApProvider.getAbItemDataType(attName);
|
if(attType.equalsIgnoreCase("VTInteger") || attType.equalsIgnoreCase("VTDouble")
|
|| attType.equalsIgnoreCase("VTLong")){
|
combCons.addItem(Operator.EQUAL);
|
combCons.addItem(Operator.UNEQUAL);
|
combCons.addItem(Operator.CONTAINS);
|
combCons.addItem(Operator.IN);
|
combCons.addItem(Operator.NOTIN);
|
combCons.addItem(Operator.GTE);
|
combCons.addItem(Operator.GT);
|
combCons.addItem(Operator.LTE);
|
combCons.addItem(Operator.LT);
|
}else if(attType.equalsIgnoreCase("VTDateTime") || attType.equalsIgnoreCase("VTDate")
|
|| attType.equalsIgnoreCase("VTTime")){
|
combCons.addItem(Operator.EQUAL);
|
combCons.addItem(Operator.UNEQUAL);
|
combCons.addItem(Operator.IN);
|
combCons.addItem(Operator.NOTIN);
|
combCons.addItem(Operator.GTE);
|
combCons.addItem(Operator.LTE);
|
}else{
|
combCons.addItem(Operator.EQUAL);
|
combCons.addItem(Operator.UNEQUAL);
|
combCons.addItem(Operator.CONTAINS);
|
combCons.addItem(Operator.IN);
|
combCons.addItem(Operator.NOTIN);
|
}
|
cp_centerPanel.add(combCons, g);
|
g.gridx = 3;
|
//add by zhangweiwei 2014/12/09 start
|
final JTextField tfValue = new JTextField(100);
|
final JXDatePicker datePicker = new JXDatePicker();
|
datePicker.setPreferredSize(tfValue.getPreferredSize());
|
if(attType.equalsIgnoreCase("VTDateTime") || attType.equalsIgnoreCase("VTDate")
|
|| attType.equalsIgnoreCase("VTTime")){
|
cp_centerPanel.add(datePicker, g);
|
}else{
|
cp_centerPanel.add(tfValue, g);
|
}
|
g.gridx =4;
|
final JButton chooseButton = new JButton("选择查询模板");
|
cp_centerPanel.add(chooseButton, g);
|
g.gridwidth = GridBagConstraints.REMAINDER;
|
cp_centerPanel.updateUI();
|
chooseButton.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
// TODO Auto-generated method stub
|
// TODO 后续窗口调整 显示查询模板窗口
|
SelectorQTDialog eid = new SelectorQTDialog(cp_centerPanel);
|
QTInfo item = eid.getItem();
|
String attr = eid.getAttr();
|
//选中的查询模板
|
tfValue.setText(item.qtName + ";" + attr);
|
}
|
});
|
btnRemove.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
cp_centerPanel.remove(btnRemove);
|
cp_centerPanel.remove(labName);
|
cp_centerPanel.remove(combCons);
|
cp_centerPanel.remove(tfValue);
|
cp_centerPanel.remove(chooseButton);
|
cp_centerPanel.remove(datePicker);
|
cp_centerPanel.updateUI();
|
}
|
});
|
//add by zhangweiwei 2014/12/09 end
|
}
|
}else if (rdSenior.isSelected()){
|
initSeniorTree();
|
}
|
|
}
|
@Override
|
public void dragEnter(DragSourceDragEvent dsde) {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void dragOver(DragSourceDragEvent dsde) {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void dropActionChanged(DragSourceDragEvent dsde) {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void dragExit(DragSourceEvent dse) {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void dragDropEnd(DragSourceDropEvent dsde) {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void dragGestureRecognized(DragGestureEvent dge) {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void dragEnter(DropTargetDragEvent dtde) {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void dragOver(DropTargetDragEvent dtde) {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void dropActionChanged(DropTargetDragEvent dtde) {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void dragExit(DropTargetEvent dte) {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void drop(DropTargetDropEvent dtde) {
|
try {
|
DataFlavor stringFlavor = DataFlavor.stringFlavor;
|
Transferable trans = dtde.getTransferable();
|
if (dtde.isDataFlavorSupported(stringFlavor)) {
|
String attPath = (String) trans.getTransferData(stringFlavor);
|
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
|
if(rdGeneral.isSelected()){
|
|
int count = cp_centerPanel.getComponentCount();
|
//添加选择查询模板按钮,组件个数改变,将每行4个组件改成5个 add by zhangweiwei
|
int rowCount = count/5;
|
GridBagConstraints g = new GridBagConstraints();
|
g.anchor = GridBagConstraints.WEST;
|
g.gridx = 0;
|
g.gridy = rowCount + 1;
|
g.insets = new Insets(1, 1, 1, 1);
|
final JButton btnRemove = new JButton("x");
|
cp_centerPanel.add(btnRemove, g);
|
final JLabel labName = new JLabel(attPath);
|
g.gridx = 1;
|
cp_centerPanel.add(labName, g);
|
g.gridx = 2;
|
final JComboBox combCons = new JComboBox();
|
combCons.setPreferredSize(new Dimension(50, 20));
|
String attName = attPath;
|
if(attName.contains(".")){
|
attName = attName.substring(attName.lastIndexOf(".") + 1, attName.length());
|
}
|
String attType = ApProvider.getAbItemDataType(attName);
|
if(attType.equalsIgnoreCase("VTInteger") || attType.equalsIgnoreCase("VTDouble")
|
|| attType.equalsIgnoreCase("VTLong")){
|
combCons.addItem(Operator.EQUAL);
|
combCons.addItem(Operator.UNEQUAL);
|
combCons.addItem(Operator.CONTAINS);
|
combCons.addItem(Operator.IN);
|
combCons.addItem(Operator.NOTIN);
|
combCons.addItem(Operator.GTE);
|
combCons.addItem(Operator.GT);
|
combCons.addItem(Operator.LTE);
|
combCons.addItem(Operator.LT);
|
}else if(attType.equalsIgnoreCase("VTDateTime") || attType.equalsIgnoreCase("VTDate")
|
|| attType.equalsIgnoreCase("VTTime")){
|
combCons.addItem(Operator.EQUAL);
|
combCons.addItem(Operator.UNEQUAL);
|
combCons.addItem(Operator.IN);
|
combCons.addItem(Operator.NOTIN);
|
combCons.addItem(Operator.GTE);
|
combCons.addItem(Operator.LTE);
|
}else{
|
combCons.addItem(Operator.EQUAL);
|
combCons.addItem(Operator.UNEQUAL);
|
combCons.addItem(Operator.CONTAINS);
|
combCons.addItem(Operator.IN);
|
combCons.addItem(Operator.NOTIN);
|
}
|
cp_centerPanel.add(combCons, g);
|
g.gridx =3;
|
//add by zhangweiwei 2014/12/09 start
|
final JTextField tfValue = new JTextField(100);
|
// final JXDatePicker datePicker = new JXDatePicker();
|
final Chooser chooser = Chooser.getInstance();
|
chooser.setLayout(cp_centerPanel.getLayout());
|
// datePicker.setPreferredSize(tfValue.getPreferredSize());
|
if(attType.equalsIgnoreCase("VTDateTime") || attType.equalsIgnoreCase("VTDate")
|
|| attType.equalsIgnoreCase("VTTime")){
|
JTextField text = new JTextField(50);
|
chooser.register(text);
|
cp_centerPanel.add(chooser, g);
|
// cp_centerPanel.add(datePicker, g);
|
}else{
|
cp_centerPanel.add(tfValue, g);
|
}
|
g.gridx =4;
|
final JButton chooseButton = new JButton("选择查询模板");
|
cp_centerPanel.add(chooseButton, g);
|
g.gridwidth = GridBagConstraints.REMAINDER;
|
cp_centerPanel.updateUI();
|
chooseButton.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
// TODO Auto-generated method stub
|
// TODO 后续窗口调整 显示查询模板查询窗口
|
SelectorQTDialog eid = new SelectorQTDialog(cp_centerPanel);
|
QTInfo item = eid.getItem();
|
String attr = eid.getAttr();
|
//选中的查询模板
|
tfValue.setText(item.qtName + ";" + attr);
|
}
|
});
|
btnRemove.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
cp_centerPanel.remove(btnRemove);
|
cp_centerPanel.remove(labName);
|
cp_centerPanel.remove(combCons);
|
cp_centerPanel.remove(tfValue);
|
cp_centerPanel.remove(chooser);
|
// cp_centerPanel.remove(datePicker);
|
cp_centerPanel.remove(chooseButton);
|
cp_centerPanel.updateUI();
|
}
|
});
|
//add by zhangweiwei 2014/12/09 end
|
}else if(rdSenior.isSelected()){
|
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) seniorTree.getLastSelectedPathComponent();
|
if(selectedNode == null){
|
JOptionPane.showMessageDialog(cp_centerPanel, "请选中查询条件树", "请选中查询条件树", JOptionPane.WARNING_MESSAGE);
|
return;
|
}
|
Object obj = selectedNode.getUserObject();
|
if(!(obj instanceof String)){
|
JOptionPane.showMessageDialog(cp_centerPanel, "请选中查询条件树", "请选中查询条件树", JOptionPane.WARNING_MESSAGE);
|
return;
|
}else if(!obj.equals(AND) && !obj.equals(OR)){
|
JOptionPane.showMessageDialog(cp_centerPanel, "请选中逻辑条件添加查询项", "请选中逻辑条件", JOptionPane.WARNING_MESSAGE);
|
return;
|
}else{
|
DefaultMutableTreeNode node = new DefaultMutableTreeNode(attPath);
|
selectedNode.add(node);
|
seniorTree.updateUI();
|
}
|
}
|
|
} else {
|
dtde.rejectDrop();
|
}
|
} catch (UnsupportedFlavorException e) {
|
e.printStackTrace();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
|
}
|
|
/**
|
* 去掉节点中已经包含的查询条件值
|
* @param userObj
|
* @return
|
*/
|
private String trimUserObj(String userObj){
|
if(userObj.contains(EQUAL)){
|
userObj = userObj.substring(0, userObj.indexOf(EQUAL)).trim();
|
}else if(userObj.contains(CONTAINS)){
|
userObj = userObj.substring(0, userObj.indexOf(CONTAINS)).trim();
|
}else if(userObj.contains(UNEQUAL)){
|
userObj = userObj.substring(0, userObj.indexOf(UNEQUAL)).trim();
|
}else if(userObj.contains(" " + IN)){
|
userObj = userObj.substring(0, userObj.indexOf(" " + IN)).trim();
|
}else if(userObj.contains(" " + NOTIN)){
|
userObj = userObj.substring(0, userObj.indexOf(" " + NOTIN)).trim();
|
}else if(userObj.contains(GTE)){
|
userObj = userObj.substring(0, userObj.indexOf(GTE)).trim();
|
}else if(userObj.contains(GT)){
|
userObj = userObj.substring(0, userObj.indexOf(GT)).trim();
|
}else if(userObj.contains(LTE)){
|
userObj = userObj.substring(0, userObj.indexOf(LTE)).trim();
|
}else if(userObj.contains(LT)){
|
userObj = userObj.substring(0, userObj.indexOf(LT)).trim();
|
}
|
return userObj;
|
}
|
|
/**
|
* 清空查询条件的值
|
*/
|
private void clearValue(){
|
if(rdGeneral.isSelected()){
|
Component[] comps = cp_centerPanel.getComponents();
|
for(int i = 0; i < comps.length; i++){
|
if(i == i/5*5+3){
|
if(comps[i] instanceof JXDatePicker){
|
((JXDatePicker) comps[i]).setDate(null);
|
}else if(comps[i] instanceof Chooser){
|
Component[] texts = ((Chooser)comps[i]).getComponents();
|
((JTextField)texts[0]).setText("");
|
}else{
|
((JTextField) comps[i]).setText("");
|
}
|
}
|
}
|
cp_centerPanel.updateUI();
|
}else if(rdSenior.isSelected()){
|
if(seniorTree == null){
|
return;
|
}
|
DefaultMutableTreeNode node = (DefaultMutableTreeNode)seniorTree.getModel().getRoot();
|
while(node != null){
|
if(node.getLevel() >= 2){
|
String userObj = trimUserObj((String)node.getUserObject());
|
node.setUserObject(userObj);
|
}
|
node = node.getNextNode();
|
}
|
seniorTree.updateUI();
|
}
|
}
|
|
/**
|
* 执行查询
|
*/
|
private void queryAction(){
|
QueryTemplate qt = getQT();
|
String checkInfo = OQTool.checkQT(qt);
|
if(!checkInfo.equals("OK")){
|
JOptionPane.showMessageDialog(this, checkInfo, checkInfo, JOptionPane.ERROR_MESSAGE);
|
return;
|
}
|
qt.setId("qt1");
|
try {
|
LinkObject[] result = QTClient.getService().findLTObjects(qt.getId(), OQTool.qtTOXMl(qt).asXML());
|
//TODO clauseList 查询显示列
|
QueryResultDialog dialog = new QueryResultDialog(result, qt.getClauseList());
|
dialog.setVisible(true);
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 组装查询模板
|
* @return
|
*/
|
public QueryTemplate getQT(){
|
QueryTemplate qt = new QueryTemplate();
|
qt.setType(QTConstants.TYPE_LINK);
|
//TODO String qtId =
|
qt.setLinkType(linkTypeName);
|
qt.setDirection(direction);
|
qt.setBtmType(btmName);
|
if(QTPanelForLink.getInstance().isAllType()){
|
qt.setBtmType("*");
|
}
|
qt.setVersion(QTPanelForLink.getInstance().getVersion());
|
qt.setQueryISLeaf(QTPanelForLink.getInstance().isQueryIsLeaf());
|
qt.setLevel(QTPanelForLink.getInstance().getLevel());
|
List<String> clauseList = new ArrayList<String>();
|
//TODO 查询列 显示列
|
clauseList.add("*");
|
qt.setClauseList(clauseList);
|
Condition con = new Condition();
|
qt.setCondition(con);
|
HashMap<String, ConditionItem> ciMap = getCIMap();
|
con.setCIMap(ciMap);
|
con.setRootCIName(con.getRootCINameByCIMap(ciMap));
|
return qt;
|
}
|
|
/**
|
* 获取高级树的UI结构
|
* @return
|
*/
|
public Document getSeniorTreeDoc(){
|
if(rdGeneral.isSelected()){
|
return null;
|
}
|
return OQTool.parseTreeToDoc(seniorTree);
|
}
|
|
/**
|
* 获取查询条件
|
* @return
|
*/
|
private HashMap<String, ConditionItem> getCIMap(){
|
HashMap<String, ConditionItem> ciMap = new HashMap<String, ConditionItem>();
|
//普通查询条件
|
if(rdGeneral.isSelected()){
|
Component[] comps = cp_centerPanel.getComponents();
|
//add by zhangweiwei 2014/12/09 start 因增加选择查询模板按钮将每行组件数由4改成5
|
int k = comps.length / 5;
|
//移除
|
ArrayList<Component> compList = new ArrayList<Component>();
|
for(int i = 0; i < k; i++){
|
String text = null;
|
if(comps[i * 5 + 3] instanceof JXDatePicker){
|
Date date = ((JXDatePicker) comps[i * 5 + 3]).getDate();
|
if(date != null){
|
text = OQTool.df.format(date);
|
}
|
}else if(comps[i * 5 + 3] instanceof Chooser){
|
Component[] texts = ((Chooser)comps[i * 5 + 3]).getComponents();
|
text = ((JTextField)texts[0]).getText();
|
}else{
|
text = ((JTextField) comps[i * 5 + 3]).getText();
|
}
|
if(text != null && !text.equals("")){
|
compList.add(comps[i * 5 + 0]);
|
compList.add(comps[i * 5 + 1]);
|
compList.add(comps[i * 5 + 2]);
|
compList.add(comps[i * 5 + 3]);
|
compList.add(comps[i * 5 + 4]);
|
}
|
}
|
|
Component[] newComps = compList.toArray(new Component[0]);
|
int newK = newComps.length / 5;
|
/**
|
* 加入叶子节点
|
*/
|
for(int i = 0; i < newK; i++){
|
ConditionItem ci = new ConditionItem();
|
String id = "ci" + (i + 1);
|
ci.setId(id);
|
ci.setLeafFlag(true);
|
|
String clause = ((JLabel) newComps[i * 5 + 1]).getText();
|
String operator = (String) ((JComboBox)newComps[i * 5 + 2]).getSelectedItem();
|
String ordinaryValue = null;
|
if(newComps[i * 5 + 3] instanceof JXDatePicker){
|
ordinaryValue = OQTool.df.format(((JXDatePicker) newComps[i * 5 + 3]).getDate());
|
}else if(newComps[i * 5 + 3] instanceof Chooser){
|
Component[] texts = ((Chooser)comps[i * 5 + 3]).getComponents();
|
ordinaryValue = ((JTextField)texts[0]).getText();
|
}else{
|
ordinaryValue = ((JTextField) newComps[i * 5 + 3]).getText();
|
}
|
//add by zhangweiwei 2014/12/09 end 因增加选择查询模板按钮将每行组件数由4改成5
|
LeafInfo leafInfo = new LeafInfo();
|
if(clause.contains("T_OID.") || clause.contains("F_OID.")){
|
//去掉T_OID.或者F_OID.
|
String clause_ = clause.substring(6);
|
//属性为参照属性
|
if(clause_.contains(".")){
|
int fpIndex = clause_.indexOf(".");
|
String refAbName = clause.substring(0, fpIndex + 6);
|
clause = clause.substring(fpIndex + 6 + 1);
|
leafInfo.setClause(refAbName);
|
//去掉T_OID.或者F_OID.
|
refAbName = refAbName.substring(6);
|
leafInfo.setOperator(Operator.IN);
|
QueryTemplate qt = getRefQT(refAbName, clause, operator, ordinaryValue);
|
LeafValue lValue = new LeafValue();
|
lValue.setQueryTemplate(qt);
|
leafInfo.setValue(lValue);
|
//属性为非参照属性
|
}else{
|
leafInfo.setClause(clause);
|
leafInfo.setOperator(operator);
|
LeafValue lValue = new LeafValue();
|
leafInfo.setValue(lValue);
|
//add by zhangweiwei 2014/12/09 start
|
//如果嵌套Link
|
if(ordinaryValue.contains(";")){
|
leafInfo.setOperator(Operator.IN);
|
String[] values = ordinaryValue.split(";");
|
String QTname = values[0];
|
String attr = values[1].substring(0, values[1].length());
|
try {
|
QTInfo qt = QTDClient.getService().getQT(QTname);
|
String qtText = qt.qtText;
|
QueryTemplate qt_ = OQTool.getQTByQTText(qt.qtName, qtText);
|
List<String> clauseList = new ArrayList<String>();
|
clauseList.add(attr);
|
qt_.setClauseList(clauseList);
|
lValue.setQueryTemplate(qt_);
|
//lValue.setAttr(attr);
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
catch (DocumentException e1) {
|
e1.printStackTrace();
|
}
|
}else{
|
lValue.setOrdinaryValue(ordinaryValue);
|
}
|
//add by zhangweiwei 2014/12/09 end
|
}
|
}else{
|
//属性为参照属性
|
if(clause.contains(".")){
|
int fpIndex = clause.indexOf(".");
|
String refAbName = clause.substring(0, fpIndex);
|
clause = clause.substring(fpIndex + 1);
|
leafInfo.setClause(refAbName);
|
leafInfo.setOperator(Operator.IN);
|
QueryTemplate qt = getRefQT(refAbName, clause, operator, ordinaryValue);
|
LeafValue lValue = new LeafValue();
|
lValue.setQueryTemplate(qt);
|
leafInfo.setValue(lValue);
|
//属性为非参照属性
|
}else{
|
leafInfo.setClause(clause);
|
leafInfo.setOperator(operator);
|
LeafValue lValue = new LeafValue();
|
leafInfo.setValue(lValue);
|
//add by zhangweiwei 2014/12/09 start
|
//如果嵌套Link
|
if(ordinaryValue.contains(";")){
|
leafInfo.setOperator(Operator.IN);
|
String[] values = ordinaryValue.split(";");
|
String QTname = values[0];
|
String attr = values[1].substring(0, values[1].length());
|
try {
|
QTInfo qt = QTDClient.getService().getQT(QTname);
|
String qtText = qt.qtText;
|
QueryTemplate qt_ = OQTool.getQTByQTText(qt.qtName, qtText);
|
List<String> clauseList = new ArrayList<String>();
|
clauseList.add(attr);
|
qt_.setClauseList(clauseList);
|
lValue.setQueryTemplate(qt_);
|
//lValue.setAttr(attr);
|
} catch (VCIError e) {
|
e.printStackTrace();
|
} catch (DocumentException e1) {
|
e1.printStackTrace();
|
}
|
|
}else{
|
lValue.setOrdinaryValue(ordinaryValue);
|
}
|
//add by zhangweiwei 2014/12/09 end
|
}
|
}
|
|
ci.setLeafInfo(leafInfo);
|
ciMap.put(ci.getId(), ci);
|
}
|
|
Iterator<String> iterator = ciMap.keySet().iterator();
|
ArrayList<ConditionItem> ciList = new ArrayList<ConditionItem>();
|
String lCIId = null;
|
while(iterator.hasNext()){
|
lCIId = iterator.next();
|
break;
|
}
|
int count = ciMap.size();
|
while(iterator.hasNext()){
|
String rCIId = iterator.next();
|
ConditionItem pCI = new ConditionItem();
|
String pId = "ci" + ++count;
|
pCI.setId(pId);
|
pCI.setLeafFlag(false);
|
ChildrenInfo pChildrenInfo = new ChildrenInfo();
|
pChildrenInfo.setLeftCIName(lCIId);
|
pChildrenInfo.setConnector(Connector.AND);
|
pChildrenInfo.setRightCIName(rCIId);
|
pCI.setChildrenInfo(pChildrenInfo);
|
ciList.add(pCI);
|
lCIId = pId;
|
}
|
for(Iterator<ConditionItem> i = ciList.iterator(); i.hasNext();){
|
ConditionItem ci = i.next();
|
ciMap.put(ci.getId(), ci);
|
}
|
//高级查询条件
|
}else if(rdSenior.isSelected()){
|
ciMap = getCIMapForSeniorTree();
|
|
OQTool.parseTreeToDoc(seniorTree);
|
}
|
return ciMap;
|
}
|
|
/**
|
* 获取高级查询的查询条件集合
|
* @return
|
*/
|
private HashMap<String, ConditionItem> getCIMapForSeniorTree() {
|
HashMap<String, ConditionItem> ciMap = new HashMap<String, ConditionItem>();
|
DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) seniorTree.getModel().getRoot();
|
DefaultMutableTreeNode nextNode = rootNode.getNextNode();
|
if (nextNode == null) {
|
// 无查询条件的查询
|
return null;
|
}
|
ArrayList<ConditionItem> ciList = new ArrayList<ConditionItem>();
|
String connector = (String) rootNode.getUserObject();
|
@SuppressWarnings("unchecked")
|
Enumeration<DefaultMutableTreeNode> children = rootNode.children();
|
while(children.hasMoreElements()){
|
DefaultMutableTreeNode child = children.nextElement();
|
String obj = (String) child.getUserObject();
|
if(obj.equals(AND) || obj.equals(OR)){
|
List<ConditionItem> subCIList = getCIList(child, ciList.size() + 1);
|
if(ciList.size() > 0){
|
ConditionItem leftCI = ciList.get(ciList.size() - 1);
|
ConditionItem rightCI = subCIList.get(subCIList.size() - 1);
|
ciList.addAll(subCIList);
|
ConditionItem pCI = new ConditionItem();
|
pCI.setId("ci" + (ciList.size() + 1));
|
ciList.add(pCI);
|
pCI.setLeafFlag(false);
|
ChildrenInfo cInfo = new ChildrenInfo();
|
pCI.setChildrenInfo(cInfo);
|
cInfo.setLeftCIName(leftCI.getId());
|
cInfo.setConnector(connector);
|
cInfo.setRightCIName(rightCI.getId());
|
}else{
|
ciList.addAll(subCIList);
|
}
|
}else{
|
String text = (String) child.getUserObject();
|
if(text == null || text.equals("")){
|
continue;
|
}
|
if(!text.contains(Operator.EQUAL) && !text.contains(Operator.UNEQUAL) && !text.contains(Operator.CONTAINS)
|
&& !text.contains(Operator.IN) && !text.contains(Operator.NOTIN) &&!text.contains(Operator.GTE) && !text.contains(Operator.GT)
|
&& !text.contains(Operator.LTE) && !text.contains(Operator.LT)){
|
continue;
|
}
|
if(ciList.size() > 0){
|
ConditionItem leftCI = ciList.get(ciList.size() - 1);
|
ConditionItem rightCI = getCIByNode(child, ciList.size() + 1);
|
ciList.add(rightCI);
|
ConditionItem pCI = new ConditionItem();
|
pCI.setId("ci" + (ciList.size() + 1));
|
ciList.add(pCI);
|
pCI.setLeafFlag(false);
|
ChildrenInfo cInfo = new ChildrenInfo();
|
pCI.setChildrenInfo(cInfo);
|
cInfo.setLeftCIName(leftCI.getId());
|
cInfo.setConnector(connector);
|
cInfo.setRightCIName(rightCI.getId());
|
}else{
|
ConditionItem ci = getCIByNode(child, ciList.size() + 1);
|
ciList.add(ci);
|
}
|
}
|
}
|
|
for(int i = 0; i < ciList.size(); i++){
|
ConditionItem ci = ciList.get(i);
|
ciMap.put(ci.getId(), ci);
|
}
|
return ciMap;
|
}
|
|
/**
|
* 树化一个查询条件组节点
|
* @param node
|
* @param beginId
|
* @return
|
*/
|
private List<ConditionItem> getCIList(DefaultMutableTreeNode node, int beginId){
|
List<ConditionItem> ciList = new ArrayList<ConditionItem>();
|
String connector = (String)node.getUserObject();
|
@SuppressWarnings("unchecked")
|
Enumeration<DefaultMutableTreeNode> children = node.children();
|
|
while(children.hasMoreElements()){
|
DefaultMutableTreeNode child = children.nextElement();
|
String obj = (String) child.getUserObject();
|
if(obj.equals(AND) || obj.equals(OR)){
|
List<ConditionItem> subCIList = getCIList(child, beginId);
|
if(ciList.size() > 0){
|
ConditionItem leftCI = ciList.get(ciList.size() - 1);
|
ConditionItem rightCI = subCIList.get(subCIList.size() - 1);
|
ciList.addAll(subCIList);
|
beginId = beginId + subCIList.size();
|
ConditionItem pCI = new ConditionItem();
|
pCI.setId("ci" + beginId);
|
ciList.add(pCI);
|
beginId = beginId + 1;
|
pCI.setLeafFlag(false);
|
ChildrenInfo cInfo = new ChildrenInfo();
|
pCI.setChildrenInfo(cInfo);
|
cInfo.setLeftCIName(leftCI.getId());
|
cInfo.setConnector(connector);
|
cInfo.setRightCIName(rightCI.getId());
|
}else{
|
ciList.addAll(subCIList);
|
beginId = beginId + subCIList.size();
|
}
|
}else{
|
String text = (String) child.getUserObject();
|
if(text == null || text.equals("")){
|
continue;
|
}
|
if(!text.contains(Operator.EQUAL) && !text.contains(Operator.UNEQUAL) && !text.contains(Operator.CONTAINS)
|
&& !text.contains(Operator.IN) && !text.contains(Operator.NOTIN) &&!text.contains(Operator.GTE) && !text.contains(Operator.GT)
|
&& !text.contains(Operator.LTE) && !text.contains(Operator.LT)){
|
continue;
|
}
|
if(ciList.size() > 0){
|
ConditionItem leftCI = ciList.get(ciList.size() - 1);
|
ConditionItem rightCI = getCIByNode(child, beginId);
|
ciList.add(rightCI);
|
beginId = beginId + 1;
|
ConditionItem pCI = new ConditionItem();
|
pCI.setId("ci" + beginId);
|
ciList.add(pCI);
|
beginId = beginId + 1;
|
pCI.setLeafFlag(false);
|
ChildrenInfo cInfo = new ChildrenInfo();
|
pCI.setChildrenInfo(cInfo);
|
cInfo.setLeftCIName(leftCI.getId());
|
cInfo.setConnector(connector);
|
cInfo.setRightCIName(rightCI.getId());
|
}else{
|
ConditionItem ci = getCIByNode(child, beginId);
|
ciList.add(ci);
|
beginId = beginId + 1;
|
}
|
}
|
}
|
return ciList;
|
}
|
/**
|
* 获取参照的查询模板
|
* @param refAbName: 参照属性名
|
* @param clause: 属性参照的业务类型中的属性
|
* @param operator
|
* @param ordinaryValue
|
* @return
|
*/
|
private QueryTemplate getRefQT(String refAbName, String clause,
|
String operator, String ordinaryValue) {
|
QueryTemplate qt = new QueryTemplate();
|
List<String> clauseList = new ArrayList<String>();
|
clauseList.add("OID");
|
qt.setClauseList(clauseList);
|
AttribItem refAb = ApProvider.getAbItemByName(refAbName);
|
OtherInfo otherInfo = OtherInfo.getOtherInfoByText(refAb.other);
|
int refFlag = otherInfo.getRefFlag();
|
String type = otherInfo.getRefTypeName();
|
if(refFlag == 0){
|
qt.setType(QTConstants.TYPE_BTM);
|
qt.setBtmType(type);
|
}else if(refFlag == 1){
|
qt.setType(QTConstants.TYPE_LINK);
|
qt.setLinkType(type);
|
}
|
Condition condition = new Condition();
|
qt.setCondition(condition);
|
condition.setRootCIName("ci1");
|
HashMap<String, ConditionItem> ciMap = new HashMap<String, ConditionItem>();
|
condition.setCIMap(ciMap);
|
ConditionItem ci = new ConditionItem();
|
ci.setId("ci1");
|
ciMap.put(ci.getId(), ci);
|
ci.setLeafFlag(true);
|
LeafInfo leafInfo = new LeafInfo();
|
if(clause.contains(".")){
|
int fpIndex = clause.indexOf(".");
|
String refAbName_ = clause.substring(0, fpIndex);
|
clause = clause.substring(fpIndex + 1);
|
leafInfo.setClause(refAbName_);
|
leafInfo.setOperator(Operator.IN);
|
QueryTemplate qt_ = getRefQT(refAbName_, clause, operator, ordinaryValue);
|
LeafValue lValue = new LeafValue();
|
lValue.setQueryTemplate(qt_);
|
leafInfo.setValue(lValue);
|
qt.setId("qt_" + refAbName + "_" + refAbName_);
|
}else{
|
leafInfo.setClause(clause);
|
leafInfo.setOperator(operator);
|
LeafValue lValue = new LeafValue();
|
lValue.setOrdinaryValue(ordinaryValue);
|
leafInfo.setValue(lValue);
|
qt.setId("qt_" + refAbName + "_" + clause);
|
}
|
ci.setLeafInfo(leafInfo);
|
condition.setCIMap(ciMap);
|
return qt;
|
}
|
|
/**
|
* 高级查询
|
* 把Node内容解析成ConditionItem
|
* @param nextNode
|
* @param id
|
* @return
|
*/
|
private ConditionItem getCIByNode(DefaultMutableTreeNode nextNode, int id){
|
String text = (String) nextNode.getUserObject();
|
ConditionItem ci = new ConditionItem();
|
ci.setId("ci" + id);
|
ci.setLeafFlag(true);
|
LeafInfo leafInfo = new LeafInfo();
|
ci.setLeafInfo(leafInfo);
|
String operator = null;
|
if(text.contains(Operator.EQUAL)){
|
operator = Operator.EQUAL;
|
}else if(text.contains(Operator.CONTAINS)){
|
operator = Operator.CONTAINS;
|
}else if(text.contains(Operator.UNEQUAL)){
|
operator = Operator.UNEQUAL;
|
}else if(text.contains(Operator.IN)){
|
operator = Operator.IN;
|
}else if(text.contains(Operator.NOTIN)){
|
operator = Operator.NOTIN;
|
}else if(text.contains(Operator.GTE)){
|
operator = Operator.GTE;
|
}else if(text.contains(Operator.GT)){
|
operator = Operator.GT;
|
}else if(text.contains(Operator.LTE)){
|
operator = Operator.LTE;
|
}else if(text.contains(Operator.LT)){
|
operator = Operator.LT;
|
}
|
int operatorIndex = text.indexOf(operator);
|
String clause = text.substring(0, operatorIndex).trim();
|
String ordinaryValue = text.substring(operatorIndex + 2).trim();
|
if(clause.contains("T_OID.") || clause.contains("F_OID.")){
|
//去掉T_OID.或者F_OID.
|
String clause_ = clause.substring(6);
|
//属性为参照属性
|
if(clause_.contains(".")){
|
int fpIndex = clause_.indexOf(".");
|
String refAbName = clause.substring(0, fpIndex + 6);
|
clause = clause.substring(fpIndex + 6 + 1);
|
leafInfo.setClause(refAbName);
|
//去掉T_OID.或者F_OID.
|
refAbName = refAbName.substring(6);
|
leafInfo.setOperator(Operator.IN);
|
QueryTemplate qt = getRefQT(refAbName, clause, operator, ordinaryValue);
|
LeafValue lValue = new LeafValue();
|
lValue.setQueryTemplate(qt);
|
leafInfo.setValue(lValue);
|
//属性为非参照属性
|
}else{
|
leafInfo.setClause(clause);
|
leafInfo.setOperator(operator);
|
LeafValue lValue = new LeafValue();
|
leafInfo.setValue(lValue);
|
lValue.setOrdinaryValue(ordinaryValue);
|
}
|
}else{
|
//属性为参照属性
|
if(clause.contains(".")){
|
int fpIndex = clause.indexOf(".");
|
String refAbName = clause.substring(0, fpIndex);
|
clause = clause.substring(fpIndex + 1);
|
leafInfo.setClause(refAbName);
|
leafInfo.setOperator(Operator.IN);
|
QueryTemplate qt = getRefQT(refAbName, clause, operator, ordinaryValue);
|
LeafValue lValue = new LeafValue();
|
lValue.setQueryTemplate(qt);
|
leafInfo.setValue(lValue);
|
//属性为非参照属性
|
}else{
|
leafInfo.setClause(clause);
|
leafInfo.setOperator(operator);
|
LeafValue lValue = new LeafValue();
|
leafInfo.setValue(lValue);
|
lValue.setOrdinaryValue(ordinaryValue);
|
}
|
}
|
|
return ci;
|
}
|
|
/**
|
* 返回普通或者 高级
|
* rdGeneral: 0
|
* rdSenior : 1
|
* @return
|
*/
|
public short getRadioFlag(){
|
short flag = 0;
|
if(rdSenior.isSelected()){
|
flag = 1;
|
}
|
return flag;
|
}
|
|
/**
|
* 根据查询模板设置UI
|
* @param qtWrapper
|
*/
|
public void setQTUI(QTInfo qtWrapper){
|
cp_centerPanel.removeAll();
|
QueryTemplate qt = null;
|
try {
|
qt = OQTool.getQTByDoc(DocumentHelper.parseText(qtWrapper.qtText), qtWrapper.qtName);
|
} catch (DocumentException e1) {
|
e1.printStackTrace();
|
} catch (VCIError e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
Condition condition = qt.getCondition();
|
if(condition == null){
|
cp_centerPanel.updateUI();
|
return;
|
}
|
Map<String, ConditionItem> ciMap = qt.getCondition().getCIMap();
|
String rootName = qt.getCondition().getRootCIName();
|
ConditionItem rootCI = ciMap.get(rootName);
|
int levelFlag = qtWrapper.levelFlag;
|
if(levelFlag == 0){
|
rdGeneral.setSelected(true);
|
//当rdGeneral的Selected状态由false变为true时 , initCP_centerPanel
|
//会设为默认的(将模板定义中的条件都加入), 此时先将默认的移除, 再加入qt的条件
|
//---START---
|
cp_centerPanel.removeAll();
|
cp_centerPanel.updateUI();
|
//---END---
|
ConditionItem lCI = null;
|
ConditionItem rCI = null;
|
if(!rootCI.isLeaf()){
|
lCI = ciMap.get(rootCI.getChildrenInfo().getLeftCIName());
|
rCI = ciMap.get(rootCI.getChildrenInfo().getRightCIName());
|
}
|
|
List<ConditionItem> ciList = getCILeafList(ciMap, lCI, rootCI, rCI);
|
for(int i = 0; i < ciList.size(); i++){
|
ConditionItem ci = ciList.get(i);
|
LeafInfo leafInfo = ci.getLeafInfo();
|
GridBagConstraints g = new GridBagConstraints();
|
g.anchor = GridBagConstraints.WEST;
|
g.gridx = 0;
|
g.gridy = i;
|
g.insets = new Insets(1, 1, 1, 1);
|
final JButton btnRemove = new JButton("x");
|
cp_centerPanel.add(btnRemove, g);
|
//获取leafInfo中的clause(有参照时加上参照)和value
|
Map<String, String> map = OQTool.getClauseAndValue(leafInfo);
|
String attName = map.get("clause");
|
String value = map.get("value");
|
final JLabel labName = new JLabel(attName);
|
g.gridx = 1;
|
cp_centerPanel.add(labName, g);
|
g.gridx = 2;
|
final JComboBox combCons = new JComboBox();
|
combCons.setPreferredSize(new Dimension(80, 20));
|
|
if(attName.contains(".")){
|
attName = attName.substring(attName.lastIndexOf(".") + 1, attName.length());
|
}
|
String attType = OQTool.getAbItemDataType(attName);
|
if(attType.equalsIgnoreCase("VTInteger") || attType.equalsIgnoreCase("VTDouble")
|
|| attType.equalsIgnoreCase("VTLong")){
|
combCons.addItem(Operator.EQUAL);
|
combCons.addItem(Operator.UNEQUAL);
|
combCons.addItem(Operator.CONTAINS);
|
combCons.addItem(Operator.IN);
|
combCons.addItem(Operator.NOTIN);
|
combCons.addItem(Operator.GTE);
|
combCons.addItem(Operator.GT);
|
combCons.addItem(Operator.LTE);
|
combCons.addItem(Operator.LT);
|
}else if(attType.equalsIgnoreCase("VTDateTime") || attType.equalsIgnoreCase("VTDate")
|
|| attType.equalsIgnoreCase("VTTime")){
|
combCons.addItem(Operator.EQUAL);
|
combCons.addItem(Operator.UNEQUAL);
|
combCons.addItem(Operator.IN);
|
combCons.addItem(Operator.NOTIN);
|
combCons.addItem(Operator.GTE);
|
combCons.addItem(Operator.LTE);
|
}else{
|
combCons.addItem(Operator.EQUAL);
|
combCons.addItem(Operator.UNEQUAL);
|
combCons.addItem(Operator.CONTAINS);
|
combCons.addItem(Operator.IN);
|
combCons.addItem(Operator.NOTIN);
|
}
|
String operator = leafInfo.getOperator();
|
if(operator.equals(Operator.EQUAL)){
|
combCons.setSelectedItem(Operator.EQUAL);
|
}else if(operator.equals(Operator.UNEQUAL)){
|
combCons.setSelectedItem(Operator.UNEQUAL);
|
}else if(operator.equals(Operator.CONTAINS) || operator.equals(Operator.LIKE)){
|
combCons.setSelectedItem(Operator.CONTAINS);
|
}else if(operator.equals(Operator.IN)){
|
combCons.setSelectedItem(Operator.IN);
|
}else if(operator.equals(Operator.NOTIN)){
|
combCons.setSelectedItem(Operator.NOTIN);
|
}else if(operator.equals(Operator.GTE)){
|
combCons.setSelectedItem(Operator.GTE);
|
}else if(operator.equals(Operator.GT)){
|
combCons.setSelectedItem(Operator.GT);
|
}else if(operator.equals(Operator.LTE)){
|
combCons.setSelectedItem(Operator.LTE);
|
}else if(operator.equals(Operator.LT)){
|
combCons.setSelectedItem(Operator.LT);
|
}
|
cp_centerPanel.add(combCons, g);
|
g.gridx = 3;
|
//add by zhangweiwei 2014/12/09 start
|
final JTextField tfValue = new JTextField(100);
|
// final JXDatePicker datePicker = new JXDatePicker();
|
// datePicker.setPreferredSize(tfValue.getPreferredSize());
|
final Chooser chooser = Chooser.getInstance();
|
chooser.setLayout(cp_centerPanel.getLayout());
|
if(attType.equalsIgnoreCase("VTDateTime") || attType.equalsIgnoreCase("VTDate")
|
|| attType.equalsIgnoreCase("VTTime")){
|
cp_centerPanel.add(chooser, g);
|
try {
|
if (value == null || value.equalsIgnoreCase("null")) {
|
// datePicker.setDate(null);
|
JTextField text = new JTextField(value);
|
text.setPreferredSize(tfValue.getPreferredSize());
|
chooser.register(text);
|
} else {
|
// datePicker.setDate(Tool.df.parse(value));
|
JTextField text = new JTextField(value);
|
text.setPreferredSize(tfValue.getPreferredSize());
|
chooser.register(text);
|
}
|
} catch (Exception e1) {
|
e1.printStackTrace();
|
}
|
|
// cp_centerPanel.add(datePicker, g);
|
// try {
|
// datePicker.setDate(Tool.df.parse(value));
|
// } catch (ParseException e1) {
|
// e1.printStackTrace();
|
// }
|
}else{
|
cp_centerPanel.add(tfValue, g);
|
tfValue.setText(value);
|
}
|
g.gridx =4;
|
final JButton chooseButton = new JButton("选择查询模板");
|
cp_centerPanel.add(chooseButton, g);
|
g.gridwidth = GridBagConstraints.REMAINDER;
|
cp_centerPanel.updateUI();
|
chooseButton.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
// TODO Auto-generated method stub
|
// TODO 后续窗口调整 显示查询模板窗口
|
SelectorQTDialog eid = new SelectorQTDialog(cp_centerPanel);
|
QTInfo item = eid.getItem();
|
String attr = eid.getAttr();
|
//选中的查询模板
|
tfValue.setText(item.qtName + ";" + attr);
|
}
|
});
|
btnRemove.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
cp_centerPanel.remove(btnRemove);
|
cp_centerPanel.remove(labName);
|
cp_centerPanel.remove(combCons);
|
cp_centerPanel.remove(tfValue);
|
cp_centerPanel.remove(chooser);
|
// cp_centerPanel.remove(datePicker);
|
cp_centerPanel.remove(chooseButton);
|
cp_centerPanel.updateUI();
|
}
|
});
|
//add by zhangweiwei 2014/12/09 end
|
}
|
}else if(levelFlag == 1){
|
rdSenior.setSelected(true);
|
Document doc = null;
|
try {
|
if(qtWrapper.qtUIText != null && !qtWrapper.qtUIText.equals("")){
|
doc = DocumentHelper.parseText(qtWrapper.qtUIText);
|
}
|
} catch (DocumentException e) {
|
e.printStackTrace();
|
}
|
seniorTree = OQTool.parseDocToTree(doc);
|
initSeniorTree();
|
seniorTree.updateUI();
|
}
|
cp_centerPanel.updateUI();
|
}
|
|
/**
|
* 按先左后右顺序返回ciMap的叶子节点
|
* @param ciMap
|
* @return
|
*/
|
private List<ConditionItem> getCILeafList(Map<String, ConditionItem> ciMap, ConditionItem left, ConditionItem root, ConditionItem right){
|
List<ConditionItem> ciList = new ArrayList<ConditionItem>();
|
//针对只有一个查询节点的情况
|
if(root.isLeaf()){
|
ciList.add(root);
|
}
|
if(left != null){
|
if(left.isLeaf()){
|
ciList.add(left);
|
}else{
|
ConditionItem left_ = ciMap.get(left.getChildrenInfo().getLeftCIName());
|
ConditionItem root_ = left;
|
ConditionItem right_ = ciMap.get(left.getChildrenInfo().getRightCIName());
|
ciList.addAll(getCILeafList(ciMap, left_, root_, right_));
|
}
|
}
|
|
if(right != null){
|
if(right.isLeaf()){
|
ciList.add(right);
|
}else{
|
ConditionItem left_ = ciMap.get(right.getChildrenInfo().getLeftCIName());
|
ConditionItem root_ = left;
|
ConditionItem right_ = ciMap.get(right.getChildrenInfo().getRightCIName());
|
ciList.addAll(getCILeafList(ciMap, left_, root_, right_));
|
}
|
}
|
return ciList;
|
}
|
|
/**
|
* 初始高级查询树
|
*/
|
private void initSeniorTree(){
|
if(seniorTree == null){
|
seniorRoot = new DefaultMutableTreeNode(AND);
|
seniorTree = new JTree(seniorRoot);
|
}
|
seniorTree.addMouseListener(new MouseListener() {
|
|
@Override
|
public void mouseReleased(MouseEvent e) {
|
|
}
|
|
@Override
|
public void mousePressed(MouseEvent e) {
|
|
}
|
|
@Override
|
public void mouseExited(MouseEvent e) {
|
|
}
|
|
@Override
|
public void mouseEntered(MouseEvent e) {
|
|
}
|
|
@Override
|
public void mouseClicked(MouseEvent e) {
|
|
}
|
});
|
|
GridBagConstraints g1 = new GridBagConstraints();
|
g1.gridx = 0;
|
g1.gridy = 0;
|
g1.weightx = 1.0;
|
g1.weighty = 1.0;
|
g1.fill = GridBagConstraints.BOTH;
|
seniorTree.setAutoscrolls(true);
|
seniorTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
cp_centerPanel.add(seniorTree, g1);
|
}
|
|
|
/**
|
* 增加逻辑条件
|
*/
|
private void addCondition(){
|
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) seniorTree.getLastSelectedPathComponent();
|
if(selectedNode == null){
|
JOptionPane.showMessageDialog(this, "请选择条件项或逻辑运算符", "选择条件", JOptionPane.INFORMATION_MESSAGE);
|
return;
|
}
|
|
//对逻辑条件增加逻辑子节点
|
String obj = (String) selectedNode.getUserObject();
|
if (obj.equals(AND) || obj.equals(OR)) {
|
DefaultMutableTreeNode node = new DefaultMutableTreeNode(AND);
|
selectedNode.add(node);
|
seniorTree.updateUI();
|
}else{
|
JOptionPane.showMessageDialog(this, "只能对逻辑条件增加逻辑条件", "只能对逻辑条件增加逻辑条件", JOptionPane.INFORMATION_MESSAGE);
|
return;
|
}
|
}
|
|
/**
|
* 修改条件项或逻辑条件
|
*/
|
private void modifyCondition(){
|
|
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) seniorTree.getLastSelectedPathComponent();
|
if(selectedNode == null){
|
JOptionPane.showMessageDialog(this, "请选择条件项或逻辑运算符", "选择条件", JOptionPane.INFORMATION_MESSAGE);
|
return;
|
}
|
|
//变更与或
|
if(selectedNode.getUserObject().equals(AND)){
|
selectedNode.setUserObject(OR);
|
}else if(selectedNode.getUserObject().equals(OR)){
|
selectedNode.setUserObject(AND);
|
//变更条件
|
}else{
|
String attName = (String) selectedNode.getUserObject();
|
if(attName.contains(".")){
|
attName = attName.substring(attName.lastIndexOf(".") + 1, attName.length());
|
}
|
ConditionDialog dialog = new ConditionDialog(attName);
|
dialog.setVisible(true);
|
int disposeEvent = dialog.getDisposeEvent();
|
if(disposeEvent == ConditionDialog.disposeByOK){
|
String cons = dialog.getCons();
|
String value = dialog.getValue();
|
String userObj = trimUserObj((String)selectedNode.getUserObject());
|
String all = userObj + " " + cons + " " + value;
|
selectedNode.setUserObject(all);
|
seniorTree.updateUI();
|
}
|
}
|
seniorTree.updateUI();
|
}
|
|
/**
|
* 删除条件
|
*/
|
private void deleteCondition(){
|
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) seniorTree.getLastSelectedPathComponent();
|
if(selectedNode == null){
|
JOptionPane.showMessageDialog(this, "请选择条件项或逻辑运算符", "选择条件", JOptionPane.INFORMATION_MESSAGE);
|
return;
|
}
|
if (selectedNode.isRoot()) {
|
JOptionPane.showMessageDialog(this, "不可删除根节点", "不可删除根节点", JOptionPane.INFORMATION_MESSAGE);
|
return;
|
}
|
int option = JOptionPane.showConfirmDialog(cp_centerPanel, "删除该条件", "删除该条件", JOptionPane.YES_NO_OPTION);
|
if (option != JOptionPane.YES_OPTION) {
|
return;
|
}
|
((DefaultMutableTreeNode) selectedNode.getParent()).remove(selectedNode);
|
seniorTree.updateUI();
|
}
|
|
/**
|
* 获取当前选择的查询模板定义名字
|
* @return
|
*/
|
public String getSelectedQTDName(){
|
if(combLinkQTD == null || combLinkQTD.getSelectedItem() == null || ((QTDWrapper)combLinkQTD.getSelectedItem()).qtd == null){
|
JOptionPane.showMessageDialog(this, "无查询模板", "无查询模板", JOptionPane.INFORMATION_MESSAGE);
|
return null;
|
}
|
return ((QTDWrapper) combLinkQTD.getSelectedItem()).qtd.name;
|
}
|
|
public boolean isLinkTypeSelected(){
|
if(rdLinkType.isSelected()){
|
return true;
|
}else{
|
return false;
|
}
|
}
|
|
/**
|
* 获取业务类型选择按钮
|
* @return
|
*/
|
public JRadioButton getRadioBtm(){
|
return rdBtm;
|
}
|
|
/**
|
* 获取链接类型选择按钮
|
* @return
|
*/
|
public JRadioButton getRadioLinkType(){
|
return rdLinkType;
|
}
|
}
|