Search in sources :

Example 11 with QueryEditorPart

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));
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) MapperParserImpl(com.navercorp.dbtools.sqlmap.parser.MapperParserImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryCondition(com.navercorp.dbtools.sqlmap.parser.QueryCondition) Map(java.util.Map) HashMap(java.util.HashMap) MapperFile(com.navercorp.dbtools.sqlmap.parser.MapperFile)

Example 12 with QueryEditorPart

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();
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

Example 13 with QueryEditorPart

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;
}
Also used : JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) Shell(org.eclipse.swt.widgets.Shell) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) IEditorReference(org.eclipse.ui.IEditorReference) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) Job(org.eclipse.core.runtime.jobs.Job)

Example 14 with QueryEditorPart

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());
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) LoginQueryEditDialog(com.cubrid.cubridmanager.ui.common.dialog.LoginQueryEditDialog) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) IEditorInput(org.eclipse.ui.IEditorInput)

Example 15 with QueryEditorPart

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;
}
Also used : QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Aggregations

QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)51 IEditorPart (org.eclipse.ui.IEditorPart)41 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)39 QueryUnit (com.cubrid.common.ui.query.editor.QueryUnit)21 PartInitException (org.eclipse.ui.PartInitException)19 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)13 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)8 ArrayList (java.util.ArrayList)7 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)6 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)5 List (java.util.List)5 StyledText (org.eclipse.swt.custom.StyledText)5 ShardIdSelectionDialog (com.cubrid.common.ui.common.dialog.ShardIdSelectionDialog)4 CombinedQueryEditorComposite (com.cubrid.common.ui.query.control.CombinedQueryEditorComposite)4 IOException (java.io.IOException)4 IEditorReference (org.eclipse.ui.IEditorReference)4 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)3 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)3 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)3 Control (org.eclipse.swt.widgets.Control)3