use of com.cubrid.common.ui.query.editor.QueryEditorPart in project cubrid-manager by CUBRID.
the class ColumnSelectSqlAction method run.
public void run() {
Object[] objs = this.getSelectedObj();
if (!isSupported(objs)) {
setEnabled(false);
return;
}
ISchemaNode table = (ISchemaNode) ((ISchemaNode) objs[0]).getParent().getParent();
StringBuilder buf = new StringBuilder();
for (int i = 0; i < objs.length; i++) {
ISchemaNode columnNode = (ISchemaNode) objs[i];
String column = columnNode.getName().split(",")[0];
buf.append(QuerySyntax.escapeKeyword(column));
if (i != objs.length - 1) {
buf.append(',');
}
}
String cols = buf.toString();
if (StringUtil.isEmpty(cols)) {
return;
}
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 " + cols + " FROM " + escapedTableName + ";";
editor.setQuery(sql, false, true, false);
} catch (PartInitException e) {
LOGGER.error(e.getMessage());
}
}
use of com.cubrid.common.ui.query.editor.QueryEditorPart in project cubrid-manager by CUBRID.
the class InformationWindow method updateLocation.
/**
* Update the location
*/
public void updateLocation() {
int x = 0, y = 0;
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null || window.getActivePage() == null) {
return;
}
Shell windowShell = this.getShell();
if (windowShell == null) {
InfoWindowManager.dispose();
return;
}
IEditorPart editPart = window.getActivePage().getActiveEditor();
if (editPart != null && editPart instanceof QueryEditorPart) {
QueryEditorPart queryEditorPart = (QueryEditorPart) editPart;
CombinedQueryEditorComposite combinedComposite = queryEditorPart.getCombinedQueryComposite();
if (combinedComposite != null && !combinedComposite.isDisposed()) {
Rectangle compositeBounds = combinedComposite.getBounds();
if (compositeBounds.width < width + horizonalMargin || compositeBounds.height < height + verticalMargin) {
windowShell.setVisible(false);
return;
}
Point size = infoText.computeSize(SWT.DEFAULT, SWT.DEFAULT);
width = size.x;
height = size.y;
Point endLocation = Display.getCurrent().map(combinedComposite, null, new Point(compositeBounds.width, compositeBounds.height));
x = endLocation.x - width - horizonalMargin;
y = endLocation.y - height - verticalMargin;
windowShell.setBounds(x, y, width, height);
if (StringUtil.isEmpty(infoText.getText())) {
windowShell.setVisible(false);
} else {
windowShell.setVisible(true);
}
}
}
}
use of com.cubrid.common.ui.query.editor.QueryEditorPart in project cubrid-manager by CUBRID.
the class ImportDataFromFileDialog method showResultSet.
/**
*
* Show the result set by query editor
*
* @param parameterList List<PstmtParameter>
*/
private void showResultSet(List<PstmtParameter> parameterList) {
// FIXME move this logic to core module
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
String showedSql = sqlTxt.getText();
String executedSql = showedSql;
while (executedSql.endsWith(";")) {
executedSql = executedSql.substring(0, executedSql.length() - 1);
}
executedSql += ";";
int threadCount = threadCountSpinner.getSelection();
String fileName = fileNameTxt.getText();
String charset = fileCharsetCombo.getText();
int totalLine = Integer.parseInt(totalLinesText.getText());
int commitedLineOnce = commitLineSpinner.getSelection();
ImportFileHandler handler = ImportFileHandlerFactory.getHandler(fileName, charset);
PstmtDataTask task = new PstmtDataTask(sqlTxt.getText(), database, fileName, parameterList, 0, totalLine, commitedLineOnce, charset, firstRowAsColumnBtn.getSelection(), false, null, handler);
List<List<PstmtParameter>> rowParameterList = null;
try {
rowParameterList = task.getRowParameterList();
} catch (RuntimeException ex) {
String errorMsg = null;
if (ex.getCause() == null) {
errorMsg = ex.getMessage();
} else {
if (ex.getCause() instanceof OutOfMemoryError) {
errorMsg = Messages.errNoAvailableMemory;
} else {
errorMsg = ex.getCause().getMessage();
}
}
errorMsg = errorMsg == null || errorMsg.trim().length() == 0 ? "Unknown error." : errorMsg;
CommonUITool.openErrorBox(getShell(), errorMsg);
return;
} catch (Exception ex) {
String errorMsg = ex.getMessage();
errorMsg = errorMsg == null || errorMsg.trim().length() == 0 ? "Unknown error." : errorMsg;
CommonUITool.openErrorBox(getShell(), errorMsg);
return;
} finally {
if (importFileHandler instanceof XLSImportFileHandler) {
XLSImportFileHandler xlsHandler = (XLSImportFileHandler) importFileHandler;
xlsHandler.dispose();
} else if (importFileHandler instanceof XLSXImportFileHandler) {
XLSXImportFileHandler xlsHandler = (XLSXImportFileHandler) importFileHandler;
xlsHandler.dispose();
}
}
close();
int rows = rowParameterList == null ? 0 : rowParameterList.size();
int rowsOfThread = rows;
if (threadCount > 1) {
rowsOfThread = rows / threadCount;
}
int rowsOfLastThread = rowsOfThread + (rows % threadCount == 0 ? 0 : rows % threadCount);
int currentRow = 0;
for (int i = 0; i < threadCount; i++) {
QueryUnit editorInput = new QueryUnit();
IEditorPart editor = null;
try {
editor = window.getActivePage().openEditor(editorInput, QueryEditorPart.ID);
} catch (PartInitException e) {
editor = null;
}
if (editor != null) {
QueryEditorPart queryEditor = ((QueryEditorPart) editor);
int endRow = currentRow + rowsOfThread;
if (i == threadCount - 1) {
endRow = currentRow + rowsOfLastThread;
}
List<List<PstmtParameter>> paraList = new ArrayList<List<PstmtParameter>>();
StringBuffer showedSqlBuffer = new StringBuffer();
StringBuffer executeSqlBuffer = new StringBuffer();
for (int j = currentRow; j < endRow; j++) {
showedSqlBuffer.append(getCommentSqlValue(rowParameterList.get(j)));
paraList.add(rowParameterList.get(j));
executeSqlBuffer.append(executedSql);
}
showedSqlBuffer.append(showedSql);
currentRow = endRow;
if (!queryEditor.isConnected() && database != null) {
queryEditor.connect(database);
}
if (queryEditor.isConnected()) {
queryEditor.setQuery(showedSqlBuffer.toString(), executedSql, rowParameterList, true, true, false);
} else {
queryEditor.setQuery(showedSqlBuffer.toString(), true, false, false);
}
}
}
}
use of com.cubrid.common.ui.query.editor.QueryEditorPart in project cubrid-manager by CUBRID.
the class FavoriteQueryNavigatorView method saveFile.
/**
* Save query editor's sql into locally managed file.
*/
private void saveFile() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null || window.getActivePage() == null) {
CommonUITool.openErrorBox(Messages.errCanNotFindQueryEditor);
return;
}
IEditorPart editor = window.getActivePage().getActiveEditor();
if (editor == null || !(editor instanceof QueryEditorPart)) {
CommonUITool.openErrorBox(Messages.errCanNotFindQueryEditor);
return;
}
QueryEditorPart queryEditor = (QueryEditorPart) editor;
String query = queryEditor.getCurrentQuery();
addFavoriteQuery(query);
}
use of com.cubrid.common.ui.query.editor.QueryEditorPart 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());
}
}
Aggregations