Package realcix20.guis.views.settings.tools

Source Code of realcix20.guis.views.settings.tools.GVManager

/*���ܼ�飄1�7
*��ݱ�GV�е���Ϣ���SettingsDialog��
*����IFUI=true������Ӧ��������SettingsDialog�п��Ա��û��༭��ȫ�ֱ���IFUI=false��ȫ�ֱ�Ϊ
*����ʹ�ã��û��޷��޸ġ�
*ʹ����GVGroup,GV�ࡣ
*/
package realcix20.guis.views.settings.tools;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.Iterator;
import java.util.Vector;

import javax.swing.JComboBox;
import javax.swing.JComponent;

import realcix20.guis.utils.Item;
import realcix20.utils.DAO;
import realcix20.utils.Resources;

public class GVManager {
            
    //��ȡ��GV�����GVGroup���ϲ������ӦGV��
    public static Vector generateGVGroups() {       
        Vector gvGroups = new Vector();           
        DAO dao = DAO.getInstance();
        dao.query(Resources.SELECT_GROUPS_FROM_GV_SQL);
        ResultSet rs = dao.executeQuery();
        try {
            while (rs.next()) {
                GVGroup gvGroup = new GVGroup(rs.getString("GRP"), new Vector());
                gvGroups.add(gvGroup);
            }
            rs.close();
        } catch (Exception e) {
            e.printStackTrace();
        }                  
        dao.query(Resources.SELECT_GV_SQL);
        rs = dao.executeQuery();
        try {
            while (rs.next()) {                   
                String vid = rs.getString("VID");
                String vvalue = rs.getString("VVALUE");
                int ordinal = rs.getInt("ORDINAL");
                String defvalue = rs.getString("DEFVALUE");
                boolean ifui = rs.getBoolean("IFUI");
                String grp = rs.getString("GRP");
                int inputtype = rs.getInt("INPUTTYPE");
                String inputpar = rs.getString("INPUTPAR");
                GV gv = new GV(vid, vvalue, ordinal, defvalue, ifui, grp, inputtype, inputpar);
                add(gv, gvGroups);                   
            }
            rs.close();
        } catch (Exception e) {
            e.printStackTrace();
        }       
        return gvGroups;           
    }
   
    //���GRP����GVGroup��
    public static GVGroup findGVGroup(String grp, Vector gvGroups) {       
        GVGroup gvGroup = null;
        Iterator gvGroupsIter = gvGroups.iterator();
        while (gvGroupsIter.hasNext()) {
            GVGroup tempGvGroup = (GVGroup)gvGroupsIter.next();           
            if (tempGvGroup.getGrp().equals(grp)) {
                gvGroup = tempGvGroup;
                break;
            }
        }
        return gvGroup;      
    }
   
    //���ָ��GV��GRP������ӵ�GVGroup�С�
    private static void add(GV gv, Vector gvGroups) {       
        Iterator gvGroupsIter = gvGroups.iterator();
        while (gvGroupsIter.hasNext()) {
            GVGroup gvGroup = (GVGroup)gvGroupsIter.next();
            if (gv.getGrp().equals(gvGroup.getGrp())) {
                gvGroup.getGvs().add(gv);
                break;
            }
        }       
    }
   
    /*���GV��INPUTTYPE����4��ɿؼ���ĿǰINPUTTYPEֻ��Ϊ1����ֻ��JComboBox�ؼ���   
     *���INPUTPAR�����е�SELECT SQL 4���ѡ������SELECT SQL�Ľ��ֻ�ᅣ1�7�У�����м�ΪID��ΪVALUE,����ᅣ1�7��
     *���һ��ΪID���ڶ���ΪVALUE��     
     */
    public static JComponent getComponent(GV gv) {       
        JComponent component = null;
        if (gv.getInputtype() == 1) {
            JComboBox comboBox = new JComboBox();
            DAO dao = DAO.getInstance();
            dao.query(gv.getInputpar());
            ResultSet rs = dao.executeQuery();
            try {
                while (rs.next()) {
                    ResultSetMetaData rsmd = rs.getMetaData();
                    Item item = null;
                    if (rsmd.getColumnCount() == 1) {
                        item = new Item(rs.getObject(1), rs.getObject(1));
                    } else if (rsmd.getColumnCount() == 2) {
                        item = new Item(rs.getObject(1), rs.getObject(2));
                    }
                    comboBox.addItem(item);
                }
                rs.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
            for (int i = 0 ; i < comboBox.getItemCount(); i++) {
                Item item = (Item)comboBox.getItemAt(i);
                if (item.getFactValue().equals(gv.getVvalue())) {
                    comboBox.setSelectedIndex(i);
                }
            }
            component = comboBox;
        }
        return component;       
    }
   
}
TOP

Related Classes of realcix20.guis.views.settings.tools.GVManager

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.