Search in sources :

Example 6 with QueryUnit

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

the class SchemaInfoEditorPart method dispose.

@Override
public void dispose() {
    if (cubridNode.getType().equals(NodeType.USER_TABLE) || cubridNode.getType().equals(NodeType.USER_VIEW) || cubridNode.getType().equals(NodeType.SYSTEM_TABLE) || cubridNode.getType().equals(NodeType.SYSTEM_VIEW)) {
        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        QueryUnit unit = new QueryUnit();
        unit.setDatabase(((DefaultSchemaNode) cubridNode).getDatabase());
        try {
            IEditorPart editor = window.getActivePage().openEditor(unit, QueryEditorPart.ID);
            if (editor != null)
                ((QueryEditorPart) editor).connect(unit.getDatabase());
        } catch (PartInitException e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
    super.dispose();
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

Example 7 with QueryUnit

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

the class CopyQueryEditorAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    IEditorPart editor = window.getActivePage().getActiveEditor();
    if (editor instanceof QueryEditorPart) {
        QueryUnit queryUnit = new QueryUnit();
        QueryEditorPart qep = (QueryEditorPart) editor;
        CubridDatabase database = qep.getSelectedDatabase();
        if (database != null) {
            queryUnit.setDatabase(database);
        }
        // [TOOLS-2425]Support shard broker
        if (database != null) {
            DatabaseInfo dbInfo = database.getDatabaseInfo();
            if (dbInfo != null && dbInfo.isShard()) {
                ShardIdSelectionDialog dialog = new ShardIdSelectionDialog(Display.getDefault().getActiveShell());
                dialog.setDatabaseInfo(dbInfo);
                dialog.setShardId(0);
                if (dialog.open() == IDialogConstants.OK_ID) {
                    dbInfo.setCurrentShardId(dialog.getShardId());
                }
            }
        }
        try {
            IEditorPart newEditor = window.getActivePage().openEditor(queryUnit, QueryEditorPart.ID);
            if (newEditor != null && database != null) {
                ((QueryEditorPart) newEditor).connect(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) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ShardIdSelectionDialog(com.cubrid.common.ui.common.dialog.ShardIdSelectionDialog) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 8 with QueryUnit

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

the class DatabaseQueryNewAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    Object[] obj = this.getSelectedObj();
    CubridDatabase[] cubridDatabases = handleSelectionObj(obj);
    if (cubridDatabases.length == 0) {
        return;
    }
    /*Limit max number one time*/
    if (cubridDatabases.length > LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM) {
        CommonUITool.openConfirmBox(Messages.bind(Messages.msgMaxOpenNum, LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM));
        List<CubridDatabase> list = new ArrayList<CubridDatabase>(LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM);
        for (int i = 0; i < LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM; i++) {
            list.add(cubridDatabases[i]);
        }
        cubridDatabases = new CubridDatabase[LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM];
        list.toArray(cubridDatabases);
    }
    // [TOOLS-2425]Support shard broker
    // it is used in order to check first shard database when you open several editor of databases.
    int count = cubridDatabases.length;
    for (CubridDatabase database : cubridDatabases) {
        QueryUnit queryUnit = new QueryUnit();
        queryUnit.setDatabase(database);
        // [TOOLS-2425]Support shard broker
        DatabaseInfo dbInfo = database.getDatabaseInfo();
        if (dbInfo == null) {
            continue;
        }
        int shardId = 0;
        int shardVal = 0;
        int shardQueryType = DatabaseInfo.SHARD_QUERY_TYPE_VAL;
        if (count == 1) {
            // [TOOLS-2425]Support shard broker
            if (dbInfo != null && dbInfo.isShard()) {
                ShardIdSelectionDialog dialog = new ShardIdSelectionDialog(getShell());
                dialog.setDatabaseInfo(dbInfo);
                dialog.setShardId(shardId);
                dialog.setShardVal(shardVal);
                dialog.setShardQueryType(shardQueryType);
                if (dialog.open() == IDialogConstants.OK_ID) {
                    shardId = dialog.getShardId();
                    shardVal = dialog.getShardVal();
                    shardQueryType = dialog.getShardQueryType();
                }
            }
        }
        try {
            IEditorPart editor = window.getActivePage().openEditor(queryUnit, QueryEditorPart.ID);
            if (editor != null && database != null) {
                QueryEditorPart editorPart = (QueryEditorPart) editor;
                editorPart.connect(database);
                // [TOOLS-2425]Support shard broker
                if (dbInfo.isShard()) {
                    editorPart.setShardId(shardId);
                    editorPart.setShardVal(shardVal);
                    editorPart.setShardQueryType(shardQueryType);
                    editorPart.changeQueryEditorPartNameWithShard();
                }
            }
        } catch (PartInitException e) {
            LOGGER.error(e.getMessage());
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ArrayList(java.util.ArrayList) ShardIdSelectionDialog(com.cubrid.common.ui.common.dialog.ShardIdSelectionDialog) IEditorPart(org.eclipse.ui.IEditorPart) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) PartInitException(org.eclipse.ui.PartInitException) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 9 with QueryUnit

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

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

the class CommonUITool method openQueryEditor.

/**
	 * Open new query editor.
	 *
	 * @param database of query editor.
	 * @param careDBRunType whether care the database running type that only whether donot open the query editor if the running type is not CS.
	 * @throws PartInitException when open editor error.
	 */
public static QueryEditorPart openQueryEditor(CubridDatabase database, boolean careDBRunType) throws PartInitException {
    IWorkbenchPage page = LayoutUtil.getActivePage();
    if (page == null) {
        return null;
    }
    if (database != null && careDBRunType && database.getRunningType() != DbRunningType.CS) {
        return null;
    }
    QueryUnit input = new QueryUnit();
    input.setDatabase(database);
    IEditorPart editor = page.openEditor(input, QueryEditorPart.ID);
    if (editor != null) {
        ((QueryEditorPart) editor).connect(database);
    }
    return (QueryEditorPart) editor;
}
Also used : QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart)

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