Search in sources :

Example 11 with SQLEditorBase

use of org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase in project dbeaver by serge-rider.

the class SQLEditorHandlerNavigateQuery method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (!(activeEditor instanceof SQLEditorBase)) {
        return null;
    }
    SQLEditorBase editor = (SQLEditorBase) activeEditor;
    String actionId = event.getCommand().getId();
    SQLScriptElement nextQuery;
    switch(actionId) {
        case SQLEditorCommands.CMD_SQL_QUERY_NEXT:
            nextQuery = editor.extractNextQuery(true);
            break;
        case SQLEditorCommands.CMD_SQL_QUERY_PREV:
            nextQuery = editor.extractNextQuery(false);
            break;
        default:
            nextQuery = null;
            break;
    }
    if (nextQuery != null) {
        editor.selectAndReveal(nextQuery.getOffset(), nextQuery.getLength());
    }
    return null;
}
Also used : SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) SQLScriptElement(org.jkiss.dbeaver.model.sql.SQLScriptElement) IEditorPart(org.eclipse.ui.IEditorPart)

Example 12 with SQLEditorBase

use of org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase in project dbeaver by serge-rider.

the class BaseSQLDialog method createSQLPanel.

protected Composite createSQLPanel(Composite parent) {
    Composite panel = UIUtils.createPlaceholder(parent, 1);
    panel.setLayoutData(new GridData(GridData.FILL_BOTH));
    if (isLabelVisible()) {
        UIUtils.createControlLabel(panel, SQLEditorMessages.pref_page_sql_format_label_SQLPreview);
    }
    // new Label(panel, SWT.SEPARATOR | SWT.HORIZONTAL).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Composite editorPH = new Composite(panel, SWT.BORDER);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.verticalIndent = 3;
    gd.horizontalSpan = 1;
    gd.minimumHeight = 100;
    gd.minimumWidth = 100;
    editorPH.setLayoutData(gd);
    editorPH.setLayout(new FillLayout());
    sqlViewer = new SQLEditorBase() {

        @NotNull
        @Override
        public SQLDialect getSQLDialect() {
            return BaseSQLDialog.this.getSQLDialect();
        }

        @Override
        public DBCExecutionContext getExecutionContext() {
            return BaseSQLDialog.this.getExecutionContext();
        }
    };
    updateSQL();
    sqlViewer.createPartControl(editorPH);
    if (isWordWrap()) {
        Object text = sqlViewer.getAdapter(Control.class);
        if (text instanceof StyledText) {
            ((StyledText) text).setWordWrap(true);
        }
    }
    sqlViewer.reloadSyntaxRules();
    return panel;
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) BasicSQLDialect(org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect) SQLDialect(org.jkiss.dbeaver.model.sql.SQLDialect) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) NotNull(org.jkiss.code.NotNull)

Example 13 with SQLEditorBase

use of org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase in project dbeaver by serge-rider.

the class WorkbenchContextListener method partDeactivated.

@Override
public void partDeactivated(IWorkbenchPart part) {
    IContextService contextService = PlatformUI.getWorkbench().getService(IContextService.class);
    if (contextService == null) {
        return;
    }
    try {
        contextService.deferUpdates(true);
        if (activationNavigator != null && part instanceof INavigatorModelView) {
            contextService.deactivateContext(activationNavigator);
            activationNavigator = null;
        }
        if (activationSQL != null && part instanceof SQLEditorBase) {
            contextService.deactivateContext(activationSQL);
            activationSQL = null;
        }
    } finally {
        contextService.deferUpdates(false);
    }
//        log.info(part.getClass().getSimpleName() + " DEACTIVATED: " + contextService.getActiveContextIds());
}
Also used : SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) IContextService(org.eclipse.ui.contexts.IContextService) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView)

Example 14 with SQLEditorBase

use of org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase in project dbeaver by serge-rider.

the class BaseSQLDialog method createSQLPanel.

protected Composite createSQLPanel(Composite parent) {
    Composite panel = UIUtils.createPlaceholder(parent, 1);
    panel.setLayoutData(new GridData(GridData.FILL_BOTH));
    if (isLabelVisible()) {
        UIUtils.createControlLabel(panel, "SQL Preview");
    }
    //        new Label(panel, SWT.SEPARATOR | SWT.HORIZONTAL).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Composite editorPH = new Composite(panel, SWT.BORDER);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.verticalIndent = 3;
    gd.horizontalSpan = 1;
    gd.minimumHeight = 100;
    gd.minimumWidth = 100;
    editorPH.setLayoutData(gd);
    editorPH.setLayout(new FillLayout());
    sqlViewer = new SQLEditorBase() {

        @NotNull
        @Override
        protected SQLDialect getSQLDialect() {
            return BaseSQLDialog.this.getSQLDialect();
        }

        @Override
        public DBCExecutionContext getExecutionContext() {
            return BaseSQLDialog.this.getExecutionContext();
        }
    };
    updateSQL();
    sqlViewer.createPartControl(editorPH);
    if (isWordWrap()) {
        Object text = sqlViewer.getAdapter(Control.class);
        if (text instanceof StyledText) {
            ((StyledText) text).setWordWrap(true);
        }
    }
    sqlViewer.reloadSyntaxRules();
    parent.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            sqlViewer.dispose();
        }
    });
    return panel;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) SQLDialect(org.jkiss.dbeaver.model.sql.SQLDialect) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) DisposeEvent(org.eclipse.swt.events.DisposeEvent) NotNull(org.jkiss.code.NotNull)

Example 15 with SQLEditorBase

use of org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase in project dbeaver by serge-rider.

the class NavigateObjectHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (activeEditor instanceof SQLEditorBase) {
        SQLEditorBase editor = (SQLEditorBase) activeEditor;
        IHyperlink hyperlink = getCurrentHyperlink(editor);
        if (hyperlink != null) {
            IRegion selRegion2 = hyperlink.getHyperlinkRegion();
            editor.getTextViewer().setSelectedRange(selRegion2.getOffset(), selRegion2.getLength());
            hyperlink.open();
        }
    }
    return null;
}
Also used : SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) IEditorPart(org.eclipse.ui.IEditorPart) IRegion(org.eclipse.jface.text.IRegion)

Aggregations

SQLEditorBase (org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase)25 IEditorPart (org.eclipse.ui.IEditorPart)14 StyledText (org.eclipse.swt.custom.StyledText)7 FillLayout (org.eclipse.swt.layout.FillLayout)7 GridData (org.eclipse.swt.layout.GridData)7 DisposeEvent (org.eclipse.swt.events.DisposeEvent)4 DisposeListener (org.eclipse.swt.events.DisposeListener)4 Composite (org.eclipse.swt.widgets.Composite)4 NotNull (org.jkiss.code.NotNull)4 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)4 StringEditorInput (org.jkiss.dbeaver.ui.editors.StringEditorInput)4 SubEditorSite (org.jkiss.dbeaver.ui.editors.SubEditorSite)4 InputStream (java.io.InputStream)3 IRegion (org.eclipse.jface.text.IRegion)3 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 IContextService (org.eclipse.ui.contexts.IContextService)3 SQLDialect (org.jkiss.dbeaver.model.sql.SQLDialect)3 EntityEditor (org.jkiss.dbeaver.ui.editors.entity.EntityEditor)3