Search in sources :

Example 26 with QueryEditorPart

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

the class CommonUITool method getActiveQueryEditorPart.

/**
	 * Get the active query editor
	 *
	 * @return
	 */
public static QueryEditorPart getActiveQueryEditorPart() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IEditorPart editor = window.getActivePage().getActiveEditor();
    if (editor instanceof QueryEditorPart) {
        return (QueryEditorPart) editor;
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) IEditorPart(org.eclipse.ui.IEditorPart)

Example 27 with QueryEditorPart

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

Example 28 with QueryEditorPart

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

Example 29 with QueryEditorPart

use of com.cubrid.common.ui.query.editor.QueryEditorPart 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 {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null || window.getActivePage() == null) {
        return;
    }
    if (database == null) {
        window.getActivePage().openEditor(new QueryUnit(), QueryEditorPart.ID);
        return;
    }
    CubridDatabase cdb = database;
    if (database == null || !database.isLogined()) {
        LoginQueryEditorDialog dialog = new LoginQueryEditorDialog(getShell());
        dialog.setSelectedConnName(getInitConnectionName(database));
        if (dialog.open() != IDialogConstants.OK_ID) {
            return;
        }
        cdb = DatabaseNavigatorMenu.SELF_DATABASE;
    }
    // [TOOLS-2425]Support shard broker
    boolean isShrd = false;
    int shardId = 0;
    int shardVal = 0;
    int shardQueryType = DatabaseInfo.SHARD_QUERY_TYPE_ID;
    if (cdb != null) {
        DatabaseInfo dbInfo = cdb.getDatabaseInfo();
        if (dbInfo != null && dbInfo.isShard()) {
            isShrd = true;
            ShardIdSelectionDialog dialog = new ShardIdSelectionDialog(getShell());
            dialog.setDatabaseInfo(dbInfo);
            dialog.setShardId(0);
            dialog.setShardVal(0);
            dialog.setShardQueryType(shardQueryType);
            if (dialog.open() == IDialogConstants.OK_ID) {
                shardId = dialog.getShardId();
                shardVal = dialog.getShardVal();
                shardQueryType = dialog.getShardQueryType();
            }
        }
    }
    QueryUnit input = new QueryUnit();
    input.setDatabase(cdb);
    IEditorPart editor = window.getActivePage().openEditor(input, QueryEditorPart.ID);
    if (editor != null) {
        QueryEditorPart editorPart = (QueryEditorPart) editor;
        editorPart.connect(cdb);
        // [TOOLS-2425]Support shard broker
        if (isShrd) {
            editorPart.setShardId(shardId);
            editorPart.setShardVal(shardVal);
            editorPart.setShardQueryType(shardQueryType);
            editorPart.changeQueryEditorPartNameWithShard();
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) LoginQueryEditorDialog(com.cubrid.cubridquery.ui.common.dialog.LoginQueryEditorDialog) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ShardIdSelectionDialog(com.cubrid.common.ui.common.dialog.ShardIdSelectionDialog) IEditorPart(org.eclipse.ui.IEditorPart) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 30 with QueryEditorPart

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

the class QueryNewCustomAction method openQueryEditor.

/**
	 * Open new query editor.
	 * 
	 * @param database of query editor.
	 * @throws PartInitException when open editor error.
	 */
private void openQueryEditor(CubridDatabase database) throws PartInitException {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null || window.getActivePage() == null) {
        return;
    }
    CubridDatabase cdb = DatabaseNavigatorMenu.NULL_DATABASE;
    LoginQueryEditorDialog loginDialog = new LoginQueryEditorDialog(getShell());
    loginDialog.setSelectedConnName(getInitConnectionName(database));
    if (loginDialog.open() == IDialogConstants.OK_ID) {
        cdb = DatabaseNavigatorMenu.SELF_DATABASE;
    } else {
        return;
    }
    // [TOOLS-2425]Support shard broker
    if (cdb != null) {
        DatabaseInfo dbInfo = cdb.getDatabaseInfo();
        if (dbInfo != null && dbInfo.isShard()) {
            ShardIdSelectionDialog dialog = new ShardIdSelectionDialog(getShell());
            dialog.setDatabaseInfo(dbInfo);
            dialog.setShardId(0);
            dialog.setShardVal(0);
            dialog.setShardQueryType(dbInfo.getShardQueryType());
            if (dialog.open() == IDialogConstants.OK_ID) {
                dbInfo.setCurrentShardId(dialog.getShardId());
            }
        }
    }
    QueryUnit input = new QueryUnit();
    input.setDatabase(cdb);
    IEditorPart editor = window.getActivePage().openEditor(input, QueryEditorPart.ID);
    if (editor != null) {
        ((QueryEditorPart) editor).connect(cdb);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) LoginQueryEditorDialog(com.cubrid.cubridquery.ui.common.dialog.LoginQueryEditorDialog) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ShardIdSelectionDialog(com.cubrid.common.ui.common.dialog.ShardIdSelectionDialog) IEditorPart(org.eclipse.ui.IEditorPart) 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