use of org.jkiss.dbeaver.model.struct.DBSObjectFilter in project dbeaver by serge-rider.
the class NavigatorHandlerFilterClear method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getCurrentSelection(event);
DBNNode node = NavigatorUtils.getSelectedNode(selection);
if (node instanceof DBNDatabaseItem) {
node = node.getParentNode();
}
if (node instanceof DBNDatabaseFolder) {
final DBNDatabaseFolder folder = (DBNDatabaseFolder) node;
DBXTreeItem itemsMeta = folder.getItemsMeta();
if (itemsMeta != null) {
folder.setNodeFilter(itemsMeta, new DBSObjectFilter());
NavigatorHandlerRefresh.refreshNavigator(Collections.singleton(folder));
}
}
return null;
}
use of org.jkiss.dbeaver.model.struct.DBSObjectFilter in project dbeaver by serge-rider.
the class NavigatorHandlerFilterToggle method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getCurrentSelection(event);
DBNNode node = NavigatorUtils.getSelectedNode(selection);
if (node instanceof DBNDatabaseItem) {
node = node.getParentNode();
}
if (node instanceof DBNDatabaseFolder) {
final DBNDatabaseFolder folder = (DBNDatabaseFolder) node;
DBXTreeItem itemsMeta = folder.getItemsMeta();
if (itemsMeta != null) {
final DBSObjectFilter nodeFilter = folder.getNodeFilter(itemsMeta, true);
if (nodeFilter != null) {
nodeFilter.setEnabled(!nodeFilter.isEnabled());
NavigatorHandlerRefresh.refreshNavigator(Collections.singleton(folder));
}
}
}
return null;
}
use of org.jkiss.dbeaver.model.struct.DBSObjectFilter in project dbeaver by dbeaver.
the class MSSQLDatabase method loadSchemas.
private List<MSSQLSchema> loadSchemas(JDBCSession session) throws DBException {
boolean showAllSchemas = dataSource.isShowAllSchemas();
final DBSObjectFilter schemaFilters = dataSource.getContainer().getObjectFilter(GenericSchema.class, this, false);
String sysSchema = DBUtils.getQuotedIdentifier(this) + ".sys";
String sql;
if (showAllSchemas) {
if (dataSource.isServerVersionAtLeast(SQLServerConstants.SQL_SERVER_2005_VERSION_MAJOR, 0)) {
sql = "SELECT name FROM " + DBUtils.getQuotedIdentifier(this) + ".sys.schemas";
} else {
sql = "SELECT name FROM " + DBUtils.getQuotedIdentifier(this) + ".dbo.sysusers";
}
} else {
sql = "SELECT DISTINCT s.name\n" + "FROM " + sysSchema + ".schemas s, " + sysSchema + ".sysobjects o\n" + "WHERE s.schema_id=o.uid\n" + "ORDER BY 1";
}
List<MSSQLSchema> result = new ArrayList<>();
try (JDBCPreparedStatement dbStat = session.prepareStatement(sql)) {
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
while (dbResult.next()) {
String name = JDBCUtils.safeGetString(dbResult, 1);
if (name == null) {
continue;
}
name = name.trim();
if (schemaFilters != null && !schemaFilters.matches(name)) {
// Doesn't match filter
continue;
}
MSSQLSchema schema = new MSSQLSchema(this, name);
result.add(schema);
}
}
} catch (SQLException e) {
throw new DBException(e, dataSource);
}
if (result.isEmpty()) {
if (!showAllSchemas) {
// Perhaps all schemas were filtered out
result.add(new MSSQLSchema(this, SQLServerConstants.DEFAULT_SCHEMA_NAME));
} else {
// Maybe something went wrong. LEt's try to use native function
log.warn("Schema read failed: empty list returned. Try generic method.");
try (JDBCResultSet dbResult = session.getMetaData().getSchemas()) {
while (dbResult.next()) {
result.add(new MSSQLSchema(this, dbResult.getString("TABLE_SCHEM")));
}
} catch (SQLException e) {
log.error("Error reading schemas from database metadata", e);
}
}
}
return result;
}
use of org.jkiss.dbeaver.model.struct.DBSObjectFilter in project dbeaver by dbeaver.
the class NavigatorHandlerFilterToggle method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getCurrentSelection(event);
DBNNode node = NavigatorUtils.getSelectedNode(selection);
if (node instanceof DBNDatabaseItem) {
node = node.getParentNode();
}
if (node instanceof DBNDatabaseFolder) {
final DBNDatabaseFolder folder = (DBNDatabaseFolder) node;
DBXTreeItem itemsMeta = folder.getItemsMeta();
if (itemsMeta != null) {
final DBSObjectFilter nodeFilter = folder.getNodeFilter(itemsMeta, true);
if (nodeFilter != null) {
nodeFilter.setEnabled(!nodeFilter.isEnabled());
NavigatorHandlerRefresh.refreshNavigator(Collections.singleton(folder));
}
}
}
return null;
}
use of org.jkiss.dbeaver.model.struct.DBSObjectFilter in project dbeaver by dbeaver.
the class EditObjectFilterDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
getShell().setText(NLS.bind(CoreMessages.dialog_filter_title, objectTitle));
// getShell().setImage(DBIcon.EVENT.getImage());
Composite composite = (Composite) super.createDialogArea(parent);
Composite topPanel = UIUtils.createPlaceholder(composite, globalFilter ? 1 : 2);
topPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
enableButton = UIUtils.createCheckbox(topPanel, CoreMessages.dialog_filter_button_enable, false);
enableButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
filter.setEnabled(enableButton.getSelection());
enableFiltersContent();
}
});
enableButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
enableButton.setSelection(filter.isEnabled());
if (!globalFilter) {
Link globalLink = UIUtils.createLink(topPanel, CoreMessages.dialog_filter_global_link, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
setReturnCode(SHOW_GLOBAL_FILTERS_ID);
close();
}
});
globalLink.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
}
blockControl = UIUtils.createPlaceholder(composite, 1);
blockControl.setLayoutData(new GridData(GridData.FILL_BOTH));
includeTable = createEditableList(CoreMessages.dialog_filter_list_include, filter.getInclude());
excludeTable = createEditableList(CoreMessages.dialog_filter_list_exclude, filter.getExclude());
UIUtils.createInfoLabel(blockControl, CoreMessages.dialog_connection_edit_wizard_general_filter_hint_text);
{
Group sfGroup = UIUtils.createControlGroup(composite, CoreMessages.dialog_connection_edit_wizard_general_filter_save_label, 4, GridData.FILL_HORIZONTAL, 0);
namesCombo = UIUtils.createLabelCombo(sfGroup, CoreMessages.dialog_connection_edit_wizard_general_filter_name_label, SWT.DROP_DOWN);
namesCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
namesCombo.add(NULL_FILTER_NAME);
List<String> sfNames = new ArrayList<>();
for (DBSObjectFilter sf : dsRegistry.getSavedFilters()) {
sfNames.add(sf.getName());
}
Collections.sort(sfNames);
for (String sfName : sfNames) {
namesCombo.add(sfName);
}
namesCombo.setText(CommonUtils.notEmpty(filter.getName()));
namesCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
changeSavedFilter();
}
});
Button saveButton = UIUtils.createPushButton(sfGroup, CoreMessages.dialog_connection_edit_wizard_general_filter_save_button, null);
saveButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
saveConfigurations();
}
});
Button removeButton = UIUtils.createPushButton(sfGroup, CoreMessages.dialog_connection_edit_wizard_general_filter_remove_button, null);
removeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
dsRegistry.removeSavedFilter(namesCombo.getText());
namesCombo.setText(NULL_FILTER_NAME);
}
});
}
enableFiltersContent();
return composite;
}
Aggregations