Search in sources :

Example 21 with DBSObjectContainer

use of org.jkiss.dbeaver.model.struct.DBSObjectContainer in project dbeaver by dbeaver.

the class SQLCompletionProposal method apply.

@Override
public void apply(IDocument document) {
    try {
        String replaceOn = replacementString;
        if (replacementAfter != null) {
            replaceOn += replacementAfter;
        }
        if (dataSource != null) {
            if (dataSource.getContainer().getPreferenceStore().getBoolean(SQLPreferenceConstants.INSERT_SPACE_AFTER_PROPOSALS)) {
                boolean insertTrailingSpace;
                if (object instanceof DBSObjectContainer) {
                // Do not append trailing space after schemas/catalogs/etc.
                } else {
                    int docLen = document.getLength();
                    if (docLen <= replacementOffset + replacementLength + 2) {
                        insertTrailingSpace = true;
                    } else {
                        insertTrailingSpace = document.getChar(replacementOffset + replacementLength) != ' ';
                    }
                    if (insertTrailingSpace) {
                        replaceOn += " ";
                    }
                    cursorPosition++;
                }
            }
        }
        document.replace(replacementOffset, replacementLength, replaceOn);
    } catch (BadLocationException e) {
        // ignore
        log.debug(e);
    }
}
Also used : DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) Point(org.eclipse.swt.graphics.Point) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

DBSObjectContainer (org.jkiss.dbeaver.model.struct.DBSObjectContainer)21 DBException (org.jkiss.dbeaver.DBException)9 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)9 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)5 DBXTreeNode (org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode)5 DBSObjectSelector (org.jkiss.dbeaver.model.struct.DBSObjectSelector)4 DataSourceDescriptor (org.jkiss.dbeaver.registry.DataSourceDescriptor)4 GridData (org.eclipse.swt.layout.GridData)3 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)3 DBSSchema (org.jkiss.dbeaver.model.struct.rdb.DBSSchema)3 CSmartCombo (org.jkiss.dbeaver.ui.controls.CSmartCombo)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 IStatus (org.eclipse.core.runtime.IStatus)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 TemplateVariable (org.eclipse.jface.text.templates.TemplateVariable)2 Point (org.eclipse.swt.graphics.Point)2 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)2 DBPDataSourceInfo (org.jkiss.dbeaver.model.DBPDataSourceInfo)2 DBPSystemObject (org.jkiss.dbeaver.model.DBPSystemObject)2