未验证 提交 38c587c5 编写于 作者: S Serge Rider 提交者: GitHub

Merge pull request #3067 from dbeaver/#3065

#3065
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
<property id="template" label="Template" type="string" description="Source of substrings" <property id="template" label="Template" type="string" description="Source of substrings"
defaultValue="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."/> defaultValue="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."/>
<property id="minLength" label="Min Length" type="integer" defaultValue="1" description="Minimum length"/> <property id="minLength" label="Min Length" type="integer" defaultValue="1" description="Minimum length"/>
<property id="maxLength" label="Max Length" type="integer" description="Maximum length (0 means the column length)"/> <property id="maxLength" label="Max Length" type="integer" defaultValue="100" description="Maximum length (0 means the column length)"/>
<property id="nulls" label="NULLs" type="integer" defaultValue="10" description="NULL values (%)"/> <property id="nulls" label="NULLs" type="integer" defaultValue="10" description="NULL values (%)"/>
</propertyGroup> </propertyGroup>
......
...@@ -174,7 +174,7 @@ public class MockDataExecuteWizard extends AbstractToolWizard<DBSDataManipulato ...@@ -174,7 +174,7 @@ public class MockDataExecuteWizard extends AbstractToolWizard<DBSDataManipulato
} catch (Exception e) { } catch (Exception e) {
String message = " Error removing the data: " + e.getMessage() + "."; String message = " Error removing the data: " + e.getMessage() + ".";
log.error(message, e); log.error(message, e);
logPage.appendLog(message, true); logPage.appendLog(message + "\n", true);
} finally { } finally {
monitor.done(); monitor.done();
} }
...@@ -242,9 +242,19 @@ public class MockDataExecuteWizard extends AbstractToolWizard<DBSDataManipulato ...@@ -242,9 +242,19 @@ public class MockDataExecuteWizard extends AbstractToolWizard<DBSDataManipulato
} }
insertStats.accumulate(batch.execute(session)); insertStats.accumulate(batch.execute(session));
} }
catch (Exception e) {
String message = " Error generating Mock Data: " + e.getMessage() + ".";
log.error(message, e);
logPage.appendLog(message + "\n", true);
if (e instanceof DBException) {
throw e;
}
}
finally { finally {
batch.close(); if (batch != null) {
batch = null; batch.close();
batch = null;
}
} }
} }
......
...@@ -42,7 +42,9 @@ public class MockDataSettings { ...@@ -42,7 +42,9 @@ public class MockDataSettings {
public static final String PROP_REMOVE_OLD_DATA = "removeOldData"; //$NON-NLS-1$ public static final String PROP_REMOVE_OLD_DATA = "removeOldData"; //$NON-NLS-1$
public static final String PROP_ROWS_NUMBER = "rowsNumber"; //$NON-NLS-1$ public static final String PROP_ROWS_NUMBER = "rowsNumber"; //$NON-NLS-1$
public static final String KEY_SELECTED_ATTRIBUTE = "selectedAttribute"; //$NON-NLS-1$
public static final String KEY_SELECTED_GENERATOR = "selectedGenerator"; //$NON-NLS-1$ public static final String KEY_SELECTED_GENERATOR = "selectedGenerator"; //$NON-NLS-1$
public static final String KEY_PRESET_ID = "presetId"; //$NON-NLS-1$
public static final String KEY_GENERATOR_SECTION = "GENERATOR_SECTION"; //$NON-NLS-1$ public static final String KEY_GENERATOR_SECTION = "GENERATOR_SECTION"; //$NON-NLS-1$
private DBSEntity dbsEntity; private DBSEntity dbsEntity;
...@@ -51,6 +53,7 @@ public class MockDataSettings { ...@@ -51,6 +53,7 @@ public class MockDataSettings {
private boolean removeOldData; private boolean removeOldData;
private long rowsNumber = 1000; private long rowsNumber = 1000;
private String selectedAttribute; // attribute.name
private Map<String, MockGeneratorDescriptor> generatorDescriptors = new HashMap<>(); // generatorId -> MockGeneratorDescriptor private Map<String, MockGeneratorDescriptor> generatorDescriptors = new HashMap<>(); // generatorId -> MockGeneratorDescriptor
private Map<String, AttributeGeneratorProperties> attributeGenerators = new HashMap<>(); // attribute.name -> generators properties private Map<String, AttributeGeneratorProperties> attributeGenerators = new HashMap<>(); // attribute.name -> generators properties
...@@ -105,6 +108,14 @@ public class MockDataSettings { ...@@ -105,6 +108,14 @@ public class MockDataSettings {
return attributes; return attributes;
} }
public String getSelectedAttribute() {
return selectedAttribute;
}
public void setSelectedAttribute(String selectedAttribute) {
this.selectedAttribute = selectedAttribute;
}
private void putGenerator(AttributeGeneratorProperties generatorProperties, MockGeneratorDescriptor generator) { private void putGenerator(AttributeGeneratorProperties generatorProperties, MockGeneratorDescriptor generator) {
generatorDescriptors.put(generator.getId(), generator); generatorDescriptors.put(generator.getId(), generator);
generatorProperties.putGeneratorPropertySource(generator.getId(), new PropertySourceCustom(generator.getProperties(), null)); generatorProperties.putGeneratorPropertySource(generator.getId(), new PropertySourceCustom(generator.getProperties(), null));
...@@ -158,6 +169,7 @@ public class MockDataSettings { ...@@ -158,6 +169,7 @@ public class MockDataSettings {
} }
// load selected generators // load selected generators
selectedAttribute = dialogSettings.get(KEY_SELECTED_ATTRIBUTE);
VoidProgressMonitor voidProgressMonitor = new VoidProgressMonitor(); VoidProgressMonitor voidProgressMonitor = new VoidProgressMonitor();
IDialogSettings tableSection = UIUtils.getSettingsSection(dialogSettings, dbsEntity.getName()); IDialogSettings tableSection = UIUtils.getSettingsSection(dialogSettings, dbsEntity.getName());
for (Map.Entry<String, AttributeGeneratorProperties> entry : attributeGenerators.entrySet()) { for (Map.Entry<String, AttributeGeneratorProperties> entry : attributeGenerators.entrySet()) {
...@@ -167,6 +179,7 @@ public class MockDataSettings { ...@@ -167,6 +179,7 @@ public class MockDataSettings {
if (selectedGeneratorId != null) { if (selectedGeneratorId != null) {
AttributeGeneratorProperties attrGeneratorProperties = entry.getValue(); AttributeGeneratorProperties attrGeneratorProperties = entry.getValue();
attrGeneratorProperties.setSelectedGeneratorId(selectedGeneratorId); attrGeneratorProperties.setSelectedGeneratorId(selectedGeneratorId);
attrGeneratorProperties.setPresetId(attributeSection.get(KEY_PRESET_ID));
PropertySourceCustom generatorPropertySource = attrGeneratorProperties.getGeneratorPropertySource(selectedGeneratorId); PropertySourceCustom generatorPropertySource = attrGeneratorProperties.getGeneratorPropertySource(selectedGeneratorId);
IDialogSettings generatorSection = UIUtils.getSettingsSection(attributeSection, KEY_GENERATOR_SECTION); IDialogSettings generatorSection = UIUtils.getSettingsSection(attributeSection, KEY_GENERATOR_SECTION);
...@@ -190,6 +203,7 @@ public class MockDataSettings { ...@@ -190,6 +203,7 @@ public class MockDataSettings {
dialogSettings.put(PROP_ROWS_NUMBER, rowsNumber); dialogSettings.put(PROP_ROWS_NUMBER, rowsNumber);
// save selected generators // save selected generators
dialogSettings.put(KEY_SELECTED_ATTRIBUTE, selectedAttribute);
IDialogSettings tableSection = UIUtils.getSettingsSection(dialogSettings, dbsEntity.getName()); IDialogSettings tableSection = UIUtils.getSettingsSection(dialogSettings, dbsEntity.getName());
for (Map.Entry<String, AttributeGeneratorProperties> attrEntry : attributeGenerators.entrySet()) { for (Map.Entry<String, AttributeGeneratorProperties> attrEntry : attributeGenerators.entrySet()) {
String attributeName = attrEntry.getKey(); String attributeName = attrEntry.getKey();
...@@ -198,6 +212,7 @@ public class MockDataSettings { ...@@ -198,6 +212,7 @@ public class MockDataSettings {
IDialogSettings attributeSection = UIUtils.getSettingsSection(tableSection, attributeName); IDialogSettings attributeSection = UIUtils.getSettingsSection(tableSection, attributeName);
String selectedGeneratorId = attrGeneratorProperties.getSelectedGeneratorId(); String selectedGeneratorId = attrGeneratorProperties.getSelectedGeneratorId();
attributeSection.put(KEY_SELECTED_GENERATOR, selectedGeneratorId); attributeSection.put(KEY_SELECTED_GENERATOR, selectedGeneratorId);
attributeSection.put(KEY_PRESET_ID, attrGeneratorProperties.getPresetId());
IDialogSettings generatorSection = UIUtils.getSettingsSection(attributeSection, KEY_GENERATOR_SECTION); IDialogSettings generatorSection = UIUtils.getSettingsSection(attributeSection, KEY_GENERATOR_SECTION);
PropertySourceCustom generatorPropertySource = attrGeneratorProperties.getGeneratorPropertySource(selectedGeneratorId); PropertySourceCustom generatorPropertySource = attrGeneratorProperties.getGeneratorPropertySource(selectedGeneratorId);
...@@ -212,12 +227,17 @@ public class MockDataSettings { ...@@ -212,12 +227,17 @@ public class MockDataSettings {
public class AttributeGeneratorProperties { public class AttributeGeneratorProperties {
private final DBSAttributeBase attribute; private final DBSAttributeBase attribute;
private String selectedGeneratorId = null; // id private String selectedGeneratorId = null;
private String presetId = null;
private Map<String, PropertySourceCustom> generators = new HashMap<>(); // generatorId -> PropertySourceCustom private Map<String, PropertySourceCustom> generators = new HashMap<>(); // generatorId -> PropertySourceCustom
public AttributeGeneratorProperties(DBSAttributeBase attribute) { public AttributeGeneratorProperties(DBSAttributeBase attribute) {
this.attribute = attribute; this.attribute = attribute;
} }
public DBSAttributeBase getAttribute() { return attribute; }
public DBSAttributeBase getAttribute() {
return attribute;
}
public String getSelectedGeneratorId() { public String getSelectedGeneratorId() {
if (selectedGeneratorId == null && !CommonUtils.isEmpty(getGenerators())) { if (selectedGeneratorId == null && !CommonUtils.isEmpty(getGenerators())) {
...@@ -234,7 +254,10 @@ public class MockDataSettings { ...@@ -234,7 +254,10 @@ public class MockDataSettings {
if ((selectedGeneratorId == null || !generatorDescriptors.keySet().contains(selectedGeneratorId)) && !CommonUtils.isEmpty(getGenerators())) { if ((selectedGeneratorId == null || !generatorDescriptors.keySet().contains(selectedGeneratorId)) && !CommonUtils.isEmpty(getGenerators())) {
selectedGeneratorId = getGenerators().iterator().next(); selectedGeneratorId = getGenerators().iterator().next();
} }
this.selectedGeneratorId = selectedGeneratorId; if (this.selectedGeneratorId != selectedGeneratorId) {
this.selectedGeneratorId = selectedGeneratorId;
presetId = null;
}
return selectedGeneratorId; return selectedGeneratorId;
} }
...@@ -249,6 +272,14 @@ public class MockDataSettings { ...@@ -249,6 +272,14 @@ public class MockDataSettings {
return generators.get(generatorId); return generators.get(generatorId);
} }
public String getPresetId() {
return presetId;
}
public void setPresetId(String presetId) {
this.presetId = presetId;
}
public boolean isEmpty() { public boolean isEmpty() {
return generators.isEmpty(); return generators.isEmpty();
} }
......
...@@ -31,6 +31,8 @@ import org.jkiss.dbeaver.Log; ...@@ -31,6 +31,8 @@ import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.ext.mockdata.MockDataSettings.AttributeGeneratorProperties; import org.jkiss.dbeaver.ext.mockdata.MockDataSettings.AttributeGeneratorProperties;
import org.jkiss.dbeaver.ext.mockdata.model.MockGeneratorDescriptor; import org.jkiss.dbeaver.ext.mockdata.model.MockGeneratorDescriptor;
import org.jkiss.dbeaver.model.DBValueFormatting; import org.jkiss.dbeaver.model.DBValueFormatting;
import org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSAttributeBase; import org.jkiss.dbeaver.model.struct.DBSAttributeBase;
import org.jkiss.dbeaver.runtime.properties.PropertySourceCustom; import org.jkiss.dbeaver.runtime.properties.PropertySourceCustom;
import org.jkiss.dbeaver.ui.DBeaverIcons; import org.jkiss.dbeaver.ui.DBeaverIcons;
...@@ -60,6 +62,7 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute ...@@ -60,6 +62,7 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute
private DBSAttributeBase selectedAttribute; private DBSAttributeBase selectedAttribute;
private boolean firstInit = true; private boolean firstInit = true;
private Combo generatorCombo; private Combo generatorCombo;
private Combo presetCombo;
private Label generatorDescriptionLabel; private Label generatorDescriptionLabel;
private Link generatorDescriptionLink; private Link generatorDescriptionLink;
...@@ -143,14 +146,25 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute ...@@ -143,14 +146,25 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute
if (cell.getColumnIndex() == 0) { if (cell.getColumnIndex() == 0) {
cell.setImage(DBeaverIcons.getImage(DBValueFormatting.getTypeImage(attribute))); cell.setImage(DBeaverIcons.getImage(DBValueFormatting.getTypeImage(attribute)));
cell.setText(attribute.getName()); cell.setText(attribute.getName());
if (attributeGeneratorProperties.isEmpty()) { if (attributeGeneratorProperties != null && attributeGeneratorProperties.isEmpty()) {
cell.setForeground(table.getDisplay().getSystemColor(SWT.COLOR_RED)); cell.setForeground(table.getDisplay().getSystemColor(SWT.COLOR_RED));
noGeneratorInfoLabel.setVisible(true); noGeneratorInfoLabel.setVisible(true);
} }
} else { } else {
if (!attributeGeneratorProperties.isEmpty()) { if (attributeGeneratorProperties != null && !attributeGeneratorProperties.isEmpty()) {
String selectedGenerator = attributeGeneratorProperties.getSelectedGeneratorId(); String selectedGeneratorId = attributeGeneratorProperties.getSelectedGeneratorId();
cell.setText(mockDataSettings.getGeneratorDescriptor(selectedGenerator).getLabel()); String label = mockDataSettings.getGeneratorDescriptor(selectedGeneratorId).getLabel();
String presetId = attributeGeneratorProperties.getPresetId();
if (presetId != null) {
List<MockGeneratorDescriptor.Preset> presets = mockDataSettings.getGeneratorDescriptor(selectedGeneratorId).getPresets();
for (MockGeneratorDescriptor.Preset preset : presets) {
if (presetId.equals(preset.getId())) {
label += " [" + preset.getMnemonics() + "]";
break;
}
}
}
cell.setText(label);
} }
} }
} }
...@@ -224,7 +238,7 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute ...@@ -224,7 +238,7 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute
Composite placeholder = UIUtils.createPlaceholder(generatorsGroup, 1); Composite placeholder = UIUtils.createPlaceholder(generatorsGroup, 1);
placeholder.setLayoutData(new GridData(GridData.FILL_BOTH)); placeholder.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite labelCombo = UIUtils.createPlaceholder(placeholder, 4); Composite labelCombo = UIUtils.createPlaceholder(placeholder, 5);
gd = new GridData(GridData.FILL_HORIZONTAL); gd = new GridData(GridData.FILL_HORIZONTAL);
labelCombo.setLayoutData(gd); labelCombo.setLayoutData(gd);
...@@ -267,6 +281,18 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute ...@@ -267,6 +281,18 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute
gd.horizontalIndent = 5; gd.horizontalIndent = 5;
generatorDescriptionLink.setLayoutData(gd); generatorDescriptionLink.setLayoutData(gd);
presetCombo = new Combo(labelCombo, SWT.READ_ONLY | SWT.DROP_DOWN);
gd = new GridData();
gd.horizontalIndent = 5;
presetCombo.setLayoutData(gd);
presetCombo.setVisible(false);
presetCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
selectPreset(presetCombo.getText());
}
});
Button resetButton = new Button(labelCombo, SWT.PUSH); Button resetButton = new Button(labelCombo, SWT.PUSH);
resetButton.setText("Reset"); resetButton.setText("Reset");
resetButton.addSelectionListener(new SelectionAdapter() { resetButton.addSelectionListener(new SelectionAdapter() {
...@@ -276,6 +302,12 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute ...@@ -276,6 +302,12 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute
propertySource.resetPropertyValueToDefault(key); propertySource.resetPropertyValueToDefault(key);
} }
propsEditor.loadProperties(propertySource); propsEditor.loadProperties(propertySource);
mockDataSettings.getAttributeGeneratorProperties(selectedAttribute).setPresetId(null);
if (presetCombo.getItemCount() > 0) {
presetCombo.select(0);
}
columnsTableViewer.refresh(true, true);
} }
}); });
gd = new GridData(); gd = new GridData();
...@@ -319,6 +351,29 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute ...@@ -319,6 +351,29 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute
columnsTableViewer.refresh(true, true); columnsTableViewer.refresh(true, true);
} }
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);
}
}
}
@Override @Override
public void activatePage() { public void activatePage() {
...@@ -335,15 +390,24 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute ...@@ -335,15 +390,24 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute
columnsTableViewer.setInput(mockDataSettings.getAttributes()); columnsTableViewer.setInput(mockDataSettings.getAttributes());
} }
// select the first item // select the attributes table item
final Table table = columnsTableViewer.getTable(); final Table table = columnsTableViewer.getTable();
if (table.getItemCount() > 0) { if (table.getItemCount() > 0) {
table.select(0); int selectedItem = 0;
String selectedAttribute = mockDataSettings.getSelectedAttribute();
if (selectedAttribute != null) {
for (int i = 0; i < table.getItemCount(); i++) {
if (selectedAttribute.equals(table.getItem(i).getText())) {
selectedItem = i; break;
}
}
}
table.select(selectedItem);
// and notify the listeners // and notify the listeners
Event event = new Event(); Event event = new Event();
event.widget = table; event.widget = table;
event.display = table.getDisplay(); event.display = table.getDisplay();
event.item = table.getItem(0); event.item = table.getItem(selectedItem);
event.type = SWT.Selection; event.type = SWT.Selection;
table.notifyListeners(SWT.Selection, event); table.notifyListeners(SWT.Selection, event);
} else { } else {
...@@ -408,7 +472,10 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute ...@@ -408,7 +472,10 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute
} }
} }
selectedAttribute = attribute; selectedAttribute = attribute;
mockDataSettings.setSelectedAttribute(attribute.getName());
generatorId = attributeGeneratorProperties.setSelectedGeneratorId(generatorId); generatorId = attributeGeneratorProperties.setSelectedGeneratorId(generatorId);
// set properties
propertySource = attributeGeneratorProperties.getGeneratorPropertySource(generatorId); propertySource = attributeGeneratorProperties.getGeneratorPropertySource(generatorId);
if (propertySource != null) { if (propertySource != null) {
propsEditor.loadProperties(propertySource); propsEditor.loadProperties(propertySource);
...@@ -418,6 +485,8 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute ...@@ -418,6 +485,8 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute
propsEditor.clearProperties(); propsEditor.clearProperties();
} }
// generator combo & description
presetCombo.setVisible(false);
List<String> generators = new ArrayList<>(); List<String> generators = new ArrayList<>();
for (String genId : attributeGeneratorProperties.getGenerators()) { for (String genId : attributeGeneratorProperties.getGenerators()) {
generators.add(mockDataSettings.getGeneratorDescriptor(genId).getLabel()); generators.add(mockDataSettings.getGeneratorDescriptor(genId).getLabel());
...@@ -435,6 +504,23 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute ...@@ -435,6 +504,23 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute
generatorDescriptionLink.setVisible(true); generatorDescriptionLink.setVisible(true);
} }
// presets
List<MockGeneratorDescriptor.Preset> presets = generatorDescriptor.getPresets();
if (!presets.isEmpty()) {
presetCombo.removeAll();
presetCombo.add("Select preset...");
int presetIndex = 0, i = 1;
String presetId = attributeGeneratorProperties.getPresetId();
for (MockGeneratorDescriptor.Preset preset : presets) {
presetCombo.add(preset.getLabel());
if (presetId != null && preset.getId().equals(presetId)) {
presetIndex = i;
}
i++;
}
presetCombo.select(presetIndex);
presetCombo.setVisible(true);
}
} else { } else {
generatorCombo.setItems(new String[] {"Not found"}); generatorCombo.setItems(new String[] {"Not found"});
generatorCombo.setText("Not found"); generatorCombo.setText("Not found");
......
...@@ -34,7 +34,7 @@ public class StringTextGenerator extends AbstractMockValueGenerator { ...@@ -34,7 +34,7 @@ public class StringTextGenerator extends AbstractMockValueGenerator {
private String templateString; private String templateString;
private int minLength = 1; private int minLength = 1;
private int maxLength = 0; private int maxLength = 100;
@Override @Override
public void init(DBSDataManipulator container, DBSAttributeBase attribute, Map<Object, Object> properties) throws DBException { public void init(DBSDataManipulator container, DBSAttributeBase attribute, Map<Object, Object> properties) throws DBException {
...@@ -55,10 +55,10 @@ public class StringTextGenerator extends AbstractMockValueGenerator { ...@@ -55,10 +55,10 @@ public class StringTextGenerator extends AbstractMockValueGenerator {
this.maxLength = max; this.maxLength = max;
} }
if (maxLength == 0 || maxLength > attribute.getMaxLength()) { if (maxLength == 0 || (attribute.getMaxLength() > 0 && maxLength > attribute.getMaxLength())) {
maxLength = (int) attribute.getMaxLength(); maxLength = (int) attribute.getMaxLength();
} }
if (maxLength > templateString.length()) { if (maxLength > templateString.length()) { // TODO check templateString shouldn't be empty
maxLength = templateString.length(); maxLength = templateString.length();
} }
} }
......
...@@ -35,12 +35,15 @@ public class MockGeneratorDescriptor extends DataTypeAbstractDescriptor<MockValu ...@@ -35,12 +35,15 @@ public class MockGeneratorDescriptor extends DataTypeAbstractDescriptor<MockValu
public static final String EXTENSION_ID = "org.jkiss.dbeaver.mockGenerator"; //$NON-NLS-1$ public static final String EXTENSION_ID = "org.jkiss.dbeaver.mockGenerator"; //$NON-NLS-1$
public static final String TAG_PRESET = "preset"; //NON-NLS-1
private final String label; private final String label;
private final String description; private final String description;
private final String link; private final String link;
private final String url; private final String url;
private final DBPImage icon; private final DBPImage icon;
private List<DBPPropertyDescriptor> properties = new ArrayList<>(); private List<DBPPropertyDescriptor> properties = new ArrayList<>();
private List<Preset> presets = new ArrayList<>();
public MockGeneratorDescriptor(IConfigurationElement config) public MockGeneratorDescriptor(IConfigurationElement config)
{ {
...@@ -54,6 +57,15 @@ public class MockGeneratorDescriptor extends DataTypeAbstractDescriptor<MockValu ...@@ -54,6 +57,15 @@ public class MockGeneratorDescriptor extends DataTypeAbstractDescriptor<MockValu
for (IConfigurationElement prop : config.getChildren(PropertyDescriptor.TAG_PROPERTY_GROUP)) { for (IConfigurationElement prop : config.getChildren(PropertyDescriptor.TAG_PROPERTY_GROUP)) {
properties.addAll(PropertyDescriptor.extractProperties(prop)); properties.addAll(PropertyDescriptor.extractProperties(prop));
} }
for (IConfigurationElement preset : config.getChildren(TAG_PRESET)) {
presets.add(new Preset(
preset.getAttribute("id"),
preset.getAttribute("label"),
preset.getAttribute("mnemonics"),
PropertyDescriptor.extractProperties(preset)
));
}
} }
public String getLabel() { public String getLabel() {
...@@ -94,4 +106,37 @@ public class MockGeneratorDescriptor extends DataTypeAbstractDescriptor<MockValu ...@@ -94,4 +106,37 @@ public class MockGeneratorDescriptor extends DataTypeAbstractDescriptor<MockValu
return createInstance(); return createInstance();
} }
public List<Preset> getPresets() {
return presets;
}
public static class Preset {
private final String id;
private final String label;
private final String mnemonics;
private final List<DBPPropertyDescriptor> properties;
public Preset(String id, String label, String mnemonics, List<DBPPropertyDescriptor> properties) {
this.id = id;
this.label = label;
this.mnemonics = mnemonics;
this.properties = properties;
}
public String getId() {
return id;
}
public String getLabel() {
return label;
}
public String getMnemonics() {
return mnemonics;
}
public List<DBPPropertyDescriptor> getProperties() {
return properties;
}
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册