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

Databind testing

parent 0899d8cc
...@@ -11,6 +11,11 @@ ...@@ -11,6 +11,11 @@
<id>my-local-repo</id> <id>my-local-repo</id>
<url>file://${basedir}/lib</url> <url>file://${basedir}/lib</url>
</repository> </repository>
<repository>
<id>thingml</id>
<name>3rd Party Eclipse</name>
<url>http://maven.thingml.org/thirdparty/</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
...@@ -40,11 +45,6 @@ ...@@ -40,11 +45,6 @@
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
<version>3.3.2</version> <version>3.3.2</version>
</dependency> </dependency>
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>swt</artifactId>
<version>3.3.0-v3346</version>
</dependency>
<dependency> <dependency>
<groupId>org.eclipse.swt</groupId> <groupId>org.eclipse.swt</groupId>
<artifactId>swing2swt</artifactId> <artifactId>swing2swt</artifactId>
...@@ -57,16 +57,6 @@ ...@@ -57,16 +57,6 @@
<artifactId>org.eclipse.swt.cocoa.macosx.x86_64</artifactId> <artifactId>org.eclipse.swt.cocoa.macosx.x86_64</artifactId>
<version>4.3</version> <version>4.3</version>
</dependency> </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> <dependency>
<groupId>net.sf.supercsv</groupId> <groupId>net.sf.supercsv</groupId>
<artifactId>super-csv</artifactId> <artifactId>super-csv</artifactId>
...@@ -77,6 +67,60 @@ ...@@ -77,6 +67,60 @@
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
<version>1.3.2</version> <version>1.3.2</version>
</dependency> </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> </dependencies>
<build> <build>
<plugins> <plugins>
...@@ -91,25 +135,25 @@ ...@@ -91,25 +135,25 @@
</plugin> </plugin>
<plugin> <plugin>
<groupId>io.github.appbundler</groupId> <groupId>io.github.appbundler</groupId>
<artifactId>appbundle-maven-plugin</artifactId> <artifactId>appbundle-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<configuration> <configuration>
<mainClass>org.genesys2.anno.gui.AppWindow</mainClass> <mainClass>org.genesys2.anno.gui.AppWindow</mainClass>
<bundleName>Genesys Magic</bundleName> <bundleName>Genesys Magic</bundleName>
<jvmVersion>1.6</jvmVersion> <jvmVersion>1.6</jvmVersion>
<dictionaryFile>Info.plist.template</dictionaryFile> <dictionaryFile>Info.plist.template</dictionaryFile>
<vmOptions>-XstartOnFirstThread</vmOptions> <vmOptions>-XstartOnFirstThread</vmOptions>
</configuration> </configuration>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
<goals> <goals>
<goal>bundle</goal> <goal>bundle</goal>
</goals> </goals>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<!-- Run it --> <!-- Run it -->
<plugin> <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; ...@@ -8,12 +8,22 @@ import java.util.List;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; 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.resource.ImageDescriptor;
import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
...@@ -24,7 +34,6 @@ import org.eclipse.swt.dnd.DND; ...@@ -24,7 +34,6 @@ import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DragSource; import org.eclipse.swt.dnd.DragSource;
import org.eclipse.swt.dnd.DragSourceAdapter; import org.eclipse.swt.dnd.DragSourceAdapter;
import org.eclipse.swt.dnd.DragSourceEvent; import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.ControlAdapter; import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent; import org.eclipse.swt.events.ControlEvent;
...@@ -41,8 +50,6 @@ import org.eclipse.swt.widgets.Menu; ...@@ -41,8 +50,6 @@ import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table; 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.ToolBar;
import org.eclipse.swt.widgets.ToolItem; import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.Tree;
...@@ -54,6 +61,7 @@ import org.genesys2.anno.parser.XlsxDataSourceParser; ...@@ -54,6 +61,7 @@ import org.genesys2.anno.parser.XlsxDataSourceParser;
import swing2swt.layout.BorderLayout; import swing2swt.layout.BorderLayout;
public class AppWindow { public class AppWindow {
private DataBindingContext m_bindingContext;
private DwcaBuilder builder = new DwcaBuilder(); private DwcaBuilder builder = new DwcaBuilder();
private ExecutorService threadPool = Executors.newFixedThreadPool(4); private ExecutorService threadPool = Executors.newFixedThreadPool(4);
...@@ -70,7 +78,7 @@ public class AppWindow { ...@@ -70,7 +78,7 @@ public class AppWindow {
} }
public String getText(Object element) { public String getText(Object element) {
System.err.println("getText" + element); System.err.println("getText " + element);
if (element instanceof DataSourceFile) { if (element instanceof DataSourceFile) {
return ((DataSourceFile) element).getFile().getName(); return ((DataSourceFile) element).getFile().getName();
} }
...@@ -145,7 +153,6 @@ public class AppWindow { ...@@ -145,7 +153,6 @@ public class AppWindow {
protected Shell shlGenesysMagic; protected Shell shlGenesysMagic;
private MenuItem mntmQuit; private MenuItem mntmQuit;
private Table table;
protected DataSourceLoader dataSourceLoader; protected DataSourceLoader dataSourceLoader;
private static Image archiveIcon; private static Image archiveIcon;
private static Image spreadsheetIcon; private static Image spreadsheetIcon;
...@@ -153,6 +160,8 @@ public class AppWindow { ...@@ -153,6 +160,8 @@ public class AppWindow {
private Tree filesTree; private Tree filesTree;
private Display display; private Display display;
private TreeViewer treeViewer; private TreeViewer treeViewer;
private Table table;
private TableViewer tableViewer;
/** /**
* Launch the application. * Launch the application.
...@@ -160,12 +169,17 @@ public class AppWindow { ...@@ -160,12 +169,17 @@ public class AppWindow {
* @param args * @param args
*/ */
public static void main(String[] args) { public static void main(String[] args) {
try { Display display = Display.getDefault();
AppWindow window = new AppWindow(); Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
window.open(); public void run() {
} catch (Exception e) { try {
e.printStackTrace(); AppWindow window = new AppWindow();
} window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
});
} }
/** /**
...@@ -173,12 +187,12 @@ public class AppWindow { ...@@ -173,12 +187,12 @@ public class AppWindow {
*/ */
public void open() { public void open() {
this.display = Display.getDefault(); this.display = Display.getDefault();
fakeSpring();
loadImages(); loadImages();
createContents(); createContents();
shlGenesysMagic.open(); shlGenesysMagic.open();
shlGenesysMagic.layout(); shlGenesysMagic.layout();
fakeSpring();
while (!shlGenesysMagic.isDisposed()) { while (!shlGenesysMagic.isDisposed()) {
if (!display.readAndDispatch()) { if (!display.readAndDispatch()) {
...@@ -194,6 +208,10 @@ public class AppWindow { ...@@ -194,6 +208,10 @@ public class AppWindow {
dataSourceLoader = new DataSourceLoaderImpl(); dataSourceLoader = new DataSourceLoaderImpl();
dataSourceLoader.registerParser(new XlsxDataSourceParser()); dataSourceLoader.registerParser(new XlsxDataSourceParser());
dataSourceLoader.registerParser(new CsvDataSourceParser()); dataSourceLoader.registerParser(new CsvDataSourceParser());
DataSourceFile dsf = new DataSourceFile();
dsf.setFile(new File("/tmp/foo.bar"));
builder.addDataSource(dsf);
} }
private void loadImages() { private void loadImages() {
...@@ -299,7 +317,8 @@ public class AppWindow { ...@@ -299,7 +317,8 @@ public class AppWindow {
Object selectedObject = iterator.next(); Object selectedObject = iterator.next();
System.err.println("Remove Sel " + selectedObject); System.err.println("Remove Sel " + selectedObject);
if (selectedObject instanceof DataSourceFile) { if (selectedObject instanceof DataSourceFile) {
builder.getFileRoots().remove(selectedObject); builder.removeDataSource((DataSourceFile) selectedObject);
tableViewer.refresh();
} }
} }
...@@ -345,38 +364,22 @@ public class AppWindow { ...@@ -345,38 +364,22 @@ public class AppWindow {
tabFolder.setSelectionBackground(Display.getCurrent().getSystemColor( tabFolder.setSelectionBackground(Display.getCurrent().getSystemColor(
SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT)); SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
table = new Table(sashForm, SWT.BORDER | SWT.FULL_SELECTION); tableViewer = new TableViewer(sashForm, SWT.BORDER | SWT.FULL_SELECTION);
table.setHeaderVisible(true); table = tableViewer.getTable();
table.setLinesVisible(true); table.setLinesVisible(true);
table.setHeaderVisible(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");
DragSource dragSource = new DragSource(table, DND.DROP_LINK); DragSource dragSource = new DragSource(table, DND.DROP_LINK);
dragSource.setTransfer(new Transfer[] { TextTransfer.getInstance() }); dragSource.setTransfer(new Transfer[] { LocalSelectionTransfer.getTransfer() });
TableItem tableItem = new TableItem(table, SWT.NONE);
tableItem.setText(new String[] { "instCode",
"https://www.genesys-pgr.org/rdf/mcpd/instcode" });
dragSource.addDragListener(new DragSourceAdapter() { dragSource.addDragListener(new DragSourceAdapter() {
@Override
public void dragSetData(DragSourceEvent event) {
System.err.println("Dragging term");
event.data = "HAHA";
}
@Override @Override
public void dragStart(DragSourceEvent event) { public void dragStart(DragSourceEvent event) {
System.err.println("Starting drag"); System.err.println("Starting drag");
event.doit = true; 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() { treeViewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent e) { public void doubleClick(DoubleClickEvent e) {
...@@ -457,6 +460,7 @@ public class AppWindow { ...@@ -457,6 +460,7 @@ public class AppWindow {
}); });
tltmAddFile.setText("Open"); tltmAddFile.setText("Open");
tltmAddFile.setImage(openPackageIcon); tltmAddFile.setImage(openPackageIcon);
m_bindingContext = initDataBindings();
} }
public void addSourceFile() { public void addSourceFile() {
...@@ -472,9 +476,27 @@ public class AppWindow { ...@@ -472,9 +476,27 @@ public class AppWindow {
System.err.println(fd.getFilterPath() + " " + file); System.err.println(fd.getFilterPath() + " " + file);
builder.addDataSource(dataSourceLoader.loadDataSource(new File( builder.addDataSource(dataSourceLoader.loadDataSource(new File(
fd.getFilterPath(), file))); fd.getFilterPath(), file)));
// Update binding!
System.err.println("Updating models!");
m_bindingContext.updateModels();
} }
} }
treeViewer.refresh(); 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; ...@@ -4,7 +4,7 @@ import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class DataSourceFile { public class DataSourceFile extends AbstractModelObject {
private File file; private File file;
private List<DataSourceSheet> sheets = new ArrayList<DataSourceSheet>(); private List<DataSourceSheet> sheets = new ArrayList<DataSourceSheet>();
...@@ -14,6 +14,11 @@ public class DataSourceFile { ...@@ -14,6 +14,11 @@ public class DataSourceFile {
public void setFile(File file) { public void setFile(File file) {
this.file = file; this.file = file;
firePropertyChange("fileName", null, file);
}
public String getFileName() {
return this.file==null ? null : this.file.getName();
} }
public List<DataSourceSheet> getSheets() { public List<DataSourceSheet> getSheets() {
...@@ -22,6 +27,7 @@ public class DataSourceFile { ...@@ -22,6 +27,7 @@ public class DataSourceFile {
public void setSheets(List<DataSourceSheet> sheets) { public void setSheets(List<DataSourceSheet> sheets) {
this.sheets = sheets; this.sheets = sheets;
firePropertyChange("sheets", null, sheets);
} }
@Override @Override
......
...@@ -6,7 +6,7 @@ import java.util.HashMap; ...@@ -6,7 +6,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class DataSourceSheet { public class DataSourceSheet extends AbstractModelObject {
private File sourceFile; private File sourceFile;
private String sheetName; private String sheetName;
private List<String> columnNames = new ArrayList<String>(); private List<String> columnNames = new ArrayList<String>();
...@@ -28,6 +28,7 @@ public class DataSourceSheet { ...@@ -28,6 +28,7 @@ public class DataSourceSheet {
public void setSheetName(String sheetName) { public void setSheetName(String sheetName) {
this.sheetName = sheetName; this.sheetName = sheetName;
firePropertyChange("sheetName", null, sheetName);
} }
public List<String> getColumnNames() { public List<String> getColumnNames() {
...@@ -36,6 +37,7 @@ public class DataSourceSheet { ...@@ -36,6 +37,7 @@ public class DataSourceSheet {
public void setColumnNames(List<String> columnNames) { public void setColumnNames(List<String> columnNames) {
this.columnNames = columnNames; this.columnNames = columnNames;
firePropertyChange("columnNames", null, columnNames);
} }
public Map<String, String> getColumnTerms() { public Map<String, String> getColumnTerms() {
...@@ -44,10 +46,13 @@ public class DataSourceSheet { ...@@ -44,10 +46,13 @@ public class DataSourceSheet {
public void setColumnTerms(Map<String, String> columnTerms) { public void setColumnTerms(Map<String, String> columnTerms) {
this.columnTerms = columnTerms; this.columnTerms = columnTerms;
firePropertyChange("columnTerms", null, columnTerms);
} }
public void setHeadersIncluded(boolean headersIncluded) { public void setHeadersIncluded(boolean headersIncluded) {
System.err.println("Set headers included :" + headersIncluded);
this.headersIncluded = headersIncluded; this.headersIncluded = headersIncluded;