use of org.jkiss.dbeaver.model.IDataSourceContainerProvider in project dbeaver by serge-rider.
the class DataSourceToolbarUtils method refreshSelectorToolbar.
public static void refreshSelectorToolbar(IWorkbenchWindow window) {
if (window instanceof WorkbenchWindow) {
MTrimBar topTrim = ((WorkbenchWindow) window).getTopTrim();
for (MTrimElement element : topTrim.getChildren()) {
if (CONNECTION_SELECTOR_TOOLBAR_ID.equals(element.getElementId())) {
boolean showConnectionSelector = false;
IEditorPart activeEditor = window.getActivePage().getActiveEditor();
DBPDataSourceContainer dataSourceContainer = null;
if (activeEditor instanceof IDataSourceContainerProvider) {
showConnectionSelector = true;
dataSourceContainer = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
}
if (element instanceof MElementContainer) {
Object widget = element.getWidget();
if (widget instanceof Composite) {
Composite controlsPanel = (Composite) widget;
Color bgColor = dataSourceContainer == null ? null : UIUtils.getConnectionTypeColor(dataSourceContainer.getConnectionConfiguration().getConnectionType());
Control[] childControl = controlsPanel.getChildren();
for (Control cc : childControl) {
// if (bgColor != null) {
// Color oldBackground = cc.getBackground();
// if (oldBackground != null) {
// RGB newBackground = UIUtils.blend(oldBackground.getRGB(), bgColor.getRGB(), 50);
// cc.setBackground(UIUtils.getSharedColor(newBackground));
// continue;
// }
// }
cc.setBackground(bgColor);
}
}
MElementContainer<? extends MUIElement> container = (MElementContainer<? extends MUIElement>) element;
for (MUIElement tbItem : container.getChildren()) {
// So we need to hide/show it to force text update
if (showConnectionSelector) {
tbItem.setVisible(false);
}
tbItem.setVisible(showConnectionSelector);
}
}
return;
}
}
}
// By some reason we can't locate the toolbar (#5712?). Let's just refresh elements then - its better than nothing
updateCommandsUI();
}
use of org.jkiss.dbeaver.model.IDataSourceContainerProvider in project dbeaver by serge-rider.
the class DatabaseEditorUtils method setPartBackground.
public static void setPartBackground(IEditorPart editor, Composite composite) {
if (composite == null || composite.isDisposed()) {
return;
}
CTabFolder tabFolder = null;
Composite rootComposite = composite;
for (Composite c = composite; c != null; c = c.getParent()) {
if (!c.isDisposed() && c.getParent() instanceof CTabFolder) {
tabFolder = (CTabFolder) c.getParent();
// rootComposite = c;
break;
}
}
if (tabFolder != null) {
tabFolder.setBorderVisible(false);
}
DBPDataSourceContainer dsContainer = null;
if (editor instanceof IDataSourceContainerProvider) {
dsContainer = ((IDataSourceContainerProvider) editor).getDataSourceContainer();
} else if (editor instanceof DBPContextProvider) {
DBCExecutionContext context = ((DBPContextProvider) editor).getExecutionContext();
if (context != null) {
dsContainer = context.getDataSource().getContainer();
}
}
if (dsContainer == null) {
rootComposite.setBackground(null);
} else {
Color bgColor = UIUtils.getConnectionColor(dsContainer.getConnectionConfiguration());
rootComposite.setData(DBStyles.DATABASE_EDITOR_COMPOSITE_DATASOURCE, dsContainer);
rootComposite.setBackground(bgColor);
}
}
use of org.jkiss.dbeaver.model.IDataSourceContainerProvider in project dbeaver by serge-rider.
the class ObjectListControl method setListData.
protected void setListData(Collection<OBJECT_TYPE> items, boolean append) {
final Control itemsControl = itemsViewer.getControl();
if (itemsControl.isDisposed()) {
return;
}
itemsControl.setRedraw(false);
try {
final boolean reload = !append && (CommonUtils.isEmpty(objectList)) || (columnController == null);
{
// Collect list of items' classes
final List<Class<?>> classList = new ArrayList<>();
Class<?>[] baseTypes = getListBaseTypes(items);
if (!ArrayUtils.isEmpty(baseTypes)) {
Collections.addAll(classList, baseTypes);
}
if (!CommonUtils.isEmpty(items)) {
for (OBJECT_TYPE item : items) {
Object object = getObjectValue(item);
if (object != null && !classList.contains(object.getClass())) {
// and we need to show "Name" instead of particular name props
for (int i = 0; i < classList.size(); i++) {
Class<?> c = classList.get(i);
if (!c.isInterface() && c.isAssignableFrom(object.getClass())) {
classList.remove(i);
} else {
i++;
}
}
classList.add(object.getClass());
}
if (renderer.isTree()) {
Map<OBJECT_TYPE, Boolean> collectedSet = new IdentityHashMap<>();
collectItemClasses(item, classList, collectedSet);
}
}
}
IPropertyFilter propertyFilter = new DataSourcePropertyFilter(ObjectListControl.this instanceof IDataSourceContainerProvider ? ((IDataSourceContainerProvider) ObjectListControl.this).getDataSourceContainer() : null);
// Collect all properties
PropertySourceAbstract propertySource = getListPropertySource();
List<ObjectPropertyDescriptor> allProps = ObjectAttributeDescriptor.extractAnnotations(propertySource, classList, propertyFilter);
if (!CommonUtils.isEmpty(items)) {
// Remove hidden properties (we need to check them against all items)
try {
allProps.removeIf(p -> {
for (OBJECT_TYPE item : items) {
Object objectValue = getObjectValue(item);
if (p.isPropertyVisible(objectValue, objectValue)) {
return false;
}
}
return true;
});
} catch (Throwable e) {
log.debug(e);
}
}
if (reload) {
clearListData();
columnController = new ViewerColumnController<>(getListConfigId(classList), getItemsViewer());
}
// Create columns from classes' annotations
for (ObjectPropertyDescriptor prop : allProps) {
if (!propertySource.hasProperty(prop)) {
if (prop.isOptional()) {
// Check whether at least one itme has this property
boolean propHasValue = false;
if (!CommonUtils.isEmpty(items)) {
for (OBJECT_TYPE item : items) {
try {
Object propValue = prop.readValue(getObjectValue(item), null, true);
if (propValue != null) {
propHasValue = true;
break;
}
} catch (Throwable e) {
// Just ignore this
}
}
}
if (!propHasValue) {
continue;
}
}
propertySource.addProperty(prop);
createColumn(prop);
}
}
}
if (itemsControl.isDisposed()) {
return;
}
if (reload) {
columnController.createColumns(false);
}
if (reload || objectList.isEmpty()) {
// Set viewer content
objectList = CommonUtils.isEmpty(items) ? new ArrayList<>() : new ArrayList<>(items);
// Pack columns
sampleItems = true;
try {
List<OBJECT_TYPE> sampleList;
if (objectList.size() > 200) {
sampleList = objectList.subList(0, 100);
} else {
sampleList = objectList;
}
itemsViewer.setInput(sampleList);
if (renderer.isTree()) {
((TreeViewer) itemsViewer).expandToLevel(4);
}
if (reload) {
columnController.repackColumns();
}
} finally {
sampleItems = false;
}
// Set real content
itemsViewer.setInput(objectList);
} else if (items != null) {
if (append) {
// Simply append new list to the tail
for (OBJECT_TYPE newObject : items) {
if (!objectList.contains(newObject)) {
objectList.add(newObject);
}
}
} else {
// Update object list
if (!objectList.equals(items)) {
int newListSize = items.size();
int itemIndex = 0;
for (OBJECT_TYPE newObject : items) {
if (itemIndex >= objectList.size()) {
// Add to tail
objectList.add(itemIndex, newObject);
} else {
OBJECT_TYPE oldObject = objectList.get(itemIndex);
if (!CommonUtils.equalObjects(oldObject, newObject)) {
// Replace old object
objectList.set(itemIndex, newObject);
}
}
itemIndex++;
}
while (objectList.size() > newListSize) {
objectList.remove(objectList.size() - 1);
}
}
}
itemsViewer.refresh();
}
} finally {
itemsControl.setRedraw(true);
}
setInfo(getItemsLoadMessage(objectList.size()));
if (IS_MACOS_BIG_SUR) {
// [#10162]
itemsControl.redraw();
}
}
use of org.jkiss.dbeaver.model.IDataSourceContainerProvider in project dbeaver by dbeaver.
the class DatabaseEditorUtils method setPartBackground.
public static void setPartBackground(IEditorPart editor, Composite composite) {
if (composite == null || composite.isDisposed()) {
return;
}
CTabFolder tabFolder = null;
Composite rootComposite = composite;
for (Composite c = composite; c != null; c = c.getParent()) {
if (!c.isDisposed() && c.getParent() instanceof CTabFolder) {
tabFolder = (CTabFolder) c.getParent();
// rootComposite = c;
break;
}
}
if (tabFolder != null) {
tabFolder.setBorderVisible(false);
}
DBPDataSourceContainer dsContainer = null;
if (editor instanceof IDataSourceContainerProvider) {
dsContainer = ((IDataSourceContainerProvider) editor).getDataSourceContainer();
} else if (editor instanceof DBPContextProvider) {
DBCExecutionContext context = ((DBPContextProvider) editor).getExecutionContext();
if (context != null) {
dsContainer = context.getDataSource().getContainer();
}
}
if (dsContainer == null) {
rootComposite.setBackground(null);
} else {
Color bgColor = UIUtils.getConnectionColor(dsContainer.getConnectionConfiguration());
rootComposite.setData(DBStyles.DATABASE_EDITOR_COMPOSITE_DATASOURCE, dsContainer);
rootComposite.setBackground(bgColor);
}
}
Aggregations