use of com.cubrid.common.ui.query.editor.QueryEditorPart 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 com.cubrid.common.ui.query.editor.QueryEditorPart 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 com.cubrid.common.ui.query.editor.QueryEditorPart in project cubrid-manager by CUBRID.
the class ApplicationWorkbenchWindowAdvisor method preWindowShellClose.
/**
* Performs arbitrary actions as the window's shell is being closed
* directly, and possibly veto the close.
*
* @return <code>true</code> to allow the window to close, and
* <code>false</code> to prevent the window from closing
* @see org.eclipse.ui.IWorkbenchWindow#close
* @see WorkbenchAdvisor#preShutdown()
*/
public boolean preWindowShellClose() {
Shell shell = getWindowConfigurer().getWindow().getShell();
GeneralPreference.setMaximizeWindowOnStartUp(shell.getMaximized());
if (timer != null) {
timer.cancel();
HeartBeatTaskManager.getInstance().cancel();
}
/*Close the information window*/
InfoWindowManager.dispose();
/*All opened queryEditor*/
List<QueryEditorPart> editorPartList = QueryEditorUtil.getAllQueryEditorPart();
boolean isNeedSaveQueryEditor = isNeedSaveQueryEditor(editorPartList);
boolean hasJobRunning = false;
final JobFamily jobFamily = new JobFamily();
jobFamily.setServerName(JobFamily.ALL_SERVER);
Job[] jobs = Job.getJobManager().find(jobFamily);
if (jobs.length > 0) {
hasJobRunning = true;
}
boolean isExit = false;
if (hasJobRunning) {
isExit = CommonUITool.openConfirmBox(getWindowConfigurer().getWindow().getShell(), Messages.msgExistConfirmWithJob);
if (isExit) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
try {
Job.getJobManager().cancel(jobFamily);
} catch (Exception e) {
LOGGER.error("Stopping background jobs was failed.", e);
}
}
});
if (isNeedSaveQueryEditor) {
processSaveQueryEditor();
}
}
} else {
if (isNeedSaveQueryEditor) {
processSaveQueryEditor();
return true;
} else {
if (GeneralPreference.isAlwaysExit()) {
return true;
}
MessageDialogWithToggle dialog = MessageDialogWithToggle.openOkCancelConfirm(getWindowConfigurer().getWindow().getShell(), com.cubrid.common.ui.common.Messages.titleExitConfirm, Messages.msgExistConfirm, com.cubrid.common.ui.common.Messages.msgToggleExitConfirm, false, CommonUIPlugin.getDefault().getPreferenceStore(), GeneralPreference.IS_ALWAYS_EXIT);
isExit = dialog.getReturnCode() == 0 ? true : false;
}
}
if (isExit) {
for (List<IEditorReference> list : perspectiveEditorMap.values()) {
IEditorReference[] references = new IEditorReference[list.size()];
list.toArray(references);
getWindowConfigurer().getWindow().getActivePage().closeEditors(references, false);
}
}
return isExit;
}
use of com.cubrid.common.ui.query.editor.QueryEditorPart in project cubrid-manager by CUBRID.
the class QueryNewCustomAction method run.
/**
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
Object[] selected = getSelectedObj();
LoginQueryEditDialog dialog = new LoginQueryEditDialog(getShell());
if (selected != null && selected.length == 1 && selected[0] instanceof ISchemaNode) {
dialog.setSelServerName(((ISchemaNode) selected[0]).getServer().getServerName());
dialog.setSelDatabaseName(((ISchemaNode) selected[0]).getDatabase().getName());
} else if (selected != null && selected.length == 1 && selected[0] instanceof CubridServer) {
dialog.setSelServerName(((CubridServer) selected[0]).getName());
} else {
dialog.setSelServerName(DatabaseNavigatorMenu.SELF_DATABASE_SELECTED_LABEL);
}
if (dialog.open() == IDialogConstants.OK_ID) {
try {
IEditorInput input = new QueryUnit();
IEditorPart editor = window.getActivePage().openEditor(input, QueryEditorPart.ID);
((QueryEditorPart) editor).connect(DatabaseNavigatorMenu.SELF_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 CopyToClipboardAction method openNewQueryEditor.
/**
* Open the new query editor
*
* @return IEditorPart
*/
private IEditorPart openNewQueryEditor() {
IWorkbenchPage activePage = LayoutUtil.getActivePage();
QueryUnit queryUnit = new QueryUnit();
Object[] selected = getSelectedObj();
CubridDatabase database = null;
if (selected.length >= 1 && selected[0] instanceof ISchemaNode) {
database = ((ISchemaNode) selected[0]).getDatabase();
queryUnit.setDatabase(database);
}
try {
IEditorPart editor = activePage.openEditor(queryUnit, QueryEditorPart.ID);
if (editor != null && database != null) {
((QueryEditorPart) editor).connect(database);
}
return editor;
} catch (PartInitException e) {
LOGGER.error(e.getMessage());
}
return null;
}
Aggregations