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;
}
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 + ")";
}
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;
}
}
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;
}
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();
}
}
Aggregations