Search in sources :

Example 41 with QueryEditorPart

use of com.cubrid.common.ui.query.editor.QueryEditorPart in project cubrid-manager by CUBRID.

the class QueryTunerRunAction method getDatabaseWithSelection.

/**
	 * get the schema information.
	 *
	 * @return schemaInfo
	 */
private CubridDatabase getDatabaseWithSelection() {
    // FIXME extract to module
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (null == window) {
        return null;
    }
    IEditorPart editor = window.getActivePage().getActiveEditor();
    if (editor == null) {
        return null;
    }
    if (!(editor instanceof QueryEditorPart)) {
        return null;
    }
    QueryEditorPart queryEditorPart = (QueryEditorPart) editor;
    CubridDatabase db = queryEditorPart.getSelectedDatabase();
    if (db == null || !db.isLogined()) {
        return null;
    }
    return db;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) IEditorPart(org.eclipse.ui.IEditorPart) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 42 with QueryEditorPart

use of com.cubrid.common.ui.query.editor.QueryEditorPart in project cubrid-manager by CUBRID.

the class QueryPropertyComposite method save.

/**
	 * 
	 * Save query options
	 */
public void save() {
    ServerInfo serverInfo = server == null ? null : server.getServerInfo();
    boolean isAutocommit = autocommitBtn.getSelection();
    boolean isEnableSearchUnit = searchUnitBtn.getSelection();
    int unitCount = unitCountSpinner.getSelection();
    int pageUnitCount = pageUnitCountSpinner.getSelection();
    int loadSize = loadSizeSpinner.getSelection();
    boolean isKeywordLowercase = keywordLowerBtn.getSelection();
    boolean isNoAutoUppercaseKeyword = autoNoUppercaseKeywordBtn.getSelection();
    boolean isWithoutPromptSave = withoutPromptSaveBtn.getSelection();
    boolean isShowMultiPageConfirm = multiPageConfirmBtn.getSelection();
    boolean isUseScientificNotation = useScientificNotationBtn.getSelection();
    QueryOptions.setAutoCommit(serverInfo, isAutocommit);
    QueryOptions.setEnableSearchUnit(serverInfo, isEnableSearchUnit);
    QueryOptions.setSearchUnitCount(serverInfo, unitCount);
    QueryOptions.setPageLimit(serverInfo, pageUnitCount);
    QueryOptions.setKeywordLowercase(serverInfo, isKeywordLowercase);
    QueryOptions.setNoAutoUppercaseKeyword(serverInfo, isNoAutoUppercaseKeyword);
    QueryOptions.setWithoutPromptSave(serverInfo, isWithoutPromptSave);
    QueryOptions.setFontColorRed(serverInfo, fontColorRed);
    QueryOptions.setFontColorGreen(serverInfo, fontColorGreen);
    QueryOptions.setFontColorBlue(serverInfo, fontColorBlue);
    QueryOptions.setFontString(serverInfo, fontString);
    QueryOptions.setShowStyle(serverInfo, true);
    QueryOptions.setUseScientificNotation(serverInfo, isUseScientificNotation);
    QueryOptions.setLobLoadSize(serverInfo, loadSize);
    QueryOptions.setMultiPageConfirm(isShowMultiPageConfirm);
    QueryOptions.savePref();
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    if (page != null) {
        IEditorReference[] editorRefs = page.getEditorReferences();
        for (IEditorReference ref : editorRefs) {
            IEditorPart editor = ref.getEditor(true);
            if (editor instanceof QueryEditorPart) {
                QueryEditorPart part = (QueryEditorPart) editor;
                part.refreshQueryOptions();
            }
        }
    }
}
Also used : QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) IEditorReference(org.eclipse.ui.IEditorReference) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart)

Example 43 with QueryEditorPart

use of com.cubrid.common.ui.query.editor.QueryEditorPart in project cubrid-manager by CUBRID.

the class PstmtSQLDialog method showResultSet.

/**
	 * Open the query editor and show result set
	 *
	 * @param parameterList List<PstmtParameter>
	 */
