use of com.cubrid.common.ui.query.editor.QueryUnit in project cubrid-manager by CUBRID.
the class FavoriteQueryNavigatorView method pasteToEditor.
private void pasteToEditor(String filename, String filepath, String charset, boolean isOpenFileMode) {
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;
}
String fullpath = filepath + File.separator + filename;
if (StringUtil.isEmpty(charset)) {
charset = StringUtil.getDefaultCharset();
}
try {
QueryEditorPart queryEditor = (QueryEditorPart) editor;
StringBuilder sb = new StringBuilder();
if (!isOpenFileMode) {
sb.append("/* SQL Filename: ").append(filename).append(" */").append(StringUtil.NEWLINE);
}
BufferedReader in = null;
try {
File file = new File(fullpath);
in = new BufferedReader(new InputStreamReader(new FileInputStream(file), charset));
String line = in.readLine();
while (line != null) {
sb.append(line + StringUtil.NEWLINE);
line = in.readLine();
}
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException e) {
}
}
if (!StringUtil.isEmpty(queryEditor.getCurrentQuery())) {
queryEditor.addEditorTab();
}
if (isOpenFileMode) {
queryEditor.getCombinedQueryComposite().getSqlEditorComp().open(fullpath, charset);
} else {
queryEditor.setQuery(sb.toString(), false, false, false);
}
queryEditor.setFocus();
} catch (IOException e) {
CommonUITool.openErrorBox(e.getMessage());
}
}
use of com.cubrid.common.ui.query.editor.QueryUnit in project cubrid-manager by CUBRID.
the class QueryNewAction method openQueryEditor.
/**
* Open new query editor.
*
* @param database of query editor.
* @throws PartInitException when open editor error.
*/
private void openQueryEditor(CubridDatabase database) throws PartInitException {
IWorkbenchPage page = LayoutUtil.getActivePage();
if (page == null) {
return;
}
if (database == null) {
page.openEditor(new QueryUnit(), QueryEditorPart.ID);
return;
}
if (database != null && database.getRunningType() != DbRunningType.CS) {
CommonUITool.openErrorBox(Messages.bind(Messages.msgStartDb, database.getLabel()));
return;
}
CubridDatabase cdb = database;
if (database == null || !database.isLogined()) {
LoginQueryEditDialog dialog = new LoginQueryEditDialog(getShell());
dialog.setSelServerName(getInitConnectionName(getSelectedSever()));
dialog.setSelDatabaseName(getInitDatabaseName(database));
if (dialog.open() == IDialogConstants.OK_ID) {
cdb = DatabaseNavigatorMenu.SELF_DATABASE;
} else {
return;
}
}
QueryUnit input = new QueryUnit();
input.setDatabase(cdb);
IEditorPart editor = page.openEditor(input, QueryEditorPart.ID);
if (editor != null) {
((QueryEditorPart) editor).connect(cdb);
}
}
use of com.cubrid.common.ui.query.editor.QueryUnit in project cubrid-manager by CUBRID.
the class CubridWorkbenchContrItem method openSelectQuery.
public void openSelectQuery(ISelection selection) {
final Object obj = ((IStructuredSelection) selection).getFirstElement();
if (!(obj instanceof ICubridNode)) {
return;
}
ISchemaNode table = (ISchemaNode) obj;
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
boolean existsEditor = false;
QueryEditorPart editor = null;
QueryUnit input = new QueryUnit();
input.setDatabase(table.getDatabase());
try {
IEditorPart editorPart = window.getActivePage().getActiveEditor();
if (editorPart != null && editorPart instanceof QueryEditorPart) {
QueryEditorPart queryEditorPart = (QueryEditorPart) editorPart;
if (queryEditorPart.getSelectedDatabase() == input.getDatabase()) {
editor = (QueryEditorPart) editorPart;
existsEditor = true;
}
}
if (editor == null) {
editor = (QueryEditorPart) window.getActivePage().openEditor(input, QueryEditorPart.ID);
editor.connect(table.getDatabase());
}
DefaultSchemaNode tableNode = (DefaultSchemaNode) obj;
String sql = getStmtSQL(tableNode) + StringUtil.NEWLINE + StringUtil.NEWLINE;
if (existsEditor) {
editor.newQueryTab(sql, true);
} else {
editor.setQuery(sql, false, true, false);
}
} catch (Exception e) {
LOGGER.error("", e);
}
}
use of com.cubrid.common.ui.query.editor.QueryUnit in project cubrid-manager by CUBRID.
the class OpenQueryAction method run.
public void run() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
String fileName = null;
try {
SetFileEncodingDialog dialog = new SetFileEncodingDialog(getShell(), StringUtil.getDefaultCharset(), true);
if (IDialogConstants.OK_ID != dialog.open()) {
return;
}
fileName = dialog.getFilePath();
IEditorPart editor = window.getActivePage().openEditor(new QueryUnit(), QueryEditorPart.ID);
if (editor == null) {
return;
}
QueryEditorPart queryEditor = (QueryEditorPart) editor;
queryEditor.getCombinedQueryComposite().getSqlEditorComp().open(dialog.getFilePath(), dialog.getEncoding());
Object[] obj = this.getSelectedObj();
CubridDatabase[] cubridDatabases = handleSelectionObj(obj);
if (cubridDatabases.length > 0 && cubridDatabases[0] != null) {
((QueryEditorPart) editor).connect(cubridDatabases[0]);
}
} catch (PartInitException e) {
LOGGER.error("Can not initialize the query editor UI.", e);
} catch (IOException e) {
LOGGER.error("Can not open the {} file.", fileName, e);
//TODO: message localizing
CommonUITool.openErrorBox(e.getMessage());
}
}
use of com.cubrid.common.ui.query.editor.QueryUnit in project cubrid-manager by CUBRID.
the class BrokerLogParserAction method run.
public void run() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
BrokerLogParserDialog dialog = new BrokerLogParserDialog(window.getShell());
dialog.open();
if (dialog.getReturnCode() != IDialogConstants.OK_ID) {
return;
}
String sql = dialog.getResultSql();
try {
QueryUnit input = new QueryUnit();
QueryEditorPart editor = (QueryEditorPart) window.getActivePage().openEditor(input, QueryEditorPart.ID);
editor.setQuery(sql, false, false, false);
} catch (PartInitException e) {
LOGGER.debug("Failed sql is {}.", sql);
LOGGER.error("Can not parse broker sql log.", e);
}
}
Aggregations