use of org.eclipse.ui.IViewPart in project cubrid-manager by CUBRID.
the class QueryEditorPart method runQuery.
/**
* Execute all the selected SQL script on editor, if not, execute all the
* script on editor
*
* @param isOnlyQueryPlan boolean
* @param isSqlmapQuery boolean whether or not it needs parsing a sqlmap query
* @param queries String
* @param rowParameterList List<List<PstmtParameter>>
*/
private void runQuery(boolean isOnlyQueryPlan, boolean isSqlmapQuery, String queries, List<List<PstmtParameter>> rowParameterList) {
// FIXME move this logic to core module
if (!isConnected()) {
CommonUITool.openErrorBox(Messages.qedit_tip_run_query);
return;
}
if (StringUtil.isEmpty(queries)) {
return;
}
try {
connection.getConnection(true);
} catch (SQLException e) {
CommonUITool.openErrorBox(e.getLocalizedMessage());
return;
}
try {
connection.setAutoCommit(isAutocommit);
} catch (SQLException e) {
CommonUITool.openErrorBox(e.getLocalizedMessage());
return;
}
if (!connection.hasConnection()) {
return;
}
MapperParser mapperParser = null;
boolean isXmlQueries = isSqlmapQuery && QueryUtil.isXml(queries);
if (isXmlQueries) {
try {
mapperParser = new MapperParserImpl();
} catch (Exception ignored) {
isXmlQueries = false;
}
}
if (isXmlQueries) {
boolean isNotFirstDisplayed = false;
try {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart view = page.findView(SqlmapNavigatorView.ID);
if (view == null) {
showToolTip(qeToolBar, runItem, Messages.titleSqlmapSupports, Messages.msgSqlmapSupports, 3);
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(SqlmapNavigatorView.ID, null, IWorkbenchPage.VIEW_ACTIVATE);
isNotFirstDisplayed = true;
}
} catch (PartInitException e) {
LOGGER.error(e.getMessage(), e);
}
// TODO #664 find query id on current position of xml content
// TODO #664 position
String queryId = QueryUtil.findNearbyQueryId(queries, queries.length() / 2);
MapperFile mapperFile = null;
try {
mapperFile = mapperParser.parse(getAllQueries());
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
// TODO #664 message
CommonUITool.openErrorBox(e.getLocalizedMessage());
}
List<String> queryIdList = mapperFile.getQueryIdList();
SqlmapNavigatorView.getInstance().updateQueryIdList(queryIdList, queryId);
List<QueryCondition> condList = mapperFile.getConditionList(queryId);
boolean isXmlUpdated = SqlmapPersistUtil.getInstance().isChanged(queryId, condList);
if (isXmlUpdated) {
SqlmapPersistUtil.getInstance().setConditions(queryId, condList);
}
String generatedQuery = SqlmapPersistUtil.getInstance().generateQuery(mapperFile, queryId);
String rawQuery = mapperFile.generateRawQuery(queryId);
if (rawQuery == null) {
showToolTip(qeToolBar, runItem, Messages.titleSqlmapUpdated, "Cannot find a query by the query id.\nIt seems to be commented out a query.", // TODO i18n
3);
}
List<String> bindParameters = QueryUtil.extractBindParameters(rawQuery);
for (String parameterOfSqlmap : bindParameters) {
String parameterName = QueryUtil.extractBindParameterName(parameterOfSqlmap);
SqlmapPersistUtil.getInstance().addOrModifyBindParameter(queryId, parameterName, null, BindParameterType.STRING.name());
BindParameter bindParameter = SqlmapPersistUtil.getInstance().getBindParameter(queryId, parameterName);
if (bindParameter != null) {
String value = bindParameter.getType().wrap(bindParameter.getValue());
generatedQuery = generatedQuery.replace(parameterOfSqlmap, value);
}
}
SqlmapNavigatorView.getInstance().refreshView();
if (!isNotFirstDisplayed) {
showToolTip(qeToolBar, runItem, Messages.titleSqlmapUpdated, Messages.msgSqlmapUpdated, 1);
}
return;
}
Vector<String> queryVector = QueryUtil.queriesToQuery(queries);
if (GeneralPreference.isShowAlertModifiedQueryOnAutoCommit() && isAutocommit() && !isOnlyQueryPlan && checkModifiedQueriesAndAlert(queryVector)) {
return;
}
if (isOnlyQueryPlan) {
if (!queryPlanItem.isEnabled()) {
return;
}
} else {
if (!runItem.isEnabled()) {
return;
}
}
isRunning = true;
queryPlanItem.setEnabled(false);
autoCommitItem.setEnabled(false);
setPstmtParaItem.setEnabled(false);
if (isOnlyQueryPlan) {
runQueryPlanOnly(queryVector);
} else {
runQuery(queryVector, rowParameterList, connection);
}
}
use of org.eclipse.ui.IViewPart in project cubrid-manager by CUBRID.
the class QueryEditorPart method fillInToolbar.
public void fillInToolbar() {
qeToolBar.addDatabaseChangedListener(new Listener() {
public void handleEvent(Event event) {
Object data = event.data;
if (data instanceof CubridDatabase) {
CubridDatabase database = (CubridDatabase) data;
if (database == DatabaseNavigatorMenu.NULL_DATABASE) {
resetJDBCConnection();
} else {
initConnection(database);
}
ServerInfo serverInfo = database.getServer() == null ? null : database.getServer().getServerInfo();
boolean autoCommit = QueryOptions.getAutoCommit(serverInfo);
setAutocommit(autoCommit);
}
}
});
final ToolBar toolBar = qeToolBar;
// [TOOLS-2425]Support shard broker
changeShardIdValItem = new ToolItem(toolBar, SWT.PUSH);
changeShardIdValItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/change_shard_id.png"));
changeShardIdValItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/change_shard_id_disabled.png"));
changeShardIdValItem.setToolTipText(Messages.changeShardId);
changeShardIdValItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
CubridDatabase cubridDatabase = getSelectedDatabase();
if (cubridDatabase != null) {
DatabaseInfo dbInfo = cubridDatabase.getDatabaseInfo();
if (dbInfo != null && dbInfo.isShard()) {
ShardIdSelectionDialog dialog = new ShardIdSelectionDialog(Display.getDefault().getActiveShell());
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();
changeQueryEditorPartNameWithShard();
}
}
}
}
});
CubridDatabase cubridDatabase = getSelectedDatabase();
if (cubridDatabase == null || CubridDatabase.hasValidDatabaseInfo(cubridDatabase) && cubridDatabase.getDatabaseInfo().isShard()) {
changeShardIdValItem.setEnabled(false);
}
new ToolItem(toolBar, SWT.SEPARATOR);
runItem = new ToolItem(toolBar, SWT.PUSH);
runItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_run.png"));
runItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/query_run_disabled.png"));
runItem.setToolTipText(Messages.run + "(F5)");
runItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
hideToolTip();
runQuery(false);
}
});
multiRunItem = new ToolItem(toolBar, SWT.PUSH);
multiRunItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_multi_run.png"));
multiRunItem.setToolTipText(Messages.runMultiQuery + "(F8)");
multiRunItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
changeMultiQueryMode();
}
});
queryPlanItem = new ToolItem(toolBar, SWT.PUSH);
queryPlanItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_execution_plan.png"));
queryPlanItem.setToolTipText(Messages.queryPlanTip + "(F6)");
queryPlanItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
hideToolTip();
runQuery(true);
}
});
ToolItem historyItem = new ToolItem(toolBar, SWT.PUSH);
historyItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_history.png"));
historyItem.setToolTipText(Messages.queryHistory + "(F7)");
historyItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
hideToolTip();
getCombinedQueryComposite().select(2, -1);
}
});
setPstmtParaItem = new ToolItem(toolBar, SWT.PUSH);
setPstmtParaItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/qe_set_param.png"));
setPstmtParaItem.setToolTipText(Messages.tipSetPstmt);
setPstmtParaItem.setEnabled(false);
setPstmtParaItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
hideToolTip();
if (combinedQueryComposite.getSqlEditorComp().isDisposed()) {
return;
}
PstmtSQLDialog dialog = new PstmtSQLDialog(getSite().getShell(), getSelectedDatabase());
dialog.create();
dialog.setEditorInput((QueryUnit) getEditorInput());
String queries = getSelectedText();
dialog.setSql(queries);
dialog.open();
}
});
tuneModeItem = new ToolItem(toolBar, SWT.CHECK);
tuneModeItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/tune_mode.png"));
tuneModeItem.setToolTipText(Messages.tipExecStat + "(F9)");
tuneModeItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
hideToolTip();
boolean isTuneMode = tuneModeItem.getSelection();
changeCollectExecStats(isTuneMode);
if (isTuneMode) {
showToolTip(qeToolBar, tuneModeItem, Messages.ttQeToolbarTuneModeTitle, Messages.ttQeToolbarTuneModeMSg);
} else {
hideToolTip();
}
}
});
new ToolItem(toolBar, SWT.SEPARATOR);
final ToolItem addEditorItem = new ToolItem(toolBar, SWT.PUSH);
addEditorItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/tab_item_add.png"));
addEditorItem.setToolTipText(Messages.queryEditorAddTabItemTooltip + "(Ctrl+Shift+T)");
addEditorItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
hideToolTip();
addEditorTab();
}
});
new ToolItem(toolBar, SWT.SEPARATOR);
runBatchItem = new ToolItem(toolBar, SWT.PUSH);
runBatchItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/run_batch_sql.png"));
runBatchItem.setToolTipText(Messages.batchRun);
runBatchItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
hideToolTip();
try {
// FIXME extract utility
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart view = page.findView(FavoriteQueryNavigatorView.ID);
if (view != null) {
page.hideView(view);
} else {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(FavoriteQueryNavigatorView.ID, null, IWorkbenchPage.VIEW_ACTIVATE);
}
} catch (PartInitException e) {
LOGGER.error(e.getMessage(), e);
}
}
});
new ToolItem(toolBar, SWT.SEPARATOR);
ToolItem itemFormatterr = new ToolItem(toolBar, SWT.PUSH);
itemFormatterr.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_format.png"));
itemFormatterr.setToolTipText(Messages.formatTip + "(Ctrl+Shift+F)");
itemFormatterr.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
hideToolTip();
combinedQueryComposite.getSqlEditorComp().format();
}
});
ToolItem itemIndent = new ToolItem(toolBar, SWT.PUSH);
itemIndent.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_indent_add.png"));
itemIndent.setToolTipText(Messages.indentTip + "(Tab)");
itemIndent.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
hideToolTip();
if (combinedQueryComposite.getSqlEditorComp().isDisposed()) {
return;
}
combinedQueryComposite.getSqlEditorComp().indent();
}
});
ToolItem itemUnindent = new ToolItem(toolBar, SWT.PUSH);
itemUnindent.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_indent_delete.png"));
itemUnindent.setToolTipText(Messages.unIndentTip + "(Shift+Tab)");
itemUnindent.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
hideToolTip();
if (combinedQueryComposite.getSqlEditorComp().isDisposed()) {
return;
}
combinedQueryComposite.getSqlEditorComp().unindent();
}
});
ToolItem clearItem = new ToolItem(toolBar, SWT.PUSH);
clearItem.setImage(CommonUIPlugin.getImage("/icons/queryeditor/clear_sql.png"));
clearItem.setToolTipText(Messages.clear);
clearItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
hideToolTip();
if (combinedQueryComposite.getSqlEditorComp().isDisposed()) {
return;
}
if (!CommonUITool.openConfirmBox(Messages.msgClear)) {
return;
}
combinedQueryComposite.getSqlEditorComp().setQueries("");
}
});
new ToolItem(toolBar, SWT.SEPARATOR);
ToolItem itemComment = new ToolItem(toolBar, SWT.PUSH);
itemComment.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_comment_add.png"));
itemComment.setToolTipText(Messages.commentTip + "(Ctrl+/)");
itemComment.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
hideToolTip();
if (combinedQueryComposite.getSqlEditorComp().isDisposed()) {
return;
}
combinedQueryComposite.getSqlEditorComp().comment();
}
});
ToolItem itemUncomment = new ToolItem(toolBar, SWT.PUSH);
itemUncomment.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_comment_delete.png"));
itemUncomment.setToolTipText(Messages.unCommentTip + "(Ctrl+/)");
itemUncomment.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
hideToolTip();
if (combinedQueryComposite.getSqlEditorComp().isDisposed()) {
return;
}
combinedQueryComposite.getSqlEditorComp().uncomment();
}
});
new ToolItem(toolBar, SWT.SEPARATOR);
commitItem = new ToolItem(toolBar, SWT.PUSH);
commitItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_commit.png"));
commitItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/query_commit_disabled.png"));
commitItem.setToolTipText(Messages.commit);
commitItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
hideToolTip();
commit();
}
});
commitItem.setEnabled(false);
rollbackItem = new ToolItem(toolBar, SWT.PUSH);
rollbackItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_rollback.png"));
rollbackItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/query_rollback_disabled.png"));
rollbackItem.setToolTipText(Messages.rollback);
rollbackItem.setEnabled(false);
rollbackItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
hideToolTip();
rollback();
}
});
autoCommitItem = new ToolItem(toolBar, SWT.CHECK);
autoCommitItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_auto_false.png"));
autoCommitItem.setToolTipText(Messages.autoCommit);
autoCommitItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
hideToolTip();
if (checkActive()) {
return;
}
setAutocommit(autoCommitItem.getSelection());
if (connection != null) {
try {
connection.setAutoCommit(isAutocommit());
} catch (SQLException e) {
}
}
}
});
setAutocommit(true);
new ToolItem(toolBar, SWT.SEPARATOR);
ToolItem openItem = new ToolItem(toolBar, SWT.PUSH);
openItem.setImage(CommonUIPlugin.getImage("/icons/queryeditor/file_open.png"));
openItem.setToolTipText(Messages.open);
openItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
hideToolTip();
doOpen();
}
});
ToolItem saveItem = new ToolItem(toolBar, SWT.PUSH);
saveItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/file_save.png"));
saveItem.setToolTipText(Messages.save);
saveItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
hideToolTip();
doSave(new NullProgressMonitor());
}
});
ToolItem saveAsItem = new ToolItem(toolBar, SWT.PUSH);
saveAsItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/file_saveas.png"));
saveAsItem.setToolTipText(Messages.saveAs);
saveAsItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
hideToolTip();
doSaveAs();
}
});
//Fill in the show or hide result pane tool item
new ToolItem(toolBar, SWT.SEPARATOR);
showResultItem = new ToolItem(toolBar, SWT.PUSH);
showResultItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/qe_panel_down.png"));
showResultItem.setToolTipText(Messages.tooltip_qedit_result_show_hide);
showResultItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
hideToolTip();
CTabFolder resultTabFolder = combinedQueryComposite.getResultTabFolder();
SashForm topSash = combinedQueryComposite.getTopSash();
if (resultTabFolder.getMinimized()) {
resultTabFolder.setMinimized(false);
resultTabFolder.setMaximized(false);
topSash.setMaximizedControl(null);
showResultItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/qe_panel_down.png"));
topSash.layout(true);
} else if (!resultTabFolder.getMaximized() && !resultTabFolder.getMinimized()) {
resultTabFolder.setMinimized(true);
topSash.setMaximizedControl(combinedQueryComposite.getSqlEditorComp().getParent());
showResultItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/qe_panel_up.png"));
topSash.layout(true);
}
}
});
topComposite.pack();
packToolBar();
}
use of org.eclipse.ui.IViewPart in project dbeaver by serge-rider.
the class NavigatorHandlerToggleView method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final String viewId = event.getParameter("viewId");
final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
final IViewPart view = UIUtils.findView(workbenchWindow, viewId);
if (view != null) {
workbenchWindow.getActivePage().hideView(view);
} else {
try {
workbenchWindow.getActivePage().showView(viewId);
} catch (PartInitException e) {
UIUtils.showErrorDialog(HandlerUtil.getActiveShell(event), "Toggle view", "Cannot open view " + viewId, e);
}
}
return null;
}
use of org.eclipse.ui.IViewPart in project dbeaver by serge-rider.
the class NavigatorHandlerToggleView method updateElement.
@Override
public void updateElement(UIElement element, Map parameters) {
final String viewId = (String) parameters.get("viewId");
final IViewPart view = DBeaverUI.getActiveWorkbenchWindow().getActivePage().findView(viewId);
element.setChecked(view != null);
}
use of org.eclipse.ui.IViewPart in project cubrid-manager by CUBRID.
the class CubridTitleLineContrItem method getTitleForViewOrEdit.
/**
*
* Get the title of view or editor(not including query editor)
*
* @param cubridNode the ICubridNode object
* @param workbenchPart the IWorkbenchPart object
* @return the title
*/
protected String getTitleForViewOrEdit(ICubridNode cubridNode, IWorkbenchPart workbenchPart) {
String serverTitle = "";
if (cubridNode != null && cubridNode.getServer() != null && cubridNode.getServer().isConnected()) {
CubridServer server = cubridNode.getServer();
serverTitle = server.getLabel();
ServerUserInfo userInfo = cubridNode.getServer().getServerInfo().getLoginedUserInfo();
if (userInfo != null && userInfo.getUserName() != null && userInfo.getUserName().trim().length() > 0) {
serverTitle = userInfo.getUserName() + "@" + serverTitle;
}
String monPort = cubridNode.getServer().getMonPort();
if (monPort != null && monPort.trim().length() > 0) {
serverTitle = serverTitle + ":" + monPort;
}
}
String partTitle = "";
if (cubridNode != null && workbenchPart == null) {
if (null != cubridNode.getViewId()) {
IViewPart viewPart = LayoutUtil.getViewPart(cubridNode, cubridNode.getViewId());
if (viewPart != null) {
partTitle = viewPart.getTitle();
}
}
if (null != cubridNode.getEditorId()) {
IEditorPart editorPart = LayoutUtil.getEditorPart(cubridNode, cubridNode.getEditorId());
if (editorPart != null) {
partTitle = editorPart.getTitle();
}
}
} else if (workbenchPart != null) {
partTitle = workbenchPart.getTitle();
}
String title = "";
if (serverTitle != null && serverTitle.trim().length() > 0) {
title = serverTitle;
}
if (partTitle != null && partTitle.trim().length() > 0) {
if (title != null && title.trim().length() > 0) {
title += " / ";
}
title += partTitle;
}
return title;
}
Aggregations