use of org.eclipse.ui.IWorkbenchWindow in project cubrid-manager by CUBRID.
the class QueryEditorUtil method openQueryEditorAndRunQuery.
/**
* Open query editor and run query
*
* @param database
* @param query
* @param isAutoRun
* @param isOpenInExistEditor
*/
public static void openQueryEditorAndRunQuery(CubridDatabase database, String query, boolean isAutoRun, boolean isOpenInExistEditor) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
QueryEditorPart queryEditor = null;
/*Find exist query editor*/
if (isOpenInExistEditor) {
List<QueryEditorPart> editorPartList = getAllQueryEditorPart();
for (QueryEditorPart editor : editorPartList) {
if (database.equals(editor.getSelectedDatabase())) {
queryEditor = editor;
}
}
}
boolean isNewQueryEditor = false;
/*Open new query editor*/
if (queryEditor == null) {
QueryUnit input = new QueryUnit();
input.setDatabase(database);
try {
queryEditor = (QueryEditorPart) window.getActivePage().openEditor(input, QueryEditorPart.ID);
queryEditor.connect(database);
isNewQueryEditor = true;
} catch (PartInitException ex) {
LOGGER.equals(ex.getMessage());
}
}
/*Run query*/
if (queryEditor != null) {
if (isNewQueryEditor) {
queryEditor.setQuery(query, false, isAutoRun, false);
} else {
queryEditor.newQueryTab(query, isAutoRun);
}
window.getActivePage().activate(queryEditor);
}
}
use of org.eclipse.ui.IWorkbenchWindow in project cubrid-manager by CUBRID.
the class SqlmapNavigatorView method refreshView.
public void refreshView() {
String queryId = getSelectedQueryId();
List<String> condListForQuery = new ArrayList<String>();
List<QueryCondition> condList = SqlmapPersistUtil.getInstance().getConditions(queryId);
List<Map<String, String>> condData = new ArrayList<Map<String, String>>();
for (QueryCondition cond : condList) {
Map<String, String> item = new HashMap<String, String>();
String condNameValue = cond.getConditionKey() + ":" + cond.getConditionBody();
item.put("1", condNameValue);
condData.add(item);
if (SqlmapPersistUtil.getInstance().isUsedCondition(queryId, condNameValue)) {
condListForQuery.add(condNameValue);
}
}
condView.setInput(condData);
List<Map<String, String>> paramData = new ArrayList<Map<String, String>>();
Map<String, BindParameter> bindParams = SqlmapPersistUtil.getInstance().getBindParameters(queryId);
for (Map.Entry<String, BindParameter> entry : bindParams.entrySet()) {
Map<String, String> item = new HashMap<String, String>();
item.put("0", entry.getValue().getName());
item.put("1", entry.getValue().getValue());
item.put("2", entry.getValue().getType().name());
paramData.add(item);
}
paramView.setInput(paramData);
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
IEditorPart editorPart = window.getActivePage().getActiveEditor();
if (!(editorPart instanceof QueryEditorPart)) {
return;
}
QueryEditorPart queryEditorPart = (QueryEditorPart) editorPart;
MapperFile mapperFile = null;
try {
mapperFile = new MapperParserImpl().parse(queryEditorPart.getAllQueries());
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
return;
}
String generatedQuery = mapperFile.generateQuery(queryId, condListForQuery);
List<String> bindParamList = QueryUtil.extractBindParameters(mapperFile.generateRawQuery(queryId));
for (String bindParam : bindParamList) {
String paramRawName = bindParam;
String paramName = QueryUtil.extractBindParameterName(paramRawName);
BindParameter bindValue = bindParams.get(paramName);
if (bindValue != null) {
String value = bindValue.getType() == BindParameterType.STRING ? "'" + bindValue.getValue() + "'" : bindValue.getValue();
generatedQuery = generatedQuery.replace(paramRawName, value);
}
}
sqlView.setText(formator.format(generatedQuery));
}
use of org.eclipse.ui.IWorkbenchWindow in project cubrid-manager by CUBRID.
the class SqlmapNavigatorView method getInstance.
/**
* Return current SqlmapNavigatorView instance.
*
* @return
*/
public static SqlmapNavigatorView getInstance() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return null;
}
IWorkbenchPage page = window.getActivePage();
if (page == null) {
return null;
}
IViewReference viewReference = page.findViewReference(ID);
if (viewReference != null) {
IViewPart viewPart = viewReference.getView(false);
return viewPart instanceof SqlmapNavigatorView ? (SqlmapNavigatorView) viewPart : null;
}
return null;
}
use of org.eclipse.ui.IWorkbenchWindow in project cubrid-manager by CUBRID.
the class SqlmapNavigatorView method pasteSqlToQueryEditor.
private void pasteSqlToQueryEditor(String sql) {
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;
}
QueryEditorPart queryEditor = (QueryEditorPart) editor;
if (!StringUtil.isEmpty(queryEditor.getCurrentQuery())) {
queryEditor.addEditorTab();
}
queryEditor.setQuery(sql, false, false, false);
queryEditor.setFocus();
}
use of org.eclipse.ui.IWorkbenchWindow in project cubrid-manager by CUBRID.
the class BrokerEnvStatusView method createTable.
/**
* This method initializes table
*
*/
private void createTable() {
tableViewer = new TableViewer(composite, SWT.FULL_SELECTION);
tableViewer.getTable().setHeaderVisible(true);
tableViewer.getTable().setLinesVisible(true);
BrokerTblColumnSetHelp bcsh = BrokerTblColumnSetHelp.getInstance();
bcsh.loadSetting(BrokerTblColumnSetHelp.StatusColumn.BrokerEnvStatusColumn, BrokerEnvStatusColumn.values());
TableLayout tlayout = new TableLayout();
for (BrokerEnvStatusColumn column : BrokerEnvStatusColumn.values()) {
if (column.getValue() == -1) {
tlayout.addColumnData(new ColumnWeightData(0, 0, false));
} else {
tlayout.addColumnData(new ColumnWeightData(10, 40, true));
}
}
tableViewer.getTable().setLayout(tlayout);
tableViewer.getTable().addMouseListener(new MouseAdapter() {
public void mouseDoubleClick(MouseEvent event) {
int index = -1;
if ((index = tableViewer.getTable().getSelectionIndex()) >= 0) {
TableItem tableItem = tableViewer.getTable().getItem(index);
String brokename = tableItem.getText(0).trim();
ICubridNode input = null;
for (ICubridNode node : cubridNode.getChildren()) {
if (node.getLabel().equalsIgnoreCase(brokename)) {
input = node;
break;
}
}
LayoutManager.getInstance().setCurrentSelectedNode(input);
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (null == window) {
return;
}
IWorkbenchPage activePage = window.getActivePage();
IViewPart viewPart = window.getActivePage().findView(BrokerStatusView.ID);
if (null != viewPart) {
activePage.hideView(viewPart);
}
try {
activePage.showView(BrokerStatusView.ID);
} catch (PartInitException e1) {
LOGGER.error(e1.getMessage(), e1);
}
}
}
});
makeTableColumn();
tableViewer.setContentProvider(new BrokersStatusContentProvider());
ServerInfo serverInfo = cubridNode.getServer().getServerInfo();
BrokersStatusLabelProvider brokersStatusLabelProvider = new BrokersStatusLabelProvider();
brokersStatusLabelProvider.setServerInfo(serverInfo);
tableViewer.setLabelProvider(brokersStatusLabelProvider);
}
Aggregations