use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.
the class CheckboxTreeManager method updateCheckStates.
public void updateCheckStates() {
Set<DBNDatabaseNode> parentList = new LinkedHashSet<>();
for (Object element : viewer.getCheckedElements()) {
for (DBNNode node = ((DBNDatabaseNode) element).getParentNode(); node != null; node = node.getParentNode()) {
if (node instanceof DBNDatabaseNode) {
parentList.add((DBNDatabaseNode) node);
viewer.setChecked(node, true);
}
}
}
updateElementsCheck(parentList.toArray(), true, false);
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.
the class CheckboxTreeManager method collectChildren.
private boolean collectChildren(DBRProgressMonitor monitor, final Object element, List<DBNDatabaseNode> targetChildren, List<DBNDatabaseNode> targetContainers, boolean onlyChecked) throws DBException {
if (element instanceof DBNDatabaseNode) {
for (ViewerFilter filter : filters) {
if (!filter.select(viewer, ((DBNDatabaseNode) element).getParentNode(), element)) {
return false;
}
}
boolean isChecked = ArrayUtils.contains(checkedElements, element);
for (Class<?> type : targetTypes) {
if (type.isInstance(((DBNDatabaseNode) element).getObject())) {
if (!onlyChecked || isChecked) {
targetChildren.add((DBNDatabaseNode) element);
}
return true;
}
}
((DBNDatabaseNode) element).initializeNode(monitor, null);
DBNDatabaseNode[] children = ((DBNDatabaseNode) element).getChildren(monitor);
if (!ArrayUtils.isEmpty(children)) {
boolean foundChild = false;
for (DBNDatabaseNode child : children) {
if (collectChildren(monitor, child, targetChildren, targetContainers, onlyChecked)) {
foundChild = true;
}
}
if (foundChild) {
if (!onlyChecked || isChecked) {
targetContainers.add((DBNDatabaseNode) element);
}
}
return foundChild;
}
}
return false;
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.
the class OracleCompilerDialog method createDialogArea.
@Override
protected Composite createDialogArea(Composite parent) {
GridData gd;
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(2, false));
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
{
Composite unitsGroup = new Composite(composite, SWT.NONE);
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 250;
gd.heightHint = 200;
gd.verticalIndent = 0;
gd.horizontalIndent = 0;
unitsGroup.setLayoutData(gd);
unitsGroup.setLayout(new GridLayout(1, false));
unitTable = new TableViewer(unitsGroup, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
{
final Table table = unitTable.getTable();
table.setLayoutData(new GridData(GridData.FILL_BOTH));
table.setLinesVisible(true);
table.setHeaderVisible(true);
}
ViewerColumnController columnController = new ViewerColumnController("OracleCompilerDialog", unitTable);
columnController.addColumn(OracleMessages.views_oracle_compiler_dialog_column_name, null, SWT.NONE, true, true, new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
DBSObject unit = (DBSObject) cell.getElement();
final DBNDatabaseNode node = DBeaverCore.getInstance().getNavigatorModel().getNodeByObject(unit);
if (node != null) {
cell.setText(node.getNodeName());
cell.setImage(DBeaverIcons.getImage(node.getNodeIconDefault()));
} else {
cell.setText(unit.toString());
}
}
});
columnController.addColumn(OracleMessages.views_oracle_compiler_dialog_column_type, null, SWT.NONE, true, true, new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
DBSObject unit = (DBSObject) cell.getElement();
final DBNDatabaseNode node = DBeaverCore.getInstance().getNavigatorModel().getNodeByObject(unit);
if (node != null) {
cell.setText(node.getNodeType());
} else {
//$NON-NLS-1$
cell.setText("???");
}
}
});
columnController.createColumns();
unitTable.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
getButton(COMPILE_ID).setEnabled(!selection.isEmpty());
}
});
unitTable.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
if (!selection.isEmpty()) {
OracleSourceObject unit = (OracleSourceObject) selection.getFirstElement();
NavigatorHandlerObjectOpen.openEntityEditor(unit);
}
}
});
unitTable.setContentProvider(new ListContentProvider());
unitTable.setInput(compileUnits);
}
{
Composite infoGroup = new Composite(composite, SWT.NONE);
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 400;
gd.heightHint = 200;
gd.verticalIndent = 0;
gd.horizontalIndent = 0;
infoGroup.setLayoutData(gd);
infoGroup.setLayout(new GridLayout(1, false));
compileLog = new ObjectCompilerLogViewer(infoGroup, true);
}
return composite;
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class DiagramCreateWizard method performFinish.
@Override
public boolean performFinish() {
try {
Collection<DBNNode> initialContent = pageContent.getInitialContent();
List<DBSObject> rootObjects = new ArrayList<>();
for (DBNNode node : initialContent) {
if (node instanceof DBNDatabaseNode) {
rootObjects.add(((DBNDatabaseNode) node).getObject());
}
}
DiagramCreator creator = new DiagramCreator(rootObjects);
DBeaverUI.run(getContainer(), true, true, creator);
NavigatorHandlerObjectOpen.openResource(creator.diagramFile, DBeaverUI.getActiveWorkbenchWindow());
} catch (InterruptedException ex) {
return false;
} catch (InvocationTargetException ex) {
DBUserInterface.getInstance().showError("Create error", "Cannot create diagram", ex.getTargetException());
return false;
}
return true;
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class SearchDataQuery method run.
@Override
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
try {
String searchString = params.getSearchString();
// monitor.subTask("Collect tables");
Set<DBPDataSource> dataSources = new HashSet<>();
for (DBSDataContainer searcher : params.sources) {
dataSources.add(searcher.getDataSource());
}
// Search
DBNModel dbnModel = DBeaverCore.getInstance().getNavigatorModel();
monitor.beginTask("Search \"" + searchString + "\" in " + params.sources.size() + " table(s) / " + dataSources.size() + " database(s)", params.sources.size());
try {
for (DBSDataContainer dataContainer : params.sources) {
if (monitor.isCanceled()) {
break;
}
String objectName = DBUtils.getObjectFullName(dataContainer, DBPEvaluationContext.DML);
DBNDatabaseNode node = dbnModel.findNode(dataContainer);
if (node == null) {
log.warn("Can't find tree node for object \"" + objectName + "\"");
continue;
}
monitor.subTask(objectName);
DBPDataSource dataSource = dataContainer.getDataSource();
if (dataSource == null) {
log.warn("Object \"" + objectName + "\" not connected");
continue;
}
SearchTableMonitor searchMonitor = new SearchTableMonitor();
try (DBCSession session = DBUtils.openUtilSession(searchMonitor, dataSource, "Search rows in " + objectName)) {
TestDataReceiver dataReceiver = new TestDataReceiver(searchMonitor);
try {
findRows(session, dataContainer, dataReceiver);
} catch (DBCException e) {
// Search failed in some container - just write an error in log.
// We don't want to break whole search because of one single table.
log.error("Fulltext search failed in '" + dataContainer.getName() + "'", e);
}
if (dataReceiver.rowCount > 0) {
SearchDataObject object = new SearchDataObject(node, dataReceiver.rowCount, dataReceiver.filter);
searchResult.addObjects(Collections.singletonList(object));
}
}
monitor.worked(1);
}
} finally {
monitor.done();
}
return Status.OK_STATUS;
} catch (Exception e) {
return GeneralUtils.makeExceptionStatus(e);
}
}
Aggregations