Commit b1351cd6 authored by Matija Obreza's avatar Matija Obreza
Browse files

CSV properties

parent 4dc3a5a0
......@@ -17,6 +17,7 @@
package org.genesys2.anno.gui;
import org.genesys2.anno.model.Column;
import org.genesys2.anno.parser.CsvDataSourceSheet;
public class DSW extends AbstractModelObject {
private DataSourceSheet dataSourceSheet;
......@@ -25,6 +26,10 @@ public class DSW extends AbstractModelObject {
public DataSourceSheet getDataSourceSheet() {
return dataSourceSheet;
}
public CsvDataSourceSheet getCsvDataSourceSheet() {
return (CsvDataSourceSheet) (dataSourceSheet instanceof CsvDataSourceSheet ? dataSourceSheet : null);
}
public void setDataSourceSheet(DataSourceSheet dataSourceSheet) {
this.dataSourceSheet = dataSourceSheet;
......
......@@ -44,8 +44,6 @@ import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
......@@ -110,7 +108,6 @@ public class SheetDisplay extends Composite {
private DSW dsw = new DSW();
private TableViewer tableViewer;
private Text txtHeaderRowIndex;
private Text txtCsvCharset;
private Text txtCsvQuoteChar;
private Text txtCsvSeparator;
private Button chkbxContainsHeaders;
......@@ -118,22 +115,22 @@ public class SheetDisplay extends Composite {
private Text txtColumnDescription;
private Button btnContainsMultipleValues;
private IObservableValue sampleDataDswObserveValue;
public void setDataSourceSheet(DataSourceSheet dataSourceSheet) {
this.dsw.setDataSourceSheet(dataSourceSheet);
// _log.debug("Updating targets");
// m_bindingContext.updateTargets();
}
private Composite compoCSV;
private Combo comboCharset;
private Button btnReload;
/**
* Create the composite.
*
* @param dataSourceSheet
*
* @param parent
* @param style
*/
public SheetDisplay(Composite parent, int style) {
public SheetDisplay(DataSourceSheet dataSourceSheet, Composite parent, int style) {
super(parent, SWT.NONE);
this.dsw.setDataSourceSheet(dataSourceSheet);
addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
// UNBIND ALL STUFF
......@@ -141,7 +138,7 @@ public class SheetDisplay extends Composite {
@SuppressWarnings("unchecked")
ArrayList<Object> bindings = new ArrayList<Object>(m_bindingContext.getBindings());
for (Object b : bindings) {
_log.trace("Remove binding " + b);
if (b instanceof Binding) {
......@@ -265,23 +262,6 @@ public class SheetDisplay extends Composite {
lblRowContainingHeaders.setText("Header row index");
txtHeaderRowIndex = new Text(compoHeaders, SWT.BORDER);
txtHeaderRowIndex.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
// try {
// int idx = Integer.parseInt(txtHeaderRowIndex.getText());
// if (dataSourceSheet.getHeaderRowIndex() != idx) {
// dataSourceSheet.setHeaderRowIndex(idx);
// _log.debug("Modify headerRowIndex: " + idx);
// }
// } catch (NumberFormatException e1) {
// txtHeaderRowIndex.setText(String.valueOf(dataSourceSheet
// .getHeaderRowIndex()));
// }
_log.debug("Updating model...");
m_bindingContext.updateModels();
}
});
txtHeaderRowIndex.setEnabled(false);
txtHeaderRowIndex.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
......@@ -299,52 +279,72 @@ public class SheetDisplay extends Composite {
}
});
// chkbxContainsHeaders.addSelectionListener(new SelectionAdapter() {
// @Override
// public void widgetSelected(SelectionEvent e) {
// txtHeaderRowIndex.setEnabled(chkbxContainsHeaders
// .getSelection());
// dataSourceSheet.setHeadersIncluded(chkbxContainsHeaders
// .getSelection());
// }
// });
TabItem tbtmCSV = new TabItem(tabFolder, SWT.NONE);
tbtmCSV.setText("CSV");
Composite compoCSV = new Composite(tabFolder, SWT.NONE);
tbtmCSV.setControl(compoCSV);
compoCSV.setLayout(new GridLayout(2, false));
Label lblCharacterSet = new Label(compoCSV, SWT.NONE);
lblCharacterSet.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblCharacterSet.setText("Character set");
txtCsvCharset = new Text(compoCSV, SWT.BORDER);
txtCsvCharset.setText("UTF-8");
txtCsvCharset.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
Label lblSeparator = new Label(compoCSV, SWT.NONE);
lblSeparator.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblSeparator.setText("Separator");
txtCsvSeparator = new Text(compoCSV, SWT.BORDER);
txtCsvSeparator.setText(",");
txtCsvSeparator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblQuoteCharacter = new Label(compoCSV, SWT.NONE);
lblQuoteCharacter.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblQuoteCharacter.setText("Quote character");
txtCsvQuoteChar = new Text(compoCSV, SWT.BORDER);
txtCsvQuoteChar.setText("\"");
txtCsvQuoteChar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
// CSV
// if (dsw.getDataSourceSheet().isCsv()) {
TabItem tbtmCSV = new TabItem(tabFolder, SWT.NONE);
tbtmCSV.setText("CSV");
ScrolledComposite scrolledComposite2 = new ScrolledComposite(tabFolder, SWT.V_SCROLL);
scrolledComposite2.setExpandVertical(true);
tbtmCSV.setControl(scrolledComposite2);
scrolledComposite2.setExpandHorizontal(true);
compoCSV = new Composite(scrolledComposite2, SWT.NONE);
scrolledComposite2.setContent(compoCSV);
scrolledComposite2.setMinSize(new Point(10, 200));
compoCSV.setLayout(new GridLayout(2, false));
Label lblCharacterSet = new Label(compoCSV, SWT.NONE);
lblCharacterSet.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblCharacterSet.setText("Character set");
comboCharset = new Combo(compoCSV, SWT.NONE);
comboCharset.setItems(new String[] { "UTF-8", "US-ASCII", "ISO-8859-1", "UTF-16", "windows-1250" });
comboCharset.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
comboCharset.select(0);
Label lblSeparator = new Label(compoCSV, SWT.NONE);
lblSeparator.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblSeparator.setText("Separator");
txtCsvSeparator = new Text(compoCSV, SWT.BORDER);
txtCsvSeparator.setText(",");
txtCsvSeparator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblQuoteCharacter = new Label(compoCSV, SWT.NONE);
lblQuoteCharacter.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblQuoteCharacter.setText("Quote character");
txtCsvQuoteChar = new Text(compoCSV, SWT.BORDER);
txtCsvQuoteChar.setText("\"");
txtCsvQuoteChar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
new Label(compoCSV, SWT.NONE);
btnReload = new Button(compoCSV, SWT.NONE);
btnReload.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
_log.info("Force reload of CSV data sheet");
}
});
btnReload.setText("Reload");
// }
sashForm.setWeights(new int[] { 5, 2 });
tableViewer.setContentProvider(new ContentProvider());
tableViewer.setLabelProvider(new TableLabelProvider());
m_bindingContext = initDataBindings();
// CSV
if (dsw.getDataSourceSheet().isCsv()) {
initDataBindings2(m_bindingContext);
} else {
// remove csv tab
tbtmCSV.dispose();
}
// Listen to rows change
sampleDataDswObserveValue = BeanProperties.value("dataSourceSheet.sampleData").observe(dsw);
sampleDataDswObserveValue.addChangeListener(new IChangeListener() {
......@@ -396,40 +396,48 @@ public class SheetDisplay extends Composite {
return dsw.getDataSourceSheet();
}
private void initDataBindings2(DataBindingContext bindingContext) {
//
IObservableValue observeSelectionComboCharsetObserveWidget = WidgetProperties.selection().observe(comboCharset);
IObservableValue csvDataSourceSheetcharsetDswObserveValue = BeanProperties.value("csvDataSourceSheet.charset").observe(dsw);
bindingContext.bindValue(observeSelectionComboCharsetObserveWidget, csvDataSourceSheetcharsetDswObserveValue, null, null);
//
IObservableValue observeTextTxtCsvSeparatorObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtCsvSeparator);
IObservableValue dataSourceSheetsheetDelimiterDswObserveValue = BeanProperties.value("csvDataSourceSheet.delimiterChar").observe(dsw);
bindingContext.bindValue(observeTextTxtCsvSeparatorObserveWidget, dataSourceSheetsheetDelimiterDswObserveValue, null, null);
//
IObservableValue observeTextTxtCsvQuoteCharObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtCsvQuoteChar);
IObservableValue dataSourceSheetsheetQuoteCharDswObserveValue = BeanProperties.value("csvDataSourceSheet.quoteChar").observe(dsw);
bindingContext.bindValue(observeTextTxtCsvQuoteCharObserveWidget, dataSourceSheetsheetQuoteCharDswObserveValue, null, null);
}
protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
_log.info("1");
IObservableValue observeSelectionChkbxContainsHeadersObserveWidget_1 = WidgetProperties.selection().observe(chkbxContainsHeaders);
IObservableValue headersIncludedGetDataSourceSheetObserveValue = BeanProperties.value("dataSourceSheet.headersIncluded").observe(dsw);
bindingContext.bindValue(observeSelectionChkbxContainsHeadersObserveWidget_1, headersIncludedGetDataSourceSheetObserveValue, null, null);
//
_log.info("2");
IObservableValue observeTextTxtHeaderRowIndexObserveWidget_1 = WidgetProperties.text(SWT.Modify).observe(txtHeaderRowIndex);
IObservableValue headerRowIndexGetDataSourceSheetObserveValue = BeanProperties.value("dataSourceSheet.headerRowIndex").observe(dsw);
bindingContext.bindValue(observeTextTxtHeaderRowIndexObserveWidget_1, headerRowIndexGetDataSourceSheetObserveValue, null, null);
//
_log.info("3");
IObservableValue observeEnabledTxtHeaderRowIndexObserveWidget = WidgetProperties.enabled().observe(txtHeaderRowIndex);
IObservableValue observeSelectionChkbxContainsHeadersObserveWidget = WidgetProperties.selection().observe(chkbxContainsHeaders);
bindingContext.bindValue(observeEnabledTxtHeaderRowIndexObserveWidget, observeSelectionChkbxContainsHeadersObserveWidget, null, null);
//
_log.info("4");
IObservableValue observeTextTxtRdfTermObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtRdfTerm);
IObservableValue selectedColumnrdfTermDswObserveValue = BeanProperties.value("selectedColumn.rdfTerm").observe(dsw);
bindingContext.bindValue(observeTextTxtRdfTermObserveWidget, selectedColumnrdfTermDswObserveValue, null, null);
//
_log.info("5");
IObservableValue observeSelectionBtnContainsMultipleValuesObserveWidget = WidgetProperties.selection().observe(btnContainsMultipleValues);
IObservableValue selectedColumnmultipleDswObserveValue = BeanProperties.value("selectedColumn.multiple").observe(dsw);
bindingContext.bindValue(observeSelectionBtnContainsMultipleValuesObserveWidget, selectedColumnmultipleDswObserveValue, null, null);
//
_log.info("6");
IObservableValue observeTextTextObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtColumnDescription);
IObservableValue selectedColumndescriptionDswObserveValue = BeanProperties.value("selectedColumn.description").observe(dsw);
bindingContext.bindValue(observeTextTextObserveWidget, selectedColumndescriptionDswObserveValue, null, null);
//
_log.info("7");
IObservableValue observeTextTxtColumnNameObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtColumnName);
IObservableValue selectedColumnpreferredNameDswObserveValue = BeanProperties.value("selectedColumn.preferredName").observe(dsw);
bindingContext.bindValue(observeTextTxtColumnNameObserveWidget, selectedColumnpreferredNameDswObserveValue, null, null);
......
......@@ -44,8 +44,7 @@ public final class SheetTabFactory {
tbtmOther.setText(currentSheet.getSheetName());
tbtmOther.setImage(spreadsheetIcon);
final SheetDisplay sheetDisplay = new SheetDisplay(tabFolder, SWT.NONE);
sheetDisplay.setDataSourceSheet(currentSheet);
final SheetDisplay sheetDisplay = new SheetDisplay(currentSheet, tabFolder, SWT.NONE);
tbtmOther.setControl(sheetDisplay);
tbtmOther.addDisposeListener(new DisposeListener() {
......
......@@ -25,7 +25,7 @@ public class CsvDataSourceSheet extends DataSourceSheet {
private String charset = "UTF-8";
private char quoteChar = '"';
private char delimiterChar = ',';
private boolean unixEol;
private boolean unixEol = true;
public CsvDataSourceSheet(File sourceFile) {
super(sourceFile);
......@@ -37,6 +37,7 @@ public class CsvDataSourceSheet extends DataSourceSheet {
public void setCharset(String charset) {
this.charset = charset;
System.err.println("Setting charset to " + charset);
firePropertyChange("charset", null, this.charset);
}
......
Supports Markdown
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