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());
}
}
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;
}
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;
}
Aggregations