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

Automap MCPD columns based on name

parent 0f8d8ae2
......@@ -41,6 +41,7 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
......@@ -67,6 +68,7 @@ import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.Tree;
......@@ -75,8 +77,6 @@ import org.eclipse.wb.swt.SWTResourceManager;
import org.genesys2.anno.model.ColumnDef;
import swing2swt.layout.BorderLayout;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.jface.viewers.TableViewerColumn;
public class AppWindow {
private static final Logger _log = Logger.getLogger(AppWindow.class);
......@@ -173,11 +173,13 @@ public class AppWindow {
private static Image archiveIcon;
private static Image spreadsheetIcon;
private static Image openPackageIcon;
private static Image automapColumns;
private Tree filesTree;
private Display display;
private TreeViewer treeViewer;
private Table table;
private TableViewer tableViewer;
private CTabFolder tabFolder;
/**
* Launch the application.
......@@ -222,6 +224,7 @@ public class AppWindow {
AppWindow.archiveIcon = ImageDescriptor.createFromURL(this.getClass().getResource("/icon/archive.png")).createImage();
AppWindow.openPackageIcon = ImageDescriptor.createFromURL(this.getClass().getResource("/icon/openpackage.png")).createImage();
AppWindow.spreadsheetIcon = ImageDescriptor.createFromURL(this.getClass().getResource("/icon/spreadsheet.png")).createImage();
AppWindow.automapColumns= ImageDescriptor.createFromURL(this.getClass().getResource("/icon/automap.png")).createImage();
}
public static boolean isMac() {
......@@ -352,7 +355,7 @@ public class AppWindow {
}
});
final CTabFolder tabFolder = new CTabFolder(sashForm, SWT.NONE);
tabFolder = new CTabFolder(sashForm, SWT.NONE);
tabFolder.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
tabFolder.setSelectionBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
......@@ -363,24 +366,24 @@ public class AppWindow {
DragSource dragSource = new DragSource(table, DND.DROP_LINK);
dragSource.setTransfer(new Transfer[] { LocalSelectionTransfer.getTransfer() });
TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn tblclmnPreferredName = tableViewerColumn.getColumn();
tblclmnPreferredName.setWidth(100);
tblclmnPreferredName.setText("Preferred name");
TableViewerColumn tableViewerColumn_2 = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn tblclmnTerm = tableViewerColumn_2.getColumn();
tblclmnTerm.setWidth(100);
tblclmnTerm.setText("Term");
TableViewerColumn tableViewerColumn_1 = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn tblclmnRdfTerm = tableViewerColumn_1.getColumn();
tblclmnRdfTerm.setWidth(100);
tblclmnRdfTerm.setText("RDF URL");
table.pack();
dragSource.addDragListener(new DragSourceAdapter() {
@Override
public void dragStart(DragSourceEvent event) {
......@@ -419,7 +422,7 @@ public class AppWindow {
@Override
public void run() {
try {
final List<Object[]> rows = dataSourceLoader.loadRows(currentSheet, 100);
final List<Object[]> rows = dataSourceLoader.loadRows(currentSheet, 200);
currentSheet.updateData(rows);
} catch (UnsupportedDataFormatException e) {
......@@ -452,13 +455,41 @@ public class AppWindow {
});
tltmAddFile.setText("Open");
tltmAddFile.setImage(openPackageIcon);
ToolItem tltmAutomap = new ToolItem(toolBar, SWT.NONE);
tltmAutomap.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doAutomap();
}
});
tltmAutomap.setText("Automap");
tltmAutomap.setImage(automapColumns);
m_bindingContext = initDataBindings();
}
protected void doAutomap() {
// ((SheetDisplay) c).getDataSourceSheet()) {
CTabItem currentTab = tabFolder.getSelection();
if (currentTab == null) {
_log.info("No tab selected");
return;
}
final DataSourceSheet dss = ((SheetDisplay) currentTab.getControl()).getDataSourceSheet();
_log.info("Got data source sheet " + dss);
threadPool.execute(new Runnable() {
@Override
public void run() {
dss.automap(columnDefs);
}
});
}
public void addSourceFile() {
FileDialog fd = new FileDialog(shlGenesysMagic, SWT.MULTI);
fd.setFilterNames(new String[] { "Supported source files", "Excel files", "CSV files", "All files" });
fd.setFilterExtensions(new String[] { "*.xlsx;*.xls;*.csv;*.tab", "*.xlsx;*.xls", "*.csv;*.tab", "*.*" });
fd.setFilterNames(new String[] { "Supported source files", "Excel files", "CSV files" });
fd.setFilterExtensions(new String[] { "*.xlsx;*.xls;*.csv;*.tab", "*.xlsx;*.xls", "*.csv;*.tab" });
String response = fd.open();
if (response != null) {
......
......@@ -24,6 +24,7 @@ import java.util.Map;
import org.apache.log4j.Logger;
import org.genesys2.anno.model.Column;
import org.genesys2.anno.model.ColumnDef;
import org.genesys2.anno.parser.CsvDataSourceSheet;
public class DataSourceSheet extends AbstractModelObject {
......@@ -165,4 +166,16 @@ public class DataSourceSheet extends AbstractModelObject {
public boolean isCsv() {
return this instanceof CsvDataSourceSheet;
}
public void automap(ColumnDefs columnDefs) {
for (ColumnDef columnDef : columnDefs.getColumnDefs()) {
_log.debug("Looking at " + columnDef.getPreferredName());
for (Column column : columns) {
if (columnDef.getPreferredName().equalsIgnoreCase(column.getPreferredName())) {
column.setRdfTerm(columnDef.getRdfTerm());
column.setMultiple(columnDef.hasAllowMultiple());
}
}
}
}
}
......@@ -272,6 +272,16 @@ public class SheetDisplay extends Composite {
txtHeaderRowIndex = new Text(compoHeaders, SWT.BORDER);
txtHeaderRowIndex.setEnabled(false);
txtHeaderRowIndex.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
new Label(compoHeaders, SWT.NONE);
Button btnReload2 = new Button(compoHeaders, SWT.NONE);
btnReload2.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doDataReload();
}
});
btnReload2.setText("Reload");
txtHeaderRowIndex.addListener(SWT.Verify, new Listener() {
public void handleEvent(Event e) {
......@@ -335,15 +345,7 @@ public class SheetDisplay extends Composite {
btnReload.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
_log.info("Force reload of CSV data sheet");
DataSourceSheet currentSheet = dsw.getDataSourceSheet();
try {
final List<Object[]> rows = dataSourceLoader.loadRows(currentSheet, 100);
currentSheet.updateData(rows);
} catch (Throwable t) {
_log.error("Error reloading file", t);
}
doDataReload();
}
});
btnReload.setText("Reload");
......@@ -375,6 +377,18 @@ public class SheetDisplay extends Composite {
});
}
protected void doDataReload() {
_log.info("Force reload of CSV data sheet");
DataSourceSheet currentSheet = dsw.getDataSourceSheet();
try {
final List<Object[]> rows = dataSourceLoader.loadRows(currentSheet, 200);
currentSheet.updateData(rows);
} catch (Throwable t) {
_log.error("Error reloading file", t);
}
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
......@@ -387,6 +401,9 @@ public class SheetDisplay extends Composite {
private void updateTable() {
_log.debug("Rebuilding table...");
table.clearAll();
for (TableColumn tc : table.getColumns()) {
tc.dispose();
}
DataSourceSheet dataSourceSheet = dsw.getDataSourceSheet();
......
......@@ -12,6 +12,7 @@ public class ColumnDef extends AbstractModelObject {
private String rdfTerm;
private Set<ColumnValidator> validators = new HashSet<ColumnValidator>();
private String title;
private boolean allowMultiple = false;
public ColumnDef() {
}
......@@ -71,4 +72,13 @@ public class ColumnDef extends AbstractModelObject {
public void setTitle(String title) {
this.title = title;
}
public boolean hasAllowMultiple() {
return this.allowMultiple;
}
public ColumnDef setAllowMultiple(boolean allowMultiple) {
this.allowMultiple = allowMultiple;
return this;
}
}
......@@ -40,14 +40,14 @@ public class MCPD {
ColumnDef columnDef = new ColumnDef("COLLNUMB", "Collecting number", ColumnDataType.TEXT, false, RdfMCPD.COLLNUMB);
columns.add(columnDef);
columnDef = new ColumnDef("COLLCODE", "Collecting institute code", ColumnDataType.TEXT, false, RdfMCPD.COLLCODE);
columnDef = new ColumnDef("COLLCODE", "Collecting institute code", ColumnDataType.TEXT, false, RdfMCPD.COLLCODE).setAllowMultiple(true);
columnDef.getValidators().add(new FaoWiewsInstCodeValidator());
columns.add(columnDef);
columnDef = new ColumnDef("COLLNAME", "Collecting institute name", ColumnDataType.TEXT, false, RdfMCPD.COLLNAME);
columnDef = new ColumnDef("COLLNAME", "Collecting institute name", ColumnDataType.TEXT, false, RdfMCPD.COLLNAME).setAllowMultiple(true);
columns.add(columnDef);
columnDef = new ColumnDef("COLLINSTADDRESS", "Collecting institute address", ColumnDataType.TEXT, false, RdfMCPD.COLLINSTADDRESS);
columnDef = new ColumnDef("COLLINSTADDRESS", "Collecting institute address", ColumnDataType.TEXT, false, RdfMCPD.COLLINSTADDRESS).setAllowMultiple(true);
columns.add(columnDef);
columnDef = new ColumnDef("COLLMISSID", "Collecting mission identifier", ColumnDataType.TEXT, false, RdfMCPD.COLLMISSID);
......@@ -72,7 +72,7 @@ public class MCPD {
columnDef = new ColumnDef("CROPNAME", "Common crop name", ColumnDataType.TEXT, false, RdfMCPD.CROPNAME);
columns.add(columnDef);
columnDef = new ColumnDef("ACCENAME", "Accession name", ColumnDataType.TEXT, false, RdfMCPD.ACCENAME);
columnDef = new ColumnDef("ACCENAME", "Accession name", ColumnDataType.TEXT, false, RdfMCPD.ACCENAME).setAllowMultiple(true);
columns.add(columnDef);
columnDef = new ColumnDef("ACQDATE", "Acquisition date", ColumnDataType.TEXT, false, RdfMCPD.ACQDATE);
......@@ -128,17 +128,17 @@ public class MCPD {
columnDef = new ColumnDef("DONORNUMB", "Donor accession number", ColumnDataType.TEXT, false, RdfMCPD.DONORNUMB);
columns.add(columnDef);
columnDef = new ColumnDef("OTHERNUMB", "Other identifiers associated with the accession", ColumnDataType.TEXT, false, RdfMCPD.OTHERNUMB);
columnDef = new ColumnDef("OTHERNUMB", "Other identifiers associated with the accession", ColumnDataType.TEXT, false, RdfMCPD.OTHERNUMB).setAllowMultiple(true);
columns.add(columnDef);
columnDef = new ColumnDef("DUPLSITE", "Location of safety duplicates", ColumnDataType.TEXT, false, RdfMCPD.DUPLSITE);
columnDef = new ColumnDef("DUPLSITE", "Location of safety duplicates", ColumnDataType.TEXT, false, RdfMCPD.DUPLSITE).setAllowMultiple(true);
columnDef.getValidators().add(new FaoWiewsInstCodeValidator());
columns.add(columnDef);
columnDef = new ColumnDef("DUPLINSTNAME", "Institute maintaining safety duplicates", ColumnDataType.TEXT, false, RdfMCPD.DUPLINSTNAME);
columnDef = new ColumnDef("DUPLINSTNAME", "Institute maintaining safety duplicates", ColumnDataType.TEXT, false, RdfMCPD.DUPLINSTNAME).setAllowMultiple(true);
columns.add(columnDef);
columnDef = new ColumnDef("STORAGE", "Type of germplasm storage", ColumnDataType.TEXT, false, RdfMCPD.STORAGE);
columnDef = new ColumnDef("STORAGE", "Type of germplasm storage", ColumnDataType.TEXT, false, RdfMCPD.STORAGE).setAllowMultiple(true);
columns.add(columnDef);
columnDef = new ColumnDef("MLSSTAT", "MLS status of the accession", ColumnDataType.TEXT, false, RdfMCPD.MLSSTAT);
......
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