use of org.jkiss.dbeaver.model.IDataSourceContainerProvider in project dbeaver by serge-rider.
the class NavigatorHandlerLinkEditor method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
if (activeEditor == null) {
return null;
}
NavigatorViewBase navigatorView = NavigatorUtils.getActiveNavigatorView(event);
if (navigatorView == null) {
return null;
}
if (navigatorView instanceof ProjectExplorerView) {
if (activeEditor instanceof SQLEditor) {
IFile file = EditorUtils.getFileFromInput(activeEditor.getEditorInput());
if (file != null) {
showResourceInNavigator(navigatorView, file);
}
} else if (activeEditor.getEditorInput() instanceof ProjectFileEditorInput) {
IFile editorFile = ((ProjectFileEditorInput) activeEditor.getEditorInput()).getFile();
showResourceInNavigator(navigatorView, editorFile);
}
} else if (activeEditor.getEditorInput() instanceof IDatabaseEditorInput) {
IDatabaseEditorInput editorInput = (IDatabaseEditorInput) activeEditor.getEditorInput();
DBNNode dbnNode = editorInput.getNavigatorNode();
if (dbnNode != null) {
navigatorView.showNode(dbnNode);
}
} else if (activeEditor instanceof IDataSourceContainerProvider) {
DBPDataSourceContainer dsContainer = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
@NotNull final DBSObject activeObject;
if (dsContainer != null) {
DBPDataSource dataSource = dsContainer.getDataSource();
if (dataSource != null) {
activeObject = DBUtils.getDefaultOrActiveObject(dataSource);
} else {
activeObject = dsContainer;
}
final NavigatorViewBase view = navigatorView;
DBeaverUI.runInUI(activePage.getWorkbenchWindow(), new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
DBSObject showObject = activeObject;
if (showObject instanceof DBPDataSource) {
showObject = ((DBPDataSource) showObject).getContainer();
}
DBNDatabaseNode objectNode = view.getModel().getNodeByObject(monitor, showObject, true);
if (objectNode != null) {
view.showNode(objectNode);
}
}
});
}
}
activePage.activate(navigatorView);
return null;
}
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 && (objectList == null) || (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())) {
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
List<ObjectPropertyDescriptor> allProps = ObjectAttributeDescriptor.extractAnnotations(getListPropertySource(), classList, propertyFilter);
if (reload) {
clearListData();
columnController = new ViewerColumnController(getListConfigId(classList), getItemsViewer());
}
// Create columns from classes' annotations
for (ObjectPropertyDescriptor prop : allProps) {
if (!getListPropertySource().hasProperty(prop)) {
getListPropertySource().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<OBJECT_TYPE>() : 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()));
}
use of org.jkiss.dbeaver.model.IDataSourceContainerProvider in project dbeaver by dbeaver.
the class DataSourceAutoCommitHandler method updateElement.
@Override
public void updateElement(UIElement element, Map parameters) {
IWorkbenchWindow workbenchWindow = element.getServiceLocator().getService(IWorkbenchWindow.class);
if (workbenchWindow == null || workbenchWindow.getActivePage() == null) {
return;
}
IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor();
if (activeEditor == null) {
return;
}
boolean autoCommit = true;
DBPTransactionIsolation isolation = null;
DBCExecutionContext context = getExecutionContext(activeEditor);
if (context != null && context.isConnected()) {
DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
if (txnManager != null) {
try {
// Change auto-commit mode
autoCommit = txnManager.isAutoCommit();
isolation = txnManager.getTransactionIsolation();
} catch (DBCException e) {
log.warn(e);
}
}
} else if (activeEditor instanceof IDataSourceContainerProvider) {
DBPDataSourceContainer container = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
if (container != null) {
autoCommit = container.isDefaultAutoCommit();
isolation = container.getActiveTransactionsIsolation();
}
}
element.setChecked(autoCommit);
// Update command image
element.setIcon(DBeaverIcons.getImageDescriptor(autoCommit ? UIIcon.TXN_COMMIT_AUTO : UIIcon.TXN_COMMIT_MANUAL));
String isolationName = isolation == null ? "?" : isolation.getTitle();
String text = autoCommit ? "Switch to manual commit (" + isolationName + ")" : "Switch to auto-commit";
element.setText(text);
element.setTooltip(text);
}
use of org.jkiss.dbeaver.model.IDataSourceContainerProvider in project dbeaver by dbeaver.
the class NavigatorHandlerLinkEditor method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
if (activeEditor == null) {
return null;
}
NavigatorViewBase navigatorView = NavigatorUtils.getActiveNavigatorView(event);
if (navigatorView == null) {
return null;
}
if (navigatorView instanceof ProjectExplorerView) {
if (activeEditor instanceof SQLEditor) {
IFile file = EditorUtils.getFileFromInput(activeEditor.getEditorInput());
if (file != null) {
showResourceInNavigator(navigatorView, file);
}
} else if (activeEditor.getEditorInput() instanceof ProjectFileEditorInput) {
IFile editorFile = ((ProjectFileEditorInput) activeEditor.getEditorInput()).getFile();
showResourceInNavigator(navigatorView, editorFile);
}
} else if (activeEditor.getEditorInput() instanceof IDatabaseEditorInput) {
IDatabaseEditorInput editorInput = (IDatabaseEditorInput) activeEditor.getEditorInput();
DBNNode dbnNode = editorInput.getNavigatorNode();
if (dbnNode != null) {
navigatorView.showNode(dbnNode);
}
} else if (activeEditor instanceof IDataSourceContainerProvider) {
DBPDataSourceContainer dsContainer = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
@NotNull final DBSObject activeObject;
if (dsContainer != null) {
DBPDataSource dataSource = dsContainer.getDataSource();
if (dataSource != null) {
activeObject = DBUtils.getDefaultOrActiveObject(dataSource);
} else {
activeObject = dsContainer;
}
final NavigatorViewBase view = navigatorView;
DBeaverUI.runInUI(activePage.getWorkbenchWindow(), new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
DBSObject showObject = activeObject;
if (showObject instanceof DBPDataSource) {
showObject = ((DBPDataSource) showObject).getContainer();
}
DBNDatabaseNode objectNode = view.getModel().getNodeByObject(monitor, showObject, true);
if (objectNode != null) {
view.showNode(objectNode);
}
}
});
}
}
activePage.activate(navigatorView);
return null;
}
use of org.jkiss.dbeaver.model.IDataSourceContainerProvider in project dbeaver by dbeaver.
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 && (objectList == null) || (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
List<ObjectPropertyDescriptor> allProps = ObjectAttributeDescriptor.extractAnnotations(getListPropertySource(), classList, propertyFilter);
if (reload) {
clearListData();
columnController = new ViewerColumnController(getListConfigId(classList), getItemsViewer());
}
// Create columns from classes' annotations
for (ObjectPropertyDescriptor prop : allProps) {
if (!getListPropertySource().hasProperty(prop)) {
getListPropertySource().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<OBJECT_TYPE>() : 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()));
}
Aggregations