use of com.cubrid.common.ui.query.editor.QueryEditorPart in project cubrid-manager by CUBRID.
the class CopyToClipboardAction method doRun.
/**
* Do run
*
* @param objects
*/
protected void doRun(final Object[] objects) {
final int len = objects.length;
final Display display = PlatformUI.getWorkbench().getDisplay();
BusyIndicator.showWhile(display, new Runnable() {
public void run() {
IEditorPart ep = null;
if (isCopyToEditor) {
IWorkbenchPage activePage = LayoutUtil.getActivePage();
ep = activePage.getActiveEditor();
if (!(ep instanceof QueryEditorPart)) {
ep = openNewQueryEditor();
}
if (!(ep instanceof QueryEditorPart)) {
ep = null;
}
}
StringBuffer allTableSql = new StringBuffer();
for (int i = 0; i < len; i++) {
DefaultSchemaNode table = (DefaultSchemaNode) objects[i];
String sql = getStmtSQL(table, ep);
if (sql != null && sql.trim().length() > 0) {
allTableSql.append(sql);
allTableSql.append(StringUtil.NEWLINE);
allTableSql.append(StringUtil.NEWLINE);
}
}
if (allTableSql.length() > 0) {
if (isCopyToEditor) {
if (ep instanceof QueryEditorPart) {
((QueryEditorPart) ep).setQuery(allTableSql.toString(), true, false, false);
}
} else {
CommonUITool.copyContentToClipboard(allTableSql.toString());
}
}
}
});
}
use of com.cubrid.common.ui.query.editor.QueryEditorPart 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);
}
}
use of com.cubrid.common.ui.query.editor.QueryEditorPart 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.QueryEditorPart 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.QueryEditorPart in project cubrid-manager by CUBRID.
the class FindReplaceAction method run.
/**
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IEditorPart editor = window.getActivePage().getActiveEditor();
if (editor instanceof QueryEditorPart) {
QueryEditorPart queryEditor = (QueryEditorPart) editor;
queryEditor.find();
}
}
Aggregations