Commit 141543d3 authored by Alex Igoshin's avatar Alex Igoshin
Browse files

Merged genesys2/anno-swt into master

parents b962474b 13ebe6a4
......@@ -22,6 +22,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.genesys2.anno.model.Column;
import org.genesys2.anno.model.ColumnDef;
......@@ -187,10 +188,13 @@ public class DataSourceSheet extends AbstractModelObject implements IDataSourceS
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());
column.setDescription(columnDef.getTitle());
if (StringUtils.isBlank(column.getRdfTerm())) {
// Change only if blank
if (columnDef.getPreferredName().equalsIgnoreCase(column.getPreferredName())) {
column.setRdfTerm(columnDef.getRdfTerm());
column.setMultiple(columnDef.hasAllowMultiple());
column.setDescription(columnDef.getTitle());
}
}
}
}
......
package org.genesys2.anno.gui;
import org.apache.commons.lang3.StringUtils;
import org.genesys2.anno.model.Column;
import org.genesys2.anno.model.ColumnDef;
import org.genesys2.anno.model.DatabaseSettings;
import java.io.File;
......@@ -154,7 +156,19 @@ public class JdbcDataSourceSheet extends AbstractModelObject implements IDataSou
@Override
public void automap(ColumnDefs columnDefs) {
for (ColumnDef columnDef : columnDefs.getColumnDefs()) {
// _log.debug("Looking at " + columnDef.getPreferredName());
for (Column column : columns) {
if (StringUtils.isBlank(column.getRdfTerm())) {
// Change only if blank
if (columnDef.getPreferredName().equalsIgnoreCase(column.getPreferredName())) {
column.setRdfTerm(columnDef.getRdfTerm());
column.setMultiple(columnDef.hasAllowMultiple());
column.setDescription(columnDef.getTitle());
}
}
}
}
}
@Override
......
......@@ -80,8 +80,8 @@ public class SheetDisplay extends Composite {
private static final Logger _log = Logger.getLogger(SheetDisplay.class);
private DataBindingContext m_bindingContext;
@Autowired
private JDBCRowReader jdbcRowReader;
@Autowired
private JDBCRowReader jdbcRowReader;
@Autowired
protected DataSourceLoader dataSourceLoader;
......@@ -118,12 +118,12 @@ public class SheetDisplay extends Composite {
@Override
public String getColumnText(Object element, int columnIndex) {
if (element instanceof Object[]) {
try {
Object[] elArr = (Object[]) element;
if (columnIndex < elArr.length) {
Object el = ((Object[]) element)[columnIndex];
return el == null ? "" : el.toString();
} catch (ArrayIndexOutOfBoundsException e) {
} else
return null;
}
}
return element.toString();
}
......@@ -150,7 +150,7 @@ public class SheetDisplay extends Composite {
private Text txtRegExp;
private Text txtGroupPattern;
private Text txtQueryName;
private TreeViewer treeViewer;
private TreeViewer treeViewer;
/**
* Create the composite.
......@@ -163,27 +163,27 @@ public class SheetDisplay extends Composite {
public SheetDisplay(final IDataSourceSheet dataSourceSheet, final Composite parent, final TreeViewer treeViewer, int style) {
super(parent, SWT.NONE);
this.dsw.setDataSourceSheet(dataSourceSheet);
this.treeViewer=treeViewer;
this.treeViewer = treeViewer;
addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
// UNBIND ALL STUFF
sampleDataDswObserveValue.dispose();
@SuppressWarnings("unchecked")
ArrayList<Object> bindings = new ArrayList<Object>(m_bindingContext.getBindings());
for (Object b : bindings) {
_log.trace("Remove binding " + b);
if (b instanceof Binding) {
((Binding) b).getModel().dispose();
}
m_bindingContext.removeBinding((Binding) b);
}
m_bindingContext.dispose();
}
});
@Override
public void widgetDisposed(DisposeEvent e) {
// UNBIND ALL STUFF
sampleDataDswObserveValue.dispose();
@SuppressWarnings("unchecked")
ArrayList<Object> bindings = new ArrayList<Object>(m_bindingContext.getBindings());
for (Object b : bindings) {
_log.trace("Remove binding " + b);
if (b instanceof Binding) {
((Binding) b).getModel().dispose();
}
m_bindingContext.removeBinding((Binding) b);
}
m_bindingContext.dispose();
}
});
setLayout(new BorderLayout(0, 0));
SashForm sashForm = new SashForm(this, SWT.VERTICAL);
......@@ -212,45 +212,45 @@ public class SheetDisplay extends Composite {
}
});
TabItem tbtmQuery = new TabItem(tabFolder, SWT.NONE);
tbtmQuery.setText("SQL Query");
TabItem tbtmQuery = new TabItem(tabFolder, SWT.NONE);
tbtmQuery.setText("SQL Query");
Composite compositeQuery = new Composite(tabFolder, SWT.NONE);
compositeQuery.setLayout(new GridLayout(4, false));
tbtmQuery.setControl(compositeQuery);
Composite compositeQuery = new Composite(tabFolder, SWT.NONE);
compositeQuery.setLayout(new GridLayout(4, false));
tbtmQuery.setControl(compositeQuery);
Label lblQueryName = new Label(compositeQuery, SWT.NONE);
lblQueryName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblQueryName.setText("Query name");
Label lblQueryName = new Label(compositeQuery, SWT.NONE);
lblQueryName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblQueryName.setText("Query name");
txtQueryName = new Text(compositeQuery, SWT.BORDER);
txtQueryName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
txtQueryName = new Text(compositeQuery, SWT.BORDER);
txtQueryName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lblSqlQuery = new Label(compositeQuery, SWT.NONE);
lblSqlQuery.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
lblSqlQuery.setText("SQL Query");
Label lblSqlQuery = new Label(compositeQuery, SWT.NONE);
lblSqlQuery.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
lblSqlQuery.setText("SQL Query");
txtSqlQuery = new Text(compositeQuery, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
GridData gdSqlQuery = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
gdSqlQuery.minimumHeight = 50;
txtSqlQuery.setLayoutData(gdSqlQuery);
txtSqlQuery = new Text(compositeQuery, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
GridData gdSqlQuery = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
gdSqlQuery.minimumHeight = 50;
txtSqlQuery.setLayoutData(gdSqlQuery);
Button btnReloadQuery = new Button(compositeQuery, SWT.NONE);
btnReloadQuery.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
treeViewer.refresh();
((CTabFolder)parent).getItem(0).setText(txtQueryName.getText());
executeSqlQuery(txtSqlQuery.getText(), dsw);
Button btnReloadQuery = new Button(compositeQuery, SWT.NONE);
btnReloadQuery.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
treeViewer.refresh();
((CTabFolder) parent).getItem(0).setText(txtQueryName.getText());
executeSqlQuery(txtSqlQuery.getText(), dsw);
}
});
}
});
btnReloadQuery.setText("Reload");
btnReloadQuery.setText("Reload");
if (!dsw.getDataSourceSheet().isSqlQuery()){
tbtmQuery.dispose();
}
if (!dsw.getDataSourceSheet().isSqlQuery()) {
tbtmQuery.dispose();
}
TabItem tbtmColumnProperties = new TabItem(tabFolder, SWT.NONE);
......@@ -312,35 +312,35 @@ public class SheetDisplay extends Composite {
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);
// // 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);
// // 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);
// // 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));
......@@ -411,9 +411,9 @@ public class SheetDisplay extends Composite {
}
}
});
if (dsw.getDataSourceSheet().isSqlQuery()){
tbtmSheet.dispose();
}
if (dsw.getDataSourceSheet().isSqlQuery()) {
tbtmSheet.dispose();
}
// CSV
// if (dsw.getDataSourceSheet().isCsv()) {
......@@ -435,7 +435,7 @@ public class SheetDisplay extends Composite {
lblCharacterSet.setText("Character set");
comboCharset = new Combo(compoCSV, SWT.NONE);
comboCharset.setItems(new String[] {"UTF-8", "US-ASCII", "Mac", "MacCentralEurope", "ISO-8859-1", "UTF-16", "windows-1250"});
comboCharset.setItems(new String[] { "UTF-8", "US-ASCII", "Mac", "MacCentralEurope", "ISO-8859-1", "UTF-16", "windows-1250" });
comboCharset.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
comboCharset.select(0);
......@@ -474,17 +474,17 @@ public class SheetDisplay extends Composite {
m_bindingContext = initDataBindings();
// CSV
if (dsw.getDataSourceSheet().isCsv()&&!dsw.getDataSourceSheet().isSqlQuery()) {
if (dsw.getDataSourceSheet().isCsv() && !dsw.getDataSourceSheet().isSqlQuery()) {
initDataBindings2(m_bindingContext);
} else {
// remove csv tab
tbtmCSV.dispose();
}
// SQL Query
if (dsw.getDataSourceSheet().isSqlQuery()){
initDataBindingForSqlQuery(m_bindingContext);
m_bindingContext.updateModels();
}
// SQL Query
if (dsw.getDataSourceSheet().isSqlQuery()) {
initDataBindingForSqlQuery(m_bindingContext);
m_bindingContext.updateModels();
}
// Listen to rows change
sampleDataDswObserveValue = BeanProperties.value("dataSourceSheet.sampleData").observe(dsw);
......@@ -501,20 +501,20 @@ public class SheetDisplay extends Composite {
});
}
private void executeSqlQuery(String query, DSW dsw) {
String url = ((JdbcDataSourceSheet) dsw.getDataSourceSheet()).getDatabaseSettings().getUrl();
String user = ((JdbcDataSourceSheet) dsw.getDataSourceSheet()).getDatabaseSettings().getUser();
String password = ((JdbcDataSourceSheet) dsw.getDataSourceSheet()).getDatabaseSettings().getPassword();
private void executeSqlQuery(String query, DSW dsw) {
String url = ((JdbcDataSourceSheet) dsw.getDataSourceSheet()).getDatabaseSettings().getUrl();
String user = ((JdbcDataSourceSheet) dsw.getDataSourceSheet()).getDatabaseSettings().getUser();
String password = ((JdbcDataSourceSheet) dsw.getDataSourceSheet()).getDatabaseSettings().getPassword();
IDataSourceSheet currentSheet = dsw.getDataSourceSheet();
IDataSourceSheet currentSheet = dsw.getDataSourceSheet();
final List<Object[]> rows = jdbcRowReader.getRows(query, url, user, password);
if (rows!=null){
currentSheet.updateData(rows);
}
}
final List<Object[]> rows = jdbcRowReader.getRows(query, url, user, password);
if (rows != null) {
currentSheet.updateData(rows);
}
}
protected void doDoubleClickOnRow(Object[] row) {
protected void doDoubleClickOnRow(Object[] row) {
IDataSourceSheet dataSourceSheet = getDataSourceSheet();
if (dataSourceSheet == null)
return;
......@@ -590,15 +590,15 @@ public class SheetDisplay extends Composite {
return dsw.getDataSourceSheet();
}
private void initDataBindingForSqlQuery(DataBindingContext bindingContext){
IObservableValue obTextQueryName = WidgetProperties.text(SWT.Modify).observe(txtQueryName);
IObservableValue queryNameValue = BeanProperties.value("dataSourceSheet.sheetName").observe(dsw);
bindingContext.bindValue(obTextQueryName, queryNameValue, null, null);
//
IObservableValue obTextSqlQuery = WidgetProperties.text(SWT.Modify).observe(txtSqlQuery);
IObservableValue sqlQueryValue = BeanProperties.value("dataSourceSheet.query").observe(dsw);
bindingContext.bindValue(obTextSqlQuery, sqlQueryValue, null, null);
}
private void initDataBindingForSqlQuery(DataBindingContext bindingContext) {
IObservableValue obTextQueryName = WidgetProperties.text(SWT.Modify).observe(txtQueryName);
IObservableValue queryNameValue = BeanProperties.value("dataSourceSheet.sheetName").observe(dsw);
bindingContext.bindValue(obTextQueryName, queryNameValue, null, null);
//
IObservableValue obTextSqlQuery = WidgetProperties.text(SWT.Modify).observe(txtSqlQuery);
IObservableValue sqlQueryValue = BeanProperties.value("dataSourceSheet.query").observe(dsw);
bindingContext.bindValue(obTextSqlQuery, sqlQueryValue, null, null);
}
private void initDataBindings2(DataBindingContext bindingContext) {
//
......
......@@ -18,7 +18,7 @@ package org.genesys2.anno.predefined;
public class RdfMCPD {
// http://purl.org/germplasm/germplasmTerm#
public static final String INSTCODE = "http://www.cropontology.org/rdf/CO_020:0000084";
public static final String INSTCODE = "http://rs.tdwg.org/dwc/terms/institutionCode";
public static final String ACCENUMB = "http://purl.org/germplasm/germplasmTerm#germplasmID";
public static final String GENUS = "http://rs.tdwg.org/dwc/terms/genus";
public static final String SPECIES = "http://rs.tdwg.org/dwc/terms/specificEpithet";
......@@ -30,8 +30,8 @@ public class RdfMCPD {
public static final String ACQDATE = "http://purl.org/germplasm/germplasmTerm#acquisitionDate";
public static final String ORIGCTY = "http://rs.tdwg.org/dwc/terms/country";
public static final String COLLCODE = "http://purl.org/germplasm/germplasmTerm#collectingInstituteID";
public static final String COLLNUMB = "http://rs.tdwg.org/dwc/terms/recordNumber";
// made up
public static final String COLLNUMB = "http://purl.org/germplasm/germplasmTerm#collectingNumber";
public static final String COLLNAME = "http://purl.org/germplasm/germplasmTerm#collectingInstitute";
public static final String COLLINSTADDRESS = "http://purl.org/germplasm/germplasmTerm#collectingInstituteAddress";
public static final String COLLMISSID = "http://purl.org/germplasm/germplasmTerm#collectingMissionID";
......
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