use of org.jkiss.dbeaver.ui.navigator.database.CheckboxTreeManager in project dbeaver by serge-rider.
the class SearchDataPage method createControl.
@Override
public void createControl(Composite parent) {
super.createControl(parent);
initializeDialogUnits(parent);
Composite searchGroup = new Composite(parent, SWT.NONE);
searchGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
searchGroup.setLayout(new GridLayout(3, false));
setControl(searchGroup);
UIUtils.createControlLabel(searchGroup, "String");
searchText = new Combo(searchGroup, SWT.DROP_DOWN);
searchText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
if (params.searchString != null) {
searchText.setText(params.searchString);
}
for (String history : searchHistory) {
searchText.add(history);
}
searchText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
params.searchString = searchText.getText();
updateEnablement();
}
});
Composite optionsGroup = new SashForm(searchGroup, SWT.NONE);
GridLayout layout = new GridLayout(2, true);
layout.marginHeight = 0;
layout.marginWidth = 0;
optionsGroup.setLayout(layout);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 3;
optionsGroup.setLayoutData(gd);
{
final DBeaverCore core = DBeaverCore.getInstance();
Group databasesGroup = UIUtils.createControlGroup(optionsGroup, "Databases", 1, GridData.FILL_BOTH, 0);
gd = new GridData(GridData.FILL_BOTH);
//gd.heightHint = 300;
databasesGroup.setLayoutData(gd);
final DBNProject projectNode = core.getNavigatorModel().getRoot().getProject(core.getProjectRegistry().getActiveProject());
DBNNode rootNode = projectNode == null ? core.getNavigatorModel().getRoot() : projectNode.getDatabases();
dataSourceTree = new DatabaseNavigatorTree(databasesGroup, rootNode, SWT.SINGLE | SWT.CHECK);
gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 300;
dataSourceTree.setLayoutData(gd);
final CheckboxTreeViewer viewer = (CheckboxTreeViewer) dataSourceTree.getViewer();
viewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof TreeLoadNode) {
return true;
}
if (element instanceof DBNNode) {
if (element instanceof DBNDatabaseFolder) {
DBNDatabaseFolder folder = (DBNDatabaseFolder) element;
Class<? extends DBSObject> folderItemsClass = folder.getChildrenClass();
return folderItemsClass != null && (DBSObjectContainer.class.isAssignableFrom(folderItemsClass) || DBSEntity.class.isAssignableFrom(folderItemsClass));
}
if (element instanceof DBNLocalFolder || element instanceof DBNProjectDatabases || element instanceof DBNDataSource) {
return true;
}
if (element instanceof DBSWrapper) {
DBSObject obj = ((DBSWrapper) element).getObject();
if (obj instanceof DBSObjectContainer)
return true;
if (obj instanceof DBSDataContainer && obj instanceof DBSEntity) {
if ((((DBSDataContainer) obj).getSupportedFeatures() & DBSDataContainer.DATA_SEARCH) != 0) {
return true;
}
}
}
}
return false;
}
});
checkboxTreeManager = new CheckboxTreeManager(viewer, new Class[] { DBSDataContainer.class });
viewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
updateEnablement();
}
});
}
{
//new Label(searchGroup, SWT.NONE);
Composite optionsGroup2 = UIUtils.createControlGroup(optionsGroup, "Settings", 2, GridData.FILL_HORIZONTAL, 0);
optionsGroup2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING));
if (params.maxResults <= 0) {
params.maxResults = 10;
}
final Spinner maxResultsSpinner = UIUtils.createLabelSpinner(optionsGroup2, "Sample rows", params.maxResults, 1, Integer.MAX_VALUE);
maxResultsSpinner.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
maxResultsSpinner.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
params.maxResults = maxResultsSpinner.getSelection();
}
});
final Button caseCheckbox = UIUtils.createLabelCheckbox(optionsGroup2, CoreMessages.dialog_search_objects_case_sensitive, params.caseSensitive);
caseCheckbox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
caseCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
params.caseSensitive = caseCheckbox.getSelection();
}
});
final Button fastSearchCheckbox = UIUtils.createLabelCheckbox(optionsGroup2, "Fast search (indexed)", params.fastSearch);
fastSearchCheckbox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
fastSearchCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
params.fastSearch = fastSearchCheckbox.getSelection();
}
});
final Button searchNumbersCheckbox = UIUtils.createLabelCheckbox(optionsGroup2, "Search in numbers", params.searchNumbers);
searchNumbersCheckbox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
searchNumbersCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
params.searchNumbers = searchNumbersCheckbox.getSelection();
}
});
final Button searchLOBCheckbox = UIUtils.createLabelCheckbox(optionsGroup2, "Search in LOBs", params.searchLOBs);
searchLOBCheckbox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
searchLOBCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
params.searchLOBs = searchNumbersCheckbox.getSelection();
}
});
}
final List<DBNNode> checkedNodes = new ArrayList<>();
dataSourceTree.setEnabled(false);
try {
DBeaverUI.runInProgressDialog(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Load database nodes", 1);
try {
monitor.subTask("Load tree state");
checkedNodes.addAll(loadTreeState(monitor, store, PROP_SOURCES));
} finally {
monitor.done();
}
}
});
} catch (InvocationTargetException e) {
UIUtils.showErrorDialog(getShell(), "Data sources load", "Error loading settings", e.getTargetException());
}
if (!checkedNodes.isEmpty()) {
boolean first = true;
for (DBNNode node : checkedNodes) {
((CheckboxTreeViewer) dataSourceTree.getViewer()).setChecked(node, true);
if (first) {
dataSourceTree.getViewer().reveal(NavigatorUtils.getDataSourceNode(node));
first = false;
}
}
checkboxTreeManager.updateCheckStates();
}
updateEnablement();
dataSourceTree.setEnabled(true);
}
Aggregations