Search in sources :

Example 16 with SQLEditorBase

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

the class PackageNavigateHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final OracleProcedurePackaged procedure = getSelectedProcedure(event);
    if (procedure != null) {
        OraclePackage procPackage = procedure.getParentObject();
        IEditorPart entityEditor = NavigatorHandlerObjectOpen.openEntityEditor(procPackage);
        if (entityEditor instanceof EntityEditor) {
            ((EntityEditor) entityEditor).switchFolder("source.definition");
            SQLEditorBase sqlEditor = entityEditor.getAdapter(SQLEditorBase.class);
            if (sqlEditor != null) {
                new NavigateJob(procedure, sqlEditor).schedule();
            }
        }
    }
    return null;
}
Also used : OracleProcedurePackaged(org.jkiss.dbeaver.ext.oracle.model.OracleProcedurePackaged) OraclePackage(org.jkiss.dbeaver.ext.oracle.model.OraclePackage) SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) IEditorPart(org.eclipse.ui.IEditorPart)

Example 17 with SQLEditorBase

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

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;
        }
        if (activationResults != null) {
            contextService.deactivateContext(activationResults);
            activationResults = 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 18 with SQLEditorBase

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

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
        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();
    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) 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) DisposeEvent(org.eclipse.swt.events.DisposeEvent) NotNull(org.jkiss.code.NotNull)

Example 19 with SQLEditorBase

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

the class ResultSetFilterPanel method createObjectPanel.

@NotNull
private Control createObjectPanel(Shell popup) throws PartInitException {
    Composite panel = new Composite(popup, SWT.NONE);
    GridLayout gl = new GridLayout(2, false);
    // gl.marginWidth = 0;
    gl.marginHeight = 0;
    // gl.horizontalSpacing = 0;
    panel.setLayout(gl);
    Label iconLabel = new Label(panel, SWT.NONE);
    DBPImage activeObjectImage = getActiveObjectImage();
    if (activeObjectImage != null) {
        iconLabel.setImage(DBeaverIcons.getImage(activeObjectImage));
    }
    iconLabel.setToolTipText(CoreMessages.sql_editor_resultset_filter_panel_label);
    iconLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    iconLabel.setCursor(getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    iconLabel.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseUp(MouseEvent e) {
            openEditorForActiveQuery();
        }
    });
    Composite editorPH = new Composite(panel, SWT.NONE);
    editorPH.setLayoutData(new GridData(GridData.FILL_BOTH));
    editorPH.setLayout(new FillLayout());
    final SQLEditorBase editor = new SQLEditorBase() {

        @Nullable
        @Override
        public DBCExecutionContext getExecutionContext() {
            return viewer.getExecutionContext();
        }

        @Override
        public void createPartControl(Composite parent) {
            super.createPartControl(parent);
            getAction(ITextEditorActionConstants.CONTEXT_PREFERENCES).setEnabled(false);
        }

        @Override
        public boolean isFoldingEnabled() {
            return false;
        }
    };
    editor.setHasVerticalRuler(false);
    editor.init(new SubEditorSite(viewer.getSite()), new StringEditorInput(DEFAULT_QUERY_TEXT, getActiveQueryText(), true, GeneralUtils.getDefaultFileEncoding()));
    editor.createPartControl(editorPH);
    editor.reloadSyntaxRules();
    StyledText textWidget = editor.getTextViewer().getTextWidget();
    // textWidget.setAlwaysShowScrollBars(false);
    panel.setBackground(textWidget.getBackground());
    panel.addDisposeListener(e -> editor.dispose());
    return textWidget;
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) FillLayout(org.eclipse.swt.layout.FillLayout) StringEditorInput(org.jkiss.dbeaver.ui.editors.StringEditorInput) SubEditorSite(org.jkiss.dbeaver.ui.editors.SubEditorSite) GridLayout(org.eclipse.swt.layout.GridLayout) SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) GridData(org.eclipse.swt.layout.GridData) NotNull(org.jkiss.code.NotNull)

Example 20 with SQLEditorBase

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

the class SQLCompletionAnalyzer method createCompletionProposal.

/*
        * Turns the vector into an Array of ICompletionProposal objects
        */
static SQLCompletionProposal createCompletionProposal(CompletionRequest request, String replaceString, String displayString, DBPKeywordType proposalType, @Nullable DBPImage image, boolean isObject, @Nullable DBPNamedObject object) {
    SQLEditorBase editor = request.editor;
    DBPPreferenceStore store = editor.getActivePreferenceStore();
    DBPDataSource dataSource = editor.getDataSource();
    if (dataSource != null) {
        if (isObject) {
        // Escape replace string if required
        // FIXME: do not escape! it may (will) escape identifiers twice
        // replaceString = DBUtils.getQuotedIdentifier(dataSource, replaceString);
        }
    }
    // If we have quoted string then ignore pref settings
    boolean quotedString = request.wordDetector.isQuoted(replaceString);
    if (!quotedString) {
        final int proposalCase = store.getInt(SQLPreferenceConstants.PROPOSAL_INSERT_CASE);
        switch(proposalCase) {
            case SQLPreferenceConstants.PROPOSAL_CASE_UPPER:
                replaceString = replaceString.toUpperCase();
                break;
            case SQLPreferenceConstants.PROPOSAL_CASE_LOWER:
                replaceString = replaceString.toLowerCase();
                break;
            default:
                // Do not convert case if we got it directly from object
                if (!isObject) {
                    SQLDialect dialect = editor.getSyntaxManager().getDialect();
                    DBPKeywordType keywordType = dialect.getKeywordType(replaceString);
                    if (keywordType == DBPKeywordType.KEYWORD) {
                        replaceString = editor.getSyntaxManager().getKeywordCase().transform(replaceString);
                    } else {
                        replaceString = dialect.storesUnquotedCase().transform(replaceString);
                    }
                }
                break;
        }
    }
    Image img = image == null ? null : DBeaverIcons.getImage(image);
    return new SQLCompletionProposal(request, displayString, // replacementString
    replaceString, // cursorPosition the position of the cursor following the insert
    replaceString.length(), // image to display
    img, // new ContextInformation(img, displayString, displayString), //the context information associated with this proposal
    null, proposalType, null, object);
}
Also used : SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) Image(org.eclipse.swt.graphics.Image) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)

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