Commit 8e61ea00 authored by Matija Obreza's avatar Matija Obreza
Browse files

Keep headersIncluded and headerRowIndex in DataSheetSource

parent c370d099
......@@ -11,15 +11,17 @@ public class DataSourceSheet {
private String sheetName;
private List<String> columnNames = new ArrayList<String>();
private Map<String, String> columnTerms = new HashMap<String, String>();
private boolean headersIncluded;
private int headerRowIndex;
public DataSourceSheet(File sourceFile) {
this.sourceFile = new File(sourceFile.getAbsolutePath());
}
public File getSourceFile() {
return sourceFile;
}
public String getSheetName() {
return sheetName;
}
......@@ -43,4 +45,20 @@ public class DataSourceSheet {
public void setColumnTerms(Map<String, String> columnTerms) {
this.columnTerms = columnTerms;
}
public void setHeadersIncluded(boolean headersIncluded) {
this.headersIncluded = headersIncluded;
}
public boolean isHeadersIncluded() {
return headersIncluded;
}
public int getHeaderRowIndex() {
return headerRowIndex;
}
public void setHeaderRowIndex(int headerRowIndex) {
this.headerRowIndex = headerRowIndex;
}
}
......@@ -9,9 +9,14 @@ import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
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;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
......@@ -23,9 +28,6 @@ import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import swing2swt.layout.BorderLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
public class SheetDisplay extends Composite {
private static class ContentProvider implements IStructuredContentProvider {
......@@ -72,6 +74,8 @@ public class SheetDisplay extends Composite {
private Text txtCharset;
private Text txtQuoteChar;
private Text text_1;
private Button chkbxContainsHeaders;
private TabFolder tabFolder;
public DataSourceSheet getDataSourceSheet() {
return dataSourceSheet;
......@@ -79,6 +83,9 @@ public class SheetDisplay extends Composite {
public void setDataSourceSheet(DataSourceSheet dataSourceSheet) {
this.dataSourceSheet = dataSourceSheet;
chkbxContainsHeaders.setSelection(dataSourceSheet.isHeadersIncluded());
txtHeaderRowIndex.setText(String.valueOf(dataSourceSheet
.getHeaderRowIndex()));
}
/**
......@@ -99,7 +106,7 @@ public class SheetDisplay extends Composite {
tableViewer.setContentProvider(new ContentProvider());
tableViewer.setLabelProvider(new TableLabelProvider());
TabFolder tabFolder = new TabFolder(this, SWT.NONE);
tabFolder = new TabFolder(this, SWT.NONE);
tabFolder.setLayoutData(BorderLayout.SOUTH);
TabItem tbtmColumnProperties = new TabItem(tabFolder, SWT.NONE);
......@@ -140,64 +147,102 @@ public class SheetDisplay extends Composite {
txtRdfTerm = new Text(composite, SWT.BORDER);
txtRdfTerm.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
false, 1, 1));
TabItem tbtmSheet = new TabItem(tabFolder, SWT.NONE);
tbtmSheet.setText("Headers");
Composite compoHeaders = new Composite(tabFolder, SWT.NONE);
tbtmSheet.setControl(compoHeaders);
compoHeaders.setLayout(new GridLayout(2, false));
new Label(compoHeaders, SWT.NONE);
final Button btnCheckButton = new Button(compoHeaders, SWT.CHECK);
btnCheckButton.setText("Contains headers");
chkbxContainsHeaders = new Button(compoHeaders, SWT.CHECK);
chkbxContainsHeaders.setText("Contains headers");
Label lblRowContainingHeaders = new Label(compoHeaders, SWT.NONE);
lblRowContainingHeaders.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblRowContainingHeaders.setLayoutData(new GridData(SWT.RIGHT,
SWT.CENTER, false, false, 1, 1));
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);
System.err.println("Modify headerRowIndex: " + idx);
}
} catch (NumberFormatException e1) {
txtHeaderRowIndex.setText(String.valueOf(dataSourceSheet.getHeaderRowIndex()));
}
}
});
txtHeaderRowIndex.setEnabled(false);
txtHeaderRowIndex.setText("0");
txtHeaderRowIndex.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
btnCheckButton.addSelectionListener(new SelectionAdapter() {
txtHeaderRowIndex.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
true, false, 1, 1));
txtHeaderRowIndex.addListener(SWT.Verify, new Listener() {
public void handleEvent(Event e) {
String string = e.text;
char[] chars = new char[string.length()];
string.getChars(0, chars.length, chars, 0);
for (int i = 0; i < chars.length; i++) {
if (!('0' <= chars[i] && chars[i] <= '9')) {
e.doit = false;
return;
}
}
}
});
chkbxContainsHeaders.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
txtHeaderRowIndex.setEnabled(btnCheckButton.getSelection());
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.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER,
false, false, 1, 1));
lblCharacterSet.setText("Character set");
txtCharset = new Text(compoCSV, SWT.BORDER);
txtCharset.setText("UTF-8");
txtCharset.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
txtCharset.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.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
false, 1, 1));
lblSeparator.setText("Separator");
text_1 = new Text(compoCSV, SWT.BORDER);
text_1.setText(",");
text_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
text_1.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.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER,
false, false, 1, 1));
lblQuoteCharacter.setText("Quote character");
txtQuoteChar = new Text(compoCSV, SWT.BORDER);
txtQuoteChar.setText("\"");
txtQuoteChar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
txtQuoteChar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
false, 1, 1));
}
......@@ -240,5 +285,7 @@ public class SheetDisplay extends Composite {
txtColumnIndex.setText("" + columnIndex);
txtSomeThing.setText(RandomStringUtils.randomAlphanumeric(10));
txtRdfTerm.setText("");
tabFolder.setSelection(0);
}
}
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