Commit 2b388132 authored by Matija Obreza's avatar Matija Obreza
Browse files

MCPD terms

parent a7a8037a
......@@ -72,13 +72,17 @@ import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.wb.swt.SWTResourceManager;
import org.genesys2.anno.model.ColumnDef;
import swing2swt.layout.BorderLayout;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.jface.viewers.TableViewerColumn;
public class AppWindow {
private static final Logger _log = Logger.getLogger(AppWindow.class);
private DataBindingContext m_bindingContext;
private DwcaBuilder builder = new DwcaBuilder();
private ColumnDefs columnDefs = new ColumnDefs();
private ExecutorService threadPool = Executors.newFixedThreadPool(4);
private static class ViewerLabelProvider extends LabelProvider {
......@@ -359,6 +363,16 @@ public class AppWindow {
DragSource dragSource = new DragSource(table, DND.DROP_LINK);
dragSource.setTransfer(new Transfer[] { LocalSelectionTransfer.getTransfer() });
TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn tblclmnPreferredName = tableViewerColumn.getColumn();
tblclmnPreferredName.setWidth(100);
tblclmnPreferredName.setText("Preferred name");
TableViewerColumn tableViewerColumn_1 = new TableViewerColumn(tableViewer, SWT.NONE);
TableColumn tblclmnRdfTerm = tableViewerColumn_1.getColumn();
tblclmnRdfTerm.setWidth(100);
tblclmnRdfTerm.setText("RDF Term");
dragSource.addDragListener(new DragSourceAdapter() {
@Override
public void dragStart(DragSourceEvent event) {
......@@ -456,14 +470,13 @@ public class AppWindow {
DataBindingContext bindingContext = new DataBindingContext();
//
ObservableListContentProvider listContentProvider = new ObservableListContentProvider();
IObservableMap observeMap = BeansObservables.observeMap(listContentProvider.getKnownElements(), DataSourceFile.class, "fileName");
IObservableMap[] observeMap = BeansObservables.observeMaps(listContentProvider.getKnownElements(), ColumnDef.class, new String[] { "preferredName", "rdfTerm" });
tableViewer.setLabelProvider(new ObservableMapLabelProvider(observeMap));
tableViewer.setContentProvider(listContentProvider);
//
IObservableList fileRootsBuilderObserveList = BeansObservables.observeList(Realm.getDefault(), builder, "fileRoots");
IObservableList fileRootsBuilderObserveList = BeansObservables.observeList(Realm.getDefault(), columnDefs, "columnDefs");
tableViewer.setInput(fileRootsBuilderObserveList);
//
return bindingContext;
}
}
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.anno.gui;
import java.util.ArrayList;
import java.util.List;
import org.genesys2.anno.model.ColumnDef;
import org.genesys2.anno.predefined.MCPD;
public class ColumnDefs extends AbstractModelObject {
private List<ColumnDef> columnDefs = new ArrayList<ColumnDef>();
public ColumnDefs() {
columnDefs = new MCPD().getColumnDefs();
}
public List<ColumnDef> getColumnDefs() {
return columnDefs;
}
public void addDataSource() {
firePropertyChange("columnDefs", null, this);
}
public void removeDataSource() {
firePropertyChange("columnDefs", null, this);
}
}
......@@ -28,8 +28,8 @@ import org.eclipse.core.databinding.observable.IChangeListener;
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.IStructuredSelection;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
......@@ -61,6 +61,7 @@ import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.genesys2.anno.model.Column;
import org.genesys2.anno.model.ColumnDef;
import swing2swt.layout.BorderLayout;
......@@ -233,9 +234,16 @@ public class SheetDisplay extends Composite {
@Override
public void drop(DropTargetEvent event) {
if (LocalSelectionTransfer.getTransfer().isSupportedType(event.currentDataType)) {
ISelection sel = LocalSelectionTransfer.getTransfer().getSelection();
IStructuredSelection sel = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
_log.debug("Dropped " + sel);
_log.debug("Dropped class " + sel.getClass());
Object dragged = sel.getFirstElement();
Column selColumn = dsw.getSelectedColumn();
if (dragged instanceof ColumnDef && selColumn != null) {
ColumnDef columnDef = ((ColumnDef) dragged);
_log.info("Setting RDF term to " + columnDef.getRdfTerm());
selColumn.setRdfTerm(columnDef.getRdfTerm());
}
}
}
......@@ -280,66 +288,66 @@ public class SheetDisplay extends Composite {
});
// CSV
// if (dsw.getDataSourceSheet().isCsv()) {
TabItem tbtmCSV = new TabItem(tabFolder, SWT.NONE);
tbtmCSV.setText("CSV");
ScrolledComposite scrolledComposite2 = new ScrolledComposite(tabFolder, SWT.V_SCROLL);
scrolledComposite2.setExpandVertical(true);
scrolledComposite2.setExpandHorizontal(true);
tbtmCSV.setControl(scrolledComposite2);
compoCSV = new Composite(scrolledComposite2, SWT.NO_BACKGROUND);
scrolledComposite2.setContent(compoCSV);
compoCSV.setLayout(new GridLayout(2, false));
Label lblCharacterSet = new Label(compoCSV, SWT.NONE);
lblCharacterSet.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblCharacterSet.setText("Character set");
comboCharset = new Combo(compoCSV, SWT.NONE);
comboCharset.setItems(new String[] { "UTF-8", "US-ASCII", "ISO-8859-1", "UTF-16", "windows-1250" });
comboCharset.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
comboCharset.select(0);
Label lblSeparator = new Label(compoCSV, SWT.NONE);
lblSeparator.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblSeparator.setText("Separator");
comboCsvSeparator = new Combo(compoCSV, SWT.READ_ONLY);
comboCsvSeparator.setItems(new String[] { ",", "\t" });
comboCsvSeparator.select(0);
comboCsvSeparator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblQuoteCharacter = new Label(compoCSV, SWT.NONE);
lblQuoteCharacter.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblQuoteCharacter.setText("Quote character");
txtCsvQuoteChar = new Combo(compoCSV, SWT.READ_ONLY);
txtCsvQuoteChar.setItems(new String[] { "\"", "'" });
txtCsvQuoteChar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
txtCsvQuoteChar.select(0);
new Label(compoCSV, SWT.NONE);
btnReload = new Button(compoCSV, SWT.NONE);
btnReload.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
_log.info("Force reload of CSV data sheet");
DataSourceSheet currentSheet = dsw.getDataSourceSheet();
try {
final List<Object[]> rows = dataSourceLoader.loadRows(currentSheet, 100);
currentSheet.updateData(rows);
} catch (Throwable t) {
_log.error("Error reloading file", t);
}
// if (dsw.getDataSourceSheet().isCsv()) {
TabItem tbtmCSV = new TabItem(tabFolder, SWT.NONE);
tbtmCSV.setText("CSV");
ScrolledComposite scrolledComposite2 = new ScrolledComposite(tabFolder, SWT.V_SCROLL);
scrolledComposite2.setExpandVertical(true);
scrolledComposite2.setExpandHorizontal(true);
tbtmCSV.setControl(scrolledComposite2);
compoCSV = new Composite(scrolledComposite2, SWT.NO_BACKGROUND);
scrolledComposite2.setContent(compoCSV);
compoCSV.setLayout(new GridLayout(2, false));
Label lblCharacterSet = new Label(compoCSV, SWT.NONE);
lblCharacterSet.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblCharacterSet.setText("Character set");
comboCharset = new Combo(compoCSV, SWT.NONE);
comboCharset.setItems(new String[] { "UTF-8", "US-ASCII", "ISO-8859-1", "UTF-16", "windows-1250" });
comboCharset.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
comboCharset.select(0);
Label lblSeparator = new Label(compoCSV, SWT.NONE);
lblSeparator.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblSeparator.setText("Separator");
comboCsvSeparator = new Combo(compoCSV, SWT.READ_ONLY);
comboCsvSeparator.setItems(new String[] { ",", "\t" });
comboCsvSeparator.select(0);
comboCsvSeparator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblQuoteCharacter = new Label(compoCSV, SWT.NONE);
lblQuoteCharacter.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblQuoteCharacter.setText("Quote character");
txtCsvQuoteChar = new Combo(compoCSV, SWT.READ_ONLY);
txtCsvQuoteChar.setItems(new String[] { "\"", "'" });
txtCsvQuoteChar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
txtCsvQuoteChar.select(0);
new Label(compoCSV, SWT.NONE);
btnReload = new Button(compoCSV, SWT.NONE);
btnReload.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
_log.info("Force reload of CSV data sheet");
DataSourceSheet currentSheet = dsw.getDataSourceSheet();
try {
final List<Object[]> rows = dataSourceLoader.loadRows(currentSheet, 100);
currentSheet.updateData(rows);
} catch (Throwable t) {
_log.error("Error reloading file", t);
}
});
btnReload.setText("Reload");
sashForm.setWeights(new int[] {269, 226});
}
});
btnReload.setText("Reload");
sashForm.setWeights(new int[] { 269, 226 });
tableViewer.setContentProvider(new ContentProvider());
tableViewer.setLabelProvider(new TableLabelProvider());
......@@ -419,6 +427,7 @@ public class SheetDisplay extends Composite {
bindingContext.bindValue(observeTextTxtCsvQuoteCharObserveWidget, dataSourceSheetsheetQuoteCharDswObserveValue, null, null);
}
protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
......
......@@ -16,9 +16,6 @@
package org.genesys2.anno.model;
import java.util.HashSet;
import java.util.Set;
import org.genesys2.anno.gui.AbstractModelObject;
public class Column extends AbstractModelObject {
......@@ -29,7 +26,6 @@ public class Column extends AbstractModelObject {
private boolean unique;
private boolean multiple;
private String pattern;
private Set<ColumnValidator> validators = new HashSet<ColumnValidator>();
public Column() {
}
......@@ -96,13 +92,6 @@ public class Column extends AbstractModelObject {
firePropertyChange("multiple", null, this.multiple);
}
public Set<ColumnValidator> getValidators() {
return validators;
}
public void setValidators(Set<ColumnValidator> validators) {
this.validators = validators;
}
public String getPattern() {
return pattern;
......
package org.genesys2.anno.model;
import java.util.HashSet;
import java.util.Set;
import org.genesys2.anno.gui.AbstractModelObject;
public class ColumnDef extends AbstractModelObject {
private String preferredName;
private ColumnDataType dataType;
private boolean unique;
private String rdfTerm;
private Set<ColumnValidator> validators = new HashSet<ColumnValidator>();
public ColumnDef() {
}
public ColumnDef(String preferredName, ColumnDataType dataType, boolean unique, String rdfTerm) {
this.preferredName = preferredName;
this.dataType = dataType;
this.unique = unique;
this.rdfTerm = rdfTerm;
}
public String getPreferredName() {
return preferredName;
}
public void setPreferredName(String preferredName) {
this.preferredName = preferredName;
}
public ColumnDataType getDataType() {
return dataType;
}
public void setDataType(ColumnDataType dataType) {
this.dataType = dataType;
}
public boolean isUnique() {
return unique;
}
public void setUnique(boolean unique) {
this.unique = unique;
}
public String getRdfTerm() {
return rdfTerm;
}
public void setRdfTerm(String rdfTerm) {
this.rdfTerm = rdfTerm;
}
public Set<ColumnValidator> getValidators() {
return validators;
}
public void setValidators(Set<ColumnValidator> validators) {
this.validators = validators;
}
}
......@@ -16,42 +16,37 @@
package org.genesys2.anno.predefined;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.List;
import org.genesys2.anno.model.Column;
import org.genesys2.anno.model.ColumnDataType;
import org.genesys2.anno.model.RdfMCPD;
import org.genesys2.anno.model.ColumnDef;
import org.genesys2.anno.validator.FaoWiewsInstCodeValidator;
public class MCPD {
private final Set<Column> columns;
private final List<ColumnDef> columnDefs;
public MCPD() {
Set<Column> columns = new HashSet<Column>();
Column instCode = new Column("INSTCODE", ColumnDataType.TEXT, false,
false, RdfMCPD.INSTCODE);
List<ColumnDef> columns = new ArrayList<ColumnDef>();
ColumnDef instCode = new ColumnDef("INSTCODE", ColumnDataType.TEXT, false, RdfMCPD.INSTCODE);
instCode.getValidators().add(new FaoWiewsInstCodeValidator());
columns.add(instCode);
Column acceNumb = new Column("ACCENUMB", ColumnDataType.TEXT, false,
true, RdfMCPD.ACCENUMB);
ColumnDef acceNumb = new ColumnDef("ACCENUMB", ColumnDataType.TEXT, true, RdfMCPD.ACCENUMB);
columns.add(acceNumb);
Column genus = new Column("GENUS", ColumnDataType.TEXT, false, false,
RdfMCPD.GENUS);
ColumnDef genus = new ColumnDef("GENUS", ColumnDataType.TEXT, false, RdfMCPD.GENUS);
columns.add(genus);
Column species = new Column("SPECIES", ColumnDataType.TEXT, false,
false, RdfMCPD.SPECIES);
ColumnDef species = new ColumnDef("SPECIES", ColumnDataType.TEXT, false, RdfMCPD.SPECIES);
columns.add(species);
this.columns = Collections.unmodifiableSet(columns);
this.columnDefs = Collections.unmodifiableList(columns);
}
public final Set<Column> getColumns() {
return columns;
public final List<ColumnDef> getColumnDefs() {
return columnDefs;
}
}
......@@ -14,7 +14,7 @@
* limitations under the License.
**/
package org.genesys2.anno.model;
package org.genesys2.anno.predefined;
public class RdfMCPD {
......
......@@ -18,8 +18,8 @@ package org.genesys2.anno.validator;
import org.apache.commons.lang3.StringUtils;
import org.genesys2.anno.model.Column;
import org.genesys2.anno.model.RdfMCPD;
import org.genesys2.anno.model.RowValidator;
import org.genesys2.anno.predefined.RdfMCPD;
public class GenusSpeciesValidator implements RowValidator {
......
Supports Markdown
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