Commit 6a453d96 authored by Matija Obreza's avatar Matija Obreza
Browse files

Scrollable column info composite

parent 8e61ea00
......@@ -392,9 +392,9 @@ public class AppWindow {
final List<Object[]> rows = dataSourceLoader
.loadRows(currentSheet, 100);
for (Object[] row : rows) {
System.err.println(ArrayUtils.toString(row));
}
// for (Object[] row : rows) {
// System.err.println(ArrayUtils.toString(row));
// }
// Need to update sheetDisplay
display.asyncExec(new Runnable() {
......
......@@ -11,8 +11,8 @@ 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;
private boolean headersIncluded = true;
private int headerRowIndex = 0;
public DataSourceSheet(File sourceFile) {
this.sourceFile = new File(sourceFile.getAbsolutePath());
......@@ -57,7 +57,7 @@ public class DataSourceSheet {
public int getHeaderRowIndex() {
return headerRowIndex;
}
public void setHeaderRowIndex(int headerRowIndex) {
this.headerRowIndex = headerRowIndex;
}
......
package org.genesys2.anno.gui;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
......@@ -28,6 +29,10 @@ import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import swing2swt.layout.BorderLayout;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Combo;
public class SheetDisplay extends Composite {
private static class ContentProvider implements IStructuredContentProvider {
......@@ -76,6 +81,8 @@ public class SheetDisplay extends Composite {
private Text text_1;
private Button chkbxContainsHeaders;
private TabFolder tabFolder;
private Object[] headerRow;
private Text text;
public DataSourceSheet getDataSourceSheet() {
return dataSourceSheet;
......@@ -98,23 +105,30 @@ public class SheetDisplay extends Composite {
super(parent, style);
setLayout(new BorderLayout(0, 0));
tableViewer = new TableViewer(this, SWT.BORDER);
SashForm sashForm = new SashForm(this, SWT.VERTICAL);
sashForm.setLayoutData(BorderLayout.CENTER);
tableViewer = new TableViewer(sashForm, SWT.BORDER);
table = tableViewer.getTable();
table.setLinesVisible(true);
table.setHeaderVisible(true);
table.setLayoutData(BorderLayout.CENTER);
tableViewer.setContentProvider(new ContentProvider());
tableViewer.setLabelProvider(new TableLabelProvider());
tabFolder = new TabFolder(this, SWT.NONE);
tabFolder.setLayoutData(BorderLayout.SOUTH);
tabFolder = new TabFolder(sashForm, SWT.NONE);
TabItem tbtmColumnProperties = new TabItem(tabFolder, SWT.NONE);
tbtmColumnProperties.setText("Column");
Composite composite = new Composite(tabFolder, SWT.NONE);
tbtmColumnProperties.setControl(composite);
ScrolledComposite scrolledComposite = new ScrolledComposite(tabFolder,
SWT.V_SCROLL);
scrolledComposite.setExpandVertical(true);
tbtmColumnProperties.setControl(scrolledComposite);
scrolledComposite.setExpandHorizontal(true);
Composite composite = new Composite(scrolledComposite, SWT.NO_BACKGROUND);
composite.setLayout(new GridLayout(3, false));
scrolledComposite.setContent(composite);
scrolledComposite.setMinSize(new Point(10, 200));
new Label(composite, SWT.NONE);
Label lblColumn = new Label(composite, SWT.NONE);
......@@ -132,13 +146,31 @@ public class SheetDisplay extends Composite {
Label lblThisIsA = new Label(composite, SWT.NONE);
lblThisIsA.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
false, 1, 1));
lblThisIsA.setText("This is a label");
lblThisIsA.setText("Column name");
txtSomeThing = new Text(composite, SWT.BORDER);
txtSomeThing.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
false, 1, 1));
new Label(composite, SWT.NONE);
Label lblColumnDescription = new Label(composite, SWT.NONE);
lblColumnDescription.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP,
false, false, 1, 1));
lblColumnDescription.setText("Column description");
text = new Text(composite, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
GridData gd_text = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
gd_text.minimumHeight = 30;
gd_text.heightHint = 40;
text.setLayoutData(gd_text);
new Label(composite, SWT.NONE);
new Label(composite, SWT.NONE);
Button btnContainsMultipleValues = new Button(composite, SWT.CHECK);
btnContainsMultipleValues
.setText("Contains multiple values, separated");
new Label(composite, SWT.NONE);
Label lblNewLabel = new Label(composite, SWT.NONE);
lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
false, 1, 1));
......@@ -147,6 +179,15 @@ public class SheetDisplay extends Composite {
txtRdfTerm = new Text(composite, SWT.BORDER);
txtRdfTerm.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
false, 1, 1));
new Label(composite, SWT.NONE);
Label lblData = new Label(composite, SWT.NONE);
lblData.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblData.setText("Data type");
Combo combo = new Combo(composite, SWT.NONE);
combo.setItems(new String[] {"Text (general blah-blah)", "Number", "Date, time, timestamp"});
combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
TabItem tbtmSheet = new TabItem(tabFolder, SWT.NONE);
tbtmSheet.setText("Headers");
......@@ -170,12 +211,13 @@ public class SheetDisplay extends Composite {
public void focusLost(FocusEvent e) {
try {
int idx = Integer.parseInt(txtHeaderRowIndex.getText());
if (dataSourceSheet.getHeaderRowIndex()!=idx) {
if (dataSourceSheet.getHeaderRowIndex() != idx) {
dataSourceSheet.setHeaderRowIndex(idx);
System.err.println("Modify headerRowIndex: " + idx);
}
} catch (NumberFormatException e1) {
txtHeaderRowIndex.setText(String.valueOf(dataSourceSheet.getHeaderRowIndex()));
txtHeaderRowIndex.setText(String.valueOf(dataSourceSheet
.getHeaderRowIndex()));
}
}
});
......@@ -243,6 +285,11 @@ public class SheetDisplay extends Composite {
txtQuoteChar.setText("\"");
txtQuoteChar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
false, 1, 1));
sashForm.setWeights(new int[] {237, 258});
tableViewer.setContentProvider(new ContentProvider());
tableViewer.setLabelProvider(new TableLabelProvider());
}
......@@ -264,9 +311,30 @@ public class SheetDisplay extends Composite {
columnCount = Math.max(columnCount, row.length);
}
ArrayList<Object[]> clone = null;
Object[] headerRow = null;
if (dataSourceSheet.isHeadersIncluded()) {
clone = new ArrayList<Object[]>(rows.size());
int headerRowIndex = dataSourceSheet.getHeaderRowIndex();
headerRow = rows.get(headerRowIndex);
System.err.println("HEADERS: " + ArrayUtils.toString(headerRow));
for (int i = headerRowIndex + 1; i < rows.size(); i++) {
clone.add(rows.get(i));
}
}
this.headerRow = headerRow;
for (int i = 0; i < columnCount; i++) {
final TableColumn c = new TableColumn(table, SWT.NONE);
c.setText("Column " + i);
String headerColumnName = (headerRow != null
&& headerRow.length > i ? String.valueOf(headerRow[i])
: null);
c.setText(headerColumnName == null ? "Column " + i
: headerColumnName);
c.setWidth(100);
final int columnIndex = i;
c.addListener(SWT.Selection, new Listener() {
......@@ -278,14 +346,20 @@ public class SheetDisplay extends Composite {
});
}
tableViewer.setInput(rows);
if (headerRow != null) {
tableViewer.setInput(clone);
} else {
tableViewer.setInput(rows);
}
}
private void fillColumnInfo(int columnIndex) {
txtColumnIndex.setText("" + columnIndex);
txtSomeThing.setText(RandomStringUtils.randomAlphanumeric(10));
txtSomeThing.setText(this.headerRow != null
&& this.headerRow.length > columnIndex ? String
.valueOf(this.headerRow[columnIndex]) : "");
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