Search in sources :

Example 1 with SQLEditorComposite

use of com.cubrid.common.ui.query.control.SQLEditorComposite in project cubrid-manager by CUBRID.

the class QueryOpenAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null || window.getActivePage() == null) {
        return;
    }
    IEditorPart editor = window.getActivePage().getActiveEditor();
    if (editor != null && editor.isDirty()) {
        int confirm = CommonUITool.openMsgBox(editor.getSite().getShell(), MessageDialog.WARNING, Messages.saveResource, Messages.bind(Messages.saveConfirm, editor.getTitle()), new String[] { Messages.btnYes, Messages.btnNo, Messages.cancel });
        switch(confirm) {
            case 0:
                editor.doSave(null);
                break;
            case 1:
                break;
            default:
                return;
        }
    }
    try {
        if (editor == null) {
            IEditorInput input = new QueryUnit();
            editor = window.getActivePage().openEditor(input, QueryEditorPart.ID);
        }
    } catch (PartInitException e) {
        CommonUITool.openErrorBox(e.getMessage());
    }
    if (editor == null) {
        return;
    }
    try {
        QueryEditorPart queryEditor = (QueryEditorPart) editor;
        SQLEditorComposite editorComp = queryEditor.getCombinedQueryComposite().getSqlEditorComp();
        String encoding = editorComp.getDocument().getEncoding();
        SetFileEncodingDialog dialog = new SetFileEncodingDialog(getShell(), encoding, true);
        if (IDialogConstants.OK_ID == dialog.open()) {
            editorComp.open(dialog.getFilePath(), dialog.getEncoding());
        }
    } catch (IOException e) {
        CommonUITool.openErrorBox(e.getMessage());
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) SQLEditorComposite(com.cubrid.common.ui.query.control.SQLEditorComposite) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) SetFileEncodingDialog(com.cubrid.common.ui.query.dialog.SetFileEncodingDialog) IEditorInput(org.eclipse.ui.IEditorInput)

Example 2 with SQLEditorComposite

use of com.cubrid.common.ui.query.control.SQLEditorComposite in project cubrid-manager by CUBRID.

the class QueryEditorPart method runQueryPlanOnly.

/**
	 * Fetch execution plans while running SQLs
	 *
	 * @param queries String
	 */
