Commit 5f750959 authored by Matija Obreza's avatar Matija Obreza
Browse files

Automap only if not mapped, automap in JdbcDataSourceSheet,...

Automap only if not mapped, automap in JdbcDataSourceSheet, ArrayIndexOutOfBoundsException in SheetDisplay.
parent b962474b
...@@ -22,6 +22,7 @@ import java.util.HashMap; ...@@ -22,6 +22,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.genesys2.anno.model.Column; import org.genesys2.anno.model.Column;
import org.genesys2.anno.model.ColumnDef; import org.genesys2.anno.model.ColumnDef;
...@@ -187,10 +188,13 @@ public class DataSourceSheet extends AbstractModelObject implements IDataSourceS ...@@ -187,10 +188,13 @@ public class DataSourceSheet extends AbstractModelObject implements IDataSourceS
for (ColumnDef columnDef : columnDefs.getColumnDefs()) { for (ColumnDef columnDef : columnDefs.getColumnDefs()) {
_log.debug("Looking at " + columnDef.getPreferredName()); _log.debug("Looking at " + columnDef.getPreferredName());
for (Column column : columns) { for (Column column : columns) {
if (columnDef.getPreferredName().equalsIgnoreCase(column.getPreferredName())) { if (StringUtils.isBlank(column.getRdfTerm())) {
column.setRdfTerm(columnDef.getRdfTerm()); // Change only if blank
column.setMultiple(columnDef.hasAllowMultiple()); if (columnDef.getPreferredName().equalsIgnoreCase(column.getPreferredName())) {
column.setDescription(columnDef.getTitle()); column.setRdfTerm(columnDef.getRdfTerm());
column.setMultiple(columnDef.hasAllowMultiple());
column.setDescription(columnDef.getTitle());
}
} }
} }
} }
......
package org.genesys2.anno.gui; package org.genesys2.anno.gui;
import org.apache.commons.lang3.StringUtils;
import org.genesys2.anno.model.Column; import org.genesys2.anno.model.Column;
import org.genesys2.anno.model.ColumnDef;
import org.genesys2.anno.model.DatabaseSettings; import org.genesys2.anno.model.DatabaseSettings;
import java.io.File; import java.io.File;
...@@ -154,7 +156,19 @@ public class JdbcDataSourceSheet extends AbstractModelObject implements IDataSou ...@@ -154,7 +156,19 @@ public class JdbcDataSourceSheet extends AbstractModelObject implements IDataSou
@Override @Override
public void automap(ColumnDefs columnDefs) { 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 @Override
......
...@@ -80,8 +80,8 @@ public class SheetDisplay extends Composite { ...@@ -80,8 +80,8 @@ public class SheetDisplay extends Composite {
private static final Logger _log = Logger.getLogger(SheetDisplay.class); private static final Logger _log = Logger.getLogger(SheetDisplay.class);
private DataBindingContext m_bindingContext; private DataBindingContext m_bindingContext;
@Autowired @Autowired
private JDBCRowReader jdbcRowReader; private JDBCRowReader jdbcRowReader;
@Autowired @Autowired
protected DataSourceLoader dataSourceLoader; protected DataSourceLoader dataSourceLoader;
...@@ -118,12 +118,12 @@ public class SheetDisplay extends Composite { ...@@ -118,12 +118,12 @@ public class SheetDisplay extends Composite {
@Override @Override
public String getColumnText(Object element, int columnIndex) { public String getColumnText(Object element, int columnIndex) {
if (element instanceof Object[]) { if (element instanceof Object[]) {
try { Object[] elArr = (Object[]) element;
if (columnIndex < elArr.length) {
Object el = ((Object[]) element)[columnIndex]; Object el = ((Object[]) element)[columnIndex];
return el == null ? "" : el.toString(); return el == null ? "" : el.toString();
} catch (ArrayIndexOutOfBoundsException e) { } else
return null; return null;
}
} }
return element.toString(); return element.toString();
} }
...@@ -150,7 +150,7 @@ public class SheetDisplay extends Composite { ...@@ -150,7 +150,7 @@ public class SheetDisplay extends Composite {
private Text txtRegExp; private Text txtRegExp;
private Text txtGroupPattern; private Text txtGroupPattern;
private Text txtQueryName; private Text txtQueryName;
private TreeViewer treeViewer; private TreeViewer treeViewer;
/** /**
* Create the composite. * Create the composite.
...@@ -163,27 +163,27 @@ public class SheetDisplay extends Composite { ...@@ -163,27 +163,27 @@ public class SheetDisplay extends Composite {
public SheetDisplay(final IDataSourceSheet dataSourceSheet, final Composite parent, final TreeViewer treeViewer, int style) { public SheetDisplay(final IDataSourceSheet dataSourceSheet, final Composite parent, final TreeViewer treeViewer, int style) {
super(parent, SWT.NONE); super(parent, SWT.NONE);
this.dsw.setDataSourceSheet(dataSourceSheet); this.dsw.setDataSourceSheet(dataSourceSheet);
this.treeViewer=treeViewer; this.treeViewer = treeViewer;
addDisposeListener(new DisposeListener() { addDisposeListener(new DisposeListener() {
@Override @Override
public void widgetDisposed(DisposeEvent e) { public void widgetDisposed(DisposeEvent e) {
// UNBIND ALL STUFF // UNBIND ALL STUFF
sampleDataDswObserveValue.dispose(); sampleDataDswObserveValue.dispose();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ArrayList<Object> bindings = new ArrayList<Object>(m_bindingContext.getBindings()); ArrayList<Object> bindings = new ArrayList<Object>(m_bindingContext.getBindings());
for (Object b : bindings) { for (Object b : bindings) {
_log.trace("Remove binding " + b); _log.trace("Remove binding " + b);
if (b instanceof Binding) { if (b instanceof Binding) {
((Binding) b).getModel().dispose(); ((Binding) b).getModel().dispose();
} }
m_bindingContext.removeBinding((Binding) b); m_bindingContext.removeBinding((Binding) b);
} }
m_bindingContext.dispose(); m_bindingContext.dispose();
} }
}); });
setLayout(new BorderLayout(0, 0)); setLayout(new BorderLayout(0, 0));
SashForm sashForm = new SashForm(this, SWT.VERTICAL); SashForm sashForm = new SashForm(this, SWT.VERTICAL);
...@@ -212,45 +212,45 @@ public class SheetDisplay extends Composite { ...@@ -212,45 +212,45 @@ public class SheetDisplay extends Composite {
} }
}); });
TabItem tbtmQuery = new TabItem(tabFolder, SWT.NONE); TabItem tbtmQuery = new TabItem(tabFolder, SWT.NONE);
tbtmQuery.setText("SQL Query"); tbtmQuery.setText("SQL Query");
Composite compositeQuery = new Composite(tabFolder, SWT.NONE); Composite compositeQuery = new Composite(tabFolder, SWT.NONE);
compositeQuery.setLayout(new GridLayout(4, false)); compositeQuery.setLayout(new GridLayout(4, false));
tbtmQuery.setControl(compositeQuery); tbtmQuery.setControl(compositeQuery);
Label lblQueryName = new Label(compositeQuery, SWT.NONE); Label lblQueryName = new Label(compositeQuery, SWT.NONE);
lblQueryName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); lblQueryName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblQueryName.setText("Query name"); lblQueryName.setText("Query name");
txtQueryName = new Text(compositeQuery, SWT.BORDER); txtQueryName = new Text(compositeQuery, SWT.BORDER);
txtQueryName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1)); txtQueryName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lblSqlQuery = new Label(compositeQuery, SWT.NONE); Label lblSqlQuery = new Label(compositeQuery, SWT.NONE);
lblSqlQuery.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1)); lblSqlQuery.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
lblSqlQuery.setText("SQL Query"); lblSqlQuery.setText("SQL Query");
txtSqlQuery = new Text(compositeQuery, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI); txtSqlQuery = new Text(compositeQuery, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
GridData gdSqlQuery = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1); GridData gdSqlQuery = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
gdSqlQuery.minimumHeight = 50; gdSqlQuery.minimumHeight = 50;
txtSqlQuery.setLayoutData(gdSqlQuery); txtSqlQuery.setLayoutData(gdSqlQuery);
Button btnReloadQuery = new Button(compositeQuery, SWT.NONE); Button btnReloadQuery = new Button(compositeQuery, SWT.NONE);
btnReloadQuery.addSelectionListener(new SelectionAdapter() { btnReloadQuery.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
treeViewer.refresh(); treeViewer.refresh();
((CTabFolder)parent).getItem(0).setText(txtQueryName.getText()); ((CTabFolder) parent).getItem(0).setText(txtQueryName.getText());
executeSqlQuery(txtSqlQuery.getText(), dsw); executeSqlQuery(txtSqlQuery.getText(), dsw);
} }
}); });
btnReloadQuery.setText("Reload"); btnReloadQuery.setText("Reload");
if (!dsw.getDataSourceSheet().isSqlQuery()){ if (!dsw.getDataSourceSheet().isSqlQuery()) {
tbtmQuery.dispose(); tbtmQuery.dispose();
} }
TabItem tbtmColumnProperties = new TabItem(tabFolder, SWT.NONE); TabItem tbtmColumnProperties = new TabItem(tabFolder, SWT.NONE);
...@@ -312,35 +312,35 @@ public class SheetDisplay extends Composite { ...@@ -312,35 +312,35 @@ public class SheetDisplay extends Composite {
txtRegExp = new Text(composite, SWT.BORDER); txtRegExp = new Text(composite, SWT.BORDER);
txtRegExp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 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.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
//// lblData.setText("Data type"); // // lblData.setText("Data type");
//// // //
//// Combo comboDataType = new Combo(composite, SWT.NONE); // // Combo comboDataType = new Combo(composite, SWT.NONE);
//// comboDataType.setItems(new String[] { "Text (general blah-blah)", "Number", "Date, time, timestamp" }); //// comboDataType.setItems(new String[] { "Text (general blah-blah)", "Number", "Date, time, timestamp" });
//// comboDataType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); //// 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); // // new Label(composite, SWT.NONE);
//// new Label(composite, SWT.NONE); // // new Label(composite, SWT.NONE);
// //
// Button btnAnalyzeColumnData = new Button(composite, SWT.NONE); // Button btnAnalyzeColumnData = new Button(composite, SWT.NONE);
// btnAnalyzeColumnData.addSelectionListener(new SelectionAdapter() { // btnAnalyzeColumnData.addSelectionListener(new SelectionAdapter() {
// @Override // @Override
// public void widgetSelected(SelectionEvent e) { // public void widgetSelected(SelectionEvent e) {
// _log.debug("Do column analysis"); // _log.debug("Do column analysis");
// } // }
// }); // });
// btnAnalyzeColumnData.setText("Analyze column data"); // 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);
DropTarget dropTarget = new DropTarget(composite, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT | DND.DROP_LINK); DropTarget dropTarget = new DropTarget(composite, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT | DND.DROP_LINK);
dropTarget.setTransfer(new Transfer[] { LocalSelectionTransfer.getTransfer() }); dropTarget.setTransfer(new Transfer[] { LocalSelectionTransfer.getTransfer() });
Label lblGroupPattern = new Label(composite, SWT.NONE); Label lblGroupPattern = new Label(composite, SWT.NONE);
lblGroupPattern.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); lblGroupPattern.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblGroupPattern.setText("Group pattern:"); lblGroupPattern.setText("Group pattern:");
txtGroupPattern = new Text(composite, SWT.BORDER); txtGroupPattern = new Text(composite, SWT.BORDER);
txtGroupPattern.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); txtGroupPattern.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
...@@ -411,9 +411,9 @@ public class SheetDisplay extends Composite { ...@@ -411,9 +411,9 @@ public class SheetDisplay extends Composite {
} }
} }
}); });
if (dsw.getDataSourceSheet().isSqlQuery()){ if (dsw.getDataSourceSheet().isSqlQuery()) {
tbtmSheet.dispose(); tbtmSheet.dispose();
} }
// CSV // CSV
// if (dsw.getDataSourceSheet().isCsv()) { // if (dsw.getDataSourceSheet().isCsv()) {
...@@ -435,7 +435,7 @@ public class SheetDisplay extends Composite { ...@@ -435,7 +435,7 @@ public class SheetDisplay extends Composite {
lblCharacterSet.setText("Character set"); lblCharacterSet.setText("Character set");
comboCharset = new Combo(compoCSV, SWT.NONE); 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.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
comboCharset.select(0); comboCharset.select(0);
...@@ -474,17 +474,17 @@ public class SheetDisplay extends Composite { ...@@ -474,17 +474,17 @@ public class SheetDisplay extends Composite {
m_bindingContext = initDataBindings(); m_bindingContext = initDataBindings();
// CSV // CSV
if (dsw.getDataSourceSheet().isCsv()&&!dsw.getDataSourceSheet().isSqlQuery()) { if (dsw.getDataSourceSheet().isCsv() && !dsw.getDataSourceSheet().isSqlQuery()) {
initDataBindings2(m_bindingContext); initDataBindings2(m_bindingContext);
} else { } else {
// remove csv tab // remove csv tab
tbtmCSV.dispose(); tbtmCSV.dispose();
} }
// SQL Query // SQL Query
if (dsw.getDataSourceSheet().isSqlQuery()){ if (dsw.getDataSourceSheet().isSqlQuery()) {
initDataBindingForSqlQuery(m_bindingContext); initDataBindingForSqlQuery(m_bindingContext);
m_bindingContext.updateModels(); m_bindingContext.updateModels();
} }
// Listen to rows change // Listen to rows change
sampleDataDswObserveValue = BeanProperties.value("dataSourceSheet.sampleData").observe(dsw); sampleDataDswObserveValue = BeanProperties.value("dataSourceSheet.sampleData").observe(dsw);
...@@ -501,20 +501,20 @@ public class SheetDisplay extends Composite { ...@@ -501,20 +501,20 @@ public class SheetDisplay extends Composite {
}); });
} }
private void executeSqlQuery(String query, DSW dsw) { private void executeSqlQuery(String query, DSW dsw) {
String url = ((JdbcDataSourceSheet) dsw.getDataSourceSheet()).getDatabaseSettings().getUrl(); String url = ((JdbcDataSourceSheet) dsw.getDataSourceSheet()).getDatabaseSettings().getUrl();
String user = ((JdbcDataSourceSheet) dsw.getDataSourceSheet()).getDatabaseSettings().getUser(); String user = ((JdbcDataSourceSheet) dsw.getDataSourceSheet()).getDatabaseSettings().getUser();
String password = ((JdbcDataSourceSheet) dsw.getDataSourceSheet()).getDatabaseSettings().getPassword(); 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); final List<Object[]> rows = jdbcRowReader.getRows(query, url, user, password);
if (rows!=null){ if (rows != null) {
currentSheet.updateData(rows); currentSheet.updateData(rows);
} }
} }
protected void doDoubleClickOnRow(Object[] row) { protected void doDoubleClickOnRow(Object[] row) {
IDataSourceSheet dataSourceSheet = getDataSourceSheet(); IDataSourceSheet dataSourceSheet = getDataSourceSheet();
if (dataSourceSheet == null) if (dataSourceSheet == null)
return; return;
...@@ -590,15 +590,15 @@ public class SheetDisplay extends Composite { ...@@ -590,15 +590,15 @@ public class SheetDisplay extends Composite {
return dsw.getDataSourceSheet(); return dsw.getDataSourceSheet();
} }
private void initDataBindingForSqlQuery(DataBindingContext bindingContext){ private void initDataBindingForSqlQuery(DataBindingContext bindingContext) {
IObservableValue obTextQueryName = WidgetProperties.text(SWT.Modify).observe(txtQueryName); IObservableValue obTextQueryName = WidgetProperties.text(SWT.Modify).observe(txtQueryName);
IObservableValue queryNameValue = BeanProperties.value("dataSourceSheet.sheetName").observe(dsw); IObservableValue queryNameValue = BeanProperties.value("dataSourceSheet.sheetName").observe(dsw);
bindingContext.bindValue(obTextQueryName, queryNameValue, null, null); bindingContext.bindValue(obTextQueryName, queryNameValue, null, null);
// //
IObservableValue obTextSqlQuery = WidgetProperties.text(SWT.Modify).observe(txtSqlQuery); IObservableValue obTextSqlQuery = WidgetProperties.text(SWT.Modify).observe(txtSqlQuery);
IObservableValue sqlQueryValue = BeanProperties.value("dataSourceSheet.query").observe(dsw); IObservableValue sqlQueryValue = BeanProperties.value("dataSourceSheet.query").observe(dsw);
bindingContext.bindValue(obTextSqlQuery, sqlQueryValue, null, null); bindingContext.bindValue(obTextSqlQuery, sqlQueryValue, null, null);
} }
private void initDataBindings2(DataBindingContext bindingContext) { private void initDataBindings2(DataBindingContext bindingContext) {
// //
......
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