Search in sources :

Example 21 with QueryEditorPart

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

the class GotoLineDialog method getActiveSQLEditorComposite.

/**
	 * 
	 * Get active SQL editor composite
	 * 
	 * @return SQLEditorComposite
	 */
private SQLEditorComposite getActiveSQLEditorComposite() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IEditorPart editor = window.getActivePage().getActiveEditor();
    if (editor instanceof QueryEditorPart) {
        QueryEditorPart queryEditor = (QueryEditorPart) editor;
        return queryEditor.getCombinedQueryComposite().getSqlEditorComp();
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) IEditorPart(org.eclipse.ui.IEditorPart)

Example 22 with QueryEditorPart

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

the class BatchRunDialog method buttonPressed.

/**
	 * Call this method when the button in button bar is pressed
	 * 
	 * @param buttonId the button id
	 */
protected void buttonPressed(int buttonId) {
    if (buttonId == RUN_ID) {
        if (!MessageDialog.openConfirm(PlatformUI.getWorkbench().getDisplay().getActiveShell(), Messages.titleBatchRunConfirm, Messages.msgBatchRunConfirm)) {
            return;
        }
        List<String> fileList = container.getFileList();
        RunSQLFileEditorInput input = new RunSQLFileEditorInput(cubridDatabase, fileList);
        try {
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, RunSQLFileViewPart.ID);
        } catch (Exception e) {
            LOGGER.error(e.getLocalizedMessage());
        }
        super.buttonPressed(IDialogConstants.OK_ID);
    } else if (buttonId == PASTE_ID) {
        //			if (!MessageDialog.openConfirm(
        //					PlatformUI.getWorkbench().getDisplay().getActiveShell(),
        //					Messages.titleBatchRunConfirm, Messages.msgBatchRunPasteConfirm)) {
        //				return;
        //			}
        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (window == null || window.getActivePage() == null) {
            return;
        }
        IEditorPart editor = window.getActivePage().getActiveEditor();
        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;
        }
        QueryEditorPart oldEditor = (QueryEditorPart) editor;
        try {
            QueryEditorPart queryEditor = (QueryEditorPart) editor;
            String encoding = queryEditor.getCombinedQueryComposite().getSqlEditorComp().getDocument().getEncoding();
            StringBuilder sb = new StringBuilder();
            List<String> fileList = container.getFileList();
            for (int i = 0; i < fileList.size(); i++) {
                sb.delete(0, sb.length());
                sb.append("/* SQL Filename: ").append(fileList.get(i)).append(" */").append(StringUtil.NEWLINE);
                BufferedReader in = null;
                try {
                    in = new BufferedReader(new InputStreamReader(new FileInputStream(new File(fileList.get(i))), encoding));
                    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) {
                    }
                }
                try {
                    QueryUnit input = new QueryUnit();
                    QueryEditorPart newEditor = (QueryEditorPart) window.getActivePage().openEditor(input, QueryEditorPart.ID);
                    newEditor.setQuery(sb.toString(), false, false, false);
                    newEditor.connect(oldEditor.getSelectedDatabase());
                } catch (Exception e) {
                    CommonUITool.openErrorBox(e.getMessage());
                }
            }
        } catch (IOException e) {
            CommonUITool.openErrorBox(e.getMessage());
        }
        super.buttonPressed(IDialogConstants.OK_ID);
    } else {
        super.buttonPressed(buttonId);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) InputStreamReader(java.io.InputStreamReader) RunSQLFileEditorInput(com.cubrid.common.ui.common.sqlrunner.part.RunSQLFileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) IOException(java.io.IOException) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) BufferedReader(java.io.BufferedReader) List(java.util.List) PartInitException(org.eclipse.ui.PartInitException) File(java.io.File) IEditorInput(org.eclipse.ui.IEditorInput)

Example 23 with QueryEditorPart

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

the class ReformatColumnsAliasDialog method getActiveSQLEditorComposite.

private SQLEditorComposite getActiveSQLEditorComposite() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IEditorPart editor = window.getActivePage().getActiveEditor();
    if (editor instanceof QueryEditorPart) {
        QueryEditorPart queryEditor = (QueryEditorPart) editor;
        return queryEditor.getCombinedQueryComposite().getSqlEditorComp();
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) IEditorPart(org.eclipse.ui.IEditorPart)

Example 24 with QueryEditorPart

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

the class LayoutUtil method checkAllQueryEditor.

/**
	 * 
	 * When server disconnect or delete,check query editor whether some
	 * transaction are not commit
	 * 
	 * @param cubridServer the CubridServer object
	 * @return <code>true</code> if transaction is commited;<code>false</code>
	 *         otherwise
	 */
public static boolean checkAllQueryEditor(CubridServer cubridServer) {
    IWorkbenchPage page = getActivePage();
    if (page == null) {
        return true;
    }
    IEditorReference[] editorRefArr = page.getEditorReferences();
    if (editorRefArr == null || editorRefArr.length == 0) {
        return true;
    }
    boolean isContinue = true;
    for (IEditorReference editorRef : editorRefArr) {
        String editorId = editorRef.getId();
        if (editorId != null && editorId.equals(QueryEditorPart.ID)) {
            QueryEditorPart queryEditor = (QueryEditorPart) editorRef.getEditor(false);
            CubridDatabase db = queryEditor.getSelectedDatabase();
            if (db != null && db.getServer() != null && db.getServer().getId().equals(cubridServer.getId())) {
                isContinue = queryEditor.resetJDBCConnection();
            }
        }
    }
    return isContinue;
}
Also used : QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 25 with QueryEditorPart

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

the class LayoutUtil method checkAllQueryEditor.

/**
	 * 
	 * When database logout or stop,check query editor whether some transaction
	 * are not commit
	 * 
	 * @param databaseNode the CubridDatabase object
	 * @return <code>true</code> if transaction is commited;<code>false</code>
	 *         otherwise
	 */
public static boolean checkAllQueryEditor(CubridDatabase databaseNode) {
    IWorkbenchPage page = getActivePage();
    if (page == null) {
        return true;
    }
    boolean isContinue = true;
    IEditorReference[] editorRefArr = page.getEditorReferences();
    if (editorRefArr == null || editorRefArr.length == 0) {
        return true;
    }
    for (IEditorReference editorRef : editorRefArr) {
        String editorId = editorRef.getId();
        if (editorId != null && editorId.equals(QueryEditorPart.ID)) {
            QueryEditorPart queryEditor = (QueryEditorPart) editorRef.getEditor(false);
            CubridDatabase db = queryEditor.getSelectedDatabase();
            if (db != null && db.getId().equals(databaseNode.getId())) {
                isContinue = queryEditor.resetJDBCConnection();
            }
        }
    }
    return isContinue;
}
Also used : QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) 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