private void runQueryPlanOnly(Vector<String> qVector) {
    try {
        connection.getConnection(true);
    } catch (SQLException e) {
        CommonUITool.openErrorBox(e.getLocalizedMessage());
        return;
    }
    if (!connection.hasConnection()) {
        return;
    }
    // clearPlan();
    CUBRIDStatementProxy statement = null;
    int i = 0;
    try {
        int len = qVector.size();
        for (i = 0; i < len; i++) {
            String sql = qVector.get(i).toString();
            statement = getStatement(connection.getConnection(), false);
            StructQueryPlan sq = new StructQueryPlan(sql, statement.getQueryplan(sql), new Date());
            if (combinedQueryComposite.getQueryPlanResultComp().isDisposed()) {
                combinedQueryComposite.newQueryPlanComp();
            }
            combinedQueryComposite.getQueryPlanResultComp().makePlan(sq, i);
            QueryUtil.freeQuery(statement);
            statement = null;
            if (collectExecStats) {
                displayTuneModeResult(new TuneModeModel(sq, null));
            }
        }
    } catch (Exception ee) {
        int errorCode = 0;
        if (SQLException.class.isInstance(ee)) {
            errorCode = ((SQLException) ee).getErrorCode();
        }
        String errmsg = "";
        if (isAutocommit) {
            try {
                queryAction(QUERY_ACTION.ROLLBACK);
            } catch (SQLException e1) {
                LOGGER.error("", e1);
            }
        }
        SQLEditorComposite sqlEditorComp = combinedQueryComposite.getSqlEditorComp();
        sqlEditorComp.txtFind((String) qVector.get(i), 0, false, false, true, false);
        StyledText txaEdit = sqlEditorComp.getText();
        int line = txaEdit.getLineAtOffset(txaEdit.getSelection().x) + 1;
        String errorLineMsg = Messages.bind(Messages.errWhere, line);
        errmsg += Messages.runError + errorCode + StringUtil.NEWLINE + errorLineMsg + StringUtil.NEWLINE + Messages.errorHead + ee.getMessage();
        CTabFolder queryResultTabFolder = combinedQueryComposite.getQueryResultComp().getQueryResultTabFolder();
        StyledText logMessagesArea = combinedQueryComposite.getQueryResultComp().getLogMessagesArea();
        QueryResultComposite queryResult = combinedQueryComposite.getQueryResultComp();
        queryResultTabFolder.setSelection(0);
        String logMessage = logMessagesArea.getText();
        if (logMessage != null && logMessage.length() > 0) {
            logMessage += StringUtil.NEWLINE;
        }
        logMessagesArea.setText(logMessage + StringUtil.NEWLINE + errmsg);
        logMessagesArea.setTopIndex(logMessagesArea.getLineCount() - 1);
        queryResult.setSelection();
        LOGGER.error(ee.getMessage(), ee);
    } finally {
        QueryUtil.freeQuery(statement);
        statement = null;
    }
    autoCommitItem.setEnabled(true);
    queryPlanItem.setEnabled(true);
    setPstmtParaItem.setEnabled(true);
    isRunning = false;
}
Also used : TuneModeModel(com.cubrid.common.ui.query.control.tunemode.TuneModeModel) SQLEditorComposite(com.cubrid.common.ui.query.control.SQLEditorComposite) QueryResultComposite(com.cubrid.common.ui.query.control.QueryResultComposite) StyledText(org.eclipse.swt.custom.StyledText) CTabFolder(org.eclipse.swt.custom.CTabFolder) SQLException(java.sql.SQLException) CUBRIDStatementProxy(com.cubrid.jdbc.proxy.driver.CUBRIDStatementProxy) Point(org.eclipse.swt.graphics.Point) StructQueryPlan(com.cubrid.common.core.queryplan.StructQueryPlan) Date(java.util.Date) PartInitException(org.eclipse.ui.PartInitException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 3 with SQLEditorComposite

use of com.cubrid.common.ui.query.control.SQLEditorComposite in project cubrid-manager by CUBRID.

the class QueryEditorPart method queryErrSkipOrNot.

/**
	 * Open a message dialog to confirm skip query error or not.
	 *
	 * @param ee SQLException
	 * @param errorSql String
	 * @return value boolean[]
	 *
	 */
public boolean[] queryErrSkipOrNot(final SQLException ee, String errorSql) {
    final boolean[] value = new boolean[2];
    SQLEditorComposite sqlEditorComp = combinedQueryComposite.getSqlEditorComp();
    StyledText txaEdit = sqlEditorComp.getText();
    if (txaEdit != null && !txaEdit.isDisposed()) {
        sqlEditorComp.txtFind(errorSql, 0, false, false, true, false);
        line = txaEdit.getLineAtOffset(txaEdit.getSelection().x) + 1;
    }
    String errorLineMsg = Messages.bind(Messages.errWhere, line);
    String errMsg = Messages.skipOrNot + StringUtil.NEWLINE + StringUtil.NEWLINE + Messages.runError + ee.getErrorCode() + StringUtil.NEWLINE + errorLineMsg + StringUtil.NEWLINE + Messages.errorHead + ee.getMessage();
    MessageDialog dialog = new MessageDialog(QueryEditorPart.this.getEditorSite().getShell(), Messages.warning, null, errMsg, MessageDialog.QUESTION, new String[] { Messages.btnYes, Messages.btnNo }, 1) {

        Button btn = null;

        protected Control createCustomArea(Composite parent) {
            btn = new Button(parent, SWT.CHECK);
            btn.setText(Messages.showOneTimeTip);
            return btn;
        }

        protected void buttonPressed(int buttonId) {
            value[0] = btn.getSelection();
            if (buttonId == IDialogConstants.CANCEL_ID) {
                value[1] = false;
            } else {
                value[1] = true;
            }
            close();
        }
    };
    dialog.open();
    return value;
}
Also used : SQLEditorComposite(com.cubrid.common.ui.query.control.SQLEditorComposite) StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) MultiDBQueryComposite(com.cubrid.common.ui.query.control.MultiDBQueryComposite) QueryResultComposite(com.cubrid.common.ui.query.control.QueryResultComposite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) SQLEditorComposite(com.cubrid.common.ui.query.control.SQLEditorComposite) CombinedQueryEditorComposite(com.cubrid.common.ui.query.control.CombinedQueryEditorComposite) Button(org.eclipse.swt.widgets.Button) MessageDialog(org.eclipse.jface.dialogs.MessageDialog)

Aggregations

SQLEditorComposite (com.cubrid.common.ui.query.control.SQLEditorComposite)3 QueryResultComposite (com.cubrid.common.ui.query.control.QueryResultComposite)2 IOException (java.io.IOException)2 StyledText (org.eclipse.swt.custom.StyledText)2 PartInitException (org.eclipse.ui.PartInitException)2 StructQueryPlan (com.cubrid.common.core.queryplan.StructQueryPlan)1 CombinedQueryEditorComposite (com.cubrid.common.ui.query.control.CombinedQueryEditorComposite)1 MultiDBQueryComposite (com.cubrid.common.ui.query.control.MultiDBQueryComposite)1 TuneModeModel (com.cubrid.common.ui.query.control.tunemode.TuneModeModel)1 SetFileEncodingDialog (com.cubrid.common.ui.query.dialog.SetFileEncodingDialog)1 QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)1 QueryUnit (com.cubrid.common.ui.query.editor.QueryUnit)1 CUBRIDStatementProxy (com.cubrid.jdbc.proxy.driver.CUBRIDStatementProxy)1 SQLException (java.sql.SQLException)1 Date (java.util.Date)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 Point (org.eclipse.swt.graphics.Point)1 Button (org.eclipse.swt.widgets.Button)1