use of org.jkiss.dbeaver.model.virtual.DBVEntityAttribute in project dbeaver by serge-rider.
the class TransformerSettingsDialog method saveTransformerSettings.
private void saveTransformerSettings() {
if (currentAttribute == null) {
// Nothign to save - just ignore
return;
}
DBVEntityAttribute vAttr = vEntity.getVirtualAttribute(currentAttribute, true);
if (vAttr == null) {
log.error("Can't get attribute settings for " + currentAttribute.getName());
return;
}
DBVTransformSettings settings = DBVUtils.getTransformSettings(vAttr, true);
if (settings == null) {
log.error("Can't get transform settings for " + currentAttribute.getName());
return;
}
if (selector) {
settings.setCustomTransformer(transformer == null ? null : transformer.getId());
}
if (transformer == null) {
settings.setTransformOptions(new LinkedHashMap<>());
} else {
final Map<String, Object> properties = propertySource.getPropertiesWithDefaults();
for (Map.Entry<String, Object> prop : properties.entrySet()) {
if (prop.getValue() != null) {
settings.setTransformOption(prop.getKey().toString(), prop.getValue().toString());
}
}
}
}
use of org.jkiss.dbeaver.model.virtual.DBVEntityAttribute in project dbeaver by serge-rider.
the class EditVirtualAttributePage method createPageContents.
@Override
protected Control createPageContents(Composite parent) {
final Composite dialogArea = UIUtils.createComposite(parent, 1);
dialogArea.setLayoutData(new GridData(GridData.FILL_BOTH));
DBPDataSource dataSource = vAttr.getEntity().getDataSource();
Composite panel = UIUtils.createComposite(dialogArea, 2);
panel.setLayoutData(new GridData(GridData.FILL_BOTH));
String name = vAttr.getName();
int index = 1;
for (; ; ) {
DBVEntityAttribute vAttr2 = vAttr.getEntity().getVirtualAttribute(name);
if (vAttr2 == null || vAttr2 == vAttr) {
break;
}
index++;
name = vAttr.getName() + index;
}
nameText = UIUtils.createLabelText(panel, "Column Name", name);
typeCombo = UIUtils.createLabelCombo(panel, "Type Name", "Column type name", SWT.BORDER | SWT.DROP_DOWN);
{
DBPDataTypeProvider dataTypeProvider = DBUtils.getAdapter(DBPDataTypeProvider.class, dataSource);
if (dataTypeProvider != null) {
List<DBSDataType> localDataTypes = new ArrayList<>(dataTypeProvider.getLocalDataTypes());
localDataTypes.sort(Comparator.comparing(DBSDataType::getFullTypeName));
for (DBSDataType dataType : localDataTypes) {
typeCombo.add(dataType.getFullTypeName());
}
String defTypeName = vAttr.getTypeName();
if (CommonUtils.isEmpty(defTypeName)) {
defTypeName = dataTypeProvider.getDefaultDataTypeName(DBPDataKind.STRING);
vAttr.setTypeName(defTypeName);
DBSDataType dataType = dataTypeProvider.getLocalDataType(defTypeName);
if (dataType != null) {
vAttr.setDataKind(dataType.getDataKind());
}
}
if (!CommonUtils.isEmpty(defTypeName)) {
typeCombo.setText(defTypeName);
}
typeCombo.addModifyListener(e -> {
DBSDataType dataType = dataTypeProvider.getLocalDataType(typeCombo.getText());
if (dataType != null) {
kindCombo.setText(dataType.getDataKind().name());
}
});
} else {
typeCombo.setText(CommonUtils.notEmpty(vAttr.getTypeName()));
}
ContentAssistUtils.installContentProposal(typeCombo, new ComboContentAdapter(), new StringContentProposalProvider(typeCombo.getItems()));
}
kindCombo = UIUtils.createLabelCombo(panel, "Data Kind", "Column data kind", SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
for (DBPDataKind dataKind : DBPDataKind.values()) {
if (dataKind != DBPDataKind.UNKNOWN) {
kindCombo.add(dataKind.name());
}
}
kindCombo.setText(vAttr.getDataKind().name());
expressionText = UIUtils.createLabelText(panel, "Expression", CommonUtils.notEmpty(vAttr.getExpression()), SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 300;
gd.heightHint = expressionText.getLineHeight() * 5;
expressionText.setLayoutData(gd);
List<String> expressionProposals = new ArrayList<>();
if (viewer != null) {
for (DBDAttributeBinding attr : viewer.getModel().getAttributes()) {
expressionProposals.add(attr.getLabel());
}
}
ContentAssistUtils.installContentProposal(expressionText, new SmartTextContentAdapter(), new StringContentProposalProvider(expressionProposals.toArray(new String[0])));
previewText = UIUtils.createLabelText(panel, "Preview", "", SWT.BORDER | SWT.READ_ONLY);
previewText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
expressionText.addModifyListener(e -> generatePreviewValue());
generatePreviewValue();
return dialogArea;
}
use of org.jkiss.dbeaver.model.virtual.DBVEntityAttribute in project dbeaver by dbeaver.
the class DBUtils method injectAndFilterAttributeBindings.
public static DBDAttributeBinding[] injectAndFilterAttributeBindings(@NotNull DBPDataSource dataSource, @NotNull DBSDataContainer dataContainer, DBDAttributeBinding[] bindings, boolean filterAttributes) {
// Add custom attributes
DBVEntity vEntity = DBVUtils.getVirtualEntity(dataContainer, false);
if (vEntity != null) {
List<DBVEntityAttribute> customAttributes = DBVUtils.getCustomAttributes(vEntity);
if (!CommonUtils.isEmpty(customAttributes)) {
DBDAttributeBinding[] customBindings = new DBDAttributeBinding[customAttributes.size()];
for (int i = 0; i < customAttributes.size(); i++) {
customBindings[i] = new DBDAttributeBindingCustom(null, dataContainer, dataSource, customAttributes.get(i), bindings.length + i);
}
DBDAttributeBinding[] combinedAttrs = new DBDAttributeBinding[bindings.length + customBindings.length];
System.arraycopy(bindings, 0, combinedAttrs, 0, bindings.length);
System.arraycopy(customBindings, 0, combinedAttrs, bindings.length, customBindings.length);
bindings = combinedAttrs;
}
}
if (filterAttributes && dataContainer instanceof DBDAttributeFilter) {
return ((DBDAttributeFilter) dataContainer).filterAttributeBindings(bindings);
} else {
return bindings;
}
}
use of org.jkiss.dbeaver.model.virtual.DBVEntityAttribute in project dbeaver by dbeaver.
the class EditVirtualAttributePage method createPageContents.
@Override
protected Control createPageContents(Composite parent) {
final Composite dialogArea = UIUtils.createComposite(parent, 1);
dialogArea.setLayoutData(new GridData(GridData.FILL_BOTH));
DBPDataSource dataSource = vAttr.getEntity().getDataSource();
Composite panel = UIUtils.createComposite(dialogArea, 2);
panel.setLayoutData(new GridData(GridData.FILL_BOTH));
String name = vAttr.getName();
int index = 1;
for (; ; ) {
DBVEntityAttribute vAttr2 = vAttr.getEntity().getVirtualAttribute(name);
if (vAttr2 == null || vAttr2 == vAttr) {
break;
}
index++;
name = vAttr.getName() + index;
}
nameText = UIUtils.createLabelText(panel, "Column Name", name);
typeCombo = UIUtils.createLabelCombo(panel, "Type Name", "Column type name", SWT.BORDER | SWT.DROP_DOWN);
{
DBPDataTypeProvider dataTypeProvider = DBUtils.getAdapter(DBPDataTypeProvider.class, dataSource);
if (dataTypeProvider != null) {
List<DBSDataType> localDataTypes = new ArrayList<>(dataTypeProvider.getLocalDataTypes());
localDataTypes.sort(Comparator.comparing(DBSDataType::getFullTypeName));
for (DBSDataType dataType : localDataTypes) {
typeCombo.add(dataType.getFullTypeName());
}
String defTypeName = vAttr.getTypeName();
if (CommonUtils.isEmpty(defTypeName)) {
defTypeName = dataTypeProvider.getDefaultDataTypeName(DBPDataKind.STRING);
vAttr.setTypeName(defTypeName);
DBSDataType dataType = dataTypeProvider.getLocalDataType(defTypeName);
if (dataType != null) {
vAttr.setDataKind(dataType.getDataKind());
}
}
if (!CommonUtils.isEmpty(defTypeName)) {
typeCombo.setText(defTypeName);
}
typeCombo.addModifyListener(e -> {
DBSDataType dataType = dataTypeProvider.getLocalDataType(typeCombo.getText());
if (dataType != null) {
kindCombo.setText(dataType.getDataKind().name());
}
});
} else {
typeCombo.setText(CommonUtils.notEmpty(vAttr.getTypeName()));
}
ContentAssistUtils.installContentProposal(typeCombo, new ComboContentAdapter(), new StringContentProposalProvider(typeCombo.getItems()));
}
kindCombo = UIUtils.createLabelCombo(panel, "Data Kind", "Column data kind", SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
for (DBPDataKind dataKind : DBPDataKind.values()) {
if (dataKind != DBPDataKind.UNKNOWN) {
kindCombo.add(dataKind.name());
}
}
kindCombo.setText(vAttr.getDataKind().name());
expressionText = UIUtils.createLabelText(panel, "Expression", CommonUtils.notEmpty(vAttr.getExpression()), SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 300;
gd.heightHint = expressionText.getLineHeight() * 5;
expressionText.setLayoutData(gd);
List<String> expressionProposals = new ArrayList<>();
if (viewer != null) {
for (DBDAttributeBinding attr : viewer.getModel().getAttributes()) {
expressionProposals.add(attr.getLabel());
}
}
ContentAssistUtils.installContentProposal(expressionText, new SmartTextContentAdapter(), new StringContentProposalProvider(expressionProposals.toArray(new String[0])));
previewText = UIUtils.createLabelText(panel, "Preview", "", SWT.BORDER | SWT.READ_ONLY);
previewText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
expressionText.addModifyListener(e -> generatePreviewValue());
generatePreviewValue();
return dialogArea;
}
use of org.jkiss.dbeaver.model.virtual.DBVEntityAttribute in project dbeaver by dbeaver.
the class VirtualAttributeDeleteAction method run.
@Override
public void run() {
if (!(attr instanceof DBDAttributeBindingCustom)) {
return;
}
DBVEntityAttribute vAttr = ((DBDAttributeBindingCustom) attr).getEntityAttribute();
if (!UIUtils.confirmAction(resultSetViewer.getControl().getShell(), "Delete column '" + vAttr.getName() + "'", "Are you sure you want to delete virtual column '" + vAttr.getName() + "'?")) {
return;
}
DBVEntity vEntity = resultSetViewer.getModel().getVirtualEntity(false);
vEntity.removeVirtualAttribute(vAttr);
vEntity.persistConfiguration();
resultSetViewer.refreshMetaData();
}
Aggregations