use of com.cubrid.common.ui.query.control.CombinedQueryEditorComposite in project cubrid-manager by CUBRID.
the class QueryEditorPart method dispose.
/**
* When dispose query editor, interrupt query thread, clear result and query
* plan, reset query connection
*/
public void dispose() {
if (isTransaction()) {
String msg = Messages.bind(Messages.connCloseConfirm, new String[] { this.getSelectedDatabase().getLabel() });
String[] buttons = new String[] { Messages.btnYes, Messages.btnNo };
MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), com.cubrid.common.ui.common.Messages.titleConfirm, null, msg, MessageDialog.QUESTION, buttons, 0) {
protected void buttonPressed(int buttonId) {
switch(buttonId) {
case 0:
try {
queryAction(QUERY_ACTION.COMMIT);
} catch (SQLException ex) {
CommonUITool.openErrorBox(Messages.bind(com.cubrid.common.ui.common.Messages.errCommonTip, ex.getErrorCode(), ex.getMessage()));
LOGGER.error("", ex);
}
setReturnCode(0);
close();
break;
case 1:
try {
queryAction(QUERY_ACTION.ROLLBACK);
} catch (SQLException ex) {
CommonUITool.openErrorBox(Messages.bind(com.cubrid.common.ui.common.Messages.errCommonTip, ex.getErrorCode(), ex.getMessage()));
LOGGER.error("", ex);
}
setReturnCode(1);
close();
break;
default:
break;
}
}
};
int returnVal = dialog.open();
if (returnVal != 0 && returnVal != 1) {
try {
queryAction(QUERY_ACTION.ROLLBACK);
} catch (SQLException ex) {
LOGGER.error("", ex);
String errmsg = Messages.bind(com.cubrid.common.ui.common.Messages.errCommonTip, ex.getErrorCode(), ex.getMessage());
CommonUITool.openErrorBox(errmsg);
}
}
}
try {
if (connection.hasConnection()) {
queryAction(QUERY_ACTION.CLOSE);
}
if (queryThread != null && !queryThread.isInterrupted()) {
queryThread.interrupt();
queryThread = null;
}
for (CombinedQueryEditorComposite combinedQueryEditorComposite : getAllCombinedQueryEditorComposite()) {
clearResult(combinedQueryEditorComposite);
clearPlan(combinedQueryEditorComposite);
combinedQueryEditorComposite.getSqlEditorComp().release();
}
} catch (Exception event) {
LOGGER.error("", event);
} finally {
connection.close();
connection = null;
}
if (result != null) {
result.dispose();
}
super.dispose();
}
use of com.cubrid.common.ui.query.control.CombinedQueryEditorComposite in project cubrid-manager by CUBRID.
the class QueryEditorPart method promptToSaveOnClose.
public int promptToSaveOnClose() {
ServerInfo serverInfo = getSelectedServer() == null ? null : getSelectedServer().getServerInfo();
boolean isWithoutPrompt = QueryOptions.getWithoutPromptSave(serverInfo);
CTabItem[] items = combinedQueryEditortabFolder.getItems();
if (items.length == 0) {
willClose = true;
return ISaveablePart2.NO;
}
if (items.length > 1) {
String msg = Messages.bind(Messages.msgConfirmEditorClose, items.length);
if (!CommonUITool.openConfirmBox(msg)) {
return ISaveablePart2.CANCEL;
}
}
if (isWithoutPrompt) {
willClose = true;
return ISaveablePart2.NO;
}
willClose = true;
int dirtyCount = 0;
for (CombinedQueryEditorComposite combinedQueryEditorComposite : getAllCombinedQueryEditorComposite()) {
if (combinedQueryEditorComposite.isDirty()) {
dirtyCount++;
}
}
String msg = Messages.bind(Messages.msgConfirmEditorSave, dirtyCount);
if (dirtyCount > 0 && !CommonUITool.openConfirmBox(msg)) {
return ISaveablePart2.NO;
}
int cancelCount = 0;
for (CTabItem item : items) {
if (item instanceof SubQueryEditorTabItem) {
CombinedQueryEditorComposite combinedQueryEditorComposite = ((SubQueryEditorTabItem) item).getControl();
try {
if (combinedQueryEditorComposite.isDirty()) {
if (combinedQueryEditorComposite.getSqlEditorComp().save()) {
combinedQueryEditorComposite.dispose();
item.dispose();
} else {
cancelCount++;
}
}
} catch (IOException e) {
LOGGER.error("", e);
}
}
}
if (cancelCount > 0) {
return ISaveablePart2.CANCEL;
}
return ISaveablePart2.NO;
}
use of com.cubrid.common.ui.query.control.CombinedQueryEditorComposite in project cubrid-manager by CUBRID.
the class ERSchemaEditor method generateSqlsToQueryEditor.
private void generateSqlsToQueryEditor(List<StringBuffer> sqls) throws PartInitException {
final boolean isSupportOnServer = CompatibleUtil.isCommentSupports(database.getDatabaseInfo());
final QueryEditorPart editPart = CommonUITool.openQueryEditor(database, false);
editPart.setQuery(sqls.get(0).toString(), true, false, false);
if (sqls.size() > 1) {
editPart.newQueryTab(sqls.get(1).toString(), false);
}
UIJob job = new UIJob("") {
public IStatus runInUIThread(IProgressMonitor monitor) {
String tabMessage = isSupportOnServer ? Messages.edittabNameAlterSQL : Messages.edittabNameInsertSQL;
List<CombinedQueryEditorComposite> allTabItems = editPart.getAllCombinedQueryEditorComposite();
editPart.updateTabName(allTabItems.get(0).getSubQueryEditorTabItem(), tabMessage, true);
if (allTabItems.size() > 1) {
editPart.updateTabName(allTabItems.get(1).getSubQueryEditorTabItem(), Messages.edittabNameUpdateSQL, true);
}
return Status.OK_STATUS;
}
};
job.setPriority(UIJob.BUILD);
job.schedule();
}
use of com.cubrid.common.ui.query.control.CombinedQueryEditorComposite in project cubrid-manager by CUBRID.
the class RestoreQueryEditorAction method run.
public void run() {
ApplicationPersistUtil util = ApplicationPersistUtil.getInstance();
List<ArrayList<RestorableQueryEditorInfo>> restoreList = util.getEditorStatusListAtLastSession();
if (restoreList == null || restoreList.size() == 0) {
CommonUITool.openInformationBox(Messages.errNoRestoreQueryEditor);
return;
}
if (!CommonUITool.openConfirmBox(Messages.restoreQueryEditorConfirm)) {
return;
}
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
CommonUITool.openErrorBox(Messages.restoreQueryEditorRestoreFailed);
return;
}
for (List<RestorableQueryEditorInfo> editorStatusList : ApplicationPersistUtil.getInstance().getEditorStatusListAtLastSession()) {
QueryUnit input = new QueryUnit();
try {
QueryEditorPart editor = (QueryEditorPart) window.getActivePage().openEditor(input, QueryEditorPart.ID);
if (editor == null) {
continue;
}
for (int i = 0; i < editorStatusList.size(); i++) {
RestorableQueryEditorInfo editorStatus = editorStatusList.get(i);
if (editorStatus == null) {
continue;
}
String sql = CheckQueryEditorTask.getQuery(editorStatus);
CombinedQueryEditorComposite combinedQueryComposite = null;
if (i == 0) {
combinedQueryComposite = editor.getCombinedQueryComposite();
} else {
combinedQueryComposite = editor.addEditorTab();
}
if (combinedQueryComposite != null) {
combinedQueryComposite.getSqlEditorComp().setQueries(sql);
}
}
editor.setCombinedQueryEditortabFolderSelecton(0);
} catch (PartInitException e) {
e.printStackTrace();
}
}
ApplicationPersistUtil.getInstance().clearRestorableQueryEditors();
StatusLineContrItem statusCont = LayoutManager.getInstance().getStatusLineContrItem();
statusCont.changeStuatusLineForNavigator(null);
CommonUITool.openInformationBox(Messages.restoreQueryEditorTitle, Messages.restoreQueryEditorRestoreSuccess);
}
Aggregations