use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class ToolsContextMenuHandler method getLocationFromControl.
@Nullable
private Point getLocationFromControl(Shell activeShell, Control focusControl) {
Point location = null;
final Display display = activeShell.getDisplay();
if (focusControl instanceof Table) {
final Table table = (Table) focusControl;
final int selectionIndex = table.getSelectionIndex();
if (selectionIndex < 0) {
location = display.map(focusControl, null, table.getLocation());
} else {
Rectangle absBounds = display.map(focusControl, null, table.getItem(selectionIndex).getBounds());
location = new Point(absBounds.x, absBounds.y + table.getItemHeight());
}
} else if (focusControl instanceof Tree) {
final Tree tree = (Tree) focusControl;
final TreeItem[] selection = tree.getSelection();
if (ArrayUtils.isEmpty(selection)) {
location = display.map(focusControl, null, tree.getLocation());
} else {
Rectangle absBounds = display.map(focusControl, null, selection[0].getBounds());
location = new Point(absBounds.x, absBounds.y + tree.getItemHeight());
}
} else if (focusControl instanceof StyledText) {
final StyledText styledText = (StyledText) focusControl;
final int caretOffset = styledText.getCaretOffset();
location = styledText.getLocationAtOffset(caretOffset);
location = display.map(styledText, null, location);
location.y += styledText.getLineHeight();
}
return location;
}
use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class UIUtils method getSelectionProvider.
@Nullable
public static ISelectionProvider getSelectionProvider(IServiceLocator serviceLocator) {
ISelectionProvider selectionProvider = serviceLocator.getService(ISelectionProvider.class);
if (selectionProvider != null) {
return selectionProvider;
}
IWorkbenchPartSite partSite = getWorkbenchPartSite(serviceLocator);
if (partSite == null) {
IWorkbenchPart activePart = serviceLocator.getService(IWorkbenchPart.class);
if (activePart == null) {
IWorkbenchWindow activeWindow = DBeaverUI.getActiveWorkbenchWindow();
if (activeWindow != null) {
activePart = activeWindow.getActivePage().getActivePart();
}
}
if (activePart != null) {
partSite = activePart.getSite();
}
}
if (partSite != null) {
return partSite.getSelectionProvider();
} else {
return null;
}
}
use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class AttributeEditPage method createPageContents.
@Override
protected Control createPageContents(Composite parent) {
Composite propsGroup = new Composite(parent, SWT.NONE);
propsGroup.setLayout(new GridLayout(2, false));
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
propsGroup.setLayoutData(gd);
//$NON-NLS-2$
final Text nameText = UIUtils.createLabelText(propsGroup, "Name", attribute.getName());
nameText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
if (attribute instanceof DBPNamedObject2) {
((DBPNamedObject2) attribute).setName(nameText.getText());
}
}
});
UIUtils.createControlLabel(propsGroup, "Properties").setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
final PropertyTreeViewer propertyViewer = new PropertyTreeViewer(propsGroup, SWT.BORDER);
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 400;
propertyViewer.getControl().setLayoutData(gd);
propertyViewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
return true;
}
});
PropertySourceAbstract pc = new PropertySourceEditable(commandContext, attribute, attribute) {
@Override
public void setPropertyValue(@Nullable DBRProgressMonitor monitor, Object editableValue, ObjectPropertyDescriptor prop, Object newValue) throws IllegalArgumentException {
super.setPropertyValue(monitor, editableValue, prop, newValue);
/*
if (prop.getId().equals("dataType")) {
newValue = getPropertyValue(monitor, editableValue, prop);
if (newValue instanceof DBSDataType) {
DBPPropertyDescriptor lengthProp = getProperty("maxLength");
if (lengthProp instanceof ObjectPropertyDescriptor) {
DBPDataKind dataKind = ((DBSDataType) newValue).getDataKind();
if (dataKind == DBPDataKind.STRING) {
setPropertyValue(monitor, editableValue, (ObjectPropertyDescriptor) lengthProp, 100);
} else {
setPropertyValue(monitor, editableValue, (ObjectPropertyDescriptor) lengthProp, null);
}
propertyViewer.update(lengthProp, null);
}
}
}
*/
}
};
pc.collectProperties();
for (DBPPropertyDescriptor prop : pc.getProperties()) {
if (prop instanceof ObjectPropertyDescriptor) {
if (((ObjectPropertyDescriptor) prop).isEditPossible() && !((ObjectPropertyDescriptor) prop).isNameProperty()) {
continue;
}
}
pc.removeProperty(prop);
}
propertyViewer.loadProperties(pc);
return propsGroup;
}
use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class ContentEditor method getContent.
@Nullable
DBDContent getContent() {
IValueController valueController = getValueController();
Object value = valueController == null ? null : valueController.getValue();
if (value instanceof DBDContent) {
return (DBDContent) value;
} else {
return null;
}
}
use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class MySQLDataSource method getErrorPosition.
@Nullable
@Override
public ErrorPosition[] getErrorPosition(@NotNull DBRProgressMonitor monitor, @NotNull DBCExecutionContext context, @NotNull String query, @NotNull Throwable error) {
String message = error.getMessage();
if (!CommonUtils.isEmpty(message)) {
Matcher matcher = ERROR_POSITION_PATTERN.matcher(message);
if (matcher.find()) {
DBPErrorAssistant.ErrorPosition pos = new DBPErrorAssistant.ErrorPosition();
pos.line = Integer.parseInt(matcher.group(1)) - 1;
return new ErrorPosition[] { pos };
}
}
return null;
}
Aggregations