Search in sources :

Example 6 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class ActionUtils method findCommandDescription.

@Nullable
public static String findCommandDescription(String commandId, IServiceLocator serviceLocator, boolean shortcutOnly) {
    String commandName = null;
    String shortcut = null;
    ICommandService commandService = serviceLocator.getService(ICommandService.class);
    if (commandService != null) {
        Command command = commandService.getCommand(commandId);
        if (command != null && command.isDefined()) {
            try {
                commandName = command.getName();
            } catch (NotDefinedException e) {
                log.debug(e);
            }
        }
    }
    IBindingService bindingService = serviceLocator.getService(IBindingService.class);
    if (bindingService != null) {
        TriggerSequence sequence = null;
        for (Binding b : bindingService.getBindings()) {
            ParameterizedCommand parameterizedCommand = b.getParameterizedCommand();
            if (parameterizedCommand != null && commandId.equals(parameterizedCommand.getId())) {
                sequence = b.getTriggerSequence();
            }
        }
        if (sequence == null) {
            sequence = bindingService.getBestActiveBindingFor(commandId);
        }
        if (sequence != null) {
            shortcut = sequence.format();
        }
    }
    if (shortcutOnly) {
        return shortcut == null ? "?" : shortcut;
    }
    if (shortcut == null) {
        return commandName;
    }
    if (commandName == null) {
        return shortcut;
    }
    return commandName + " (" + shortcut + ")";
}
Also used : Binding(org.eclipse.jface.bindings.Binding) TriggerSequence(org.eclipse.jface.bindings.TriggerSequence) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Command(org.eclipse.core.commands.Command) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) IBindingService(org.eclipse.ui.keys.IBindingService) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) ICommandService(org.eclipse.ui.commands.ICommandService) Nullable(org.jkiss.code.Nullable)

Example 7 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class SQLEditor method getCurrentLines.

@Nullable
@Override
public int[] getCurrentLines() {
    synchronized (runningQueries) {
        Document document = getDocument();
        if (document == null || runningQueries.isEmpty()) {
            return null;
        }
        List<Integer> lines = new ArrayList<>(runningQueries.size() * 2);
        for (SQLQuery statementInfo : runningQueries) {
            try {
                int firstLine = document.getLineOfOffset(statementInfo.getOffset());
                int lastLine = document.getLineOfOffset(statementInfo.getOffset() + statementInfo.getLength());
                for (int k = firstLine; k <= lastLine; k++) {
                    lines.add(k);
                }
            } catch (BadLocationException e) {
            // ignore - this may happen is SQL was edited after execution start
            }
        }
        if (lines.isEmpty()) {
            return null;
        }
        int[] results = new int[lines.size()];
        for (int i = 0; i < lines.size(); i++) {
            results[i] = lines.get(i);
        }
        return results;
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SQLQuery(org.jkiss.dbeaver.model.sql.SQLQuery) Point(org.eclipse.swt.graphics.Point) Nullable(org.jkiss.code.Nullable)

Example 8 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class GenerateSQLContributor method getSelectionFromPart.

@Nullable
static IStructuredSelection getSelectionFromPart(IWorkbenchPart part) {
    if (part == null) {
        return null;
    }
    ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
    if (selectionProvider == null) {
        return null;
    }
    ISelection selection = selectionProvider.getSelection();
    if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
        return null;
    }
    return (IStructuredSelection) selection;
}
Also used : ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Nullable(org.jkiss.code.Nullable)

Example 9 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class JDBCCallableStatementImpl method getResultSet.

@Nullable
@Override
public JDBCResultSet getResultSet() throws SQLException {
    JDBCResultSet resultSet = makeResultSet(getOriginal().getResultSet());
    if (resultSet == null && procedure != null) {
        JDBCResultSetCallable procResults = new JDBCResultSetCallable(getConnection(), this);
        try {
            Collection<? extends DBSProcedureParameter> params = procedure.getParameters(getConnection().getProgressMonitor());
            if (!CommonUtils.isEmpty(params)) {
                for (DBSProcedureParameter param : params) {
                    if (param.getParameterKind() == DBSProcedureParameterKind.OUT || param.getParameterKind() == DBSProcedureParameterKind.INOUT) {
                        procResults.addColumn(param.getName(), param.getParameterType());
                    }
                }
            }
        } catch (DBException e) {
            log.warn("Error extracting callable results", e);
        }
        procResults.addRow();
        return procResults;
    }
    return resultSet;
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBSProcedureParameter(org.jkiss.dbeaver.model.struct.rdb.DBSProcedureParameter) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) Nullable(org.jkiss.code.Nullable)

Example 10 with Nullable

use of org.jkiss.code.Nullable in project dbeaver by serge-rider.

the class SCMRoot method parseComposite.

@Nullable
@Override
public IToken parseComposite(@NotNull SCMSourceScanner scanner) {
    for (; ; ) {
        IToken token = scanner.nextToken();
        if (token.isEOF()) {
            break;
        }
        parseToken(this, token);
    }
    return null;
}
Also used : IToken(org.eclipse.jface.text.rules.IToken) Nullable(org.jkiss.code.Nullable)

Aggregations

Nullable (org.jkiss.code.Nullable)49 DBException (org.jkiss.dbeaver.DBException)6 Tree (org.eclipse.swt.widgets.Tree)5 TreeColumn (org.eclipse.swt.widgets.TreeColumn)5 TreeItem (org.eclipse.swt.widgets.TreeItem)5 NotNull (org.jkiss.code.NotNull)5 SQLException (java.sql.SQLException)4 Matcher (java.util.regex.Matcher)4 SQLScriptStatusDialog (org.jkiss.dbeaver.ui.dialogs.sql.SQLScriptStatusDialog)4 DB2TableColumn (org.jkiss.dbeaver.ext.db2.model.DB2TableColumn)3 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)3 DBCResultSet (org.jkiss.dbeaver.model.exec.DBCResultSet)3 DBCStatement (org.jkiss.dbeaver.model.exec.DBCStatement)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 IProject (org.eclipse.core.resources.IProject)2 IStatus (org.eclipse.core.runtime.IStatus)2 IFindReplaceTarget (org.eclipse.jface.text.IFindReplaceTarget)2 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)2 Font (org.eclipse.swt.graphics.Font)2