Search in sources :

Example 1 with QueryEditorPart

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

the class PstmtOneDataDialog 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();
    close();
    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);
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

Example 2 with QueryEditorPart

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

the class ObjectInfoComposite method appendToEditor.

/**
	 * Append the sql to the sqlEditor and select it
	 * 
	 * @param sql
	 */
private void appendToEditor(String sql) {
    StringBuffer queries = new StringBuffer();
    IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (part instanceof QueryEditorPart) {
        QueryEditorPart editorPart = (QueryEditorPart) part;
        SQLEditorComposite sqlEditor = editorPart.getCombinedQueryComposite().getSqlEditorComp();
        queries.append(sqlEditor.getAllQueries());
        int index = queries.length();
        if (index > 0) {
            String last = queries.substring(index - 1);
            if (!(NEWLINE.equals(last) || "\n".equals(last))) {
                queries.append(NEWLINE);
                index += NEWLINE.length();
            }
        }
        queries.append(sql);
        sqlEditor.setQueries(queries.toString());
        sqlEditor.forcusCursor(index, sql.length());
    }
}
Also used : QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) IEditorPart(org.eclipse.ui.IEditorPart)

Example 3 with QueryEditorPart

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

the class SqlPstmtAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IEditorPart editor = window.getActivePage().getActiveEditor();
    if (editor instanceof QueryEditorPart) {
        QueryEditorPart queryEditor = (QueryEditorPart) editor;
        PstmtSQLDialog dialog = new PstmtSQLDialog(queryEditor.getSite().getShell(), queryEditor.getSelectedDatabase());
        dialog.create();
        dialog.setEditorInput((QueryUnit) queryEditor.getEditorInput());
        String queries = queryEditor.getCombinedQueryComposite().getSqlEditorComp().getText().getSelectionText();
        dialog.setSql(queries);
        dialog.open();
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) PstmtSQLDialog(com.cubrid.common.ui.cubrid.table.dialog.PstmtSQLDialog) IEditorPart(org.eclipse.ui.IEditorPart)

Example 4 with QueryEditorPart

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

the class QueryOpenAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null || window.getActivePage() == null) {
        return;
    }
    IEditorPart editor = window.getActivePage().getActiveEditor();
    if (editor != null && editor.isDirty()) {
        int confirm = CommonUITool.openMsgBox(editor.getSite().getShell(), MessageDialog.WARNING, Messages.saveResource, Messages.bind(Messages.saveConfirm, editor.getTitle()), new String[] { Messages.btnYes, Messages.btnNo, Messages.cancel });
        switch(confirm) {
            case 0:
                editor.doSave(null);
                break;
            case 1:
                break;
            default:
                return;
        }
    }
    try {
        if (editor == null) {
            IEditorInput input = new QueryUnit();
            editor = window.getActivePage().openEditor(input, QueryEditorPart.ID);
        }
    } catch (PartInitException e) {
        CommonUITool.openErrorBox(e.getMessage());
    }
    if (editor == null) {
        return;
    }
    try {
        QueryEditorPart queryEditor = (QueryEditorPart) editor;
        SQLEditorComposite editorComp = queryEditor.getCombinedQueryComposite().getSqlEditorComp();
        String encoding = editorComp.getDocument().getEncoding();
        SetFileEncodingDialog dialog = new SetFileEncodingDialog(getShell(), encoding, true);
        if (IDialogConstants.OK_ID == dialog.open()) {
            editorComp.open(dialog.getFilePath(), dialog.getEncoding());
        }
    } catch (IOException e) {
        CommonUITool.openErrorBox(e.getMessage());
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) SQLEditorComposite(com.cubrid.common.ui.query.control.SQLEditorComposite) 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) IOException(java.io.IOException) SetFileEncodingDialog(com.cubrid.common.ui.query.dialog.SetFileEncodingDialog) IEditorInput(org.eclipse.ui.IEditorInput)

Example 5 with QueryEditorPart

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

the class RunQueryAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    Control control = getFocusProvider();
    if (!(control instanceof StyledText)) {
        showNoSelectionQueryError();
        return;
    }
    StyledText stext = (StyledText) control;
    String data = stext.getSelectionText();
    if (StringUtil.isEmpty(data)) {
        showNoSelectionQueryError();
        return;
    }
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        showNoSelectionQueryError();
        return;
    }
    IEditorPart editor = window.getActivePage().getActiveEditor();
    if (editor == null || !(editor instanceof QueryEditorPart)) {
        showNoSelectionQueryError();
        return;
    }
    ((QueryEditorPart) editor).runQuery(false);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Control(org.eclipse.swt.widgets.Control) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) StyledText(org.eclipse.swt.custom.StyledText) IEditorPart(org.eclipse.ui.IEditorPart)

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