Search in sources :

Example 1 with QueryUnit

use of com.cubrid.common.ui.query.editor.QueryUnit 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 2 with QueryUnit

use of com.cubrid.common.ui.query.editor.QueryUnit 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 3 with QueryUnit

use of com.cubrid.common.ui.query.editor.QueryUnit 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 4 with QueryUnit

use of com.cubrid.common.ui.query.editor.QueryUnit 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)

Example 5 with QueryUnit

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

the class TableSelectAllAction method doRun.

private void doRun(ISchemaNode table) {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    QueryUnit input = new QueryUnit();
    input.setDatabase(table.getDatabase());
    try {
        QueryEditorPart editor = (QueryEditorPart) window.getActivePage().openEditor(input, QueryEditorPart.ID);
        editor.connect(table.getDatabase());
        // FIXME move this logic to core module
        String escapedTableName = QuerySyntax.escapeKeyword(table.getName());
        String sql = "SELECT * FROM " + escapedTableName + ";";
        if (table.getDatabase() != null) {
            sql = DatabaseInfo.wrapShardQuery(table.getDatabase().getDatabaseInfo(), sql);
        }
        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)

Aggregations

QueryUnit (com.cubrid.common.ui.query.editor.QueryUnit)22 QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)21 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)19 IEditorPart (org.eclipse.ui.IEditorPart)18 PartInitException (org.eclipse.ui.PartInitException)17 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)7 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)5 ShardIdSelectionDialog (com.cubrid.common.ui.common.dialog.ShardIdSelectionDialog)4 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)3 IEditorInput (org.eclipse.ui.IEditorInput)3 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)3 SetFileEncodingDialog (com.cubrid.common.ui.query.dialog.SetFileEncodingDialog)2 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)2 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)2 LoginQueryEditDialog (com.cubrid.cubridmanager.ui.common.dialog.LoginQueryEditDialog)2 LoginQueryEditorDialog (com.cubrid.cubridquery.ui.common.dialog.LoginQueryEditorDialog)2 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2