Search in sources :

Example 1 with RunSQLFileEditorInput

use of com.cubrid.common.ui.common.sqlrunner.part.RunSQLFileEditorInput in project cubrid-manager by CUBRID.

the class RunSQLFileDialog method buttonPressed.

/**
	 * When press button,call it
	 * 
	 * @param buttonId the button id
	 */
protected void buttonPressed(int buttonId) {
    if (buttonId == IDialogConstants.OK_ID) {
        if (!validate()) {
            return;
        }
        for (CubridDatabase database : cubridDatabases) {
            RunSQLFileEditorInput input = new RunSQLFileEditorInput(database, filesList, fileCharsetCombo.getText(), threadCountSpinner.getSelection(), commitCountSpinner.getSelection(), saveErrExcelPath.getText());
            try {
                IWorkbench workbench = PlatformUI.getWorkbench();
                IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
                workbenchWindow.getActivePage().openEditor(input, RunSQLFileViewPart.ID);
            } catch (Exception e) {
                LOGGER.error("", e);
            }
        }
    }
    setReturnCode(buttonId);
    close();
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) RunSQLFileEditorInput(com.cubrid.common.ui.common.sqlrunner.part.RunSQLFileEditorInput) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 2 with RunSQLFileEditorInput

use of com.cubrid.common.ui.common.sqlrunner.part.RunSQLFileEditorInput 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)

Aggregations

RunSQLFileEditorInput (com.cubrid.common.ui.common.sqlrunner.part.RunSQLFileEditorInput)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)1 QueryUnit (com.cubrid.common.ui.query.editor.QueryUnit)1 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 List (java.util.List)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IWorkbench (org.eclipse.ui.IWorkbench)1 PartInitException (org.eclipse.ui.PartInitException)1