use of org.jkiss.dbeaver.model.struct.DBSObjectFilter in project dbeaver by dbeaver.
the class EditObjectFilterDialog method changeSavedFilter.
private void changeSavedFilter() {
String filterName = namesCombo.getText();
if (CommonUtils.equalObjects(filterName, filter.getName())) {
return;
}
if (CommonUtils.isEmpty(filterName)) {
// Reset filter
fillFilterValues(includeTable, null);
fillFilterValues(excludeTable, null);
} else {
// Find saved filter
DBSObjectFilter savedFilter = dsRegistry.getSavedFilter(filterName);
if (savedFilter != null) {
fillFilterValues(includeTable, savedFilter.getInclude());
fillFilterValues(excludeTable, savedFilter.getExclude());
}
}
filter.setName(filterName);
}
use of org.jkiss.dbeaver.model.struct.DBSObjectFilter in project dbeaver by dbeaver.
the class ConnectionPageGeneral method createControl.
@Override
public void createControl(Composite parent) {
boldFont = UIUtils.makeBoldFont(parent.getFont());
Composite group = UIUtils.createComposite(parent, 1);
{
Composite miscGroup = UIUtils.createControlGroup(group, CoreMessages.pref_page_ui_general_group_general, 2, GridData.FILL_HORIZONTAL, 0);
// $NON-NLS-1$
String connectionName = dataSourceDescriptor == null ? "" : dataSourceDescriptor.getName();
connectionNameText = UIUtils.createLabelText(miscGroup, CoreMessages.dialog_connection_wizard_final_label_connection_name, CommonUtils.toString(connectionName));
connectionNameText.addModifyListener(e -> {
connectionNameChanged = true;
ConnectionPageGeneral.this.getContainer().updateButtons();
});
{
UIUtils.createControlLabel(miscGroup, CoreMessages.dialog_connection_wizard_final_label_connection_type);
Composite ctGroup = UIUtils.createComposite(miscGroup, 2);
connectionTypeCombo = new CSmartCombo<>(ctGroup, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY, new ConnectionTypeLabelProvider());
loadConnectionTypes();
connectionTypeCombo.select(0);
connectionTypeCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DBPConnectionType type = connectionTypeCombo.getItem(connectionTypeCombo.getSelectionIndex());
getWizard().firePropertyChangeEvent(ConnectionWizard.PROP_CONNECTION_TYPE, getActiveDataSource().getConnectionConfiguration().getConnectionType(), type);
}
});
final GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.widthHint = UIUtils.getFontHeight(connectionTypeCombo) * 20;
connectionTypeCombo.setLayoutData(gd);
UIUtils.createDialogButton(ctGroup, CoreMessages.dialog_connection_wizard_final_label_connection_types_edit, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DBPConnectionType curConType = connectionTypeCombo.getSelectedItem();
DataSourceDescriptor dataSource = getActiveDataSource();
UIUtils.showPreferencesFor(getControl().getShell(), dataSource.getConnectionConfiguration().getConnectionType(), PrefPageConnectionTypes.PAGE_ID);
loadConnectionTypes();
if (!connectionTypeCombo.getItems().contains(curConType)) {
curConType = connectionTypeCombo.getItems().get(0);
}
connectionTypeCombo.select(curConType);
getWizard().firePropertyChangeEvent(ConnectionWizard.PROP_CONNECTION_TYPE, curConType, curConType);
}
});
}
{
UIUtils.createControlLabel(miscGroup, CoreMessages.dialog_connection_wizard_final_label_navigator_settings);
Composite ctGroup = UIUtils.createComposite(miscGroup, 2);
navigatorSettingsCombo = new Combo(ctGroup, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
final GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.widthHint = UIUtils.getFontHeight(navigatorSettingsCombo) * 20;
navigatorSettingsCombo.setLayoutData(gd);
for (String ncPresetName : DataSourceNavigatorSettings.PRESETS.keySet()) {
navigatorSettingsCombo.add(ncPresetName);
}
navigatorSettingsCombo.select(0);
navigatorSettingsCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (navigatorSettingsCombo.getSelectionIndex() == navigatorSettingsCombo.getItemCount() - 1) {
// Custom - no changes
} else {
DataSourceNavigatorSettings.Preset newSettings = DataSourceNavigatorSettings.PRESETS.get(navigatorSettingsCombo.getText());
if (newSettings == null) {
throw new IllegalStateException("Invalid preset name: " + navigatorSettingsCombo.getText());
}
ConnectionPageGeneral.this.navigatorSettings = newSettings.getSettings();
}
}
});
UIUtils.createDialogButton(ctGroup, CoreMessages.dialog_connection_wizard_final_label_navigator_settings_customize, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
editNavigatorSettings();
}
});
}
{
UIUtils.createControlLabel(miscGroup, CoreMessages.dialog_connection_wizard_final_label_connection_folder);
connectionFolderCombo = new Combo(miscGroup, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.widthHint = UIUtils.getFontHeight(connectionFolderCombo) * 20;
connectionFolderCombo.setLayoutData(gd);
loadConnectionFolders();
connectionFolderCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
dataSourceFolder = connectionFolders.get(connectionFolderCombo.getSelectionIndex());
}
});
}
{
Label descLabel = UIUtils.createControlLabel(miscGroup, CoreMessages.dialog_connection_wizard_description);
descLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
descriptionText = new Text(miscGroup, SWT.BORDER | SWT.V_SCROLL | SWT.WRAP | SWT.MULTI);
final GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.heightHint = descriptionText.getLineHeight() * 3;
descriptionText.setLayoutData(gd);
}
}
Composite refsGroup = UIUtils.createComposite(group, 3);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
refsGroup.setLayoutData(gd);
{
// Security
Group securityGroup = UIUtils.createControlGroup(refsGroup, CoreMessages.dialog_connection_wizard_final_group_security, 1, GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_BEGINNING, 0);
readOnlyConnection = UIUtils.createCheckbox(securityGroup, CoreMessages.dialog_connection_wizard_final_checkbox_connection_readonly, dataSourceDescriptor != null && dataSourceDescriptor.isConnectionReadOnly());
readOnlyConnection.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
UIUtils.createDialogButton(securityGroup, "Edit permissions ...", new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
editPermissions();
}
});
}
{
// Filters
filtersGroup = UIUtils.createControlGroup(refsGroup, CoreMessages.dialog_connection_wizard_final_group_filters, 1, GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_BEGINNING, 0);
for (final FilterInfo filterInfo : filters) {
filterInfo.link = UIUtils.createLink(filtersGroup, "<a>" + filterInfo.title + "</a>", new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
EditObjectFilterDialog dialog = new EditObjectFilterDialog(getShell(), getWizard().getDataSourceRegistry(), filterInfo.title, filterInfo.filter != null ? filterInfo.filter : new DBSObjectFilter(), true);
if (dialog.open() == IDialogConstants.OK_ID) {
filterInfo.filter = dialog.getFilter();
if (filterInfo.filter != null && !filterInfo.filter.isNotApplicable()) {
filterInfo.link.setFont(boldFont);
} else {
filterInfo.link.setFont(getFont());
}
}
}
});
filterInfo.link.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
}
{
Composite linkGroup = UIUtils.createComposite(refsGroup, 1);
gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.horizontalSpan = 2;
linkGroup.setLayoutData(gd);
Link initConfigLink = new Link(linkGroup, SWT.NONE);
initConfigLink.setText("<a>" + CoreMessages.dialog_connection_wizard_connection_init_description + "</a>");
initConfigLink.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (getWizard().isNew()) {
DataSourceDescriptor dataSource = getActiveDataSource();
EditWizardPageDialog dialog = new EditWizardPageDialog(getWizard(), new ConnectionPageInitialization(dataSource), dataSource);
dialog.open();
} else {
getWizard().openSettingsPage(ConnectionPageInitialization.PAGE_NAME);
}
}
});
initConfigLink.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
Link shellConfigLink = new Link(linkGroup, SWT.NONE);
shellConfigLink.setText("<a>" + CoreMessages.dialog_connection_edit_wizard_shell_cmd + "</a>");
shellConfigLink.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (getWizard().isNew()) {
DataSourceDescriptor dataSource = getActiveDataSource();
EditWizardPageDialog dialog = new EditWizardPageDialog(getWizard(), new ConnectionPageShellCommands(dataSource), dataSource);
dialog.open();
} else {
getWizard().openSettingsPage(ConnectionPageShellCommands.PAGE_NAME);
}
}
});
shellConfigLink.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
}
setControl(group);
UIUtils.setHelp(group, IHelpContextIds.CTX_CON_WIZARD_FINAL);
}
use of org.jkiss.dbeaver.model.struct.DBSObjectFilter in project dbeaver by dbeaver.
the class GenericMetaModel method loadSchemas.
public List<GenericSchema> loadSchemas(JDBCSession session, GenericDataSource dataSource, GenericCatalog catalog) throws DBException {
if (dataSource.isOmitSchema()) {
return null;
}
try {
final GenericMetaObject schemaObject = getMetaObject(GenericConstants.OBJECT_SCHEMA);
final DBSObjectFilter schemaFilters = dataSource.getContainer().getObjectFilter(GenericSchema.class, catalog, false);
final List<GenericSchema> tmpSchemas = new ArrayList<>();
JDBCResultSet dbResult = null;
boolean catalogSchemas = false, schemasFiltered = false;
if (catalog != null) {
try {
dbResult = session.getMetaData().getSchemas(catalog.getName(), schemaFilters != null && schemaFilters.hasSingleMask() ? schemaFilters.getSingleMask() : dataSource.getAllObjectsPattern());
catalogSchemas = true;
} catch (Throwable e) {
if (isSchemasOptional()) {
// This method not supported (may be old driver version)
// Use general schema reading method
log.debug("Error reading schemas in catalog '" + catalog.getName() + "' - " + e.getClass().getSimpleName() + " - " + e.getMessage());
} else {
throw e;
}
}
} else if (dataSource.isSchemaFiltersEnabled()) {
// incorrect results.
try {
dbResult = session.getMetaData().getSchemas(null, schemaFilters != null && schemaFilters.hasSingleMask() ? schemaFilters.getSingleMask() : dataSource.getAllObjectsPattern());
} catch (Throwable e) {
if (isSchemasOptional()) {
log.debug("Error reading global schemas " + " - " + e.getMessage());
} else {
throw e;
}
}
}
if (dbResult == null) {
dbResult = session.getMetaData().getSchemas();
}
try {
while (dbResult.next()) {
if (session.getProgressMonitor().isCanceled()) {
break;
}
String schemaName = GenericUtils.safeGetString(schemaObject, dbResult, JDBCConstants.TABLE_SCHEM);
if (CommonUtils.isEmpty(schemaName)) {
// some drivers uses TABLE_OWNER column instead of TABLE_SCHEM
schemaName = GenericUtils.safeGetString(schemaObject, dbResult, JDBCConstants.TABLE_OWNER);
}
boolean nullSchema = false;
if (CommonUtils.isEmpty(schemaName)) {
if (supportsNullSchemas()) {
schemaName = DEFAULT_NULL_SCHEMA_NAME;
nullSchema = true;
} else {
continue;
}
}
if (schemaFilters != null && !schemaFilters.matches(schemaName)) {
// Doesn't match filter
schemasFiltered = true;
continue;
}
String catalogName = GenericUtils.safeGetString(schemaObject, dbResult, JDBCConstants.TABLE_CATALOG);
if (!CommonUtils.isEmpty(catalogName)) {
if (catalog == null) {
if (!dataSource.isOmitCatalog()) {
// Invalid schema's catalog or schema without catalog (then do not use schemas as structure)
log.debug("Catalog name (" + catalogName + ") found for schema '" + schemaName + "' while schema doesn't have parent catalog");
}
} else if (!catalog.getName().equals(catalogName)) {
if (!catalogSchemas) {
// Just skip it - we have list of all existing schemas and this one belongs to another catalog
continue;
}
log.debug("Catalog name '" + catalogName + "' differs from schema's catalog '" + catalog.getName() + "'");
}
}
session.getProgressMonitor().subTask("Schema " + schemaName);
GenericSchema schema = createSchemaImpl(dataSource, catalog, schemaName);
if (nullSchema) {
schema.setVirtual(true);
}
tmpSchemas.add(schema);
}
} finally {
dbResult.close();
}
if (tmpSchemas.isEmpty() && catalogSchemas && !schemasFiltered && dataSource.getCatalogs().size() == 1) {
// There is just one catalog and empty schema list. Try to read global schemas
return loadSchemas(session, dataSource, null);
}
if (dataSource.isOmitSingleSchema() && catalog == null && tmpSchemas.size() == 1 && (schemaFilters == null || schemaFilters.isNotApplicable())) {
// Only one schema and no catalogs
// Most likely it is a fake one, let's skip it
// Anyway using "%" instead is ok
tmpSchemas.clear();
}
return tmpSchemas;
} catch (UnsupportedOperationException | SQLFeatureNotSupportedException e) {
// Schemas are not supported
log.debug("Can't read schema list: " + e.getMessage());
return null;
} catch (Throwable ex) {
if (isSchemasOptional()) {
// Schemas are not supported - just ignore this error
log.warn("Can't read schema list", ex);
return null;
} else {
log.error("Can't read schema list", ex);
throw new DBException(ex, dataSource);
}
}
}
use of org.jkiss.dbeaver.model.struct.DBSObjectFilter in project dbeaver by serge-rider.
the class ObjectPropertyTester method test.
@SuppressWarnings("unchecked")
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (!(receiver instanceof DBNNode)) {
return false;
}
Display display = Display.getCurrent();
if (display == null) {
return false;
}
DBNNode node = (DBNNode) receiver;
switch(property) {
case PROP_CAN_OPEN:
return node.isPersisted();
case PROP_CAN_CREATE_SINGLE:
{
return canCreateObject(node, true);
}
case PROP_CAN_CREATE_MULTI:
{
return canCreateObject(node, false);
}
case PROP_CAN_PASTE:
{
/*
Clipboard clipboard = new Clipboard(display);
try {
if (clipboard.getContents(TreeNodeTransfer.getInstance()) == null) {
return false;
}
} finally {
clipboard.dispose();
}
*/
if (node instanceof DBNResource) {
return property.equals(PROP_CAN_PASTE);
}
return canCreateObject(node, null);
// Do not check PASTE command state. It requires clipboard contents check
// which means UI interaction which can break menu popup [RedHat]
// and also is a slow operation. So let paste be always enabled.
/*
// Check objects in clipboard
Collection<DBNNode> cbNodes = TreeNodeTransfer.getFromClipboard();
if (cbNodes == null) {
return false;
}
for (DBNNode nodeObject : cbNodes) {
if (nodeObject.isManagable() && nodeObject instanceof DBSWrapper) {
DBSObject pasteObject = ((DBSWrapper)nodeObject).getObject();
if (pasteObject == null || objectType != pasteObject.getClass()) {
return false;
}
} else {
return false;
}
}
*/
}
case PROP_CAN_DELETE:
{
if (node instanceof DBNDataSource || node instanceof DBNLocalFolder) {
return true;
}
if (DBNUtils.isReadOnly(node)) {
return false;
}
if (node instanceof DBSWrapper) {
DBSObject object = ((DBSWrapper) node).getObject();
if (object == null || DBUtils.isReadOnly(object) || !(node.getParentNode() instanceof DBNContainer)) {
return false;
}
DBEObjectMaker objectMaker = getObjectManager(object.getClass(), DBEObjectMaker.class);
return objectMaker != null && objectMaker.canDeleteObject(object);
} else if (node instanceof DBNResource) {
if ((((DBNResource) node).getFeatures() & DBPResourceHandler.FEATURE_DELETE) != 0) {
return true;
}
}
break;
}
case PROP_CAN_RENAME:
{
if (node.supportsRename()) {
return true;
}
if (node instanceof DBNDatabaseNode) {
if (DBNUtils.isReadOnly(node)) {
return false;
}
DBSObject object = ((DBNDatabaseNode) node).getObject();
return object != null && !DBUtils.isReadOnly(object) && object.isPersisted() && node.getParentNode() instanceof DBNContainer && getObjectManager(object.getClass(), DBEObjectRenamer.class) != null;
}
break;
}
case PROP_CAN_MOVE_UP:
case PROP_CAN_MOVE_DOWN:
{
if (node instanceof DBNDatabaseNode) {
if (DBNUtils.isReadOnly(node)) {
return false;
}
DBSObject object = ((DBNDatabaseNode) node).getObject();
if (object instanceof DBPOrderedObject) {
DBEObjectReorderer objectReorderer = getObjectManager(object.getClass(), DBEObjectReorderer.class);
if (objectReorderer != null) {
final int position = ((DBPOrderedObject) object).getOrdinalPosition();
if (property.equals(PROP_CAN_MOVE_UP)) {
return position > objectReorderer.getMinimumOrdinalPosition(object);
}
return position < objectReorderer.getMaximumOrdinalPosition(object);
}
}
}
break;
}
case PROP_CAN_FILTER:
{
if (node instanceof DBNDatabaseItem) {
node = node.getParentNode();
}
if (node instanceof DBNDatabaseFolder && ((DBNDatabaseFolder) node).getItemsMeta() != null) {
return true;
}
break;
}
case PROP_CAN_FILTER_OBJECT:
{
if (node.getParentNode() instanceof DBNDatabaseFolder && ((DBNDatabaseFolder) node.getParentNode()).getItemsMeta() != null) {
return true;
}
break;
}
case PROP_HAS_FILTER:
{
if (node instanceof DBNDatabaseItem) {
node = node.getParentNode();
}
if (node instanceof DBNDatabaseFolder && ((DBNDatabaseFolder) node).getItemsMeta() != null) {
DBSObjectFilter filter = ((DBNDatabaseFolder) node).getNodeFilter(((DBNDatabaseFolder) node).getItemsMeta(), true);
if ("defined".equals(expectedValue)) {
return filter != null && !filter.isEmpty();
} else {
return filter != null && !filter.isNotApplicable();
}
}
break;
}
}
return false;
}
use of org.jkiss.dbeaver.model.struct.DBSObjectFilter in project dbeaver by serge-rider.
the class DataSourceSerializerModern method readObjectFiler.
private static DBSObjectFilter readObjectFiler(Map<String, Object> map) {
DBSObjectFilter filter = new DBSObjectFilter();
filter.setName(JSONUtils.getString(map, RegistryConstants.ATTR_NAME));
filter.setDescription(JSONUtils.getString(map, RegistryConstants.ATTR_DESCRIPTION));
filter.setEnabled(JSONUtils.getBoolean(map, RegistryConstants.ATTR_ENABLED));
filter.setInclude(JSONUtils.deserializeStringList(map, RegistryConstants.TAG_INCLUDE));
filter.setExclude(JSONUtils.deserializeStringList(map, RegistryConstants.TAG_EXCLUDE));
return filter;
}
Aggregations