use of com.cubrid.common.ui.query.editor.QueryEditorPart in project cubrid-manager by CUBRID.
the class CommonUITool method getActiveQueryEditorPart.
/**
* Get the active query editor
*
* @return
*/
public static QueryEditorPart getActiveQueryEditorPart() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IEditorPart editor = window.getActivePage().getActiveEditor();
if (editor instanceof QueryEditorPart) {
return (QueryEditorPart) editor;
}
return null;
}
use of com.cubrid.common.ui.query.editor.QueryEditorPart 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;
}
use of com.cubrid.common.ui.query.editor.QueryEditorPart 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.QueryEditorPart 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 {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null || window.getActivePage() == null) {
return;
}
if (database == null) {
window.getActivePage().openEditor(new QueryUnit(), QueryEditorPart.ID);
return;
}
CubridDatabase cdb = database;
if (database == null || !database.isLogined()) {
LoginQueryEditorDialog dialog = new LoginQueryEditorDialog(getShell());
dialog.setSelectedConnName(getInitConnectionName(database));
if (dialog.open() != IDialogConstants.OK_ID) {
return;
}
cdb = DatabaseNavigatorMenu.SELF_DATABASE;
}
// [TOOLS-2425]Support shard broker
boolean isShrd = false;
int shardId = 0;
int shardVal = 0;
int shardQueryType = DatabaseInfo.SHARD_QUERY_TYPE_ID;
if (cdb != null) {
DatabaseInfo dbInfo = cdb.getDatabaseInfo();
if (dbInfo != null && dbInfo.isShard()) {
isShrd = true;
ShardIdSelectionDialog dialog = new ShardIdSelectionDialog(getShell());
dialog.setDatabaseInfo(dbInfo);
dialog.setShardId(0);
dialog.setShardVal(0);
dialog.setShardQueryType(shardQueryType);
if (dialog.open() == IDialogConstants.OK_ID) {
shardId = dialog.getShardId();
shardVal = dialog.getShardVal();
shardQueryType = dialog.getShardQueryType();
}
}
}
QueryUnit input = new QueryUnit();
input.setDatabase(cdb);
IEditorPart editor = window.getActivePage().openEditor(input, QueryEditorPart.ID);
if (editor != null) {
QueryEditorPart editorPart = (QueryEditorPart) editor;
editorPart.connect(cdb);
// [TOOLS-2425]Support shard broker
if (isShrd) {
editorPart.setShardId(shardId);
editorPart.setShardVal(shardVal);
editorPart.setShardQueryType(shardQueryType);
editorPart.changeQueryEditorPartNameWithShard();
}
}
}
use of com.cubrid.common.ui.query.editor.QueryEditorPart in project cubrid-manager by CUBRID.
the class QueryNewCustomAction method openQueryEditor.
/**
* Open new query editor.
*
* @param database of query editor.
* @throws PartInitException when open editor error.
*/
private void openQueryEditor(CubridDatabase database) throws PartInitException {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null || window.getActivePage() == null) {
return;
}
CubridDatabase cdb = DatabaseNavigatorMenu.NULL_DATABASE;
LoginQueryEditorDialog loginDialog = new LoginQueryEditorDialog(getShell());
loginDialog.setSelectedConnName(getInitConnectionName(database));
if (loginDialog.open() == IDialogConstants.OK_ID) {
cdb = DatabaseNavigatorMenu.SELF_DATABASE;
} else {
return;
}
// [TOOLS-2425]Support shard broker
if (cdb != null) {
DatabaseInfo dbInfo = cdb.getDatabaseInfo();
if (dbInfo != null && dbInfo.isShard()) {
ShardIdSelectionDialog dialog = new ShardIdSelectionDialog(getShell());
dialog.setDatabaseInfo(dbInfo);
dialog.setShardId(0);
dialog.setShardVal(0);
dialog.setShardQueryType(dbInfo.getShardQueryType());
if (dialog.open() == IDialogConstants.OK_ID) {
dbInfo.setCurrentShardId(dialog.getShardId());
}
}
}
QueryUnit input = new QueryUnit();
input.setDatabase(cdb);
IEditorPart editor = window.getActivePage().openEditor(input, QueryEditorPart.ID);
if (editor != null) {
((QueryEditorPart) editor).connect(cdb);
}
}
Aggregations