use of com.cubrid.common.ui.query.editor.QueryUnit in project cubrid-manager by CUBRID.
the class SchemaInfoEditorPart method dispose.
@Override
public void dispose() {
if (cubridNode.getType().equals(NodeType.USER_TABLE) || cubridNode.getType().equals(NodeType.USER_VIEW) || cubridNode.getType().equals(NodeType.SYSTEM_TABLE) || cubridNode.getType().equals(NodeType.SYSTEM_VIEW)) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
QueryUnit unit = new QueryUnit();
unit.setDatabase(((DefaultSchemaNode) cubridNode).getDatabase());
try {
IEditorPart editor = window.getActivePage().openEditor(unit, QueryEditorPart.ID);
if (editor != null)
((QueryEditorPart) editor).connect(unit.getDatabase());
} catch (PartInitException e) {
LOGGER.error(e.getMessage(), e);
}
}
super.dispose();
}
use of com.cubrid.common.ui.query.editor.QueryUnit in project cubrid-manager by CUBRID.
the class CopyQueryEditorAction method run.
/**
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
IEditorPart editor = window.getActivePage().getActiveEditor();
if (editor instanceof QueryEditorPart) {
QueryUnit queryUnit = new QueryUnit();
QueryEditorPart qep = (QueryEditorPart) editor;
CubridDatabase database = qep.getSelectedDatabase();
if (database != null) {
queryUnit.setDatabase(database);
}
// [TOOLS-2425]Support shard broker
if (database != null) {
DatabaseInfo dbInfo = database.getDatabaseInfo();
if (dbInfo != null && dbInfo.isShard()) {
ShardIdSelectionDialog dialog = new ShardIdSelectionDialog(Display.getDefault().getActiveShell());
dialog.setDatabaseInfo(dbInfo);
dialog.setShardId(0);
if (dialog.open() == IDialogConstants.OK_ID) {
dbInfo.setCurrentShardId(dialog.getShardId());
}
}
}
try {
IEditorPart newEditor = window.getActivePage().openEditor(queryUnit, QueryEditorPart.ID);
if (newEditor != null && database != null) {
((QueryEditorPart) newEditor).connect(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 DatabaseQueryNewAction method run.
/**
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
Object[] obj = this.getSelectedObj();
CubridDatabase[] cubridDatabases = handleSelectionObj(obj);
if (cubridDatabases.length == 0) {
return;
}
/*Limit max number one time*/
if (cubridDatabases.length > LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM) {
CommonUITool.openConfirmBox(Messages.bind(Messages.msgMaxOpenNum, LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM));
List<CubridDatabase> list = new ArrayList<CubridDatabase>(LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM);
for (int i = 0; i < LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM; i++) {
list.add(cubridDatabases[i]);
}
cubridDatabases = new CubridDatabase[LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM];
list.toArray(cubridDatabases);
}
// [TOOLS-2425]Support shard broker
// it is used in order to check first shard database when you open several editor of databases.
int count = cubridDatabases.length;
for (CubridDatabase database : cubridDatabases) {
QueryUnit queryUnit = new QueryUnit();
queryUnit.setDatabase(database);
// [TOOLS-2425]Support shard broker
DatabaseInfo dbInfo = database.getDatabaseInfo();
if (dbInfo == null) {
continue;
}
int shardId = 0;
int shardVal = 0;
int shardQueryType = DatabaseInfo.SHARD_QUERY_TYPE_VAL;
if (count == 1) {
// [TOOLS-2425]Support shard broker
if (dbInfo != null && dbInfo.isShard()) {
ShardIdSelectionDialog dialog = new ShardIdSelectionDialog(getShell());
dialog.setDatabaseInfo(dbInfo);
dialog.setShardId(shardId);
dialog.setShardVal(shardVal);
dialog.setShardQueryType(shardQueryType);
if (dialog.open() == IDialogConstants.OK_ID) {
shardId = dialog.getShardId();
shardVal = dialog.getShardVal();
shardQueryType = dialog.getShardQueryType();
}
}
}
try {
IEditorPart editor = window.getActivePage().openEditor(queryUnit, QueryEditorPart.ID);
if (editor != null && database != null) {
QueryEditorPart editorPart = (QueryEditorPart) editor;
editorPart.connect(database);
// [TOOLS-2425]Support shard broker
if (dbInfo.isShard()) {
editorPart.setShardId(shardId);
editorPart.setShardVal(shardVal);
editorPart.setShardQueryType(shardQueryType);
editorPart.changeQueryEditorPartNameWithShard();
}
}
} catch (PartInitException e) {
LOGGER.error(e.getMessage());
}
}
}
use of com.cubrid.common.ui.query.editor.QueryUnit in project cubrid-manager by CUBRID.
the class BatchRunDialog method buttonPressed.
/**
* Call this method when the button in button bar is pressed
*
* @param buttonId the button id
*/
protected void buttonPressed(int buttonId) {
if (buttonId == RUN_ID) {
if (!MessageDialog.openConfirm(PlatformUI.getWorkbench().getDisplay().getActiveShell(), Messages.titleBatchRunConfirm, Messages.msgBatchRunConfirm)) {
return;
}
List<String> fileList = container.getFileList();
RunSQLFileEditorInput input = new RunSQLFileEditorInput(cubridDatabase, fileList);
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, RunSQLFileViewPart.ID);
} catch (Exception e) {
LOGGER.error(e.getLocalizedMessage());
}
super.buttonPressed(IDialogConstants.OK_ID);
} else if (buttonId == PASTE_ID) {
// if (!MessageDialog.openConfirm(
// PlatformUI.getWorkbench().getDisplay().getActiveShell(),
// Messages.titleBatchRunConfirm, Messages.msgBatchRunPasteConfirm)) {
// return;
// }
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null || window.getActivePage() == null) {
return;
}
IEditorPart editor = window.getActivePage().getActiveEditor();
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;
}
QueryEditorPart oldEditor = (QueryEditorPart) editor;
try {
QueryEditorPart queryEditor = (QueryEditorPart) editor;
String encoding = queryEditor.getCombinedQueryComposite().getSqlEditorComp().getDocument().getEncoding();
StringBuilder sb = new StringBuilder();
List<String> fileList = container.getFileList();
for (int i = 0; i < fileList.size(); i++) {
sb.delete(0, sb.length());
sb.append("/* SQL Filename: ").append(fileList.get(i)).append(" */").append(StringUtil.NEWLINE);
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(new FileInputStream(new File(fileList.get(i))), encoding));
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) {
}
}
try {
QueryUnit input = new QueryUnit();
QueryEditorPart newEditor = (QueryEditorPart) window.getActivePage().openEditor(input, QueryEditorPart.ID);
newEditor.setQuery(sb.toString(), false, false, false);
newEditor.connect(oldEditor.getSelectedDatabase());
} catch (Exception e) {
CommonUITool.openErrorBox(e.getMessage());
}
}
} catch (IOException e) {
CommonUITool.openErrorBox(e.getMessage());
}
super.buttonPressed(IDialogConstants.OK_ID);
} else {
super.buttonPressed(buttonId);
}
}
use of com.cubrid.common.ui.query.editor.QueryUnit in project cubrid-manager by CUBRID.
the class CommonUITool method openQueryEditor.
/**
* Open new query editor.
*
* @param database of query editor.
* @param careDBRunType whether care the database running type that only whether donot open the query editor if the running type is not CS.
* @throws PartInitException when open editor error.
*/
public static QueryEditorPart openQueryEditor(CubridDatabase database, boolean careDBRunType) throws PartInitException {
IWorkbenchPage page = LayoutUtil.getActivePage();
if (page == null) {
return null;
}
if (database != null && careDBRunType && database.getRunningType() != DbRunningType.CS) {
return null;
}
QueryUnit input = new QueryUnit();
input.setDatabase(database);
IEditorPart editor = page.openEditor(input, QueryEditorPart.ID);
if (editor != null) {
((QueryEditorPart) editor).connect(database);
}
return (QueryEditorPart) editor;
}
Aggregations