use of com.cubrid.common.ui.query.editor.QueryUnit 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.editor.QueryUnit in project cubrid-manager by CUBRID.
the class SqlmapNavigatorView method pasteSqlToQueryEditor.
private void pasteSqlToQueryEditor(String sql) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null || window.getActivePage() == null) {
return;
}
IEditorPart editor = window.getActivePage().getActiveEditor();
try {
if (editor == null || !(editor instanceof QueryEditorPart)) {
editor = window.getActivePage().openEditor(new QueryUnit(), QueryEditorPart.ID);
}
} catch (PartInitException e) {
editor = null;
}
if (editor == null) {
return;
}
QueryEditorPart queryEditor = (QueryEditorPart) editor;
if (!StringUtil.isEmpty(queryEditor.getCurrentQuery())) {
queryEditor.addEditorTab();
}
queryEditor.setQuery(sql, false, false, false);
queryEditor.setFocus();
}
use of com.cubrid.common.ui.query.editor.QueryUnit in project cubrid-manager by CUBRID.
the class QueryNewCustomAction method run.
/**
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
Object[] selected = getSelectedObj();
LoginQueryEditDialog dialog = new LoginQueryEditDialog(getShell());
if (selected != null && selected.length == 1 && selected[0] instanceof ISchemaNode) {
dialog.setSelServerName(((ISchemaNode) selected[0]).getServer().getServerName());
dialog.setSelDatabaseName(((ISchemaNode) selected[0]).getDatabase().getName());
} else if (selected != null && selected.length == 1 && selected[0] instanceof CubridServer) {
dialog.setSelServerName(((CubridServer) selected[0]).getName());
} else {
dialog.setSelServerName(DatabaseNavigatorMenu.SELF_DATABASE_SELECTED_LABEL);
}
if (dialog.open() == IDialogConstants.OK_ID) {
try {
IEditorInput input = new QueryUnit();
IEditorPart editor = window.getActivePage().openEditor(input, QueryEditorPart.ID);
((QueryEditorPart) editor).connect(DatabaseNavigatorMenu.SELF_DATABASE);
} catch (PartInitException e) {
LOGGER.error(e.getMessage());
}
}
}
use of com.cubrid.common.ui.query.editor.QueryUnit in project cubrid-manager by CUBRID.
the class CopyToClipboardAction method openNewQueryEditor.
/**
* Open the new query editor
*
* @return IEditorPart
*/
private IEditorPart openNewQueryEditor() {
IWorkbenchPage activePage = LayoutUtil.getActivePage();
QueryUnit queryUnit = new QueryUnit();
Object[] selected = getSelectedObj();
CubridDatabase database = null;
if (selected.length >= 1 && selected[0] instanceof ISchemaNode) {
database = ((ISchemaNode) selected[0]).getDatabase();
queryUnit.setDatabase(database);
}
try {
IEditorPart editor = activePage.openEditor(queryUnit, QueryEditorPart.ID);
if (editor != null && database != null) {
((QueryEditorPart) editor).connect(database);
}
return editor;
} catch (PartInitException e) {
LOGGER.error(e.getMessage());
}
return null;
}
use of com.cubrid.common.ui.query.editor.QueryUnit in project cubrid-manager by CUBRID.
the class TableSelectAllAction method doRun.
private void doRun(ISchemaNode table) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
QueryUnit input = new QueryUnit();
input.setDatabase(table.getDatabase());
try {
QueryEditorPart editor = (QueryEditorPart) window.getActivePage().openEditor(input, QueryEditorPart.ID);
editor.connect(table.getDatabase());
// FIXME move this logic to core module
String escapedTableName = QuerySyntax.escapeKeyword(table.getName());
String sql = "SELECT * FROM " + escapedTableName + ";";
if (table.getDatabase() != null) {
sql = DatabaseInfo.wrapShardQuery(table.getDatabase().getDatabaseInfo(), sql);
}
editor.setQuery(sql, false, true, false);
} catch (Exception e) {
LOGGER.error("", e);
}
}
Aggregations