private void showResultSet(List<PstmtParameter> parameterList) {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    String querySql = sqlTxt.getText();
    IEditorPart editor = window.getActivePage().findEditor(editorInput);
    if (editor == null) {
        try {
            editor = window.getActivePage().openEditor(editorInput, QueryEditorPart.ID);
        } catch (PartInitException e) {
            editor = null;
        }
    }
    if (editor != null) {
        window.getActivePage().bringToTop(editor);
        QueryEditorPart queryEditor = ((QueryEditorPart) editor);
        if (!queryEditor.isConnected() && database != null) {
            queryEditor.connect(database);
        }
        String allInputSql = getCommentSqlValue(parameterList) + querySql;
        List<List<PstmtParameter>> rowParameterList = new ArrayList<List<PstmtParameter>>();
        rowParameterList.add(parameterList);
        if (queryEditor.isConnected()) {
            queryEditor.setQuery(allInputSql, querySql, rowParameterList, true, true, false);
        } else {
            queryEditor.setQuery(allInputSql, true, false, false);
        }
    }
    close();
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

Example 44 with QueryEditorPart

use of com.cubrid.common.ui.query.editor.QueryEditorPart in project cubrid-manager by CUBRID.

the class QueryNewAction method openQueryEditor.

/**
	 * Open new query editor.
	 * 
	 * @param database of query editor.
	 * @throws PartInitException when open editor error.
	 */
private void openQueryEditor(CubridDatabase database) throws PartInitException {
    IWorkbenchPage page = LayoutUtil.getActivePage();
    if (page == null) {
        return;
    }
    if (database == null) {
        page.openEditor(new QueryUnit(), QueryEditorPart.ID);
        return;
    }
    if (database != null && database.getRunningType() != DbRunningType.CS) {
        CommonUITool.openErrorBox(Messages.bind(Messages.msgStartDb, database.getLabel()));
        return;
    }
    CubridDatabase cdb = database;
    if (database == null || !database.isLogined()) {
        LoginQueryEditDialog dialog = new LoginQueryEditDialog(getShell());
        dialog.setSelServerName(getInitConnectionName(getSelectedSever()));
        dialog.setSelDatabaseName(getInitDatabaseName(database));
        if (dialog.open() == IDialogConstants.OK_ID) {
            cdb = DatabaseNavigatorMenu.SELF_DATABASE;
        } else {
            return;
        }
    }
    QueryUnit input = new QueryUnit();
    input.setDatabase(cdb);
    IEditorPart editor = page.openEditor(input, QueryEditorPart.ID);
    if (editor != null) {
        ((QueryEditorPart) editor).connect(cdb);
    }
}
Also used : QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) LoginQueryEditDialog(com.cubrid.cubridmanager.ui.common.dialog.LoginQueryEditDialog) IEditorPart(org.eclipse.ui.IEditorPart) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 45 with QueryEditorPart

use of com.cubrid.common.ui.query.editor.QueryEditorPart in project cubrid-manager by CUBRID.

the class CubridWorkbenchContrItem method openSelectQuery.

public void openSelectQuery(ISelection selection) {
    final Object obj = ((IStructuredSelection) selection).getFirstElement();
    if (!(obj instanceof ICubridNode)) {
        return;
    }
    ISchemaNode table = (ISchemaNode) obj;
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    boolean existsEditor = false;
    QueryEditorPart editor = null;
    QueryUnit input = new QueryUnit();
    input.setDatabase(table.getDatabase());
    try {
        IEditorPart editorPart = window.getActivePage().getActiveEditor();
        if (editorPart != null && editorPart instanceof QueryEditorPart) {
            QueryEditorPart queryEditorPart = (QueryEditorPart) editorPart;
            if (queryEditorPart.getSelectedDatabase() == input.getDatabase()) {
                editor = (QueryEditorPart) editorPart;
                existsEditor = true;
            }
        }
        if (editor == null) {
            editor = (QueryEditorPart) window.getActivePage().openEditor(input, QueryEditorPart.ID);
            editor.connect(table.getDatabase());
        }
        DefaultSchemaNode tableNode = (DefaultSchemaNode) obj;
        String sql = getStmtSQL(tableNode) + StringUtil.NEWLINE + StringUtil.NEWLINE;
        if (existsEditor) {
            editor.newQueryTab(sql, true);
        } else {
            editor.setQuery(sql, false, true, false);
        }
    } catch (Exception e) {
        LOGGER.error("", e);
    }
}
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) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) IEditorPart(org.eclipse.ui.IEditorPart) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) SQLException(java.sql.SQLException) PartInitException(org.eclipse.ui.PartInitException)

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