use of org.jkiss.dbeaver.model.struct.DBSObjectFilter in project dbeaver by serge-rider.
the class NavigatorHandlerFilterConfig method configureFilters.
public static void configureFilters(Shell shell, DBNNode node) {
final DBNDatabaseFolder folder = (DBNDatabaseFolder) node;
DBXTreeItem itemsMeta = folder.getItemsMeta();
if (itemsMeta != null) {
DBSObjectFilter objectFilter = folder.getNodeFilter(itemsMeta, true);
if (objectFilter == null) {
objectFilter = new DBSObjectFilter();
}
boolean globalFilter = folder.getValueObject() instanceof DBPDataSource;
String parentName = "?";
if (folder.getValueObject() instanceof DBSObject) {
parentName = ((DBSObject) folder.getValueObject()).getName();
}
EditObjectFilterDialog dialog = new EditObjectFilterDialog(shell, globalFilter ? "All " + node.getNodeType() : node.getNodeType() + " of " + parentName, objectFilter, globalFilter);
switch(dialog.open()) {
case IDialogConstants.OK_ID:
folder.setNodeFilter(itemsMeta, dialog.getFilter());
NavigatorHandlerRefresh.refreshNavigator(Collections.singletonList(folder));
break;
case EditObjectFilterDialog.SHOW_GLOBAL_FILTERS_ID:
objectFilter = folder.getDataSource().getContainer().getObjectFilter(folder.getChildrenClass(), null, false);
dialog = new EditObjectFilterDialog(shell, "All " + node.getNodeType(), objectFilter != null ? objectFilter : new DBSObjectFilter(), true);
if (dialog.open() == IDialogConstants.OK_ID) {
// Set global filter
folder.getDataSource().getContainer().setObjectFilter(folder.getChildrenClass(), null, dialog.getFilter());
folder.getDataSource().getContainer().persistConfiguration();
NavigatorHandlerRefresh.refreshNavigator(Collections.singletonList(folder));
}
break;
}
}
}
use of org.jkiss.dbeaver.model.struct.DBSObjectFilter in project dbeaver by dbeaver.
the class SQLServerMetaModel method loadSchemas.
@Override
public List<GenericSchema> loadSchemas(JDBCSession session, GenericDataSource dataSource, GenericCatalog catalog) throws DBException {
if (catalog == null) {
// Schemas MUST be in catalog
return null;
}
boolean showAllSchemas = ((SQLServerDataSource) dataSource).isShowAllSchemas();
final DBSObjectFilter schemaFilters = dataSource.getContainer().getObjectFilter(GenericSchema.class, catalog, false);
String sysSchema = getSystemSchemaFQN(dataSource, catalog);
String sql;
if (showAllSchemas) {
if (getServerType() == ServerType.SQL_SERVER && dataSource.isServerVersionAtLeast(SQLServerConstants.SQL_SERVER_2005_VERSION_MAJOR, 0)) {
sql = "SELECT name FROM " + sysSchema + ".schemas";
} else {
sql = "SELECT name FROM " + sysSchema + ".sysusers";
}
} else {
if (getServerType() == ServerType.SQL_SERVER) {
sql = "SELECT DISTINCT s.name\n" + "FROM " + sysSchema + ".schemas s, " + sysSchema + ".sysobjects o\n" + "WHERE s.schema_id=o.uid\n" + "ORDER BY 1";
} else {
sql = "SELECT DISTINCT u.name\n" + "FROM " + sysSchema + ".sysusers u, " + sysSchema + ".sysobjects o\n" + "WHERE u.uid=o.uid\n" + "ORDER BY 1";
}
}
boolean schemaReadFailed = false;
List<GenericSchema> 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;
}
SQLServerSchema schema = createSchemaImpl(dataSource, catalog, name);
result.add(schema);
}
}
} catch (SQLException e) {
if (dataSource.discoverErrorType(e) == DBPErrorAssistant.ErrorType.CONNECTION_LOST) {
throw new DBException(e, dataSource);
} else {
log.warn("Schema read failed: empty list returned. Try generic method.", e);
schemaReadFailed = true;
}
}
if (result.isEmpty()) {
if (!schemaReadFailed && !showAllSchemas) {
// Perhaps all schemas were filtered out
result.add(new GenericSchema(dataSource, catalog, SQLServerConstants.DEFAULT_SCHEMA_NAME));
} else {
// Maybe something went wrong. LEt's try to use native function
return super.loadSchemas(session, dataSource, catalog);
}
}
return result;
}
use of org.jkiss.dbeaver.model.struct.DBSObjectFilter in project dbeaver by dbeaver.
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 dbeaver.
the class NavigatorHandlerFilterConfig method configureFilters.
public static void configureFilters(Shell shell, DBNNode node) {
final DBNDatabaseFolder folder = (DBNDatabaseFolder) node;
DBXTreeItem itemsMeta = folder.getItemsMeta();
if (itemsMeta != null) {
DBSObjectFilter objectFilter = folder.getNodeFilter(itemsMeta, true);
if (objectFilter == null) {
objectFilter = new DBSObjectFilter();
}
final DBPDataSourceRegistry dsRegistry = DBeaverCore.getInstance().getProjectManager().getDataSourceRegistry(folder.getOwnerProject());
final boolean globalFilter = folder.getValueObject() instanceof DBPDataSource;
String parentName = "?";
if (folder.getValueObject() instanceof DBSObject) {
parentName = ((DBSObject) folder.getValueObject()).getName();
}
EditObjectFilterDialog dialog = new EditObjectFilterDialog(shell, dsRegistry, globalFilter ? "All " + node.getNodeType() : node.getNodeType() + " of " + parentName, objectFilter, globalFilter);
switch(dialog.open()) {
case IDialogConstants.OK_ID:
folder.setNodeFilter(itemsMeta, dialog.getFilter());
NavigatorHandlerRefresh.refreshNavigator(Collections.singletonList(folder));
break;
case EditObjectFilterDialog.SHOW_GLOBAL_FILTERS_ID:
objectFilter = folder.getDataSource().getContainer().getObjectFilter(folder.getChildrenClass(), null, false);
dialog = new EditObjectFilterDialog(shell, dsRegistry, "All " + node.getNodeType(), objectFilter != null ? objectFilter : new DBSObjectFilter(), true);
if (dialog.open() == IDialogConstants.OK_ID) {
// Set global filter
folder.getDataSource().getContainer().setObjectFilter(folder.getChildrenClass(), null, dialog.getFilter());
folder.getDataSource().getContainer().persistConfiguration();
NavigatorHandlerRefresh.refreshNavigator(Collections.singletonList(folder));
}
break;
}
}
}
use of org.jkiss.dbeaver.model.struct.DBSObjectFilter in project dbeaver by serge-rider.
the class NavigatorUtils method filterSelection.
public static void filterSelection(final ISelection selection, boolean exclude) {
if (selection instanceof IStructuredSelection) {
Map<DBNDatabaseFolder, DBSObjectFilter> folders = new HashMap<>();
for (Object item : ((IStructuredSelection) selection).toArray()) {
if (item instanceof DBNNode) {
final DBNNode node = (DBNNode) item;
DBNDatabaseFolder folder = (DBNDatabaseFolder) node.getParentNode();
DBSObjectFilter nodeFilter = folders.get(folder);
if (nodeFilter == null) {
nodeFilter = folder.getNodeFilter(folder.getItemsMeta(), true);
if (nodeFilter == null) {
nodeFilter = new DBSObjectFilter();
}
folders.put(folder, nodeFilter);
}
if (exclude) {
nodeFilter.addExclude(node.getNodeName());
} else {
nodeFilter.addInclude(node.getNodeName());
}
nodeFilter.setEnabled(true);
}
}
// Save folders
for (Map.Entry<DBNDatabaseFolder, DBSObjectFilter> entry : folders.entrySet()) {
entry.getKey().setNodeFilter(entry.getKey().getItemsMeta(), entry.getValue());
}
// Refresh all folders
NavigatorHandlerRefresh.refreshNavigator(folders.keySet());
}
}
Aggregations