Commit b3576ec5 authored by Matija Obreza's avatar Matija Obreza

Logging

parent 1ca24a1b
......@@ -131,6 +131,11 @@
<artifactId>org.eclipse.osgi</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
<build>
<plugins>
......
......@@ -19,26 +19,29 @@ package org.genesys2.anno.gui;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import org.apache.log4j.Logger;
public abstract class AbstractModelObject {
private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
private static final Logger _log = Logger.getLogger(AbstractModelObject.class);
public void addPropertyChangeListener(PropertyChangeListener listener) {
// System.out.println("Adding listener to " + this.getClass() + " of " + listener);
_log.debug("Adding listener to " + this.getClass() + " of " + listener);
propertyChangeSupport.addPropertyChangeListener(listener);
}
public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
// System.out.println("Adding property listener '" + propertyName + "' to " + this.getClass() + " of " + listener);
_log.debug("Adding property listener '" + propertyName + "' to " + this.getClass() + " of " + listener);
propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
// System.out.println("Removing property listener from " + this.getClass() + " of " + listener);
_log.debug("Removing property listener from " + this.getClass() + " of " + listener);
propertyChangeSupport.removePropertyChangeListener(listener);
}
public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
// System.out.println("Removing property listener '" + propertyName + "' from " + this.getClass() + " of " + listener);
_log.debug("Removing property listener '" + propertyName + "' from " + this.getClass() + " of " + listener);
propertyChangeSupport.removePropertyChangeListener(propertyName, listener);
}
......
......@@ -24,6 +24,7 @@ import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.log4j.Logger;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeansObservables;
import org.eclipse.core.databinding.observable.Realm;
......@@ -77,13 +78,14 @@ import org.genesys2.anno.parser.XlsxDataSourceParser;
import swing2swt.layout.BorderLayout;
public class AppWindow {
private static final Logger _log = Logger.getLogger(AppWindow.class);
private DataBindingContext m_bindingContext;
private DwcaBuilder builder = new DwcaBuilder();
private ExecutorService threadPool = Executors.newFixedThreadPool(4);
private static class ViewerLabelProvider extends LabelProvider {
public Image getImage(Object element) {
System.err.println("getImage " + element);
_log.debug("getImage " + element);
if (element instanceof DataSourceFile) {
return archiveIcon;
}
......@@ -94,7 +96,7 @@ public class AppWindow {
}
public String getText(Object element) {
System.err.println("getText " + element);
_log.debug("getText " + element);
if (element instanceof DataSourceFile) {
return ((DataSourceFile) element).getFile().getName();
}
......@@ -113,7 +115,7 @@ public class AppWindow {
}
public Object[] getElements(Object inputElement) {
System.err.println("getElements " + inputElement + " "
_log.debug("getElements " + inputElement + " "
+ inputElement.getClass());
if (inputElement instanceof DwcaBuilder) {
return ((DwcaBuilder) inputElement).getFileRoots().toArray();
......@@ -129,7 +131,7 @@ public class AppWindow {
}
public Object[] getChildren(Object parentElement) {
System.err.println("getChildren " + parentElement + " "
_log.debug("getChildren " + parentElement + " "
+ parentElement.getClass());
if (parentElement instanceof DwcaBuilder) {
......@@ -149,7 +151,7 @@ public class AppWindow {
}
public boolean hasChildren(Object element) {
System.err.println("hasChildren " + element + " "
_log.debug("hasChildren " + element + " "
+ element.getClass());
if (element instanceof DwcaBuilder) {
......@@ -272,7 +274,7 @@ public class AppWindow {
mntmQuit.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
System.err.println("Exiting now.");
_log.debug("Exiting now.");
shlGenesysMagic.dispose();
}
});
......@@ -327,7 +329,7 @@ public class AppWindow {
.getSelection()).iterator(); iterator.hasNext();) {
Object selectedObject = iterator.next();
System.err.println("Remove Sel " + selectedObject);
_log.debug("Remove Sel " + selectedObject);
if (selectedObject instanceof DataSourceFile) {
builder.removeDataSource((DataSourceFile) selectedObject);
tableViewer.refresh();
......@@ -348,7 +350,7 @@ public class AppWindow {
&& iterator.hasNext();) {
Object selectedObject = iterator.next();
System.err.println("Sel " + selectedObject);
_log.debug("Sel " + selectedObject);
if (selectedObject instanceof DataSourceFile)
enabled = true;
......@@ -386,7 +388,7 @@ public class AppWindow {
dragSource.addDragListener(new DragSourceAdapter() {
@Override
public void dragStart(DragSourceEvent event) {
System.err.println("Starting drag");
_log.debug("Starting drag");
event.doit = true;
LocalSelectionTransfer.getTransfer().setSelection(tableViewer.getSelection());
}
......@@ -401,10 +403,10 @@ public class AppWindow {
if (selectedNode instanceof DataSourceSheet) {
final DataSourceSheet currentSheet = (DataSourceSheet) selectedNode;
System.err.println("Doubleclick " + currentSheet);
_log.debug("Doubleclick " + currentSheet);
int i = 0;
for (Control c : tabFolder.getTabList()) {
System.err.println("Looking at " + c);
_log.debug("Looking at " + c);
if (c instanceof SheetDisplay) {
if (selectedNode == ((SheetDisplay) c)
.getDataSourceSheet()) {
......@@ -472,12 +474,12 @@ public class AppWindow {
if (response != null) {
for (String file : fd.getFileNames()) {
System.err.println(fd.getFilterPath() + " " + file);
_log.debug(fd.getFilterPath() + " " + file);
builder.addDataSource(dataSourceLoader.loadDataSource(new File(
fd.getFilterPath(), file)));
// Update binding!
System.err.println("Updating models!");
_log.debug("Updating models!");
m_bindingContext.updateModels();
}
}
......
......@@ -25,21 +25,24 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.log4j.Logger;
public class DataSourceLoaderImpl implements DataSourceLoader {
private static final Logger _log = Logger.getLogger(DataSourceLoaderImpl.class);
private final List<DataSourceSheet> NO_SHEETS = new ArrayList<DataSourceSheet>();
private Set<DataSourceParser> parsers = new HashSet<DataSourceParser>();
@Override
public void registerParser(DataSourceParser parser) {
System.err.println("Adding parser " + parser.getClass().getName());
_log.debug("Adding parser " + parser.getClass().getName());
this.parsers.add(parser);
}
@Override
public DataSourceFile loadDataSource(File file) {
if (!file.exists() || !file.canRead()) {
System.err.println("Could not find or read "
_log.debug("Could not find or read "
+ file.getAbsolutePath());
return null;
}
......@@ -63,7 +66,7 @@ public class DataSourceLoaderImpl implements DataSourceLoader {
return parser.findSheets(sourceFile);
}
} catch (UnsupportedDataFormatException e) {
System.err.println(e.getMessage());
_log.debug(e.getMessage());
}
}
......@@ -82,7 +85,7 @@ public class DataSourceLoaderImpl implements DataSourceLoader {
sheet.getSheetName(), maxRows);
}
} catch (UnsupportedDataFormatException e) {
System.err.println(e.getMessage());
_log.debug(e.getMessage(), e);
}
}
......
......@@ -22,9 +22,12 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.genesys2.anno.model.Column;
public class DataSourceSheet extends AbstractModelObject {
private static final Logger _log = Logger.getLogger(DataSourceSheet.class);
private File sourceFile;
private String sheetName;
private List<String> columnNames = new ArrayList<String>();
......@@ -70,7 +73,7 @@ public class DataSourceSheet extends AbstractModelObject {
}
public void setHeadersIncluded(boolean headersIncluded) {
System.err.println("Set headers included :" + headersIncluded);
_log.debug("Set headers included :" + headersIncluded);
this.headersIncluded = headersIncluded;
firePropertyChange("headersIncluded", null, headersIncluded);
}
......@@ -84,7 +87,7 @@ public class DataSourceSheet extends AbstractModelObject {
}
public void setHeaderRowIndex(int headerRowIndex) {
System.err.println("Set header row index:" + headerRowIndex);
_log.debug("Set header row index:" + headerRowIndex);
this.headerRowIndex = headerRowIndex;
firePropertyChange("headerRowIndex", null, headerRowIndex);
}
......@@ -113,19 +116,19 @@ public class DataSourceSheet extends AbstractModelObject {
// Make sure we have the Columns in the list
ensureColumns(columnCount, headers);
System.err.println("Firing sampleData change");
_log.debug("Firing sampleData change");
firePropertyChange("sampleData", null, this.sampleData);
}
private void ensureColumns(int columnCount, Object[] headerRow) {
boolean changed = false;
for (int i = columns.size() - 1; i >= 0 && i > columnCount; i--) {
System.err.println("Removing extra columns");
_log.debug("Removing extra columns");
columns.remove(i);
changed = true;
}
for (int i = columns.size(); i < columnCount; i++) {
System.err.println("Adding column " + i);
_log.debug("Adding column " + i);
columns.add(new Column());
changed = true;
}
......
......@@ -19,13 +19,12 @@ package org.genesys2.anno.gui;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeanProperties;
import org.eclipse.core.databinding.observable.ChangeEvent;
import org.eclipse.core.databinding.observable.IChangeListener;
import org.eclipse.core.databinding.observable.IObservable;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.util.LocalSelectionTransfer;
......@@ -69,6 +68,7 @@ import org.genesys2.anno.model.Column;
import swing2swt.layout.BorderLayout;
public class SheetDisplay extends Composite {
private static final Logger _log = Logger.getLogger(SheetDisplay.class);
private DataBindingContext m_bindingContext;
private static class ContentProvider implements IStructuredContentProvider {
......@@ -107,7 +107,6 @@ public class SheetDisplay extends Composite {
private Table table;
private Text txtColumnName;
private Text txtRdfTerm;
private Text txtColumnIndex;
private DSW dsw = new DSW();
private TableViewer tableViewer;
private Text txtHeaderRowIndex;
......@@ -123,10 +122,10 @@ public class SheetDisplay extends Composite {
public void setDataSourceSheet(DataSourceSheet dataSourceSheet) {
this.dsw.setDataSourceSheet(dataSourceSheet);
// System.err.println("Updating targets");
// _log.debug("Updating targets");
// m_bindingContext.updateTargets();
}
/**
* Create the composite.
*
......@@ -140,9 +139,11 @@ public class SheetDisplay extends Composite {
// UNBIND ALL STUFF
sampleDataDswObserveValue.dispose();
@SuppressWarnings("unchecked")
ArrayList<Object> bindings = new ArrayList<Object>(m_bindingContext.getBindings());
for (Object b : bindings) {
System.out.println("Remove binfing " +b);
_log.trace("Remove binding " + b);
if (b instanceof Binding) {
((Binding) b).getModel().dispose();
}
......@@ -177,16 +178,6 @@ public class SheetDisplay extends Composite {
scrolledComposite.setMinSize(new Point(10, 200));
new Label(composite, SWT.NONE);
Label lblColumn = new Label(composite, SWT.NONE);
lblColumn.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblColumn.setText("Column");
txtColumnIndex = new Text(composite, SWT.BORDER);
txtColumnIndex.setEnabled(false);
txtColumnIndex.setEditable(false);
txtColumnIndex.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
new Label(composite, SWT.NONE);
Label lblThisIsA = new Label(composite, SWT.NONE);
lblThisIsA.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblThisIsA.setText("Column name");
......@@ -233,7 +224,7 @@ public class SheetDisplay extends Composite {
btnAnalyzeColumnData.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
System.err.println("Do column analysis");
_log.debug("Do column analysis");
}
});
btnAnalyzeColumnData.setText("Analyze column data");
......@@ -246,14 +237,14 @@ public class SheetDisplay extends Composite {
public void drop(DropTargetEvent event) {
if (LocalSelectionTransfer.getTransfer().isSupportedType(event.currentDataType)) {
ISelection sel = LocalSelectionTransfer.getTransfer().getSelection();
System.err.println("Dropped " + sel);
System.err.println("Dropped class " + sel.getClass());
_log.debug("Dropped " + sel);
_log.debug("Dropped class " + sel.getClass());
}
}
@Override
public void dragEnter(DropTargetEvent event) {
System.err.println("dragenter " + event.detail);
_log.debug("dragenter " + event.detail);
event.detail = DND.DROP_LINK;
}
});
......@@ -281,13 +272,13 @@ public class SheetDisplay extends Composite {
// int idx = Integer.parseInt(txtHeaderRowIndex.getText());
// if (dataSourceSheet.getHeaderRowIndex() != idx) {
// dataSourceSheet.setHeaderRowIndex(idx);
// System.err.println("Modify headerRowIndex: " + idx);
// _log.debug("Modify headerRowIndex: " + idx);
// }
// } catch (NumberFormatException e1) {
// txtHeaderRowIndex.setText(String.valueOf(dataSourceSheet
// .getHeaderRowIndex()));
// }
System.err.println("Updating model...");
_log.debug("Updating model...");
m_bindingContext.updateModels();
}
});
......@@ -378,7 +369,7 @@ public class SheetDisplay extends Composite {
}
private void updateTable() {
System.err.println("Rebuilding table...");
_log.debug("Rebuilding table...");
table.clearAll();
DataSourceSheet dataSourceSheet = dsw.getDataSourceSheet();
......@@ -391,53 +382,54 @@ public class SheetDisplay extends Composite {
c.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
System.err.println("Selected " + column);
_log.debug("Selected " + column);
dsw.setSelectedColumn(column);
}
});
}
tableViewer.setInput(dataSourceSheet.getSampleData());
System.out.println("Done with table update");
_log.info("Done with table update");
}
public DataSourceSheet getDataSourceSheet() {
return dsw.getDataSourceSheet();
}
protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
System.out.println("1");
_log.info("1");
IObservableValue observeSelectionChkbxContainsHeadersObserveWidget_1 = WidgetProperties.selection().observe(chkbxContainsHeaders);
IObservableValue headersIncludedGetDataSourceSheetObserveValue = BeanProperties.value("dataSourceSheet.headersIncluded").observe(dsw);
bindingContext.bindValue(observeSelectionChkbxContainsHeadersObserveWidget_1, headersIncludedGetDataSourceSheetObserveValue, null, null);
//
System.out.println("2");
_log.info("2");
IObservableValue observeTextTxtHeaderRowIndexObserveWidget_1 = WidgetProperties.text(SWT.Modify).observe(txtHeaderRowIndex);
IObservableValue headerRowIndexGetDataSourceSheetObserveValue = BeanProperties.value("dataSourceSheet.headerRowIndex").observe(dsw);
bindingContext.bindValue(observeTextTxtHeaderRowIndexObserveWidget_1, headerRowIndexGetDataSourceSheetObserveValue, null, null);
//
System.out.println("3");
_log.info("3");
IObservableValue observeEnabledTxtHeaderRowIndexObserveWidget = WidgetProperties.enabled().observe(txtHeaderRowIndex);
IObservableValue observeSelectionChkbxContainsHeadersObserveWidget = WidgetProperties.selection().observe(chkbxContainsHeaders);
bindingContext.bindValue(observeEnabledTxtHeaderRowIndexObserveWidget, observeSelectionChkbxContainsHeadersObserveWidget, null, null);
//
System.out.println("4");
_log.info("4");
IObservableValue observeTextTxtRdfTermObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtRdfTerm);
IObservableValue selectedColumnrdfTermDswObserveValue = BeanProperties.value("selectedColumn.rdfTerm").observe(dsw);
bindingContext.bindValue(observeTextTxtRdfTermObserveWidget, selectedColumnrdfTermDswObserveValue, null, null);
//
System.out.println("5");
_log.info("5");
IObservableValue observeSelectionBtnContainsMultipleValuesObserveWidget = WidgetProperties.selection().observe(btnContainsMultipleValues);
IObservableValue selectedColumnmultipleDswObserveValue = BeanProperties.value("selectedColumn.multiple").observe(dsw);
bindingContext.bindValue(observeSelectionBtnContainsMultipleValuesObserveWidget, selectedColumnmultipleDswObserveValue, null, null);
//
System.out.println("6");
_log.info("6");
IObservableValue observeTextTextObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtColumnDescription);
IObservableValue selectedColumndescriptionDswObserveValue = BeanProperties.value("selectedColumn.description").observe(dsw);
bindingContext.bindValue(observeTextTextObserveWidget, selectedColumndescriptionDswObserveValue, null, null);
//
System.out.println("7");
_log.info("7");
IObservableValue observeTextTxtColumnNameObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtColumnName);
IObservableValue selectedColumnpreferredNameDswObserveValue = BeanProperties.value("selectedColumn.preferredName").observe(dsw);
bindingContext.bindValue(observeTextTxtColumnNameObserveWidget, selectedColumnpreferredNameDswObserveValue, null, null);
......
......@@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.log4j.Logger;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
......@@ -30,6 +31,7 @@ import org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable;
import org.apache.poi.xssf.eventusermodel.XSSFReader;
import org.apache.poi.xssf.eventusermodel.XSSFReader.SheetIterator;
import org.apache.poi.xssf.model.StylesTable;
import org.genesys2.anno.gui.DataSourceLoaderImpl;
import org.genesys2.anno.gui.DataSourceSheet;
import org.genesys2.anno.gui.UnsupportedDataFormatException;
import org.genesys2.anno.reader.MyXSSFSheetHandler;
......@@ -42,6 +44,8 @@ import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
public class XlsxDataSourceParser extends BasicDataSourceParser {
private static final Logger _log = Logger.getLogger(XlsxDataSourceParser.class);
private final String[] supportedExtensions = new String[] { ".xlsx" };
@Override
......@@ -78,7 +82,7 @@ public class XlsxDataSourceParser extends BasicDataSourceParser {
sheetDataSource.setSheetName(sheetsIterator.getSheetName());
sheets.add(sheetDataSource);
} finally {
System.err.println("Closing sheet");
_log.debug("Closing sheet");
sheet.close();
System.out.println("");
}
......@@ -90,7 +94,7 @@ public class XlsxDataSourceParser extends BasicDataSourceParser {
+ sourceFile.getAbsolutePath(), e);
} finally {
System.err.println("Closing OPCPackage, no save");
_log.debug("Closing OPCPackage, no save");
}
return sheets;
}
......@@ -131,7 +135,7 @@ public class XlsxDataSourceParser extends BasicDataSourceParser {
+ sheetsIterator.getSheetName() + "'");
if (sheetName.equals(sheetsIterator.getSheetName())) {
System.err.println("Found sheet.");
_log.debug("Found sheet.");
final List<Object[]> rows = new ArrayList<Object[]>();
handler.setRowHandler(new RowHandler() {
......@@ -147,7 +151,7 @@ public class XlsxDataSourceParser extends BasicDataSourceParser {
} catch (StopParsingException e) {
// NOP
} finally {
System.err.println("Closing sheet");
_log.debug("Closing sheet");
sheet.close();
System.out.println("");
}
......@@ -165,7 +169,7 @@ public class XlsxDataSourceParser extends BasicDataSourceParser {
// TODO Auto-generated catch block
e1.printStackTrace();
} finally {
System.err.println("Closing OPCPackage");
_log.debug("Closing OPCPackage");
}
throw new UnsupportedDataFormatException("Could not parse "
......
......@@ -38,6 +38,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
......@@ -69,6 +70,7 @@ import org.xml.sax.helpers.XMLReaderFactory;
* @author Andrew Oliver (acoliver at apache dot org)
*/
public final class XSSFReadWrite {
private static final Logger _log = Logger.getLogger(XSSFReadWrite.class);
/**
* creates an {@link HSSFWorkbook} the specified OS filename.
......@@ -88,12 +90,12 @@ public final class XSSFReadWrite {
throw new IOException(e.getMessage(), e);
}
System.out.println("Data dump:\n");
_log.debug("Data dump:\n");
for (int k = 0; k < wb.getNumberOfSheets(); k++) {
Sheet sheet = wb.getSheetAt(k);
int rows = sheet.getPhysicalNumberOfRows();
System.out.println("Sheet " + k + " \"" + wb.getSheetName(k)
_log.debug("Sheet " + k + " \"" + wb.getSheetName(k)
+ "\" has " + rows + " row(s).");
for (int r = 0; r < rows; r++) {
Row row = sheet.getRow(r);
......@@ -102,7 +104,7 @@ public final class XSSFReadWrite {
}
int cells = row.getPhysicalNumberOfCells();
System.out.println("\nROW " + row.getRowNum() + " has " + cells
_log.debug("\nROW " + row.getRowNum() + " has " + cells
+ " cell(s).");
for (int c = 0; c < cells; c++) {
Cell cell = row.getCell(c);
......@@ -124,7 +126,7 @@ public final class XSSFReadWrite {
default:
}
System.out.println("CELL col=" + cell.getColumnIndex()
_log.debug("CELL col=" + cell.getColumnIndex()
+ " VALUE=" + value);
}
}
......@@ -141,20 +143,20 @@ public final class XSSFReadWrite {
Iterator<InputStream> sheets = r.getSheetsData();
while (sheets.hasNext()) {
System.out.println("Processing new sheet:\n");
_log.debug("Processing new sheet:\n");
InputStream sheet = sheets.next();
try {
InputSource sheetSource = new InputSource(sheet);
parser.parse(sheetSource);
} finally {
System.err.println("Closing sheet");
_log.debug("Closing sheet");
sheet.close();
System.out.println("");
_log.debug("");
}
}
} finally {
System.err.println("Closing OPCPackage");
_log.debug("Closing OPCPackage");
pkg.close();
}
}
......@@ -183,7 +185,7 @@ public final class XSSFReadWrite {
public void startElement(String uri, String localName, String name,
Attributes attributes) throws SAXException {
// System.out.println(">> " + name);