use of org.jkiss.dbeaver.ext.mockdata.MockDataSettings.AttributeGeneratorProperties in project dbeaver by dbeaver.
the class MockDataWizardPageSettings method saveGeneratorProperties.
private void saveGeneratorProperties() {
if (selectedAttribute != null) {
AttributeGeneratorProperties attributeGeneratorProperties = mockDataSettings.getAttributeGeneratorProperties(selectedAttribute);
String selectedGenerator = attributeGeneratorProperties.getSelectedGeneratorId();
if (selectedGenerator != null) {
attributeGeneratorProperties.putGeneratorPropertySource(selectedGenerator, propertySource);
}
}
}
use of org.jkiss.dbeaver.ext.mockdata.MockDataSettings.AttributeGeneratorProperties in project dbeaver by dbeaver.
the class MockDataWizardPageSettings method validateProperties.
public boolean validateProperties() {
Map<String, AttributeGeneratorProperties> attributeGenerators = mockDataSettings.getAttributeGenerators();
for (String attr : attributeGenerators.keySet()) {
AttributeGeneratorProperties attributeGeneratorProperties = attributeGenerators.get(attr);
String selectedGeneratorId = attributeGeneratorProperties.getSelectedGeneratorId();
if (!CommonUtils.isEmpty(selectedGeneratorId)) {
Map<Object, Object> properties = attributeGeneratorProperties.getGeneratorPropertySource(selectedGeneratorId).getPropertiesWithDefaults();
for (Object key : properties.keySet()) {
Object value = properties.get(key);
// all the numeric properties shouldn't be negative
if (value instanceof Integer && (((Integer) value) < 0)) {
return false;
}
if (value instanceof Long && (((Long) value) < 0)) {
return false;
}
}
}
}
return true;
}
use of org.jkiss.dbeaver.ext.mockdata.MockDataSettings.AttributeGeneratorProperties in project dbeaver by dbeaver.
the class MockDataWizardPageSettings method reloadProperties.
private void reloadProperties(DBSAttributeBase attribute, String generatorId) {
AttributeGeneratorProperties attributeGeneratorProperties = mockDataSettings.getAttributeGeneratorProperties(attribute);
if (generatorId == null) {
generatorId = attributeGeneratorProperties.getSelectedGeneratorId();
}
if (attribute == selectedAttribute) {
String selectedGenerator = attributeGeneratorProperties.getSelectedGeneratorId();
if (Objects.equals(selectedGenerator, generatorId)) {
// do nothing
return;
}
}
selectedAttribute = attribute;
mockDataSettings.setSelectedAttribute(attribute.getName());
generatorId = attributeGeneratorProperties.setSelectedGeneratorId(generatorId);
// set properties
propertySource = attributeGeneratorProperties.getGeneratorPropertySource(generatorId);
if (propertySource != null) {
propsEditor.loadProperties(propertySource);
propsEditor.setExpandMode(PropertyTreeViewer.ExpandMode.FIRST);
propsEditor.expandAll();
} else {
propsEditor.clearProperties();
}
// generator combo & description
List<String> generators = new ArrayList<>();
for (String genId : attributeGeneratorProperties.getGenerators()) {
generators.add(mockDataSettings.getGeneratorDescriptor(genId).getLabel());
}
generatorDescriptionLink.setVisible(false);
if (!generators.isEmpty()) {
generatorCombo.setItems(generators.toArray(new String[generators.size()]));
MockGeneratorDescriptor generatorDescriptor = mockDataSettings.getGeneratorDescriptor(generatorId);
generatorCombo.setText(generatorDescriptor.getLabel());
generatorCombo.setEnabled(true);
generatorDescriptionLabel.setText(generatorDescriptor.getDescription());
if (!CommonUtils.isEmpty(generatorDescriptor.getLink())) {
generatorDescriptionLink.setText("<a>" + generatorDescriptor.getLink() + "</a>");
generatorLinkUrl = generatorDescriptor.getUrl();
generatorDescriptionLink.setVisible(true);
}
} else {
generatorCombo.setItems(new String[] { "Not found" });
generatorCombo.setText("Not found");
generatorCombo.setEnabled(false);
generatorDescriptionLabel.setText("");
}
generatorDescriptionLink.getParent().layout();
}
use of org.jkiss.dbeaver.ext.mockdata.MockDataSettings.AttributeGeneratorProperties in project dbeaver by dbeaver.
the class MockDataWizardPageSettings method createControl.
public void createControl(Composite parent) {
Composite composite = UIUtils.createPlaceholder(parent, 1);
{
SelectionListener changeListener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
updateState();
}
};
Composite entityPlaceholder = UIUtils.createPlaceholder(composite, 2);
this.entityNameText = UIUtils.createLabelText(entityPlaceholder, "Entity", "", SWT.NONE | SWT.READ_ONLY);
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.widthHint = 230;
gd.verticalIndent = 5;
gd.horizontalIndent = 9;
entityPlaceholder.setLayoutData(gd);
Group settingsGroup = UIUtils.createControlGroup(composite, MockDataMessages.tools_mockdata_wizard_page_settings_group_settings, 4, GridData.FILL_HORIZONTAL, 0);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.verticalIndent = 5;
settingsGroup.setLayoutData(gd);
this.removeOldDataCheck = UIUtils.createCheckbox(settingsGroup, MockDataMessages.tools_mockdata_wizard_page_settings_checkbox_remove_old_data, null, mockDataSettings.isRemoveOldData(), 4);
removeOldDataCheck.addSelectionListener(changeListener);
this.rowsText = UIUtils.createLabelText(settingsGroup, "Rows ", String.valueOf(mockDataSettings.getRowsNumber()), SWT.BORDER, new GridData(110, SWT.DEFAULT));
rowsText.addSelectionListener(changeListener);
rowsText.addVerifyListener(UIUtils.getLongVerifyListener(rowsText));
rowsText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
updateState();
}
});
}
{
Group generatorsGroup = UIUtils.createControlGroup(composite, "Generators", 5, GridData.FILL_BOTH, 0);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.verticalIndent = 5;
generatorsGroup.setLayoutData(gd);
columnsTableViewer = new TableViewer(generatorsGroup, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
final Table table = columnsTableViewer.getTable();
gd = new GridData(GridData.FILL_VERTICAL);
gd.widthHint = 230;
table.setLayoutData(gd);
table.setHeaderVisible(true);
table.setLinesVisible(true);
columnsTableViewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void dispose() {
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public Object[] getElements(Object inputElement) {
if (inputElement instanceof Collection) {
return ((Collection<?>) inputElement).toArray();
}
return new Object[0];
}
});
// TODO VoidProgressMonitor
VoidProgressMonitor monitor = new VoidProgressMonitor();
CellLabelProvider labelProvider = new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
DBSAttributeBase attribute = (DBSAttributeBase) cell.getElement();
AttributeGeneratorProperties attributeGeneratorProperties = mockDataSettings.getAttributeGeneratorProperties(attribute);
if (cell.getColumnIndex() == 0) {
cell.setImage(DBeaverIcons.getImage(DBValueFormatting.getTypeImage(attribute)));
cell.setText(attribute.getName());
try {
if (DBUtils.checkUnique(monitor, mockDataSettings.getEntity(), attribute)) {
cell.setFont(boldFont);
}
} catch (DBException e) {
log.error("Error checking the attribute '" + attribute.getName() + "' properties", e);
}
if (attributeGeneratorProperties != null && attributeGeneratorProperties.isEmpty()) {
cell.setForeground(table.getDisplay().getSystemColor(SWT.COLOR_RED));
noGeneratorInfoLabel.setVisible(true);
}
} else {
if (attributeGeneratorProperties != null && !attributeGeneratorProperties.isEmpty()) {
String selectedGeneratorId = attributeGeneratorProperties.getSelectedGeneratorId();
String label = mockDataSettings.getGeneratorDescriptor(selectedGeneratorId).getLabel();
cell.setText(label.trim());
}
}
}
};
TableViewerColumn attributeColumn = new TableViewerColumn(columnsTableViewer, SWT.LEFT);
attributeColumn.setLabelProvider(labelProvider);
attributeColumn.getColumn().setText("Attribute");
TableViewerColumn generatorColumn = new TableViewerColumn(columnsTableViewer, SWT.LEFT);
generatorColumn.setLabelProvider(labelProvider);
generatorColumn.getColumn().setText("Generator");
generatorColumn.setEditingSupport(new EditingSupport(columnsTableViewer) {
@Override
protected CellEditor getCellEditor(Object element) {
DBSAttributeBase attribute = (DBSAttributeBase) element;
AttributeGeneratorProperties attributeGenerators = mockDataSettings.getAttributeGeneratorProperties(attribute);
Set<String> generators = new LinkedHashSet<>();
if (attributeGenerators.isEmpty()) {
// TODO item.setForeground(columnsTableViewer.getDisplay().getSystemColor(SWT.COLOR_RED));
noGeneratorInfoLabel.setVisible(true);
TextCellEditor textCellEditor = new TextCellEditor(columnsTableViewer.getTable());
textCellEditor.getControl().setEnabled(false);
return textCellEditor;
} else {
for (String generatorId : attributeGenerators.getGenerators()) {
generators.add(mockDataSettings.getGeneratorDescriptor(generatorId).getLabel());
}
CustomComboBoxCellEditor customComboBoxCellEditor = new CustomComboBoxCellEditor(columnsTableViewer, columnsTableViewer.getTable(), generators.toArray(new String[generators.size()]), SWT.BORDER | SWT.READ_ONLY);
return customComboBoxCellEditor;
}
}
@Override
protected boolean canEdit(Object element) // disable the generator selection
{
return true;
}
@Override
protected Object getValue(Object element) {
DBSAttributeBase attribute = (DBSAttributeBase) element;
String selectedGenerator = mockDataSettings.getAttributeGeneratorProperties(attribute).getSelectedGeneratorId();
if (selectedGenerator != null) {
return mockDataSettings.getGeneratorDescriptor(selectedGenerator).getLabel();
} else {
return "";
}
}
@Override
protected void setValue(Object element, Object value) {
DBSAttributeBase attribute = (DBSAttributeBase) element;
selectGenerator(attribute, (String) value);
}
});
table.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
saveGeneratorProperties();
reloadProperties((DBSAttributeBase) e.item.getData(), null);
}
});
// generator properties
Composite placeholder = UIUtils.createPlaceholder(generatorsGroup, 1);
placeholder.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite labelCombo = UIUtils.createPlaceholder(placeholder, 5);
gd = new GridData(GridData.FILL_HORIZONTAL);
labelCombo.setLayoutData(gd);
generatorCombo = new Combo(labelCombo, SWT.READ_ONLY | SWT.DROP_DOWN);
gd = new GridData();
gd.widthHint = 80;
generatorCombo.setLayoutData(gd);
generatorCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
selectGenerator(selectedAttribute, generatorCombo.getText());
}
});
Composite descriptionCombo = UIUtils.createPlaceholder(labelCombo, 2);
gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL);
descriptionCombo.setLayoutData(gd);
generatorDescriptionLabel = new Label(descriptionCombo, SWT.NONE);
generatorDescriptionLabel.setFont(JFaceResources.getFontRegistry().getItalic(JFaceResources.DEFAULT_FONT));
generatorDescriptionLabel.setText("");
gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL);
gd.horizontalIndent = 5;
generatorDescriptionLabel.setLayoutData(gd);
generatorDescriptionLink = UIUtils.createLink(descriptionCombo, "", new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (!CommonUtils.isEmpty(generatorLinkUrl)) {
IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
try {
support.getExternalBrowser().openURL(new URL(generatorLinkUrl));
} catch (Exception ex) {
}
}
}
});
gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
gd.horizontalIndent = 5;
generatorDescriptionLink.setLayoutData(gd);
Button resetButton = new Button(labelCombo, SWT.PUSH);
resetButton.setText("Reset");
resetButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
for (Object key : propertySource.getProperties().keySet()) {
propertySource.resetPropertyValueToDefault(key);
}
propsEditor.loadProperties(propertySource);
columnsTableViewer.refresh(true, true);
}
});
gd = new GridData();
gd.horizontalIndent = 5;
resetButton.setLayoutData(gd);
propsEditor = new PropertyTreeViewer(placeholder, SWT.BORDER);
gd = new GridData(GridData.FILL_BOTH);
gd.verticalIndent = 5;
propsEditor.getControl().setLayoutData(gd);
noGeneratorInfoLabel = UIUtils.createInfoLabel(composite, "Generators for the red highlighted attributes aren't found. So, no data will be generated for them.");
// noGeneratorInfoLabel.setForeground(columnsTableViewer.getDisplay().getSystemColor(SWT.COLOR_RED));
gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.horizontalSpan = 2;
gd.verticalIndent = 5;
noGeneratorInfoLabel.setLayoutData(gd);
noGeneratorInfoLabel.setVisible(false);
table.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
UIUtils.packColumns(table);
UIUtils.maxTableColumnsWidth(table);
table.removeControlListener(this);
}
});
}
setControl(composite);
boldFont = UIUtils.makeBoldFont(columnsTableViewer.getControl().getFont());
}
use of org.jkiss.dbeaver.ext.mockdata.MockDataSettings.AttributeGeneratorProperties in project dbeaver by dbeaver.
the class MockDataWizardPageSettings method selectPreset.
private void selectPreset(String presetName) {
AttributeGeneratorProperties attributeGeneratorProperties = mockDataSettings.getAttributeGeneratorProperties(selectedAttribute);
String generatorId = attributeGeneratorProperties.getSelectedGeneratorId();
List<MockGeneratorDescriptor.Preset> presets = mockDataSettings.getGeneratorDescriptor(generatorId).getPresets();
for (MockGeneratorDescriptor.Preset preset : presets) {
// Apply the preset
if (preset.getLabel().equals(presetName)) {
propertySource = attributeGeneratorProperties.getGeneratorPropertySource(generatorId);
VoidProgressMonitor monitor = new VoidProgressMonitor();
for (DBPPropertyDescriptor prop : preset.getProperties()) {
propertySource.setPropertyValue(monitor, prop.getId(), prop.getDefaultValue());
}
propsEditor.loadProperties(propertySource);
propsEditor.setExpandMode(PropertyTreeViewer.ExpandMode.FIRST);
propsEditor.expandAll();
attributeGeneratorProperties.setPresetId(preset.getId());
columnsTableViewer.refresh(true, true);
}
}
}
Aggregations