Search in sources :

Example 16 with QueryUnit

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

the class FavoriteQueryNavigatorView method pasteToEditor.

private void pasteToEditor(String filename, String filepath, String charset, boolean isOpenFileMode) {
    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;
    }
    String fullpath = filepath + File.separator + filename;
    if (StringUtil.isEmpty(charset)) {
        charset = StringUtil.getDefaultCharset();
    }
    try {
        QueryEditorPart queryEditor = (QueryEditorPart) editor;
        StringBuilder sb = new StringBuilder();
        if (!isOpenFileMode) {
            sb.append("/* SQL Filename: ").append(filename).append(" */").append(StringUtil.NEWLINE);
        }
        BufferedReader in = null;
        try {
            File file = new File(fullpath);
            in = new BufferedReader(new InputStreamReader(new FileInputStream(file), charset));
            String line = in.readLine();
            while (line != null) {
                sb.append(line + StringUtil.NEWLINE);
                line = in.readLine();
            }
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (IOException e) {
            }
        }
        if (!StringUtil.isEmpty(queryEditor.getCurrentQuery())) {
            queryEditor.addEditorTab();
        }
        if (isOpenFileMode) {
            queryEditor.getCombinedQueryComposite().getSqlEditorComp().open(fullpath, charset);
        } else {
            queryEditor.setQuery(sb.toString(), false, false, false);
        }
        queryEditor.setFocus();
    } catch (IOException e) {
        CommonUITool.openErrorBox(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) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 17 with QueryUnit

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

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

Example 19 with QueryUnit

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

the class OpenQueryAction method run.

public void run() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    String fileName = null;
    try {
        SetFileEncodingDialog dialog = new SetFileEncodingDialog(getShell(), StringUtil.getDefaultCharset(), true);
        if (IDialogConstants.OK_ID != dialog.open()) {
            return;
        }
        fileName = dialog.getFilePath();
        IEditorPart editor = window.getActivePage().openEditor(new QueryUnit(), QueryEditorPart.ID);
        if (editor == null) {
            return;
        }
        QueryEditorPart queryEditor = (QueryEditorPart) editor;
        queryEditor.getCombinedQueryComposite().getSqlEditorComp().open(dialog.getFilePath(), dialog.getEncoding());
        Object[] obj = this.getSelectedObj();
        CubridDatabase[] cubridDatabases = handleSelectionObj(obj);
        if (cubridDatabases.length > 0 && cubridDatabases[0] != null) {
            ((QueryEditorPart) editor).connect(cubridDatabases[0]);
        }
    } catch (PartInitException e) {
        LOGGER.error("Can not initialize the query editor UI.", e);
    } catch (IOException e) {
        LOGGER.error("Can not open the {} file.", fileName, e);
        //TODO: message localizing
        CommonUITool.openErrorBox(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) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SetFileEncodingDialog(com.cubrid.common.ui.query.dialog.SetFileEncodingDialog)

Example 20 with QueryUnit

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

the class BrokerLogParserAction method run.

public void run() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    BrokerLogParserDialog dialog = new BrokerLogParserDialog(window.getShell());
    dialog.open();
    if (dialog.getReturnCode() != IDialogConstants.OK_ID) {
        return;
    }
    String sql = dialog.getResultSql();
    try {
        QueryUnit input = new QueryUnit();
        QueryEditorPart editor = (QueryEditorPart) window.getActivePage().openEditor(input, QueryEditorPart.ID);
        editor.setQuery(sql, false, false, false);
    } catch (PartInitException e) {
        LOGGER.debug("Failed sql is {}.", sql);
        LOGGER.error("Can not parse broker sql log.", e);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) BrokerLogParserDialog(com.cubrid.common.ui.common.dialog.BrokerLogParserDialog) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) PartInitException(org.eclipse.ui.PartInitException)

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