TableImpDialogOfORACLE

public class TableImpDialogOfORACLE extends AbstractProcessDialog
{

    /**
     *
     */
    private static final long serialVersionUID = 1L;

    private DebugPrn dMsg = new DebugPrn(TableImpDialogOfORACLE.class.getName());
    //private static Logger dMsg = Logger.getLogger(DBResourceDialog.class.getName());

    private I18n I18N = null;
    private String STR_ESCAPE_RELEASED = "ESCAPE_RELEASED";
    private KeyStroke ESCAPE_STROKE = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
    private KeyStroke ENTER_STROKE = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false);

    private DatabaseInfo dbInfo = null;

    private JTextField jvalueTextArea = new JTextField("");
    private JCheckBox jcIsTruncateFirst = new JCheckBox();

    /**用户(ora) 或者 数据库名 的列表*/
    // private ZJList jcmbDBName = new ZJList();
    private ZXComboBox jcmbDBName = new ZXComboBox();

    /**显示DB信息的JTable控件列名*/
    private Vector vecColumnStrDBInfo = null;
    /**显示table信息的JTable控件列名*/
    private Vector vecColumnStrTableInfo = null;

    private NonEditableTableModel jtbModelTableInfo = null;

    // 各种 监控器 和 动作事件 处理类
    private KeyAdapter keyAdpJcmbEnter = null;
    private KeyAdapter keyAdpEscape = null;
    private ActionListener actionLsrJbutOk = null;
    private ActionListener actionLsrJbutEXECUTE = null;
    private ActionListener actionLsrJbutUpdateDBMSOwnerSystemTables = null;

    private ActionListener actionLsrCommon = null;

    private ActionListener actionFile = null;

    private ActionListener itemLsrJcmbDBName = null;
    private Action actionEscape = null;
    private JFrame jfmMain = null;
    private AbstractProcessJFrame main = null;

    private JTextField databaseLocalName = new JTextField(MainFrame.localDbName);
    private JTable jtblTableInfo = null;

    //private final static ImageIcon ICON_DBSVR_RESVIEW_DESC = UIToolKit
    //       .getIcon("uep-dev-d-dbres-browse");

    /**
     * 构造函数
     * @param frame
     * @param title
     * @param modal
     * @param inDbInfo
     */
    public TableImpDialogOfORACLE(AbstractProcessJFrame main, String title, DatabaseInfo inDBInfo)
    {
        super(main, title, true);
        I18N = STMConsts.getI18N();
        jfmMain = main;
        this.main = main;
        this.dbInfo = inDBInfo;
        boolean bOk = false;
        this.setCursor(new Cursor(Cursor.WAIT_CURSOR));

        try
        {
            defineActions();
            bOk = initialize();

        }
        catch(Exception ignore)
        {
            dMsg.error("", ignore);
            return;
        }
        this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

        if(bOk)
        {
            ToolBox.setDlgCenterDisplayLocation(this);
            setVisible(true);
        }

    }

    /**
     *
     *各种事件处理函数
     */
    private void defineActions()
    {
        // Enter键 处理
        keyAdpJcmbEnter = new KeyAdapter()
        {

            public void keyPressed(KeyEvent e)
            {
                if(e.getSource() instanceof JComboBox)
                {
                    if(!(((JComboBox) (e.getSource())).isPopupVisible()))
                    {
                        if(e.getKeyCode() == KeyEvent.VK_ENTER)
                        {
                            dMsg.error("111");
                            importTable();
                        }
                    }
                }
            }
        };
        //
        keyAdpEscape = new KeyAdapter()
        {

            public void keyPressed(KeyEvent e)
            {
                if(e.getKeyCode() == KeyEvent.VK_ESCAPE)
                {
                    close();
                }
            }
        };
        //
        actionEscape = new AbstractAction()
        {

            /**
             *
             */
            private static final long serialVersionUID = 1L;

            public void actionPerformed(ActionEvent e)
            {
                close();
            }
        };
        //
        itemLsrJcmbDBName = new ActionListener()
        {

            public void actionPerformed(ActionEvent e)
            {
                jcmbDBName_itemStateChanged(e);
            }
        };

        //
        actionLsrJbutOk = new ActionListener()
        {

            public void actionPerformed(ActionEvent e)
            {
                jbutOk_actionPerformed(e);
            }
        };

        //
        actionLsrJbutEXECUTE = new ActionListener()
        {

            public void actionPerformed(ActionEvent e)
            {
                jbutEXECUTE_actionPerformed(e);
            }
        };

        //
        actionLsrJbutUpdateDBMSOwnerSystemTables = new ActionListener()
        {

            public void actionPerformed(ActionEvent e)
            {
                jbutUpdateDBMSOwnerSystemTables_actionPerformed(e);
            }
        };

        actionLsrCommon = new ActionListener()
        {

            public void actionPerformed(ActionEvent ae)
            {
                //调度事件
                jbRefreshClicked(ae);
            }
        };

        actionFile = new ActionListener()
        {

            public void actionPerformed(ActionEvent ae)
            {
                //调度事件
                selectPath(jvalueTextArea);
            }
        };
    }

    /**
     * 更新
     * @param ae ActionEvent
     */
    private void jbRefreshClicked(ActionEvent ae)
    {

        actionLsrJbutUpdateDBMSOwnerSystemTables.actionPerformed(ae);

    }

    /**
     * 消息回调方法
     * @param msg String 系统表信息更新完成
     */
    public void addProcessMsg(String msg)
    {
        SwingUtilities.invokeLater(new UpdateHandler(this));
    }

    /**
     * 初使化操作
     *
     */
    private boolean initialize()
    {
        this.setSize(new Dimension(780, 550));
        UIToolKit.setMinimumSize(this, 780, 550);
        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        this.registerEscapeAction(this.getRootPane(), actionEscape);
        this.setupColumnStrVector();

        //-------------数据表信息-----------
        jtbModelTableInfo = new NonEditableTableModel(new Vector(), this.vecColumnStrTableInfo);

        if(addAllDBNamesToJcmbDBName() == false)
        {
            return false;
        }

        jcmbDBName.addActionListener(null);
        jcmbDBName.addActionListener(itemLsrJcmbDBName);
        jcmbDBName.setEditable(false);
        jcmbDBName.setSelectedIndex(0);
        jcmbDBName.addKeyListener(keyAdpJcmbEnter);

        //加载当前库所有表行数信息
        jtblTableInfo = TableHelper.createSortableTable(jtbModelTableInfo);
        jtblTableInfo.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        jtblTableInfo.addKeyListener(keyAdpEscape);
        setCellRender(jtblTableInfo);
        jtblTableInfo.setDefaultRenderer(String.class, new CellRender());
        jtblTableInfo.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        JScrollPane jscrPaneTableInfo = new JScrollPane();
        jscrPaneTableInfo.getViewport().add(jtblTableInfo);
        if(loadTableInfoofCurrUser() == false)
        {
            return false;
        }
        JPanel panelTableInfo = new JPanel();
        panelTableInfo.setLayout(new BorderLayout(6, 6));

        JPanel jscrDBNamesInfo = new JPanel();
        jscrDBNamesInfo.setLayout(new BorderLayout(6, 6));

        JPanel p1 = new JPanel();
        p1.setLayout(new GridBagLayout());
        p1.setPreferredSize(new Dimension(300, 30));

        /*
         p1.add(new JLabel("数据库本地服务名称:"),
         new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST,
         GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));

         p1.add(databaseLocalName,
         new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST,
         GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
         */
        p1.add(new JLabel(STMConsts.getI18N().getLabelValue("info_dataclear_database")),
                new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST,
                        GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));

        p1.add(jcmbDBName, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
                GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 150), 0,
                0));

        JPanel dblocalNamePanel = new JPanel();
        dblocalNamePanel.setLayout(new BorderLayout(6, 6));
        dblocalNamePanel.setPreferredSize(new Dimension(400, 30));

        if(!MainFrame.isDbIP_local())
        {
            dblocalNamePanel.add(new JLabel(STMConsts.getI18N().getLabelValue(
                    "info_dataclear_para_localName")), BorderLayout.WEST);

            databaseLocalName.setPreferredSize(new Dimension(100, 30));
            dblocalNamePanel.add(databaseLocalName, BorderLayout.CENTER);
        }
        JPanel p4 = new JPanel();
        p4.setLayout(new BorderLayout(6, 6));
        p4.setPreferredSize(new Dimension(600, 30));
        p4.add(p1, BorderLayout.WEST);
        p4.add(dblocalNamePanel, BorderLayout.CENTER);

        jscrDBNamesInfo.add(p4, BorderLayout.NORTH);

        JPanel p2 = new JPanel();
        p2.setLayout(new BorderLayout(6, 6));
        p2.setPreferredSize(new Dimension(600, 30));

        JButton fileButton = new JButton(STMConsts.getI18N().getLabelValue("info_imp_filebutton"));
        fileButton.setMnemonic('F');
        fileButton.addActionListener(actionFile);

        JPanel p3 = new JPanel();
        p3.setLayout(new BorderLayout(6, 6));
        p3.setPreferredSize(new Dimension(200, 30));

        p3.add(fileButton, BorderLayout.CENTER);

        p2.add(jvalueTextArea, BorderLayout.CENTER);
        p2.add(p3, BorderLayout.EAST);

        jscrDBNamesInfo.add(p2, BorderLayout.CENTER);

        panelTableInfo.add(jscrDBNamesInfo, BorderLayout.NORTH);
        jscrPaneTableInfo.setBorder(BorderFactory.createTitledBorder(""));
        panelTableInfo.add(jscrPaneTableInfo, BorderLayout.CENTER);

        //      增加提示信息:
        JPanel panelTip = new JPanel();
        //panelDBVersion.setPreferredSize(new Dimension(300, 30));
        panelTip.setBorder(new TitledBorder(BorderFactory.createTitledBorder(BorderFactory
                .createEtchedBorder(), STMConsts.getI18N().getLabelValue("info_shrink_help"),
                TitledBorder.LEFT, TitledBorder.TOP)));

        panelTip.setLayout(new BorderLayout());
        JTextArea jtaVersionInfo = new JTextArea();
        jtaVersionInfo.setLineWrap(true);
        //         jtaVersionInfo.setWrapStyleWord(true);
        jtaVersionInfo.setBackground(panelTip.getBackground());
        jtaVersionInfo.setEditable(false);
        StringBuffer text = new StringBuffer();
        //不同的操作系统提示信息不同

        //本地数据库
        if(MainFrame.isDbIP_local())
        {
            //solaris
            if(Common.OS_SOLARIS.equals(MainFrame.getOs()))
            {
                text.append(STMConsts.getI18N().getLabelValue("oracle_local_sun_help_info1"))
                        .append(System.getProperty("line.separator"));
            }
            //Windows
            else if(Common.OS_WINDOWS.equals(MainFrame.getOs()))
            {
                text.append(STMConsts.getI18N().getLabelValue("oracle_local_win_help_info1"))
                        .append(System.getProperty("line.separator"));
            }
        }
        //远程数据库
        else
        {
            //solaris
            if(Common.OS_SOLARIS.equals(MainFrame.getOs()))
            {
                text.append(STMConsts.getI18N().getLabelValue("oracle_remote_sun_help_info1"))
                        .append(System.getProperty("line.separator"));
                text.append(STMConsts.getI18N().getLabelValue("oracle_remote_sun_help_info2"))
                        .append(System.getProperty("line.separator"));
                text.append(STMConsts.getI18N().getLabelValue("oracle_remote_sun_help_info13"))
                        .append(System.getProperty("line.separator"));
            }
            //Windows
            else if(Common.OS_WINDOWS.equals(MainFrame.getOs()))
            {
                text.append(STMConsts.getI18N().getLabelValue("oracle_remote_win_help_info1"))
                        .append(System.getProperty("line.separator"));
                text.append(STMConsts.getI18N().getLabelValue("oracle_remote_win_help_info2"))
                        .append(System.getProperty("line.separator"));
                text.append(STMConsts.getI18N().getLabelValue("oracle_remote_win_help_info3"))
                        .append(System.getProperty("line.separator"));
            }
        }

        jtaVersionInfo.setText(text.toString());
        panelTip.add(jtaVersionInfo, BorderLayout.CENTER);

        panelTableInfo.add(panelTip, BorderLayout.SOUTH);

        JPanel jpTabRoot = new JPanel();
        jpTabRoot.setLayout(new GridBagLayout());
        jpTabRoot.add(panelTableInfo, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(6, 6, 6, 6), 0, 0));

        //进程信息panelProcessInfo------------------------

        //----this.getContentPane()
        JButton jbutRefresh = new JButton(I18N.getLabelValue("I18N_REFRESH_R"));
        jbutRefresh.setMnemonic('R');
        jbutRefresh.addActionListener(actionLsrCommon);

        JButton jbutClose = new JButton(I18N.getLabelValue("I18N_CANCEL"));
        jbutClose.setMnemonic('C');

        jbutClose.addActionListener(actionLsrJbutOk);

        JButton jbutEXECUTE = new JButton(I18N.getLabelValue("info_imp_button"));
        jbutEXECUTE.setMnemonic('E');
        jbutEXECUTE.registerKeyboardAction(actionLsrJbutEXECUTE, ENTER_STROKE,
                JComponent.WHEN_IN_FOCUSED_WINDOW);
        jbutEXECUTE.addActionListener(actionLsrJbutEXECUTE);

        JPanel jpButtonPanel = new JPanel();
        jpButtonPanel.setLayout(new GridBagLayout());
        jcIsTruncateFirst.setText(I18N.getLabelValue("info_imp_checkbox_truncate"));
        jpButtonPanel.add(jcIsTruncateFirst, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
                GridBagConstraints.NORTHWEST, GridBagConstraints.WEST, new Insets(0, 0, 0, 295),
                10, 0));
        jpButtonPanel.add(jbutEXECUTE, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
                GridBagConstraints.NORTHWEST, GridBagConstraints.EAST, new Insets(0, 0, 0, 3), 10,
                0));
        jpButtonPanel.add(jbutRefresh, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
                GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 3), 0, 0));

        jpButtonPanel.add(jbutClose,
                new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST,
                        GridBagConstraints.NONE, new Insets(0, 3, 0, 0), 0, 0));
        this.getContentPane().setLayout(new GridBagLayout());

        /*
         JPanel jpDesc = UIToolKit.createDialogDescPanel(I18N
         .getLabelValue("DIALOG_DESC_DBRES_VIEW_TITLE"), I18N
         .getLabelValue("DIALOG_DESC_DBRES_VIEW_DESC"), ICON_DBSVR_RESVIEW_DESC);
         this.getContentPane().add(
         jpDesc,
         new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST,
         GridBagConstraints.HORIZONTAL, new Insets(0, 0, 3, 0), 0, 0));
         */
        this.getContentPane().add(
                jpTabRoot,
                new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER,
                        GridBagConstraints.BOTH, new Insets(3, 12, 6, 12), 385, 242));
        this.getContentPane().add(
                jpButtonPanel,
                new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST,
                        GridBagConstraints.NONE, new Insets(6, 0, 12, 12), 0, 0));
        jbutClose.requestFocus();
        return true;
    }

    /**
     * 加载当前库的所有表的信息
     * @return boolean 失败返回false
     */
    private boolean loadTableInfoofCurrUser()
    {
        String dbName = (String) jcmbDBName.getSelectedItem();
        Vector vecTableInfo2D = null;
        try
        {
            vecTableInfo2D = DBAction.getAllTableInfoOfOwner(this.jfmMain, dbName, this.dbInfo);
            for(int i = 0; i < vecTableInfo2D.size(); i++)
            {
                Vector vecRowData = (Vector) vecTableInfo2D.get(i);
                Vector vecParsed = parseData(vecRowData);
                vecTableInfo2D.setElementAt(vecParsed, i);
            }
            jtbModelTableInfo.setDataVector(vecTableInfo2D, this.vecColumnStrTableInfo);
            int iWidth = this.dbInfo.getDBType() == DatabaseInfo.DBTYPE_ORACLE ? 220 : 150;
            for(int iIndex = 0; iIndex < vecColumnStrTableInfo.size(); iIndex++)
            {
                jtblTableInfo.getColumnModel().getColumn(iIndex).setPreferredWidth(iWidth);
            }
        }
        catch(FIException fiEx)
        {
            ZJShowMsgPane.showDetailMessage(this, fiEx);
            return false;
        }
        return true;
    }

    /**
     *
     *设置显示DB和Table信息的JTable列名称
     */
    private void setupColumnStrVector()
    {
        vecColumnStrDBInfo = new Vector();
        vecColumnStrTableInfo = new Vector();

        int iDBType = this.dbInfo.getDBType();
        switch(iDBType)
        {
            case DatabaseInfo.DBTYPE_ORACLE:
                //显示DB信息的JTable控件列名
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("dbSpaceName"));
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("assignSize") + "(KB)");
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("usedSize") + "(KB)");
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("leftSize") + "(KB)");
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("leftPercent") + "(%)");
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("autoextensible"));
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("datafile"));
                //显示table信息的JTable控件列名
                this.vecColumnStrTableInfo.add(I18N.getLabelValue("tabName"));
                this.vecColumnStrTableInfo.add(I18N.getLabelValue("inDbSpace"));
                this.vecColumnStrTableInfo.add(I18N.getLabelValue("recNum"));

                break;
            case DatabaseInfo.DBTYPE_MSSQL:
                //显示DB信息的JTable控件列名
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("dbName"));
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("dbSize") + "(MB)");
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("UnassignSize") + "(MB)");
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("reserveSize") + "(KB)");
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("dataSize") + "(KB)");
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("indexSize") + "(KB)");
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("unusedSize") + "(KB)");
                this.vecColumnStrDBInfo.add(I18N.getLabelValue("I18N_MDF_FREE_PERCENT") + "(%)");
                //显示table信息的JTable控件列名
                this.vecColumnStrTableInfo.add(I18N.getLabelValue("tabName"));
                this.vecColumnStrTableInfo.add(I18N.getLabelValue("recNum"));
                this.vecColumnStrTableInfo.add(I18N.getLabelValue("reserveSize") + "(KB)");
                this.vecColumnStrTableInfo.add(I18N.getLabelValue("dataSize") + "(KB)");
                this.vecColumnStrTableInfo.add(I18N.getLabelValue("indexSize") + "(KB)");
                this.vecColumnStrTableInfo.add(I18N.getLabelValue("unusedSize") + "(KB)");
                //显示 process info 的JTable控件列名

                break;

            default:
                dMsg.error("Wrong database got! iDBType=" + iDBType);
                break;
        }
    }

    /**
     * 将数据库/用户名 添加到 jcmbDBName 中
     */
    private boolean addAllDBNamesToJcmbDBName()
    {
        String[] dbName = new String[3];
        if(this.dbInfo.getDBType() == DatabaseInfo.DBTYPE_ORACLE)
        {
            dbName[0] = DatabaseInfo.EMS_ORACLE_UEP;
            dbName[1] = DatabaseInfo.EMS_ORACLE_UEPPM;
            dbName[2] = DatabaseInfo.EMS_ORACLE_CAFFM;

        }
        else
        {
            dbName[0] = DatabaseInfo.EMS_MSSQL_UEP;
            dbName[1] = DatabaseInfo.EMS_MSSQL_UEPPM;
            dbName[2] = DatabaseInfo.EMS_MSSQL_CAFFM;

        }
        String[] arrStrDBNames = null;
        try
        {
            arrStrDBNames = DBAction.getDBSOwners(this.jfmMain, this.dbInfo);
            if(arrStrDBNames != null)
            {
                for(int i = 0; i < arrStrDBNames.length; i++)
                {
                    for(int j = 0; j < dbName.length; j++)
                    {
                        if(dbName[j].equalsIgnoreCase(arrStrDBNames[i]))
                        {
                            jcmbDBName.addItem((arrStrDBNames[i]));
                        }
                    }
                }
                jcmbDBName.setSelectedIndex(0);
            }
        }
        catch(FIException fiEx)
        {
            ZJShowMsgPane.showDetailMessage(this, fiEx);
            return false;
        }
        return true;
    }

    /**
     *
     * @param itemEvent
     */
    private void jcmbDBName_itemStateChanged(ActionEvent itemEvent)
    {
        String dbName = (String) jcmbDBName.getSelectedItem();
        Vector vecTableInfo2D = null;
        this.setCursor(new Cursor(Cursor.WAIT_CURSOR));
        try
        {
            vecTableInfo2D = DBAction.getAllTableInfoOfOwner(this.jfmMain, dbName, this.dbInfo);
            jtbModelTableInfo.removeAllRow();
            for(int i = 0; i < vecTableInfo2D.size(); i++)
            {
                Vector vecRawData = (Vector) vecTableInfo2D.get(i);
                Vector vecParsed = parseData(vecRawData);
                jtbModelTableInfo.addRow(vecParsed);
            }
        }
        catch(FIException fiEx)
        {
            jtbModelTableInfo.setDataVector(vecTableInfo2D, this.vecColumnStrTableInfo);
            ZJShowMsgPane.showDetailMessage(this, fiEx);
        }
        this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }

    /**
     *
     * @param vec
     * @return
     */
    private Vector parseData(Vector vec)
    {
        Vector vecFolat = new Vector();
        int iVecSize = vec.size();
        float fvalue = (float) 0.0;
        int iDBType = this.dbInfo.getDBType();
        for(int i = 0; i < iVecSize; i++)
        {
            String tempstr = vec.get(i).toString();
            tempstr = tempstr.trim();
            String oldtemp = tempstr;
            int iUnit = tempstr.indexOf("MB");
            if(iUnit == -1)
            {
                iUnit = tempstr.indexOf("KB");
            }
            if(iUnit == -1)
            {
                iUnit = tempstr.indexOf("%");
            }
            if(iUnit == -1)
            {
                try
                {
                    //格式化显示剩余空间数据,都显示两位小数
                    switch(iDBType)
                    {
                        case DatabaseInfo.DBTYPE_MSSQL:
                            if(i == iVecSize - 1)
                            {
                                DecimalFormat df1 = new DecimalFormat("0.00");
                                vecFolat.addElement(df1.format(Float.valueOf(tempstr)));
                            }
                            else
                            {
                                vecFolat.addElement(Float.valueOf(tempstr));
                            }
                            break;
                        case DatabaseInfo.DBTYPE_ORACLE:
                            if(i == 4)
                            {
                                DecimalFormat df1 = new DecimalFormat("0.00");
                                vecFolat.addElement(df1.format(Float.valueOf(tempstr)));
                            }
                            else
                            {
                                vecFolat.addElement(Float.valueOf(tempstr));
                            }
                            break;
                    }
                    continue;
                }
                catch(NumberFormatException ex)
                {
                    vecFolat.addElement(tempstr);
                    continue;
                }
            }
            try
            {
                tempstr = tempstr.substring(0, iUnit);
                fvalue = Float.parseFloat(tempstr);
                vecFolat.addElement(new Float(fvalue));
            }
            catch(NumberFormatException ex)
            {
                vecFolat.addElement(oldtemp);
                continue;
            }
        }
        return vecFolat;
    }

    /**
     *
     * @param e
     * @JTIUP
     */
    private void jbutUpdateDBMSOwnerSystemTables_actionPerformed(ActionEvent e)
    {

        //        int iOption = ZJShowMsgPane.showConfirmDialog(STMClientView.getSTMMainFrame(),
        //                I18N.getLabelValue("I18N_UPDATE_STAT_TIP"),
        //                I18N.getLabelValue("dialogQuestion"),
        //                ZJShowMsgPane.OK_CANCEL_OPTION,
        //                ZJShowMsgPane.QUESTION_MESSAGE);
        //       if(iOption != ZJShowMsgPane.OK_OPTION) {
        //        return;
        //       }
        // begin updating...
        String strOwner = (String) jcmbDBName.getSelectedItem();
        this.setCursor(new Cursor(Cursor.WAIT_CURSOR));
        try
        {
            this.dbInfo.setOwner(strOwner);
            DBAction.updateDBMSSystemTables(this, this.dbInfo, strOwner);
        }
        catch(FIException fiEx)
        {
            ZJShowMsgPane.showDetailMessage(this, fiEx);
        }
        this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        ZJShowMsgPane.showMessageDialog(this, I18N.getLabelValue("I18N_UPDATING_TIP"),
                ZJShowMsgPane.INFORMATION_MESSAGE);
    }

    /**
     * 关闭操作
     * 也就是唯一按钮ok按钮的action响应方法
     * @param e
     * @JTIUP
     */
    private void jbutOk_actionPerformed(ActionEvent e)
    {
        this.close();
    }

    /**
     * 关闭操作
     * 也就是唯一按钮ok按钮的action响应方法
     * @param e
     * @JTIUP
     */
    private void jbutEXECUTE_actionPerformed(ActionEvent e)
    {
        importTable();
        //this.close();
    }

    /**
     * 注册escape按键事件到指定组件 当指定组件在当前窗口时,action动作会注册到escape按键响应上
     *
     * @param component
     * @param action
     */
    private void registerEscapeAction(JComponent component, Action action)
    {
        component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ESCAPE_STROKE,
                STR_ESCAPE_RELEASED);
        component.getActionMap().put(STR_ESCAPE_RELEASED, action);
    }

    /**
     * 撤销指定组件的escape事件
     * 将escape响应从指定组件上撤销
     * @param component
     */
    private void unregisterEscapeAction(JComponent component)
    {
        component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).remove(ESCAPE_STROKE);
        component.getActionMap().remove(STR_ESCAPE_RELEASED);
    }

    private void importTable()
    {

        try
        {
            if(jtblTableInfo.getSelectedRow() == -1)
            {
                throw new STMRuntimeException(STMConsts.getI18N().getLabelValue(
                        "info_dataclear_chooseTable"));
            }

            String path = jvalueTextArea.getText().trim();

            if(path.equals(""))
            {
                throw new STMRuntimeException(STMConsts.getI18N().getLabelValue(
                        "info_imp_inputfile"));
            }

            File file = new File(path);
            if(file.exists() && file.isFile())
            {

            }
            else
            {
                throw new STMRuntimeException(STMConsts.getI18N().getLabelValue(
                        "info_imp_inputfile_ag"));
            }

            String localDbName = databaseLocalName.getText().trim();
            if(!MainFrame.isDbIP_local() && "".equals(localDbName))
            {
                throw new STMRuntimeException(STMConsts.getI18N().getLabelValue(
                        "info_dataclear_inputDBlocal"));
            }
            String dbName = (String) jcmbDBName.getSelectedItem();
            String tableName = (String) jtblTableInfo.getModel().getValueAt(
                    jtblTableInfo.getSelectedRow(), 0);

//            MainFrame.waitThread = new WaitThread(main, STMConsts.getI18N().getLabelValue(
//                    "info_imp_waitng"), STMConsts.getI18N().getLabelValue("info_imp_waitng"));
//            MainFrame.waitThread.start();
            main.paintStatus(STMConsts.getI18N().getLabelValue("info_imp_waitng"));
            main.guiChange(false);
           
            if(jcIsTruncateFirst.isSelected())
            {
                String sql = "truncate table " + dbName + "." + tableName;
                DBAction.executeUpdateSql(this.jfmMain, dbInfo, dbName, sql);
            }
            //checkData(dbName,tableName);
            //exp system/system@10.40.182.168_uep tables=caffm.caf_alarm file=d://ueppm.dmp log=ueppm.log
            //imp system/system@10.40.182.168_uep fromuser=caffm  tables=caf_alarm  file=d://ueppm.dmp  ignore=y log=x.log
            Date date = new Date(System.currentTimeMillis());
            SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd_HHmm");
            String affrix = sdf1.format(date);
            String fileName = path;
            //System.out.println(new File(fileName).getParent());
            //String logfileName = path+System.getProperty("file.separator")+ tableName+"_"+affrix+".log";
            String logfileName = new File(fileName).getParent()
                    + System.getProperty("file.separator") + "imp_" + tableName + "_" + affrix
                    + ".log";

            StringBuffer impBuf = new StringBuffer();
            impBuf.append("imp ").append(dbInfo.getUser()).append("/").append(dbInfo.getPassword());
            if(!MainFrame.isDbIP_local() && !"".equals(localDbName))
            {
                impBuf.append("@").append(localDbName);
            }
            impBuf.append(" fromuser=").append(dbName);
            impBuf.append(" touser=").append(dbName);
           
            impBuf.append(" tables=").append(tableName);
            //expBuf.append("imp ").append(" caffm/U_tywg_2008@10.40.182.168_uep tables=caf_alarm");
            impBuf.append(" file=").append(fileName).append(" ignore=y ");
            //impBuf.append(" file=").append(fileName).append(" ignore=y log=").append(logfileName);
            close();
            MainFrame.localDbName = localDbName;

            List cmdList = new ArrayList();
            cmdList.add(impBuf.toString());

            DBAction.runTableExpImpProcessor(main, cmdList, MainFrame.getOs(),
                    MainFrame.ORACLE_USER_NAME);

            //dMsg.error("结束数据导入");

        }
        catch(STMRuntimeException e)
        {
            //MainFrame.closeWaitDialog();
            //main.clearStatus();
            ZJShowMsgPane.showMessageDialog(this, e.toString(), STMConsts.getI18N().getLabelValue(
                    "ZJShowMsgPane_QuestionMessage"), ZJShowMsgPane.WARNING_MESSAGE);

        }
        catch(FIException e)
        {
            //MainFrame.closeWaitDialog();
            //main.clearStatus();
            ZJShowMsgPane.showMessageDialog(this, e.toString(), STMConsts.getI18N().getLabelValue(
                    "ZJShowMsgPane_QuestionMessage"), ZJShowMsgPane.WARNING_MESSAGE);
        }

    }

    private void selectPath(JTextField path)
    {
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(new File("./"));
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        chooser.setFileFilter(new FileFilterBase("dmp"));

        int returnVal = chooser.showOpenDialog(this);

        if(returnVal == JFileChooser.APPROVE_OPTION)
        {
            path.setText(chooser.getSelectedFile().getPath());
        }
    }

    /**
     * 退出对话框
     */
    private void close()
    {
        unregisterEscapeAction(this.getRootPane());

        dispose();
    }

    private void setCellRender(JTable table)
    {
        int size = table.getColumnCount();
        for(int i = 0; i < size; i++)
        {
            Class cla = table.getColumnClass(i);
            table.setDefaultRenderer(cla, new CellRender());
        }
    }

    /**
     * <p>Title: </p>
     *
     * <p>Description: </p>
     *
     * <p>Copyright: Copyright (c) 2007</p>
     *
     * <p>Company: 中兴通讯股分有限公司</p>
     * @author wanghong
     * @version 3.0
     */
    private class CellRender extends DefaultTableCellRenderer
    {

        /**
         *
         */
        private static final long serialVersionUID = 1L;

        CellRender()
        {
        }

        /**
         * Returns the component used for drawing the cell.
         *
         * @param table the <code>JTable</code> that is asking the renderer to draw; can be <code>null</code>
         * @param value the value of the cell to be rendered. It is up to the specific renderer to interpret and draw
         *   the value. For example, if <code>value</code> is the string "true", it could be rendered as a string or it
         *   could be rendered as a check box that is checked. <code>null</code> is a valid value
         * @param isSelected true if the cell is to be rendered with the selection highlighted; otherwise false
         * @param hasFocus if true, render cell appropriately. For example, put a special border on the cell, if the
         *   cell can be edited, render in the color used to indicate editing
         * @param row the row index of the cell being drawn. When drawing the header, the value of <code>row</code> is -1
         * @param column the column index of the cell being drawn
         * @return Component
         * @todo Implement this javax.swing.table.TableCellRenderer method
         */
        public Component getTableCellRendererComponent(JTable table, Object value,
                boolean isSelected, boolean hasFocus, int row, int column)
        {
            Object disPlay = value;
            if(value instanceof Float)
            {
                //去掉小数点
                if(value.toString().endsWith(".0"))
                {
                    disPlay = String.valueOf(((Float) value).longValue());
                }
            }
            return super.getTableCellRendererComponent(table, disPlay, isSelected, hasFocus, row,
                    column);
        }
    }

    /**
     *
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2007</p>
     * <p>Company: 中兴通讯股分有限公司</p>
     * @author not attributable
     * @version 3.0
     */
    private class UpdateHandler implements Runnable
    {

        private TableImpDialogOfORACLE dbResDialog = null;

        /**
         * 更新界面
         * @param dialog DBResourceDialog
         */
        public UpdateHandler(TableImpDialogOfORACLE dialog)
        {
            dbResDialog = dialog;
        }

        /**
         * 更新界面
         */
        public void run()
        {
            dbResDialog.setCursor(new Cursor(Cursor.WAIT_CURSOR));
            try
            {
                dbResDialog.loadTableInfoofCurrUser();
            }
            catch(Exception ex)
            {
                ex.printStackTrace();
            }
            catch(Throwable ex)
            {
                ex.printStackTrace();
            }
            dbResDialog.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

        }
    }

    public AbstractProcessJFrame getMain()
    {
        return main;
    }

    public void setMain(AbstractProcessJFrame main)
    {
        this.main = main;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值