Commit 11694f4c authored by Matija Obreza's avatar Matija Obreza

Databind testing

parent 0899d8cc
......@@ -11,6 +11,11 @@
<id>my-local-repo</id>
<url>file://${basedir}/lib</url>
</repository>
<repository>
<id>thingml</id>
<name>3rd Party Eclipse</name>
<url>http://maven.thingml.org/thirdparty/</url>
</repository>
</repositories>
<dependencies>
......@@ -40,11 +45,6 @@
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>swt</artifactId>
<version>3.3.0-v3346</version>
</dependency>
<dependency>
<groupId>org.eclipse.swt</groupId>
<artifactId>swing2swt</artifactId>
......@@ -57,16 +57,6 @@
<artifactId>org.eclipse.swt.cocoa.macosx.x86_64</artifactId>
<version>4.3</version>
</dependency>
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>jface</artifactId>
<version>3.3.0-I20070606-0010</version>
</dependency>
<dependency>
<groupId>org.eclipse.jface</groupId>
<artifactId>databinding</artifactId>
<version>1.1.0-I20070606-0010</version>
</dependency>
<dependency>
<groupId>net.sf.supercsv</groupId>
<artifactId>super-csv</artifactId>
......@@ -77,6 +67,60 @@
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.maven</groupId>
<artifactId>org.eclipse.core.databinding.beans</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.maven</groupId>
<artifactId>org.eclipse.core.databinding</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.maven</groupId>
<artifactId>
org.eclipse.core.databinding.observable
</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.maven</groupId>
<artifactId>
org.eclipse.core.databinding.property
</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.maven</groupId>
<artifactId>org.eclipse.jface.databinding</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.maven</groupId>
<artifactId>org.eclipse.jface</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.maven</groupId>
<artifactId>org.eclipse.swt</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.maven</groupId>
<artifactId>org.eclipse.equinox.common</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.maven</groupId>
<artifactId>org.eclipse.core.commands</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.maven</groupId>
<artifactId>com.ibm.icu</artifactId>
<version>3.8.0</version>
</dependency>
</dependencies>
<build>
<plugins>
......@@ -91,25 +135,25 @@
</plugin>
<plugin>
<groupId>io.github.appbundler</groupId>
<groupId>io.github.appbundler</groupId>
<artifactId>appbundle-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration>
<mainClass>org.genesys2.anno.gui.AppWindow</mainClass>
<bundleName>Genesys Magic</bundleName>
<jvmVersion>1.6</jvmVersion>
<dictionaryFile>Info.plist.template</dictionaryFile>
<vmOptions>-XstartOnFirstThread</vmOptions>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
</plugin>
<configuration>
<mainClass>org.genesys2.anno.gui.AppWindow</mainClass>
<bundleName>Genesys Magic</bundleName>
<jvmVersion>1.6</jvmVersion>
<dictionaryFile>Info.plist.template</dictionaryFile>
<vmOptions>-XstartOnFirstThread</vmOptions>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Run it -->
<plugin>
......
package org.genesys2.anno.gui;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
public abstract class AbstractModelObject {
private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(
this);
public void addPropertyChangeListener(PropertyChangeListener listener) {
propertyChangeSupport.addPropertyChangeListener(listener);
}
public void addPropertyChangeListener(String propertyName,
PropertyChangeListener listener) {
propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
propertyChangeSupport.removePropertyChangeListener(listener);
}
public void removePropertyChangeListener(String propertyName,
PropertyChangeListener listener) {
propertyChangeSupport.removePropertyChangeListener(propertyName,
listener);
}
protected void firePropertyChange(String propertyName, Object oldValue,
Object newValue) {
propertyChangeSupport.firePropertyChange(propertyName, oldValue,
newValue);
}
}
\ No newline at end of file
......@@ -8,12 +8,22 @@ import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeansObservables;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.map.IObservableMap;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
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.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
......@@ -24,7 +34,6 @@ import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DragSource;
import org.eclipse.swt.dnd.DragSourceAdapter;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
......@@ -41,8 +50,6 @@ 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.TableItem;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.Tree;
......@@ -54,6 +61,7 @@ import org.genesys2.anno.parser.XlsxDataSourceParser;
import swing2swt.layout.BorderLayout;
public class AppWindow {
private DataBindingContext m_bindingContext;
private DwcaBuilder builder = new DwcaBuilder();
private ExecutorService threadPool = Executors.newFixedThreadPool(4);
......@@ -70,7 +78,7 @@ public class AppWindow {
}
public String getText(Object element) {
System.err.println("getText" + element);
System.err.println("getText " + element);
if (element instanceof DataSourceFile) {
return ((DataSourceFile) element).getFile().getName();
}
......@@ -145,7 +153,6 @@ public class AppWindow {
protected Shell shlGenesysMagic;
private MenuItem mntmQuit;
private Table table;
protected DataSourceLoader dataSourceLoader;
private static Image archiveIcon;
private static Image spreadsheetIcon;
......@@ -153,6 +160,8 @@ public class AppWindow {
private Tree filesTree;
private Display display;
private TreeViewer treeViewer;
private Table table;
private TableViewer tableViewer;
/**
* Launch the application.
......@@ -160,12 +169,17 @@ public class AppWindow {
* @param args
*/
public static void main(String[] args) {
try {
AppWindow window = new AppWindow();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
Display display = Display.getDefault();
Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
public void run() {
try {
AppWindow window = new AppWindow();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
......@@ -173,12 +187,12 @@ public class AppWindow {
*/
public void open() {
this.display = Display.getDefault();
fakeSpring();
loadImages();
createContents();
shlGenesysMagic.open();
shlGenesysMagic.layout();
fakeSpring();
while (!shlGenesysMagic.isDisposed()) {
if (!display.readAndDispatch()) {
......@@ -194,6 +208,10 @@ public class AppWindow {
dataSourceLoader = new DataSourceLoaderImpl();
dataSourceLoader.registerParser(new XlsxDataSourceParser());
dataSourceLoader.registerParser(new CsvDataSourceParser());
DataSourceFile dsf = new DataSourceFile();
dsf.setFile(new File("/tmp/foo.bar"));
builder.addDataSource(dsf);
}
private void loadImages() {
......@@ -299,7 +317,8 @@ public class AppWindow {
Object selectedObject = iterator.next();
System.err.println("Remove Sel " + selectedObject);
if (selectedObject instanceof DataSourceFile) {
builder.getFileRoots().remove(selectedObject);
builder.removeDataSource((DataSourceFile) selectedObject);
tableViewer.refresh();
}
}
......@@ -345,38 +364,22 @@ public class AppWindow {
tabFolder.setSelectionBackground(Display.getCurrent().getSystemColor(
SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
table = new Table(sashForm, SWT.BORDER | SWT.FULL_SELECTION);
table.setHeaderVisible(true);
tableViewer = new TableViewer(sashForm, SWT.BORDER | SWT.FULL_SELECTION);
table = tableViewer.getTable();
table.setLinesVisible(true);
TableColumn tblclmnColumn = new TableColumn(table, SWT.NONE);
tblclmnColumn.setWidth(100);
tblclmnColumn.setText("Column");
TableColumn tblclmnRdfTerm = new TableColumn(table, SWT.NONE);
tblclmnRdfTerm.setWidth(200);
tblclmnRdfTerm.setText("Ontology Term");
table.setHeaderVisible(true);
DragSource dragSource = new DragSource(table, DND.DROP_LINK);
dragSource.setTransfer(new Transfer[] { TextTransfer.getInstance() });
TableItem tableItem = new TableItem(table, SWT.NONE);
tableItem.setText(new String[] { "instCode",
"https://www.genesys-pgr.org/rdf/mcpd/instcode" });
dragSource.setTransfer(new Transfer[] { LocalSelectionTransfer.getTransfer() });
dragSource.addDragListener(new DragSourceAdapter() {
@Override
public void dragSetData(DragSourceEvent event) {
System.err.println("Dragging term");
event.data = "HAHA";
}
@Override
public void dragStart(DragSourceEvent event) {
System.err.println("Starting drag");
event.doit = true;
LocalSelectionTransfer.getTransfer().setSelection(tableViewer.getSelection());
}
});
sashForm.setWeights(new int[] { 3, 6, 2 });
sashForm.setWeights(new int[] { 3, 6, 3 });
treeViewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent e) {
......@@ -457,6 +460,7 @@ public class AppWindow {
});
tltmAddFile.setText("Open");
tltmAddFile.setImage(openPackageIcon);
m_bindingContext = initDataBindings();
}
public void addSourceFile() {
......@@ -472,9 +476,27 @@ public class AppWindow {
System.err.println(fd.getFilterPath() + " " + file);
builder.addDataSource(dataSourceLoader.loadDataSource(new File(
fd.getFilterPath(), file)));
// Update binding!
System.err.println("Updating models!");
m_bindingContext.updateModels();
}
}
treeViewer.refresh();
}
protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
ObservableListContentProvider listContentProvider = new ObservableListContentProvider();
IObservableMap observeMap = BeansObservables.observeMap(listContentProvider.getKnownElements(), DataSourceFile.class, "fileName");
tableViewer.setLabelProvider(new ObservableMapLabelProvider(observeMap));
tableViewer.setContentProvider(listContentProvider);
//
IObservableList fileRootsBuilderObserveList = BeansObservables.observeList(Realm.getDefault(), builder, "fileRoots");
tableViewer.setInput(fileRootsBuilderObserveList);
//
return bindingContext;
}
}
package org.genesys2.anno.gui;
import org.genesys2.anno.model.Column;
public class DSW extends AbstractModelObject {
private DataSourceSheet dataSourceSheet;
private Column selectedColumn = null;
public DataSourceSheet getDataSourceSheet() {
return dataSourceSheet;
}
public void setDataSourceSheet(DataSourceSheet dataSourceSheet) {
this.dataSourceSheet = dataSourceSheet;
firePropertyChange("dataSourceSheet", null, dataSourceSheet);
}
public Column getSelectedColumn() {
return selectedColumn;
}
public void setSelectedColumn(Column selectedColumn) {
this.selectedColumn = selectedColumn;
firePropertyChange("selectedColumn", null, selectedColumn);
}
}
......@@ -4,7 +4,7 @@ import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class DataSourceFile {
public class DataSourceFile extends AbstractModelObject {
private File file;
private List<DataSourceSheet> sheets = new ArrayList<DataSourceSheet>();
......@@ -14,6 +14,11 @@ public class DataSourceFile {
public void setFile(File file) {
this.file = file;
firePropertyChange("fileName", null, file);
}
public String getFileName() {
return this.file==null ? null : this.file.getName();
}
public List<DataSourceSheet> getSheets() {
......@@ -22,6 +27,7 @@ public class DataSourceFile {
public void setSheets(List<DataSourceSheet> sheets) {
this.sheets = sheets;
firePropertyChange("sheets", null, sheets);
}
@Override
......
......@@ -6,7 +6,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class DataSourceSheet {
public class DataSourceSheet extends AbstractModelObject {
private File sourceFile;
private String sheetName;
private List<String> columnNames = new ArrayList<String>();
......@@ -28,6 +28,7 @@ public class DataSourceSheet {
public void setSheetName(String sheetName) {
this.sheetName = sheetName;
firePropertyChange("sheetName", null, sheetName);
}
public List<String> getColumnNames() {
......@@ -36,6 +37,7 @@ public class DataSourceSheet {
public void setColumnNames(List<String> columnNames) {
this.columnNames = columnNames;
firePropertyChange("columnNames", null, columnNames);
}
public Map<String, String> getColumnTerms() {
......@@ -44,10 +46,13 @@ public class DataSourceSheet {
public void setColumnTerms(Map<String, String> columnTerms) {
this.columnTerms = columnTerms;
firePropertyChange("columnTerms", null, columnTerms);
}
public void setHeadersIncluded(boolean headersIncluded) {
System.err.println("Set headers included :" + headersIncluded);
this.headersIncluded = headersIncluded;
firePropertyChange("headersIncluded", null, headersIncluded);
}
public boolean isHeadersIncluded() {
......@@ -59,6 +64,8 @@ public class DataSourceSheet {
}
public void setHeaderRowIndex(int headerRowIndex) {
System.err.println("Set header row index:" + headerRowIndex);
this.headerRowIndex = headerRowIndex;
firePropertyChange("headerRowIndex", null, headerRowIndex);
}
}
......@@ -3,7 +3,7 @@ package org.genesys2.anno.gui;
import java.util.ArrayList;
import java.util.List;
public class DwcaBuilder {
public class DwcaBuilder extends AbstractModelObject {
private List<DataSourceFile> fileRoots = new ArrayList<DataSourceFile>();
public List<DataSourceFile> getFileRoots() {
......@@ -14,5 +14,11 @@ public class DwcaBuilder {
if (dataSource == null)
return;
fileRoots.add(dataSource);
firePropertyChange("fileRoots", null, this);
}
public void removeDataSource(DataSourceFile dataSource) {
fileRoots.remove(dataSource);
firePropertyChange("fileRoots", null, this);
}
}
......@@ -4,6 +4,12 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.ArrayUtils;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeanProperties;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
......@@ -16,7 +22,6 @@ import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DropTarget;
import org.eclipse.swt.dnd.DropTargetAdapter;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
......@@ -41,6 +46,7 @@ import org.eclipse.swt.widgets.Text;
import swing2swt.layout.BorderLayout;
public class SheetDisplay extends Composite {
private DataBindingContext m_bindingContext;
private static class ContentProvider implements IStructuredContentProvider {
public Object[] getElements(Object inputElement) {
if (inputElement instanceof List) {
......@@ -80,6 +86,7 @@ public class SheetDisplay extends Composite {
private Text txtRdfTerm;
private Text txtColumnIndex;
private DataSourceSheet dataSourceSheet;
private DSW dsw=new DSW();
private TableViewer tableViewer;
private Text txtHeaderRowIndex;
private Text txtCharset;
......@@ -90,15 +97,16 @@ public class SheetDisplay extends Composite {
private Object[] headerRow;
private Text text;
public DataSourceSheet getDataSourceSheet() {
return dataSourceSheet;
}
public void setDataSourceSheet(DataSourceSheet dataSourceSheet) {
this.dataSourceSheet = dataSourceSheet;
chkbxContainsHeaders.setSelection(dataSourceSheet.isHeadersIncluded());
txtHeaderRowIndex.setText(String.valueOf(dataSourceSheet
.getHeaderRowIndex()));
this.dsw.setDataSourceSheet(dataSourceSheet);
System.err.println("Updating targets");
m_bindingContext.updateTargets();
// m_bindingContext.updateModels();
// chkbxContainsHeaders.setSelection(dataSourceSheet.isHeadersIncluded());
// txtHeaderRowIndex.setText(String.valueOf(dataSourceSheet
// .getHeaderRowIndex()));
}
/**
......@@ -211,14 +219,18 @@ public class SheetDisplay extends Composite {
DropTarget dropTarget = new DropTarget(composite, DND.DROP_MOVE
| DND.DROP_COPY | DND.DROP_DEFAULT | DND.DROP_LINK);
dropTarget.setTransfer(new Transfer[] { TextTransfer.getInstance() });
dropTarget.setTransfer(new Transfer[] { LocalSelectionTransfer.getTransfer() });
dropTarget.addDropListener(new DropTargetAdapter() {
@Override
public void drop(DropTargetEvent event) {
System.err.println("Dropped " + event.data);
if (LocalSelectionTransfer.getTransfer().isSupportedType(event.currentDataType)) {
ISelection sel = LocalSelectionTransfer.getTransfer().getSelection();
System.err.println("Dropped " + sel);
System.err.println("Dropped class " + sel.getClass());
}
}
@Override
public void dragEnter(DropTargetEvent event) {
System.err.println("dragenter " + event.detail);
......@@ -246,16 +258,18 @@ public class SheetDisplay extends Composite {
txtHeaderRowIndex.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
try {
int idx = Integer.parseInt(txtHeaderRowIndex.getText());
if (dataSourceSheet.getHeaderRowIndex() != idx) {
dataSourceSheet.setHeaderRowIndex(idx);
System.err.println("Modify headerRowIndex: " + idx);
}
} catch (NumberFormatException e1) {
txtHeaderRowIndex.setText(String.valueOf(dataSourceSheet
.getHeaderRowIndex()));
}
// try {
// int idx = Integer.parseInt(txtHeaderRowIndex.getText());
// if (dataSourceSheet.getHeaderRowIndex() != idx) {
// dataSourceSheet.setHeaderRowIndex(idx);
// System.err.println("Modify headerRowIndex: " + idx);
// }
// } catch (NumberFormatException e1) {
// txtHeaderRowIndex.setText(String.valueOf(dataSourceSheet
// .getHeaderRowIndex()));
// }
System.err.println("Updating model...");
m_bindingContext.updateModels();
}
});
txtHeaderRowIndex.setEnabled(false);
......@@ -276,15 +290,15 @@ public class SheetDisplay extends Composite {