Search in sources :

Example 16 with Nullable

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

the class DBNModel method getParentNode.

@Nullable
public DBNDatabaseNode getParentNode(DBSObject object) {
    DBNDatabaseNode node = getNodeByObject(object);
    if (node != null) {
        if (node.getParentNode() instanceof DBNDatabaseNode) {
            return (DBNDatabaseNode) node.getParentNode();
        } else {
            log.error("Object's " + object.getName() + "' parent node is not a database node: " + node.getParentNode());
            return null;
        }
    }
    DBSObject[] path = DBUtils.getObjectPath(object, false);
    for (int i = 0; i < path.length; i++) {
        DBSObject item = path[i];
        node = getNodeByObject(item);
        if (node == null) {
            // Parent node read
            return null;
        }
        DBNDatabaseNode[] children = node.getChildNodes();
        if (ArrayUtils.isEmpty(children)) {
            // Parent node is not read
            return null;
        }
        if (item == object.getParentObject()) {
            // Try to find parent node withing children
            for (DBNDatabaseNode child : children) {
                if (child instanceof DBNDatabaseFolder) {
                    Class<?> itemsClass = ((DBNDatabaseFolder) child).getChildrenClass();
                    if (itemsClass != null && itemsClass.isAssignableFrom(object.getClass())) {
                        return child;
                    }
                }
            }
        }
    }
    // Not found
    return null;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) Nullable(org.jkiss.code.Nullable)

Example 17 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 18 with Nullable

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

the class ConnectionPageSettings method getSubPages.

@Nullable
@Override
public IDialogPage[] getSubPages() {
    if (subPages != null) {
        return subPages;
    }
    if (this.connectionEditor == null) {
        this.connectionEditor = viewDescriptor.createView(IDataSourceConnectionEditor.class);
        this.connectionEditor.setSite(this);
    }
    if (connectionEditor instanceof ICompositeDialogPage) {
        subPages = ((ICompositeDialogPage) connectionEditor).getSubPages();
        if (!ArrayUtils.isEmpty(subPages)) {
            for (IDialogPage page : subPages) {
                if (page instanceof IDataSourceConnectionEditor) {
                    ((IDataSourceConnectionEditor) page).setSite(this);
                }
            }
        }
        if (extraPages != null) {
            subPages = ArrayUtils.concatArrays(subPages, extraPages);
        }
        return subPages;
    } else {
        return extraPages;
    }
}
Also used : IDialogPage(org.eclipse.jface.dialogs.IDialogPage) Nullable(org.jkiss.code.Nullable)

Example 19 with Nullable

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

the class ExasolDataSource method getErrorPosition.

@Nullable
@Override
public ErrorPosition[] getErrorPosition(@NotNull DBRProgressMonitor monitor, @NotNull DBCExecutionContext context, @NotNull String query, @NotNull Throwable error) {
    while (error instanceof DBException) {
        if (error.getCause() == null) {
            return null;
        }
        error = error.getCause();
    }
    String message = error.getMessage();
    if (!CommonUtils.isEmpty(message)) {
        Matcher matcher = ERROR_POSITION_PATTERN.matcher(message);
        List<ErrorPosition> positions = new ArrayList<>();
        while (matcher.find()) {
            DBPErrorAssistant.ErrorPosition pos = new DBPErrorAssistant.ErrorPosition();
            pos.info = matcher.group(1);
            pos.line = Integer.parseInt(matcher.group(2)) - 1;
            pos.position = Integer.parseInt(matcher.group(3)) - 1;
            positions.add(pos);
        }
        if (!positions.isEmpty()) {
            return positions.toArray(new ErrorPosition[positions.size()]);
        }
    }
    return null;
}
Also used : DBException(org.jkiss.dbeaver.DBException) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) DBPErrorAssistant(org.jkiss.dbeaver.model.DBPErrorAssistant) Nullable(org.jkiss.code.Nullable)

Example 20 with Nullable

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

the class ResultSetUtils method getAttributeValueFromClipboard.

@Nullable
public static Object getAttributeValueFromClipboard(DBDAttributeBinding attribute) throws DBCException {
    DBPDataSource dataSource = attribute.getDataSource();
    Clipboard clipboard = new Clipboard(Display.getCurrent());
    try (DBCSession session = DBUtils.openUtilSession(VoidProgressMonitor.INSTANCE, dataSource, "Copy from clipboard")) {
        String strValue = (String) clipboard.getContents(TextTransfer.getInstance());
        return attribute.getValueHandler().getValueFromObject(session, attribute.getAttribute(), strValue, true);
    } finally {
        clipboard.dispose();
    }
}
Also used : DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) Clipboard(org.eclipse.swt.dnd.Clipboard) 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