Commit a7a8037a authored by Matija Obreza's avatar Matija Obreza
Browse files

CSV options as dropdowns, reload button

parent b1351cd6
package org.genesys2.anno.gui;
import org.genesys2.anno.parser.CsvDataSourceParser;
import org.genesys2.anno.parser.XlsxDataSourceParser;
/**
* App config with services
*
* @author matijaobreza
*
*/
public class AppConfig {
public static final AppConfig instance = new AppConfig();
private DataSourceLoaderImpl dataSourceLoader;
private AppConfig() {
dataSourceLoader = new DataSourceLoaderImpl();
dataSourceLoader.registerParser(new XlsxDataSourceParser());
dataSourceLoader.registerParser(new CsvDataSourceParser());
}
public DataSourceLoaderImpl getDataSourceLoader() {
return dataSourceLoader;
}
}
......@@ -72,8 +72,6 @@ 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.parser.CsvDataSourceParser;
import org.genesys2.anno.parser.XlsxDataSourceParser;
import swing2swt.layout.BorderLayout;
......@@ -115,8 +113,7 @@ public class AppWindow {
}
public Object[] getElements(Object inputElement) {
_log.debug("getElements " + inputElement + " "
+ inputElement.getClass());
_log.debug("getElements " + inputElement + " " + inputElement.getClass());
if (inputElement instanceof DwcaBuilder) {
return ((DwcaBuilder) inputElement).getFileRoots().toArray();
}
......@@ -124,15 +121,13 @@ public class AppWindow {
return ((DataSourceFile) inputElement).getSheets().toArray();
}
if (inputElement instanceof DataSourceSheet) {
return new Object[] { ((DataSourceSheet) inputElement)
.getSheetName() };
return new Object[] { ((DataSourceSheet) inputElement).getSheetName() };
}
return getChildren(inputElement);
}
public Object[] getChildren(Object parentElement) {
_log.debug("getChildren " + parentElement + " "
+ parentElement.getClass());
_log.debug("getChildren " + parentElement + " " + parentElement.getClass());
if (parentElement instanceof DwcaBuilder) {
return ((DwcaBuilder) parentElement).getFileRoots().toArray();
......@@ -151,8 +146,7 @@ public class AppWindow {
}
public boolean hasChildren(Object element) {
_log.debug("hasChildren " + element + " "
+ element.getClass());
_log.debug("hasChildren " + element + " " + element.getClass());
if (element instanceof DwcaBuilder) {
return ((DwcaBuilder) element).getFileRoots().size() > 0;
......@@ -171,7 +165,7 @@ public class AppWindow {
protected Shell shlGenesysMagic;
private MenuItem mntmQuit;
protected DataSourceLoader dataSourceLoader;
protected DataSourceLoader dataSourceLoader = AppConfig.instance.getDataSourceLoader();
private static Image archiveIcon;
private static Image spreadsheetIcon;
private static Image openPackageIcon;
......@@ -205,13 +199,11 @@ public class AppWindow {
*/
public void open() {
this.display = Display.getDefault();
fakeSpring();
loadImages();
createContents();
shlGenesysMagic.open();
shlGenesysMagic.layout();
while (!shlGenesysMagic.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
......@@ -222,21 +214,10 @@ public class AppWindow {
threadPool.shutdown();
}
private void fakeSpring() {
dataSourceLoader = new DataSourceLoaderImpl();
dataSourceLoader.registerParser(new XlsxDataSourceParser());
dataSourceLoader.registerParser(new CsvDataSourceParser());
}
private void loadImages() {
AppWindow.archiveIcon = ImageDescriptor.createFromURL(
this.getClass().getResource("/icon/archive.png")).createImage();
AppWindow.openPackageIcon = ImageDescriptor.createFromURL(
this.getClass().getResource("/icon/openpackage.png"))
.createImage();
AppWindow.spreadsheetIcon = ImageDescriptor.createFromURL(
this.getClass().getResource("/icon/spreadsheet.png"))
.createImage();
AppWindow.archiveIcon = ImageDescriptor.createFromURL(this.getClass().getResource("/icon/archive.png")).createImage();
AppWindow.openPackageIcon = ImageDescriptor.createFromURL(this.getClass().getResource("/icon/openpackage.png")).createImage();
AppWindow.spreadsheetIcon = ImageDescriptor.createFromURL(this.getClass().getResource("/icon/spreadsheet.png")).createImage();
}
public static boolean isMac() {
......@@ -295,8 +276,7 @@ public class AppWindow {
mntmVersion.setText("Version...");
SashForm sashForm_1 = new SashForm(shlGenesysMagic, SWT.VERTICAL);
sashForm_1.setBackground(SWTResourceManager
.getColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
sashForm_1.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
sashForm_1.setLayoutData(BorderLayout.CENTER);
SashForm sashForm = new SashForm(sashForm_1, SWT.NONE);
......@@ -325,8 +305,7 @@ public class AppWindow {
mntmRemoveFile.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
for (Iterator<?> iterator = ((IStructuredSelection) treeViewer
.getSelection()).iterator(); iterator.hasNext();) {
for (Iterator<?> iterator = ((IStructuredSelection) treeViewer.getSelection()).iterator(); iterator.hasNext();) {
Object selectedObject = iterator.next();
_log.debug("Remove Sel " + selectedObject);
......@@ -345,9 +324,7 @@ public class AppWindow {
@Override
public void menuShown(MenuEvent e) {
boolean enabled = false;
for (Iterator<?> iterator = ((IStructuredSelection) treeViewer
.getSelection()).iterator(); !enabled
&& iterator.hasNext();) {
for (Iterator<?> iterator = ((IStructuredSelection) treeViewer.getSelection()).iterator(); !enabled && iterator.hasNext();) {
Object selectedObject = iterator.next();
_log.debug("Sel " + selectedObject);
......@@ -367,16 +344,13 @@ public class AppWindow {
public void controlResized(ControlEvent e) {
// Pack to get minimum size
trclmnDataSource.pack();
trclmnDataSource.setWidth(Math.max(trclmnDataSource.getWidth(),
filesTree.getClientArea().width));
trclmnDataSource.setWidth(Math.max(trclmnDataSource.getWidth(), filesTree.getClientArea().width));
}
});
final CTabFolder tabFolder = new CTabFolder(sashForm, SWT.NONE);
tabFolder.setBackground(SWTResourceManager
.getColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
tabFolder.setSelectionBackground(Display.getCurrent().getSystemColor(
SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
tabFolder.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
tabFolder.setSelectionBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
tableViewer = new TableViewer(sashForm, SWT.BORDER | SWT.FULL_SELECTION);
table = tableViewer.getTable();
......@@ -397,8 +371,7 @@ public class AppWindow {
treeViewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent e) {
IStructuredSelection thisSelection = (IStructuredSelection) e
.getSelection();
IStructuredSelection thisSelection = (IStructuredSelection) e.getSelection();
Object selectedNode = thisSelection.getFirstElement();
if (selectedNode instanceof DataSourceSheet) {
......@@ -408,8 +381,7 @@ public class AppWindow {
for (Control c : tabFolder.getTabList()) {
_log.debug("Looking at " + c);
if (c instanceof SheetDisplay) {
if (selectedNode == ((SheetDisplay) c)
.getDataSourceSheet()) {
if (selectedNode == ((SheetDisplay) c).getDataSourceSheet()) {
tabFolder.setSelection(i);
return;
}
......@@ -417,8 +389,7 @@ public class AppWindow {
}
}
CTabItem newSheetTab = SheetTabFactory.createComposite(
tabFolder, currentSheet);
CTabItem newSheetTab = SheetTabFactory.createComposite(tabFolder, currentSheet);
// Load stuff
threadPool.execute(new Runnable() {
......@@ -426,8 +397,7 @@ public class AppWindow {
@Override
public void run() {
try {
final List<Object[]> rows = dataSourceLoader
.loadRows(currentSheet, 100);
final List<Object[]> rows = dataSourceLoader.loadRows(currentSheet, 100);
currentSheet.updateData(rows);
} catch (UnsupportedDataFormatException e) {
......@@ -448,8 +418,7 @@ public class AppWindow {
sashForm_1.setWeights(new int[] { 4 });
ToolBar toolBar = new ToolBar(shlGenesysMagic, SWT.FLAT);
toolBar.setBackground(SWTResourceManager
.getColor(SWT.COLOR_WIDGET_BACKGROUND));
toolBar.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_BACKGROUND));
toolBar.setLayoutData(BorderLayout.NORTH);
ToolItem tltmAddFile = new ToolItem(toolBar, SWT.NONE);
......@@ -466,18 +435,15 @@ public class AppWindow {
public void addSourceFile() {
FileDialog fd = new FileDialog(shlGenesysMagic, SWT.MULTI);
fd.setFilterNames(new String[] { "Supported source files",
"Excel files", "CSV files", "All files" });
fd.setFilterExtensions(new String[] { "*.xlsx;*.xls;*.csv;*.tab",
"*.xlsx;*.xls", "*.csv;*.tab", "*.*" });
fd.setFilterNames(new String[] { "Supported source files", "Excel files", "CSV files", "All files" });
fd.setFilterExtensions(new String[] { "*.xlsx;*.xls;*.csv;*.tab", "*.xlsx;*.xls", "*.csv;*.tab", "*.*" });
String response = fd.open();
if (response != null) {
for (String file : fd.getFileNames()) {
_log.debug(fd.getFilterPath() + " " + file);
builder.addDataSource(dataSourceLoader.loadDataSource(new File(
fd.getFilterPath(), file)));
builder.addDataSource(dataSourceLoader.loadDataSource(new File(fd.getFilterPath(), file)));
// Update binding!
_log.debug("Updating models!");
m_bindingContext.updateModels();
......@@ -485,6 +451,7 @@ public class AppWindow {
}
treeViewer.refresh();
}
protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
......@@ -496,8 +463,7 @@ public class AppWindow {
IObservableList fileRootsBuilderObserveList = BeansObservables.observeList(Realm.getDefault(), builder, "fileRoots");
tableViewer.setInput(fileRootsBuilderObserveList);
//
return bindingContext;
}
}
......@@ -47,7 +47,6 @@ import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
......@@ -68,6 +67,7 @@ import swing2swt.layout.BorderLayout;
public class SheetDisplay extends Composite {
private static final Logger _log = Logger.getLogger(SheetDisplay.class);
private DataBindingContext m_bindingContext;
protected DataSourceLoader dataSourceLoader = AppConfig.instance.getDataSourceLoader();
private static class ContentProvider implements IStructuredContentProvider {
public Object[] getElements(Object inputElement) {
......@@ -108,8 +108,8 @@ public class SheetDisplay extends Composite {
private DSW dsw = new DSW();
private TableViewer tableViewer;
private Text txtHeaderRowIndex;
private Text txtCsvQuoteChar;
private Text txtCsvSeparator;
private Combo txtCsvQuoteChar;
private Combo comboCsvSeparator;
private Button chkbxContainsHeaders;
private TabFolder tabFolder;
private Text txtColumnDescription;
......@@ -166,13 +166,13 @@ public class SheetDisplay extends Composite {
ScrolledComposite scrolledComposite = new ScrolledComposite(tabFolder, SWT.V_SCROLL);
scrolledComposite.setExpandVertical(true);
tbtmColumnProperties.setControl(scrolledComposite);
scrolledComposite.setExpandHorizontal(true);
tbtmColumnProperties.setControl(scrolledComposite);
Composite composite = new Composite(scrolledComposite, SWT.NO_BACKGROUND);
Composite composite = new Composite(scrolledComposite, SWT.V_SCROLL | SWT.NO_BACKGROUND);
composite.setLayout(new GridLayout(3, false));
scrolledComposite.setContent(composite);
scrolledComposite.setMinSize(new Point(10, 200));
composite.pack();
new Label(composite, SWT.NONE);
Label lblThisIsA = new Label(composite, SWT.NONE);
......@@ -287,12 +287,11 @@ public class SheetDisplay extends Composite {
ScrolledComposite scrolledComposite2 = new ScrolledComposite(tabFolder, SWT.V_SCROLL);
scrolledComposite2.setExpandVertical(true);
tbtmCSV.setControl(scrolledComposite2);
scrolledComposite2.setExpandHorizontal(true);
tbtmCSV.setControl(scrolledComposite2);
compoCSV = new Composite(scrolledComposite2, SWT.NONE);
compoCSV = new Composite(scrolledComposite2, SWT.NO_BACKGROUND);
scrolledComposite2.setContent(compoCSV);
scrolledComposite2.setMinSize(new Point(10, 200));
compoCSV.setLayout(new GridLayout(2, false));
Label lblCharacterSet = new Label(compoCSV, SWT.NONE);
......@@ -308,17 +307,20 @@ public class SheetDisplay extends Composite {
lblSeparator.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblSeparator.setText("Separator");
txtCsvSeparator = new Text(compoCSV, SWT.BORDER);
txtCsvSeparator.setText(",");
txtCsvSeparator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
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 Text(compoCSV, SWT.BORDER);
txtCsvQuoteChar.setText("\"");
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);
......@@ -326,12 +328,18 @@ public class SheetDisplay extends Composite {
@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[] { 5, 2 });
sashForm.setWeights(new int[] {269, 226});
tableViewer.setContentProvider(new ContentProvider());
tableViewer.setLabelProvider(new TableLabelProvider());
......@@ -402,11 +410,11 @@ public class SheetDisplay extends Composite {
IObservableValue csvDataSourceSheetcharsetDswObserveValue = BeanProperties.value("csvDataSourceSheet.charset").observe(dsw);
bindingContext.bindValue(observeSelectionComboCharsetObserveWidget, csvDataSourceSheetcharsetDswObserveValue, null, null);
//
IObservableValue observeTextTxtCsvSeparatorObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtCsvSeparator);
IObservableValue observeTextTxtCsvSeparatorObserveWidget = WidgetProperties.selection().observe(comboCsvSeparator);
IObservableValue dataSourceSheetsheetDelimiterDswObserveValue = BeanProperties.value("csvDataSourceSheet.delimiterChar").observe(dsw);
bindingContext.bindValue(observeTextTxtCsvSeparatorObserveWidget, dataSourceSheetsheetDelimiterDswObserveValue, null, null);
//
IObservableValue observeTextTxtCsvQuoteCharObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtCsvQuoteChar);
IObservableValue observeTextTxtCsvQuoteCharObserveWidget = WidgetProperties.selection().observe(txtCsvQuoteChar);
IObservableValue dataSourceSheetsheetQuoteCharDswObserveValue = BeanProperties.value("csvDataSourceSheet.quoteChar").observe(dsw);
bindingContext.bindValue(observeTextTxtCsvQuoteCharObserveWidget, dataSourceSheetsheetQuoteCharDswObserveValue, null, null);
......
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