use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class DatabaseNavigatorContentProvider method getChildren.
@Override
public Object[] getChildren(final Object parent) {
if (parent instanceof TreeNodeSpecial) {
return EMPTY_CHILDREN;
}
if (!(parent instanceof DBNNode)) {
return EMPTY_CHILDREN;
}
// view.getNavigatorModel().findNode(parent);
final DBNNode parentNode = (DBNNode) parent;
/*
if (parentNode == null) {
log.error("Can't find parent node '" + ((DBSObject) parent).getName() + "' in model");
return EMPTY_CHILDREN;
}
*/
if (!parentNode.hasChildren(true)) {
return EMPTY_CHILDREN;
}
if (parentNode instanceof DBNDatabaseNode && ((DBNDatabaseNode) parentNode).needsInitialization()) {
return TreeLoadVisualizer.expandChildren(navigatorTree.getViewer(), new TreeLoadService("Loading", ((DBNDatabaseNode) parentNode)));
} else {
try {
// Read children with null monitor cos' it's not a lazy node
// and no blocking process will occur
DBNNode[] children = DBNUtils.getNodeChildrenFiltered(new VoidProgressMonitor(), parentNode, true);
if (ArrayUtils.isEmpty(children)) {
return EMPTY_CHILDREN;
} else {
int longListFetchSize = Math.max(NavigatorPreferences.MIN_LONG_LIST_FETCH_SIZE, DBWorkbench.getPlatform().getPreferenceStore().getInt(NavigatorPreferences.NAVIGATOR_LONG_LIST_FETCH_SIZE));
if (children.length > longListFetchSize) {
Object[] curChildren = new Object[longListFetchSize + 1];
System.arraycopy(children, 0, curChildren, 0, longListFetchSize);
curChildren[longListFetchSize] = new TreeNodeLazyExpander(parentNode, children, longListFetchSize);
return curChildren;
}
return children;
}
} catch (Throwable ex) {
DBWorkbench.getPlatformUI().showError("Navigator error", ex.getMessage(), ex);
// Collapse this item
UIUtils.asyncExec(() -> {
navigatorTree.getViewer().collapseToLevel(parent, 1);
navigatorTree.getViewer().refresh(parent);
});
return EMPTY_CHILDREN;
}
}
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class SelectDatabaseDialog method createInstanceSelector.
private void createInstanceSelector(Composite group, DBSObjectContainer instanceContainer) {
((GridLayout) group.getLayout()).numColumns++;
instanceList = createObjectSelector(group, true, "DatabaseInstanceSelector", selectedInstances, new DBRRunnableWithResult<List<DBNDatabaseNode>>() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException {
try {
if (!CommonUtils.isEmpty(currentInstanceName) && selectedInstances.isEmpty()) {
DBSObject activeInstance = instanceContainer.getChild(monitor, currentInstanceName);
if (activeInstance != null) {
DBNDatabaseNode activeInstanceNode = DBNUtils.getNodeByObject(monitor, activeInstance, false);
if (activeInstanceNode != null) {
selectedInstances.add(activeInstanceNode);
}
}
}
Collection<? extends DBSObject> instances = instanceContainer.getChildren(new VoidProgressMonitor());
List<DBNDatabaseNode> instanceNodes = new ArrayList<>();
if (!CommonUtils.isEmpty(instances)) {
for (DBSObject instance : instances) {
DBNDatabaseNode instanceNode = DBNUtils.getNodeByObject(monitor, instance, false);
if (instanceNode != null) {
instanceNodes.add(instanceNode);
}
}
}
result = instanceNodes;
objectList.loadData();
} catch (DBException e) {
throw new InvocationTargetException(e);
}
}
});
instanceList.createProgressPanel();
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 300;
gd.minimumWidth = 300;
instanceList.setLayoutData(gd);
instanceList.getSelectionProvider().addSelectionChangedListener(event -> {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
selectedInstances.clear();
selectedInstances.addAll(selection.toList());
DBNDatabaseNode instance = selectedInstances.isEmpty() ? null : selectedInstances.get(0);
if (instance != null && !CommonUtils.equalObjects(instance.getNodeName(), currentInstanceName)) {
currentInstanceName = instance.getNodeName();
objectList.loadData();
}
});
instanceList.loadData();
closeOnFocusLost(instanceList);
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class SelectDatabaseDialog method getObjects.
protected List<DBNDatabaseNode> getObjects(DBRProgressMonitor monitor) throws DBException {
DBSObject rootObject;
if (selectedInstances != null && currentInstanceName != null) {
DBNDatabaseNode instanceNode = DBUtils.findObject(selectedInstances, currentInstanceName);
rootObject = instanceNode == null ? null : instanceNode.getObject();
} else {
rootObject = dataSourceContainer.getDataSource();
}
if (rootObject instanceof DBSObjectContainer) {
try {
Collection<? extends DBSObject> objectList = ((DBSObjectContainer) rootObject).getChildren(monitor);
if (objectList == null) {
return Collections.emptyList();
}
List<DBNDatabaseNode> nodeList = new ArrayList<>(objectList.size());
for (DBSObject object : objectList) {
if (object instanceof DBSObjectContainer) {
DBNDatabaseNode databaseNode = DBNUtils.getNodeByObject(monitor, object, false);
if (databaseNode != null) {
nodeList.add(databaseNode);
}
}
}
return nodeList;
} catch (DBException e) {
// Do not show error (it will close the dialog)
log.error(e);
return Collections.emptyList();
}
}
return objects;
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class ItemListControl method fillCustomActions.
@Override
public void fillCustomActions(IContributionManager contributionManager) {
super.fillCustomActions(contributionManager);
final DBNNode rootNode = getRootNode();
if (rootNode instanceof DBNDatabaseFolder && ((DBNDatabaseFolder) rootNode).getItemsMeta() != null) {
contributionManager.add(new Action(UINavigatorMessages.obj_editor_properties_control_action_filter_setting, DBeaverIcons.getImageDescriptor(UIIcon.FILTER)) {
@Override
public void run() {
NavigatorHandlerFilterConfig.configureFilters(getShell(), rootNode);
}
});
}
addColumnConfigAction(contributionManager);
IWorkbenchSite workbenchSite = getWorkbenchSite();
if (rootNode instanceof DBNDatabaseFolder) {
contributionManager.add(new Separator());
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_OPEN));
{
if (ObjectPropertyTester.canCreateObject(rootNode, true)) {
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_CREATE));
} else if (ObjectPropertyTester.canCreateObject(rootNode, false)) {
contributionManager.add(new Action(null, Action.AS_DROP_DOWN_MENU) {
{
setActionDefinitionId(NavigatorCommands.CMD_OBJECT_CREATE);
}
@Override
public void run() {
super.run();
}
@Override
public IMenuCreator getMenuCreator() {
return new MenuCreator(control -> {
List<IContributionItem> items = NavigatorHandlerObjectCreateNew.fillCreateMenuItems((IWorkbenchPartSite) workbenchSite, rootNode);
MenuManager menuManager = new MenuManager();
for (IContributionItem cc : items) {
menuManager.add(cc);
}
return menuManager;
});
}
});
}
}
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_DELETE));
}
if (rootNode instanceof DBNDatabaseNode && rootNode.isPersisted()) {
boolean hasReorder = false;
List<Class<?>> childrenTypes = ((DBNDatabaseNode) rootNode).getChildrenTypes(null);
for (Class<?> chilType : childrenTypes) {
if (DBWorkbench.getPlatform().getEditorsRegistry().getObjectManager(chilType, DBEObjectReorderer.class) != null) {
hasReorder = true;
break;
}
}
if (hasReorder) {
contributionManager.add(new Separator());
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_MOVE_UP));
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, NavigatorCommands.CMD_OBJECT_MOVE_DOWN));
}
}
if (rootNode instanceof DBNDatabaseNode) {
// Expand/collapse
final List<DBXTreeNode> inlineMetas = collectInlineMetas((DBNDatabaseNode) rootNode, ((DBNDatabaseNode) rootNode).getMeta());
if (!inlineMetas.isEmpty()) {
contributionManager.add(new Separator());
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.NAVIGATE_COLLAPSE_ALL, null, UIIcon.TREE_COLLAPSE_ALL));
contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.NAVIGATE_EXPAND_ALL, null, UIIcon.TREE_EXPAND_ALL));
}
}
// Save/revert
if (workbenchSite instanceof MultiPageEditorSite) {
final MultiPageEditorPart editor = ((MultiPageEditorSite) workbenchSite).getMultiPageEditor();
if (editor instanceof EntityEditor) {
contributionManager.add(new Separator());
DatabaseEditorUtils.contributeStandardEditorActions(workbenchSite, contributionManager);
}
}
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class SearchDataPage method saveTreeState.
protected void saveTreeState() {
// Object sources
StringBuilder sourcesString = new StringBuilder();
for (DBNNode node : selectorPanel.getCheckedNodes()) {
if (node instanceof DBNDatabaseNode && ((DBNDatabaseNode) node).getObject() instanceof DBSDataContainer) {
if (sourcesString.length() > 0) {
// $NON-NLS-1$
sourcesString.append("|");
}
sourcesString.append(node.getNodeItemPath());
}
}
searchStateCache.put(getClass(), sourcesString.toString());
}
Aggregations