use of org.jkiss.dbeaver.model.DBPImage in project dbeaver by dbeaver.
the class DataSourceProviderDescriptor method loadTreeIcon.
private void loadTreeIcon(DBXTreeNode node, IConfigurationElement config) {
String defaultIcon = config.getAttribute(RegistryConstants.ATTR_ICON);
IConfigurationElement[] iconElements = config.getChildren(RegistryConstants.ATTR_ICON);
if (!ArrayUtils.isEmpty(iconElements)) {
for (IConfigurationElement iconElement : iconElements) {
String icon = iconElement.getAttribute(RegistryConstants.ATTR_ICON);
String expr = iconElement.getAttribute(RegistryConstants.ATTR_IF);
boolean isDefault = CommonUtils.getBoolean(iconElement.getAttribute(RegistryConstants.ATTR_DEFAULT));
if (isDefault && CommonUtils.isEmpty(expr)) {
defaultIcon = icon;
} else {
DBPImage iconImage = iconToImage(icon);
if (iconImage != null) {
node.addIcon(new DBXTreeIcon(expr, iconImage));
}
}
}
}
if (defaultIcon != null) {
DBPImage defaultImage = iconToImage(defaultIcon);
if (defaultImage != null) {
node.setDefaultIcon(defaultImage);
}
}
}
use of org.jkiss.dbeaver.model.DBPImage in project dbeaver by serge-rider.
the class GenericConnectionPage method getImage.
@Override
public Image getImage() {
DBPDriver driver = getSite().getDriver();
DBPImage iconBig = driver.getIconBig();
if (iconBig != null) {
try {
Image image = DBeaverIcons.getImage(iconBig);
if (image.getImageData().width >= 64) {
return image;
}
} catch (Exception e) {
log.error(e);
}
}
return super.getImage();
}
use of org.jkiss.dbeaver.model.DBPImage in project dbeaver by serge-rider.
the class DataTransferPagePipes method createInputsTable.
private void createInputsTable(Composite composite) {
Composite panel = UIUtils.createComposite(composite, 1);
// UIUtils.createControlLabel(panel, DTUIMessages.data_transfer_wizard_final_group_objects);
inputsTable = new TableViewer(panel, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
inputsTable.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
inputsTable.getTable().setLinesVisible(true);
inputsTable.getTable().setHeaderVisible(true);
inputsTable.setContentProvider(new ListContentProvider());
UIUtils.createTableContextMenu(inputsTable.getTable(), null);
DBNModel nModel = DBWorkbench.getPlatform().getNavigatorModel();
CellLabelProvider labelProvider = new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
DBSObject element = (DBSObject) cell.getElement();
if (cell.getColumnIndex() == 0) {
DBNDatabaseNode objectNode = nModel.getNodeByObject(element);
DBPImage icon = objectNode != null ? objectNode.getNodeIconDefault() : DBValueFormatting.getObjectImage(element);
cell.setImage(DBeaverIcons.getImage(icon));
cell.setText(DBUtils.getObjectFullName(element, DBPEvaluationContext.UI));
} else if (element.getDescription() != null) {
cell.setText(element.getDescription());
}
}
};
{
TableViewerColumn columnName = new TableViewerColumn(inputsTable, SWT.LEFT);
columnName.setLabelProvider(labelProvider);
columnName.getColumn().setText(DTMessages.data_transfer_wizard_init_column_exported);
TableViewerColumn columnDesc = new TableViewerColumn(inputsTable, SWT.LEFT);
columnDesc.setLabelProvider(labelProvider);
columnDesc.getColumn().setText(DTMessages.data_transfer_wizard_init_column_description);
}
}
use of org.jkiss.dbeaver.model.DBPImage in project dbeaver by serge-rider.
the class GridCellRenderer method isOverLink.
boolean isOverLink(GridColumn column, int row, int x, int y) {
IGridContentProvider contentProvider = grid.getContentProvider();
Object colElement = column.getElement();
Object rowElement = grid.getRowElement(row);
int state = contentProvider.getCellState(colElement, rowElement, null);
boolean isToggle = (state & IGridContentProvider.STATE_TOGGLE) != 0;
if (isToggle) {
if (contentProvider.isElementReadOnly(colElement)) {
return false;
}
}
if (isLinkState(state) || isToggle) {
int columnAlign = contentProvider.getColumnAlign(colElement);
Point origin = grid.getOrigin(column, row);
Rectangle imageBounds;
if (isToggle) {
String cellText = grid.getCellText(colElement, rowElement);
Point textSize = grid.sizingGC.textExtent(cellText);
imageBounds = new Rectangle(0, 0, textSize.x, textSize.y);
} else {
DBPImage cellImage = grid.getCellImage(colElement, rowElement);
Image image;
if (cellImage == null) {
image = ((state & IGridContentProvider.STATE_LINK) != 0) ? LINK_IMAGE : LINK2_IMAGE;
} else {
image = DBeaverIcons.getImage(cellImage);
}
imageBounds = image.getBounds();
}
int verMargin = (grid.getItemHeight() - imageBounds.height) / 2;
switch(columnAlign) {
case IGridContentProvider.ALIGN_LEFT:
if (x >= origin.x + LEFT_MARGIN && x <= origin.x + LEFT_MARGIN + imageBounds.width && y >= origin.y + verMargin && y <= origin.y + verMargin + imageBounds.height) {
return true;
}
break;
case IGridContentProvider.ALIGN_RIGHT:
int width = column.getWidth();
if (x >= origin.x + width - (LEFT_MARGIN + imageBounds.width) && x <= origin.x + width - RIGHT_MARGIN && y >= origin.y + verMargin && y <= origin.y + verMargin + imageBounds.height) {
return true;
}
break;
case IGridContentProvider.ALIGN_CENTER:
int leftIndent = (column.getWidth() - imageBounds.width - RIGHT_MARGIN - LEFT_MARGIN) / 2;
if (x >= origin.x + LEFT_MARGIN + leftIndent && x <= origin.x + LEFT_MARGIN + leftIndent + imageBounds.width && y >= origin.y + verMargin && y <= origin.y + verMargin + imageBounds.height) {
return true;
}
break;
}
}
return false;
}
use of org.jkiss.dbeaver.model.DBPImage in project dbeaver by serge-rider.
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;
{
DBPImage cellImage = grid.getCellImage(col, row);
if (cellImage != null) {
image = DBeaverIcons.getImage(cellImage);
imageBounds = image.getBounds();
} else {
image = null;
}
if (image == null && isLinkState(state)) {
image = ((state & IGridContentProvider.STATE_LINK) != 0) ? LINK_IMAGE : LINK2_IMAGE;
imageBounds = LINK_IMAGE_BOUNDS;
}
}
int columnAlign = grid.getContentProvider().getColumnAlign(col);
if (image != null && columnAlign != IGridContentProvider.ALIGN_RIGHT) {
int y = bounds.y + (bounds.height - imageBounds.height) / 2;
if (columnAlign == IGridContentProvider.ALIGN_CENTER) {
x += (bounds.width - imageBounds.width - RIGHT_MARGIN - LEFT_MARGIN) / 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 = UITextUtils.getShortString(grid.fontMetrics, text, width);
// Replace linefeeds with space
text = CommonUtils.getSingleLineString(text);
gc.setFont(grid.normalFont);
switch(columnAlign) {
// Center
case IGridContentProvider.ALIGN_CENTER:
{
Point textSize = gc.textExtent(text);
gc.drawString(text, bounds.x + (bounds.width - textSize.x) / 2, bounds.y + TEXT_TOP_MARGIN + TOP_MARGIN, true);
break;
}
case IGridContentProvider.ALIGN_RIGHT:
{
// Right (numbers, datetimes)
Point textSize = gc.textExtent(text);
boolean useClipping = textSize.x > bounds.width;
int imageMargin = 0;
if (image != null) {
// Reduce bounds by link image size
imageMargin = imageBounds.width + INSIDE_MARGIN;
if (useClipping) {
gc.setClipping(bounds.x, bounds.y, bounds.width - imageMargin, bounds.height);
}
} else {
if (useClipping) {
gc.setClipping(bounds);
}
}
gc.drawString(text, bounds.x + bounds.width - (textSize.x + RIGHT_MARGIN + imageMargin), bounds.y + TEXT_TOP_MARGIN + TOP_MARGIN, true);
if (useClipping) {
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 (focus) {
gc.setForeground(colorLineFocused);
gc.drawRectangle(bounds.x + 1, bounds.y, bounds.width - 2, bounds.height - 1);
if (grid.isFocusControl()) {
gc.drawRectangle(bounds.x + 2, bounds.y + 1, bounds.width - 4, bounds.height - 3);
}
}
}
Aggregations