use of org.jkiss.dbeaver.model.DBPImage in project dbeaver by serge-rider.
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 serge-rider.
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 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, aggregateAsStrings)) {
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();
}
if (strValue != null) {
treeItem.setText(1, strValue);
}
}
}
}
use of org.jkiss.dbeaver.model.DBPImage in project dbeaver by serge-rider.
the class RecentTasksMenuContributor method fillContributionItems.
@Override
protected void fillContributionItems(final List<IContributionItem> menuItems) {
DBPProject project = NavigatorUtils.getSelectedProject();
if (project == null) {
return;
}
DBTTask[] tasks = project.getTaskManager().getAllTasks();
Arrays.sort(tasks, (o1, o2) -> {
DBTTaskRun lr1 = o1.getLastRun();
DBTTaskRun lr2 = o1.getLastRun();
if (lr1 == lr2)
return o1.getCreateTime().compareTo(o2.getCreateTime());
else if (lr1 == null)
return -1;
else if (lr2 == null)
return 1;
else
return lr1.getStartTime().compareTo(lr2.getStartTime());
});
for (int i = 0; i < tasks.length && i <= MAX_ITEMS; i++) {
DBTTask task = tasks[i];
DBPImage taskIcon = task.getType().getIcon();
if (taskIcon == null)
taskIcon = DBIcon.TREE_TASK;
menuItems.add(ActionUtils.makeActionContribution(new Action(task.getName(), DBeaverIcons.getImageDescriptor(taskIcon)) {
@Override
public void run() {
TaskHandlerRun.runTask(task);
}
}, false));
}
}
use of org.jkiss.dbeaver.model.DBPImage in project dbeaver by serge-rider.
the class TaskHandlerRun method updateElement.
@Override
public void updateElement(UIElement element, Map parameters) {
String taskId = CommonUtils.toString(parameters.get("task"));
if (!CommonUtils.isEmpty(taskId)) {
DBTTask task = NavigatorUtils.getSelectedProject().getTaskManager().getTaskById(taskId);
if (task != null) {
DBPImage taskIcon = task.getType().getIcon();
if (taskIcon == null)
taskIcon = DBIcon.TREE_TASK;
element.setIcon(DBeaverIcons.getImageDescriptor(taskIcon));
element.setText(task.getName());
}
}
}
Aggregations