Commit 69e5faf4 authored by Matija Obreza's avatar Matija Obreza
Browse files

Added group pattern for use with regexp

parent abd61958
......@@ -48,7 +48,7 @@ public class RowConverter {
continue;
}
Object rowValue = convertCellValue(row[i], column.isMultiple(), column.getSeparator(), column.getPattern());
Object rowValue = convertCellValue(row[i], column.isMultiple(), column.getSeparator(), column.getPattern(), column.getGroupPattern());
Object mapValue = map.get(columnDef.getRdfTerm());
if (mapValue == null) {
......@@ -91,7 +91,7 @@ public class RowConverter {
return map;
}
private static Object convertCellValue(Object value, boolean splitString, String separator, String pattern) {
private static Object convertCellValue(Object value, boolean splitString, String separator, String pattern, String groupPattern) {
if (value != null) {
if (value instanceof String) {
String stringValue = ((String) value);
......@@ -102,7 +102,7 @@ public class RowConverter {
String[] split = stringValue.split(separator);
for (int i = split.length - 1; i >= 0; i--) {
if (pattern != null) {
split[i] = valueFromPattern(split[i].trim(), pattern);
split[i] = valueFromPattern(split[i].trim(), pattern, groupPattern);
} else {
split[i] = split[i].trim();
}
......@@ -110,7 +110,7 @@ public class RowConverter {
return split;
}
return valueFromPattern(stringValue.trim(), pattern);
return valueFromPattern(stringValue.trim(), pattern, groupPattern);
}
}
......@@ -118,7 +118,7 @@ public class RowConverter {
return value;
}
private static String valueFromPattern(String trim, String pattern) {
private static String valueFromPattern(String trim, String pattern, String groupPattern) {
if (StringUtils.isBlank(pattern)) {
return trim;
}
......@@ -126,6 +126,13 @@ public class RowConverter {
Matcher matcher = pat.matcher(trim);
if (matcher.find()) {
String res = matcher.groupCount() == 0 ? matcher.group() : matcher.group(1);
if (StringUtils.isNotBlank(groupPattern)) {
res = groupPattern;
if (res.contains("$1"))
res = res.replaceAll("\\$1", matcher.group(1));
if (res.contains("$2"))
res = res.replaceAll("\\$2", matcher.group(2));
}
// System.err.println("Pattern=" + pattern + " groups=" +
// matcher.groupCount() + " res=" + res);
// throw new RuntimeException("foobar");
......
......@@ -103,7 +103,7 @@ public class DwcaBuilder extends AbstractModelObject {
column.put("dataType",sourceColumn.getDataType());
column.put("pattern",sourceColumn.getPattern());
column.put("separator",sourceColumn.getSeparator());
column.put("groupPattern", sourceColumn.getGroupPattern());
columns.put(column);
}
}
......@@ -159,6 +159,7 @@ public class DwcaBuilder extends AbstractModelObject {
if (column.has("description")) sourceColumn.setDescription(column.getString("description"));
if (column.has("pattern")) sourceColumn.setPattern(column.getString("pattern"));
if (column.has("separator")) sourceColumn.setSeparator(column.getString("separator"));
if (column.has("groupPattern")) sourceColumn.setGroupPattern(column.getString("groupPattern"));
if (column.has("dataType")) sourceColumn.setDataType( ColumnDataType.valueOf(column.getString("dataType")));
if (column.has("multiple")) sourceColumn.setMultiple(column.getBoolean("multiple"));
......
......@@ -92,9 +92,6 @@ public class PushDialog extends Dialog {
shell.open();
shell.layout();
// create worker
doTrialRun();
Display display = getParent().getDisplay();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
......@@ -134,6 +131,15 @@ public class PushDialog extends Dialog {
ToolBar toolBar = new ToolBar(shell, SWT.FLAT);
toolBar.setLayoutData(BorderLayout.NORTH);
ToolItem tltmNewItem = new ToolItem(toolBar, SWT.NONE);
tltmNewItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doTrialRun();
}
});
tltmNewItem.setText("Parse all");
ToolItem tltmPushToGenesys = new ToolItem(toolBar, SWT.NONE);
tltmPushToGenesys.addSelectionListener(new SelectionAdapter() {
@Override
......
......@@ -150,6 +150,7 @@ public class SheetDisplay extends Composite {
private Button btnReload;
private Text txtSeparator;
private Text txtRegExp;
private Text txtGroupPattern;
/**
* Create the composite.
......@@ -255,13 +256,6 @@ public class SheetDisplay extends Composite {
gd_txtSeparator.minimumWidth = 30;
txtSeparator.setLayoutData(gd_txtSeparator);
Label lblRegexpPattern = new Label(composite, SWT.RIGHT);
lblRegexpPattern.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblRegexpPattern.setText("RegExp pattern");
txtRegExp = new Text(composite, SWT.BORDER);
txtRegExp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lblNewLabel = new Label(composite, SWT.NONE);
lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblNewLabel.setText("RDF Term");
......@@ -269,30 +263,44 @@ public class SheetDisplay extends Composite {
txtRdfTerm = new Text(composite, SWT.BORDER);
txtRdfTerm.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lblData = new Label(composite, SWT.NONE);
lblData.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblData.setText("Data type");
Combo comboDataType = new Combo(composite, SWT.NONE);
comboDataType.setItems(new String[] { "Text (general blah-blah)", "Number", "Date, time, timestamp" });
comboDataType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
new Label(composite, SWT.NONE);
new Label(composite, SWT.NONE);
new Label(composite, SWT.NONE);
Label lblRegexpPattern = new Label(composite, SWT.RIGHT);
lblRegexpPattern.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblRegexpPattern.setText("RegExp pattern");
Button btnAnalyzeColumnData = new Button(composite, SWT.NONE);
btnAnalyzeColumnData.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
_log.debug("Do column analysis");
}
});
btnAnalyzeColumnData.setText("Analyze column data");
new Label(composite, SWT.NONE);
new Label(composite, SWT.NONE);
txtRegExp = new Text(composite, SWT.BORDER);
txtRegExp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
//// Label lblData = new Label(composite, SWT.NONE);
//// lblData.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
//// lblData.setText("Data type");
////
//// Combo comboDataType = new Combo(composite, SWT.NONE);
//// comboDataType.setItems(new String[] { "Text (general blah-blah)", "Number", "Date, time, timestamp" });
//// comboDataType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
//// new Label(composite, SWT.NONE);
//// new Label(composite, SWT.NONE);
//// new Label(composite, SWT.NONE);
//
// Button btnAnalyzeColumnData = new Button(composite, SWT.NONE);
// btnAnalyzeColumnData.addSelectionListener(new SelectionAdapter() {
// @Override
// public void widgetSelected(SelectionEvent e) {
// _log.debug("Do column analysis");
// }
// });
// btnAnalyzeColumnData.setText("Analyze column data");
// new Label(composite, SWT.NONE);
// new Label(composite, SWT.NONE);
DropTarget dropTarget = new DropTarget(composite, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT | DND.DROP_LINK);
dropTarget.setTransfer(new Transfer[] { LocalSelectionTransfer.getTransfer() });
Label lblGroupPattern = new Label(composite, SWT.NONE);
lblGroupPattern.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblGroupPattern.setText("Group pattern:");
txtGroupPattern = new Text(composite, SWT.BORDER);
txtGroupPattern.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
dropTarget.addDropListener(new DropTargetAdapter() {
@Override
......@@ -546,7 +554,6 @@ public class SheetDisplay extends Composite {
bindingContext.bindValue(observeTextTxtCsvQuoteCharObserveWidget, dataSourceSheetsheetQuoteCharDswObserveValue, null, null);
}
protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
......@@ -590,6 +597,10 @@ public class SheetDisplay extends Composite {
IObservableValue selectedColumnseparatorDswObserveValue = BeanProperties.value("selectedColumn.separator").observe(dsw);
bindingContext.bindValue(observeTextTxtSeparatorObserveWidget, selectedColumnseparatorDswObserveValue, null, null);
//
IObservableValue observeTextTxtGroupPatternObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtGroupPattern);
IObservableValue selectedColumngroupPatternDswObserveValue = BeanProperties.value("selectedColumn.groupPattern").observe(dsw);
bindingContext.bindValue(observeTextTxtGroupPatternObserveWidget, selectedColumngroupPatternDswObserveValue, null, null);
//
return bindingContext;
}
}
......@@ -27,6 +27,7 @@ public class Column extends AbstractModelObject {
private boolean multiple;
private String separator = ";";
private String pattern;
private String groupPattern;
public Column() {
}
......@@ -110,4 +111,13 @@ public class Column extends AbstractModelObject {
this.separator = separator;
firePropertyChange("separator", null, this.separator);
}
public String getGroupPattern() {
return groupPattern;
}
public void setGroupPattern(String groupPattern) {
this.groupPattern = groupPattern;
firePropertyChange("groupPattern", null, this.groupPattern);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment