Search in sources :

Example 16 with DBVEntityAttribute

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());
            }
        }
    }
}
Also used : DBVEntityAttribute(org.jkiss.dbeaver.model.virtual.DBVEntityAttribute) DBVTransformSettings(org.jkiss.dbeaver.model.virtual.DBVTransformSettings)

Example 17 with DBVEntityAttribute

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;
}
Also used : StringContentProposalProvider(org.jkiss.dbeaver.ui.contentassist.StringContentProposalProvider) ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) BaseObjectEditPage(org.jkiss.dbeaver.ui.editors.object.struct.BaseObjectEditPage) ArrayList(java.util.ArrayList) IHelpContextIdProvider(org.jkiss.dbeaver.ui.IHelpContextIdProvider) DBVUtils(org.jkiss.dbeaver.model.virtual.DBVUtils) DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType) Composite(org.eclipse.swt.widgets.Composite) UIUtils(org.jkiss.dbeaver.ui.UIUtils) ResultSetViewer(org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer) GridData(org.eclipse.swt.layout.GridData) org.jkiss.dbeaver.model(org.jkiss.dbeaver.model) ComboContentAdapter(org.eclipse.jface.fieldassist.ComboContentAdapter) GeneralUtils(org.jkiss.dbeaver.utils.GeneralUtils) CommonUtils(org.jkiss.utils.CommonUtils) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) SmartTextContentAdapter(org.jkiss.dbeaver.ui.contentassist.SmartTextContentAdapter) ContentAssistUtils(org.jkiss.dbeaver.ui.contentassist.ContentAssistUtils) List(java.util.List) DBException(org.jkiss.dbeaver.DBException) SWT(org.eclipse.swt.SWT) DBVEntityAttribute(org.jkiss.dbeaver.model.virtual.DBVEntityAttribute) JexlExpression(org.apache.commons.jexl3.JexlExpression) Comparator(java.util.Comparator) Control(org.eclipse.swt.widgets.Control) ComboContentAdapter(org.eclipse.jface.fieldassist.ComboContentAdapter) SmartTextContentAdapter(org.jkiss.dbeaver.ui.contentassist.SmartTextContentAdapter) Composite(org.eclipse.swt.widgets.Composite) DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType) DBVEntityAttribute(org.jkiss.dbeaver.model.virtual.DBVEntityAttribute) ArrayList(java.util.ArrayList) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) StringContentProposalProvider(org.jkiss.dbeaver.ui.contentassist.StringContentProposalProvider) GridData(org.eclipse.swt.layout.GridData) ArrayList(java.util.ArrayList) List(java.util.List)

Example 18 with DBVEntityAttribute

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;
    }
}
Also used : DBVEntityAttribute(org.jkiss.dbeaver.model.virtual.DBVEntityAttribute) DBVEntity(org.jkiss.dbeaver.model.virtual.DBVEntity) DBVEntityConstraint(org.jkiss.dbeaver.model.virtual.DBVEntityConstraint)

Example 19 with DBVEntityAttribute

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;
}
Also used : StringContentProposalProvider(org.jkiss.dbeaver.ui.contentassist.StringContentProposalProvider) ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) BaseObjectEditPage(org.jkiss.dbeaver.ui.editors.object.struct.BaseObjectEditPage) ArrayList(java.util.ArrayList) IHelpContextIdProvider(org.jkiss.dbeaver.ui.IHelpContextIdProvider) DBVUtils(org.jkiss.dbeaver.model.virtual.DBVUtils) DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType) Composite(org.eclipse.swt.widgets.Composite) UIUtils(org.jkiss.dbeaver.ui.UIUtils) ResultSetViewer(org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer) GridData(org.eclipse.swt.layout.GridData) org.jkiss.dbeaver.model(org.jkiss.dbeaver.model) ComboContentAdapter(org.eclipse.jface.fieldassist.ComboContentAdapter) GeneralUtils(org.jkiss.dbeaver.utils.GeneralUtils) CommonUtils(org.jkiss.utils.CommonUtils) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) SmartTextContentAdapter(org.jkiss.dbeaver.ui.contentassist.SmartTextContentAdapter) ContentAssistUtils(org.jkiss.dbeaver.ui.contentassist.ContentAssistUtils) List(java.util.List) DBException(org.jkiss.dbeaver.DBException) SWT(org.eclipse.swt.SWT) DBVEntityAttribute(org.jkiss.dbeaver.model.virtual.DBVEntityAttribute) JexlExpression(org.apache.commons.jexl3.JexlExpression) Comparator(java.util.Comparator) Control(org.eclipse.swt.widgets.Control) ComboContentAdapter(org.eclipse.jface.fieldassist.ComboContentAdapter) SmartTextContentAdapter(org.jkiss.dbeaver.ui.contentassist.SmartTextContentAdapter) Composite(org.eclipse.swt.widgets.Composite) DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType) DBVEntityAttribute(org.jkiss.dbeaver.model.virtual.DBVEntityAttribute) ArrayList(java.util.ArrayList) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) StringContentProposalProvider(org.jkiss.dbeaver.ui.contentassist.StringContentProposalProvider) GridData(org.eclipse.swt.layout.GridData) ArrayList(java.util.ArrayList) List(java.util.List)

Example 20 with DBVEntityAttribute

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();
}
Also used : DBVEntityAttribute(org.jkiss.dbeaver.model.virtual.DBVEntityAttribute) DBDAttributeBindingCustom(org.jkiss.dbeaver.model.data.DBDAttributeBindingCustom) DBVEntity(org.jkiss.dbeaver.model.virtual.DBVEntity)

Aggregations

DBVEntityAttribute (org.jkiss.dbeaver.model.virtual.DBVEntityAttribute)22 DBVEntity (org.jkiss.dbeaver.model.virtual.DBVEntity)10 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)6 DBVTransformSettings (org.jkiss.dbeaver.model.virtual.DBVTransformSettings)6 GridData (org.eclipse.swt.layout.GridData)4 Composite (org.eclipse.swt.widgets.Composite)4 DBDAttributeBindingCustom (org.jkiss.dbeaver.model.data.DBDAttributeBindingCustom)4 ArrayList (java.util.ArrayList)2 Comparator (java.util.Comparator)2 List (java.util.List)2 JexlExpression (org.apache.commons.jexl3.JexlExpression)2 ComboContentAdapter (org.eclipse.jface.fieldassist.ComboContentAdapter)2 SWT (org.eclipse.swt.SWT)2 MouseAdapter (org.eclipse.swt.events.MouseAdapter)2 MouseEvent (org.eclipse.swt.events.MouseEvent)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Button (org.eclipse.swt.widgets.Button)2 Combo (org.eclipse.swt.widgets.Combo)2 Control (org.eclipse.swt.widgets.Control)2