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;
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,6 +188,8 @@ public class DataSourceSheet extends AbstractModelObject implements IDataSourceS
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());
......@@ -195,6 +198,7 @@ public class DataSourceSheet extends AbstractModelObject implements IDataSourceS
}
}
}
}
@Override
public String getQuery() {
// Auto-generated method stub
......
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
......
......@@ -118,13 +118,13 @@ 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();
}
}
......@@ -163,7 +163,7 @@ 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
......@@ -240,7 +240,7 @@ public class SheetDisplay extends Composite {
@Override
public void widgetSelected(SelectionEvent e) {
treeViewer.refresh();
((CTabFolder)parent).getItem(0).setText(txtQueryName.getText());
((CTabFolder) parent).getItem(0).setText(txtQueryName.getText());
executeSqlQuery(txtSqlQuery.getText(), dsw);
}
......@@ -248,7 +248,7 @@ public class SheetDisplay extends Composite {
btnReloadQuery.setText("Reload");
if (!dsw.getDataSourceSheet().isSqlQuery()){
if (!dsw.getDataSourceSheet().isSqlQuery()) {
tbtmQuery.dispose();
}
......@@ -312,27 +312,27 @@ 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() });
......@@ -411,7 +411,7 @@ public class SheetDisplay extends Composite {
}
}
});
if (dsw.getDataSourceSheet().isSqlQuery()){
if (dsw.getDataSourceSheet().isSqlQuery()) {
tbtmSheet.dispose();
}
......@@ -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,14 +474,14 @@ 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()){
if (dsw.getDataSourceSheet().isSqlQuery()) {
initDataBindingForSqlQuery(m_bindingContext);
m_bindingContext.updateModels();
}
......@@ -509,7 +509,7 @@ public class SheetDisplay extends Composite {
IDataSourceSheet currentSheet = dsw.getDataSourceSheet();
final List<Object[]> rows = jdbcRowReader.getRows(query, url, user, password);
if (rows!=null){
if (rows != null) {
currentSheet.updateData(rows);
}
}
......@@ -590,7 +590,7 @@ public class SheetDisplay extends Composite {
return dsw.getDataSourceSheet();
}
private void initDataBindingForSqlQuery(DataBindingContext bindingContext){
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);
......
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