⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queryeditortextpanel.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        }        queryPane.executeSQLAtCursor(dc);        historyNum = 0;    }    /**     * Executes the specified query with the specified connection properties     * object.     *      * @param dc - the database connection properties object     * @param query - the query     * @param executeAsBlock - whether to execute as a block     */    public void executeSQLQuery(DatabaseConnection dc,                                 String query, boolean executeAsBlock) {        if (analyser.isExecuting()) {            return;        }        if (query == null) {            query = getQueryAreaText();        }                if (query.trim().length() == 0) {            return;        }        //queryPane.resetExecutingLine();        historyNum = 0;        queryEditor.setPreviousButtonEnabled(true);        queryEditor.setNextButtonEnabled(false);        analyser.executeSQLQuery(dc, query, executeAsBlock);            }    /**     * Executes the specified query.     *     * @param query - the query     */    public void executeSQLQuery(String query) {        executeSQLQuery(queryEditor.getSelectedConnection(), query, false);    }    /**     * Executes the specified query as a 'block' if specified.     *     * @param the query     * @param whether to execute ALL query text as one statement     */    public void executeSQLQuery(String query, boolean executeAsBlock) {        executeSQLQuery(queryEditor.getSelectedConnection(), query, executeAsBlock);    }    /**     * Executes the specified query using the specified connection     * properties object.     *     * @param the the database connection object     * @param the query     */    public void executeSQLQuery(DatabaseConnection dc, String query) {        executeSQLQuery(dc, query, false);    }        public void setLeftStatusText(String s) {        queryEditor.setLeftStatusText(s);    }        public void goToRow(int row) {        queryPane.goToRow(row);    }        public void destroyTable() {        queryEditor.destroyTable();    }        /**     * Propagates the call to interrupt the statement currently being      * executed to the QueryAnalyser.     */    public void interruptStatement() {        analyser.interruptStatement();    }    /**      * Sets the table results to the specified     * <code>ResultSet</code> object for display.     *     *  @param the table results to display     *  @param whether the row count is displayed     *  @return the row count of this <code>ResultSet</code> object     */    public int setResultSet(ResultSet rset, boolean showRowNumber)        throws SQLException {        return setResultSet(rset, showRowNumber, null);    }    /**      * Sets the table results to the specified     * <code>ResultSet</code> object for display.     *     *  @param the table results to display     *  @param whether the row count is displayed     *  @param the executed query of the result set     *  @return the row count of this <code>ResultSet</code> object     */    public int setResultSet(ResultSet rset, boolean showRowNumber, String query)      throws SQLException {        return queryEditor.setResultSet(rset, showRowNumber, query);    }    public void interrupt() {        //queryEditor.interrupt();    }    /**      * Sets the table results to the specified     * <code>ResultSet</code> object for display.     *     * @param the table results to display     */    public void setResultSet(ResultSet rset) throws SQLException {        queryEditor.setResultSet(rset);    }        /**      * Sets the table results to the specified     * <code>ResultSet</code> object for display.     *     * @param the table results to display     * @param the executed query of the result set     */    public void setResultSet(ResultSet rset, String query) throws SQLException {        queryEditor.setResultSet(rset, query);    }    public void setResultText(int r, int t) {        queryEditor.setResultText(r, t);    }        public String getQueryAreaText() {        return queryPane.getText();    }        public void setStopButtonEnabled(boolean enable) {        queryEditor.setStopButtonEnabled(enable);        popup.enableExecutes(enable);    }    /**     * Adds a comment tag to the beginning of the current line     * or selected lines.     */    public void addCommentToLines() {        queryPane.addUndoEdit();        if (getSelectedText() == null) {            int start = queryPane.getCurrentRowStart();            queryPane.insertTextAtOffset(start, "--");        }        else {            int index = queryPane.getSelectionStart();            int firstRow = queryPane.getRowAt(index);                        index = queryPane.getSelectionEnd();            int lastRow = queryPane.getRowAt(index);                        for (int i = firstRow; i <= lastRow; i++) {                index = queryPane.getRowStartOffset(i);                queryPane.insertTextAtOffset(index, "--");            }        }                // add this as an edit if its not        ensureUndo();    }    /**     * Ensures an edit may be undone by forcing an end     * to the current compound edit within the text pane.     */    protected void ensureUndo() {        if (!queryPane.canUndo()) {            queryPane.addUndoEdit();        }    }        /** pattern matcher to check for comments to be removed */    private Matcher commentRemovalMatcher;        /**     * Removes a comment tag from the current line or selected lines.     */    public void removeCommentFromLines() {        if (queryPane.getDocument().getLength() > 0) {                        if (commentRemovalMatcher == null) {                String regex = "^\\s*--";                commentRemovalMatcher = Pattern.compile(regex).matcher("");            }            // add an undo edit            queryPane.addUndoEdit();                        try {                int start = queryPane.getSelectionStart();                int end = queryPane.getSelectionEnd();                                Element map = queryPane.getElementMap();                start = queryPane.getRowAt(start);                end = queryPane.getRowAt(end);                                String text = null;                Document document = queryPane.getDocument();                for (int i = start; i <= end; i++) {                    Element line = map.getElement(i);                    int startOffset = line.getStartOffset();                    int endOffset = line.getEndOffset();                    text = queryPane.getText(startOffset, (endOffset - startOffset));                    commentRemovalMatcher.reset(text);                    if (commentRemovalMatcher.find()) {                        // retrieve the exact index of '--' since                         // matcher will return first whitespace                        int index = text.indexOf("--");                        document.remove(startOffset + index, 2);                    }                }                // add this as an edit if its not                ensureUndo();            } catch (BadLocationException e) {                e.printStackTrace();            }        }    }        /**     * Shifts the text on the current line or the currently     * selected text to the right one TAB.     */    public void shiftTextRight() {        if (getSelectedText() == null) {            int start = queryPane.getCurrentRowStart();            queryPane.shiftTextRight(start);        }        else { // simulate a tab key for selected text            try {                Robot robot = new Robot();                robot.keyPress(KeyEvent.VK_TAB);                robot.keyRelease(KeyEvent.VK_TAB);            } catch (AWTException e) {                e.printStackTrace();            }        }    }    /**     * Shifts the text on the current line or the currently     * selected text to the left one TAB.     */    public void shiftTextLeft() {        if (getSelectedText() == null) {            int start = queryPane.getCurrentRowStart();            int end = queryPane.getCurrentRowEnd();            queryPane.shiftTextLeft(start, end);        }        else { // simulate a tab key for selected text            try {                Robot robot = new Robot();                robot.keyPress(KeyEvent.VK_SHIFT);                robot.keyPress(KeyEvent.VK_TAB);                robot.keyRelease(KeyEvent.VK_TAB);                robot.keyRelease(KeyEvent.VK_SHIFT);            } catch (AWTException e) {                e.printStackTrace();            }        }            }    // ---------------------------------------------    // TextFunction implementation    // ---------------------------------------------        public void paste() {        queryPane.paste();    }        public void copy() {        queryPane.copy();    }        public void cut() {        queryPane.cut();    }        public void changeSelectionCase(boolean upper) {        queryPane.addUndoEdit();        TextUtilities.changeSelectionCase(queryPane, upper);    }        public void deleteLine() {        queryPane.addUndoEdit();        TextUtilities.deleteLine(queryPane);    }        public void deleteWord() {        queryPane.addUndoEdit();        TextUtilities.deleteWord(queryPane);    }        public void deleteSelection() {        queryPane.addUndoEdit();        TextUtilities.deleteSelection(queryPane);    }        public void insertFromFile() {        queryPane.addUndoEdit();        TextUtilities.insertFromFile(queryPane);    }        public void insertLineAfter() {        queryPane.addUndoEdit();        TextUtilities.insertLineAfter(queryPane);    }        public void insertLineBefore() {        queryPane.addUndoEdit();        TextUtilities.insertLineBefore(queryPane);    }        // ---------------------------------------------        /**     * Propagates the call to the parent QueryEditor object     * that the text content has been altered from the original     * or previously saved state.     *     * @param true | false     */    public void setContentChanged(boolean contentChanged) {        queryEditor.setContentChanged(contentChanged);    }    public void mousePressed(MouseEvent e) {        maybeShowPopup(e);    }    public void mouseReleased(MouseEvent e) {        maybeShowPopup(e);    }    private void maybeShowPopup(MouseEvent e) {        if (e.isPopupTrigger()) {            popup.show(e.getComponent(), e.getX(), e.getY());        }    }    public void mouseClicked(MouseEvent e) {}    public void mouseEntered(MouseEvent e) {}    public void mouseExited(MouseEvent e) {}        private static Insets borderInsets;    private static Color borderColour;        private class EditorScrollerBorder implements Border {                protected EditorScrollerBorder() {            if (borderInsets == null) {                borderInsets = new Insets(0,0,1,0);            }            if (borderColour == null) {                borderColour = GUIUtilities.getDefaultBorderColour();            }        }                public Insets getBorderInsets(Component c) {            return borderInsets;        }                public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {            g.setColor(borderColour);            g.drawLine(x, height-1, width, height-1);        }                public boolean isBorderOpaque() {            return false;        }            }    /** The Query Editor's popup menu function */    private class PopMenu extends JPopupMenu implements ActionListener {                private JMenuItem execute;        private JMenuItem executeBlock;        private JMenuItem stop;        private JMenuItem clearOutput;        private JMenuItem rollback;        private JMenuItem commit;                public PopMenu() {            JMenuItem cut = new JMenuItem(ActionBuilder.get("cut-command"));            cut.setText("Cut");            cut.setIcon(null);                        JMenuItem copy = new JMenuItem(ActionBuilder.get("copy-command"));            copy.setText("Copy");            copy.setIcon(null);                        JMenuItem paste = new JMenuItem(ActionBuilder.get("paste-command"));            paste.setText("Paste");            paste.setIcon(null);            execute = new JMenuItem("Execute");            execute.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));            execute.addActionListener(this);                        JMenuItem partialExecute = new JMenuItem(                    ActionBuilder.get("execute-at-cursor-command"));            partialExecute.setText("Execute Query at Cursor");            partialExecute.setIcon(null);            JMenuItem executeSelection = new JMenuItem(                    ActionBuilder.get("execute-selection-command"));            executeSelection.setText("Execute Selected Query Text");            executeSelection.setIcon(null);            executeBlock = new JMenuItem("Execute as Single Statement");            //execute.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));            executeBlock.addActionListener(this);                        stop = new JMenuItem("Cancel Query");            stop.addActionListener(this);                        commit = new JMenuItem("Commit");            commit.addActionListener(this);                        rollback = new JMenuItem("Rollback");            rollback.addActionListener(this);            clearOutput = new JMenuItem("Clear Output Log");            clearOutput.addActionListener(this);                        JMenuItem help = new JMenuItem(ActionBuilder.get("help-command"));            help.setIcon(null);            help.setActionCommand("qedit");            help.setText("Help");                        add(cut);            add(copy);            add(paste);            addSeparator();            add(execute);            add(partialExecute);            add(executeSelection);            add(executeBlock);            add(stop);            addSeparator();            add(commit);            add(rollback);            addSeparator();            add(clearOutput);            addSeparator();            add(help);                        stop.setEnabled(false);        }        public void actionPerformed(ActionEvent e) {            Object source = e.getSource();                        if (source == stop) {                interruptStatement();            }            else if (source == execute) {                executeSQLQuery(null);            }            else if (source == executeBlock) {                queryEditor.setExecutingSingle(false);                executeSQLQuery(null, true);            }            else if (source == clearOutput) {                clearOutputPane();            }            else if (source == commit) {                executeSQLQuery("commit");            }            else if (source == rollback) {                executeSQLQuery("rollback");            }        }                public void enableExecutes(boolean enable) {            stop.setEnabled(enable);            execute.setEnabled(!enable);        }                public void enableCommits(boolean enable) {            commit.setEnabled(enable);            rollback.setEnabled(enable);        }            } // class PopMenu}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -