Search in sources :

Example 16 with QueryEditorPart

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

the class CopyToClipboardAction method doRun.

/**
	 * Do run
	 * 
	 * @param objects
	 */
protected void doRun(final Object[] objects) {
    final int len = objects.length;
    final Display display = PlatformUI.getWorkbench().getDisplay();
    BusyIndicator.showWhile(display, new Runnable() {

        public void run() {
            IEditorPart ep = null;
            if (isCopyToEditor) {
                IWorkbenchPage activePage = LayoutUtil.getActivePage();
                ep = activePage.getActiveEditor();
                if (!(ep instanceof QueryEditorPart)) {
                    ep = openNewQueryEditor();
                }
                if (!(ep instanceof QueryEditorPart)) {
                    ep = null;
                }
            }
            StringBuffer allTableSql = new StringBuffer();
            for (int i = 0; i < len; i++) {
                DefaultSchemaNode table = (DefaultSchemaNode) objects[i];
                String sql = getStmtSQL(table, ep);
                if (sql != null && sql.trim().length() > 0) {
                    allTableSql.append(sql);
                    allTableSql.append(StringUtil.NEWLINE);
                    allTableSql.append(StringUtil.NEWLINE);
                }
            }
            if (allTableSql.length() > 0) {
                if (isCopyToEditor) {
                    if (ep instanceof QueryEditorPart) {
                        ((QueryEditorPart) ep).setQuery(allTableSql.toString(), true, false, false);
                    }
                } else {
                    CommonUITool.copyContentToClipboard(allTableSql.toString());
                }
            }
        }
    });
}
Also used : QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) Display(org.eclipse.swt.widgets.Display)

Example 17 with QueryEditorPart

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

Example 18 with QueryEditorPart

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

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

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

the class FindReplaceAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IEditorPart editor = window.getActivePage().getActiveEditor();
    if (editor instanceof QueryEditorPart) {
        QueryEditorPart queryEditor = (QueryEditorPart) editor;
        queryEditor.find();
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) IEditorPart(org.eclipse.ui.IEditorPart)

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