use of org.jkiss.dbeaver.model.DBPImage in project dbeaver by serge-rider.
the class PrefPageProjectSettings method performDefaults.
@Override
protected void performDefaults() {
resourceTable.removeAll();
for (ResourceHandlerDescriptor descriptor : DBeaverCore.getInstance().getProjectRegistry().getResourceHandlers()) {
if (!descriptor.isManagable()) {
continue;
}
TableItem item = new TableItem(resourceTable, SWT.NONE);
item.setData(descriptor);
final DBPImage icon = descriptor.getIcon();
if (icon != null) {
item.setImage(DBeaverIcons.getImage(icon));
}
item.setText(0, descriptor.getName());
if (descriptor.getDefaultRoot() != null) {
item.setText(1, descriptor.getDefaultRoot());
}
}
UIUtils.packColumns(resourceTable, true);
super.performDefaults();
}
use of org.jkiss.dbeaver.model.DBPImage in project dbeaver by dbeaver.
the class PrefPageProjectSettings method performDefaults.
@Override
protected void performDefaults() {
resourceTable.removeAll();
for (ResourceHandlerDescriptor descriptor : DBeaverCore.getInstance().getProjectRegistry().getResourceHandlerDescriptors()) {
if (!descriptor.isManagable()) {
continue;
}
TableItem item = new TableItem(resourceTable, SWT.NONE);
item.setData(descriptor);
final DBPImage icon = descriptor.getIcon();
if (icon != null) {
item.setImage(DBeaverIcons.getImage(icon));
}
item.setText(0, descriptor.getName());
String defaultRoot = project == null ? null : descriptor.getDefaultRoot(project);
if (defaultRoot != null) {
item.setText(1, defaultRoot);
}
}
UIUtils.packColumns(resourceTable, true);
super.performDefaults();
}
use of org.jkiss.dbeaver.model.DBPImage in project dbeaver by dbeaver.
the class GridCellRenderer method paint.
public void paint(GC gc, Rectangle bounds, boolean selected, boolean focus, Object col, Object row) {
boolean drawBackground = true;
// if (grid.isEnabled()) {
Color back = grid.getCellBackground(col, row, selected);
if (back != null) {
gc.setBackground(back);
} else {
drawBackground = false;
}
/*} else {
grid.setDefaultBackground(gc);
}*/
gc.setForeground(grid.getCellForeground(col, row, selected));
if (drawBackground) {
gc.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height);
}
String text = grid.getCellText(col, row);
final int state = grid.getContentProvider().getCellState(col, row, text);
int x = LEFT_MARGIN;
Image image;
Rectangle imageBounds = null;
if (isLinkState(state)) {
image = ((state & IGridContentProvider.STATE_LINK) != 0) ? LINK_IMAGE : LINK2_IMAGE;
imageBounds = LINK_IMAGE_BOUNDS;
} else {
DBPImage cellImage = grid.getCellImage(col, row);
if (cellImage != null) {
image = DBeaverIcons.getImage(cellImage);
imageBounds = image.getBounds();
} else {
image = null;
}
}
int columnAlign = grid.getContentProvider().getColumnAlign(col);
if (image != null && columnAlign != IGridContentProvider.ALIGN_RIGHT) {
int y = bounds.y + (bounds.height - imageBounds.height) / 2;
gc.drawImage(image, bounds.x + x, y);
x += imageBounds.width + INSIDE_MARGIN;
}
int width = bounds.width - x - RIGHT_MARGIN;
// Get cell text
if (text != null && !text.isEmpty()) {
// Get shortern version of string
text = TextUtils.getShortString(grid.fontMetrics, text, width);
// Replace linefeeds with space
text = TextUtils.getSingleLineString(text);
gc.setFont(grid.normalFont);
switch(columnAlign) {
// Center
case IGridContentProvider.ALIGN_CENTER:
break;
case IGridContentProvider.ALIGN_RIGHT:
// Right (numbers, datetimes)
int imageMargin = 0;
if (image != null) {
// Reduce bounds by link image size
imageMargin = imageBounds.width + INSIDE_MARGIN;
gc.setClipping(bounds.x, bounds.y, bounds.width - imageMargin, bounds.height);
} else {
gc.setClipping(bounds);
}
Point textSize = gc.textExtent(text);
gc.drawString(text, bounds.x + bounds.width - (textSize.x + RIGHT_MARGIN + imageMargin), bounds.y + TEXT_TOP_MARGIN + TOP_MARGIN, true);
gc.setClipping((Rectangle) null);
break;
default:
gc.drawString(text, bounds.x + x, bounds.y + TEXT_TOP_MARGIN + TOP_MARGIN, true);
break;
}
}
if (image != null && columnAlign == IGridContentProvider.ALIGN_RIGHT) {
int y = bounds.y + (bounds.height - imageBounds.height) / 2;
gc.drawImage(image, bounds.x + bounds.width - imageBounds.width - RIGHT_MARGIN, y);
}
if (grid.isLinesVisible()) {
if (selected) {
gc.setForeground(grid.getLineSelectedColor());
} else {
gc.setForeground(grid.getLineColor());
}
gc.drawLine(bounds.x, bounds.y + bounds.height, bounds.x + bounds.width, bounds.y + bounds.height);
gc.drawLine(bounds.x + bounds.width - 1, bounds.y, bounds.x + bounds.width - 1, bounds.y + bounds.height);
}
if (focus) {
gc.setForeground(colorLineFocused);
gc.drawRectangle(bounds.x, bounds.y, bounds.width - 1, bounds.height);
if (grid.isFocusControl()) {
gc.drawRectangle(bounds.x + 1, bounds.y + 1, bounds.width - 3, bounds.height - 2);
}
}
}
use of org.jkiss.dbeaver.model.DBPImage in project dbeaver by dbeaver.
the class GridColumn method computeCellWidth.
private int computeCellWidth(Object col, Object row) {
int x = 0;
x += leftMargin;
String cellText = grid.getCellText(col, row);
int state = grid.getContentProvider().getCellState(col, row, cellText);
Rectangle imageBounds;
if (GridCellRenderer.isLinkState(state)) {
imageBounds = GridCellRenderer.LINK_IMAGE_BOUNDS;
} else {
DBPImage image = grid.getContentProvider().getCellImage(col, row);
imageBounds = image == null ? null : DBeaverIcons.getImage(image).getBounds();
}
if (imageBounds != null) {
x += imageBounds.width + insideMargin;
}
x += grid.sizingGC.textExtent(cellText).x + rightMargin;
return x;
}
use of org.jkiss.dbeaver.model.DBPImage in project dbeaver by dbeaver.
the class AggregateColumnsPanel method aggregateValues.
private void aggregateValues(TreeItem parentItem, Collection<Object> values) {
List<AggregateFunctionDescriptor> functions = enabledFunctions;
Map<IAggregateFunction, TreeItem> funcMap = new IdentityHashMap<>();
for (AggregateFunctionDescriptor funcDesc : functions) {
TreeItem funcItem = (parentItem == null) ? new TreeItem(aggregateTable, SWT.NONE) : new TreeItem(parentItem, SWT.NONE);
funcItem.setData(funcDesc);
funcItem.setText(0, funcDesc.getLabel());
DBPImage icon = funcDesc.getIcon();
if (icon != null) {
funcItem.setImage(0, DBeaverIcons.getImage(icon));
}
try {
IAggregateFunction func = funcDesc.createFunction();
funcMap.put(func, funcItem);
} catch (DBException e) {
log.error(e);
}
}
IAggregateFunction[] funcs = funcMap.keySet().toArray(new IAggregateFunction[funcMap.size()]);
int[] funcCount = new int[funcs.length];
for (Object element : values) {
for (int i = 0; i < funcs.length; i++) {
if (funcs[i].accumulate(element)) {
funcCount[i]++;
}
}
}
for (int i = 0; i < funcs.length; i++) {
if (funcCount[i] <= 0) {
continue;
}
IAggregateFunction func = funcs[i];
Object result = func.getResult(funcCount[i]);
if (result != null) {
TreeItem treeItem = funcMap.get(func);
String strValue;
if (result instanceof Double || result instanceof Float || result instanceof BigDecimal) {
strValue = DOUBLE_FORMAT.format(result);
} else if (result instanceof Integer || result instanceof Long || result instanceof Short) {
strValue = INTEGER_FORMAT.format(result);
} else {
strValue = result.toString();
}
treeItem.setText(1, strValue);
}
}
}
Aggregations