Commit 12a73cf3 authored by Matija Obreza's avatar Matija Obreza
Browse files

Show Genesys JSON on dblClick in SheetDisplay

parent 93e64abc
......@@ -8,8 +8,6 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.management.RuntimeErrorException;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
......@@ -158,7 +156,7 @@ public class RowConverter {
return result;
}
private static ObjectNode toJson(Map<String, ?> row) throws GenesysJSONException, JsonGenerationException {
public static ObjectNode toJson(Map<String, ?> row) throws GenesysJSONException, JsonGenerationException {
if (row == null)
return null;
......
......@@ -15,7 +15,8 @@ import org.genesys2.anno.parser.XlsxDataSourceParser;
public class AppConfig {
public static final AppConfig instance = new AppConfig();
private DataSourceLoaderImpl dataSourceLoader;
private ExecutorService executorService=Executors.newFixedThreadPool(5);
private ExecutorService executorService = Executors.newFixedThreadPool(5);
private ColumnDefs columnDefs = new ColumnDefs();
private AppConfig() {
dataSourceLoader = new DataSourceLoaderImpl();
......@@ -34,4 +35,8 @@ public class AppConfig {
public static void shutdown() {
instance.executorService.shutdown();
}
public ColumnDefs getColumnDefs() {
return columnDefs;
}
}
......@@ -84,7 +84,7 @@ 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 ColumnDefs columnDefs = AppConfig.instance.getColumnDefs();
private ExecutorService threadPool = Executors.newFixedThreadPool(4);
private static class ViewerLabelProvider extends LabelProvider {
......
package org.genesys2.anno.gui;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -16,15 +15,12 @@ import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.genesys2.anno.converter.RowConverter;
import org.genesys2.anno.model.ColumnDef;
import com.fasterxml.jackson.core.PrettyPrinter;
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import swing2swt.layout.BorderLayout;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import swing2swt.layout.BorderLayout;
public class PushDialog extends Dialog {
private static final Logger _log = Logger.getLogger(PushDialog.class);
private static final ObjectMapper mapper = new ObjectMapper();
......@@ -112,8 +108,8 @@ public class PushDialog extends Dialog {
@Override
public void run() {
MessageBox mb = new MessageBox(shell);
mb.setMessage(e.getMessage());
mb.setText("Error loading rows");
mb.setMessage(e.getMessage());
mb.open();
}
});
......
......@@ -18,6 +18,7 @@ package org.genesys2.anno.gui;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.eclipse.core.databinding.Binding;
......@@ -28,6 +29,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.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITableLabelProvider;
......@@ -42,6 +45,8 @@ import org.eclipse.swt.dnd.DropTarget;
import org.eclipse.swt.dnd.DropTargetAdapter;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.SelectionAdapter;
......@@ -55,17 +60,19 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.genesys2.anno.converter.RowConverter;
import org.genesys2.anno.model.Column;
import org.genesys2.anno.model.ColumnDef;
import swing2swt.layout.BorderLayout;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import com.fasterxml.jackson.databind.node.ObjectNode;
public class SheetDisplay extends Composite {
private static final Logger _log = Logger.getLogger(SheetDisplay.class);
......@@ -160,6 +167,18 @@ public class SheetDisplay extends Composite {
sashForm.setLayoutData(BorderLayout.CENTER);
tableViewer = new TableViewer(sashForm, SWT.BORDER);
tableViewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent arg0) {
System.err.println("Dblclick on!!");
IStructuredSelection selection = (IStructuredSelection) arg0.getSelection();
Object row = selection.getFirstElement();
if (row == null)
return;
// System.err.println(row.getClass() + " " +
// ArrayUtils.toString(row));
doDoubleClickOnRow((Object[]) row);
}
});
table = tableViewer.getTable();
table.setLinesVisible(true);
table.setHeaderVisible(true);
......@@ -184,72 +203,72 @@ public class SheetDisplay extends Composite {
composite.setLayout(new GridLayout(4, false));
scrolledComposite.setContent(composite);
composite.pack();
Label lblThisIsA = new Label(composite, SWT.NONE);
lblThisIsA.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblThisIsA.setText("Column name");
txtColumnName = new Text(composite, SWT.BORDER);
txtColumnName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lblColumnDescription = new Label(composite, SWT.NONE);
lblColumnDescription.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
lblColumnDescription.setText("Column description");
txtColumnDescription = new Text(composite, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
GridData gd_txtColumnDescription = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
gd_txtColumnDescription.minimumHeight = 30;
gd_txtColumnDescription.heightHint = 40;
txtColumnDescription.setLayoutData(gd_txtColumnDescription);
Label lblThisIsA = new Label(composite, SWT.NONE);
lblThisIsA.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblThisIsA.setText("Column name");
txtColumnName = new Text(composite, SWT.BORDER);
txtColumnName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lblColumnDescription = new Label(composite, SWT.NONE);
lblColumnDescription.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
lblColumnDescription.setText("Column description");
txtColumnDescription = new Text(composite, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
GridData gd_txtColumnDescription = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
gd_txtColumnDescription.minimumHeight = 30;
gd_txtColumnDescription.heightHint = 40;
txtColumnDescription.setLayoutData(gd_txtColumnDescription);
new Label(composite, SWT.NONE);
btnContainsMultipleValues = new Button(composite, SWT.CHECK);
btnContainsMultipleValues.setText("Contains multiple values, separated");
btnContainsMultipleValues = new Button(composite, SWT.CHECK);
btnContainsMultipleValues.setText("Contains multiple values, separated");
Label lblSeparator_1 = new Label(composite, SWT.NONE);
lblSeparator_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblSeparator_1.setText("Separator");
txtSeparator = new Text(composite, SWT.BORDER);
txtSeparator.setText(";");
GridData gd_txtSeparator = new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1);
gd_txtSeparator.widthHint = 30;
gd_txtSeparator.minimumWidth = 30;
txtSeparator.setLayoutData(gd_txtSeparator);
Label lblRegexpPattern = new Label(composite, SWT.RIGHT);
lblRegexpPattern.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblRegexpPattern.setText("RegExp pattern");
txtRegExp = new Text(composite, SWT.BORDER);
txtRegExp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lblNewLabel = new Label(composite, SWT.NONE);
lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblNewLabel.setText("RDF Term");
txtRdfTerm = new Text(composite, SWT.BORDER);
txtRdfTerm.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lblData = new Label(composite, SWT.NONE);
lblData.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblData.setText("Data type");
Combo comboDataType = new Combo(composite, SWT.NONE);
comboDataType.setItems(new String[] { "Text (general blah-blah)", "Number", "Date, time, timestamp" });
comboDataType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
new Label(composite, SWT.NONE);
new Label(composite, SWT.NONE);
new Label(composite, SWT.NONE);
Button btnAnalyzeColumnData = new Button(composite, SWT.NONE);
btnAnalyzeColumnData.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
_log.debug("Do column analysis");
}
});
btnAnalyzeColumnData.setText("Analyze column data");
Label lblRegexpPattern = new Label(composite, SWT.RIGHT);
lblRegexpPattern.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblRegexpPattern.setText("RegExp pattern");
txtRegExp = new Text(composite, SWT.BORDER);
txtRegExp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lblNewLabel = new Label(composite, SWT.NONE);
lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblNewLabel.setText("RDF Term");
txtRdfTerm = new Text(composite, SWT.BORDER);
txtRdfTerm.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lblData = new Label(composite, SWT.NONE);
lblData.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblData.setText("Data type");
Combo comboDataType = new Combo(composite, SWT.NONE);
comboDataType.setItems(new String[] { "Text (general blah-blah)", "Number", "Date, time, timestamp" });
comboDataType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
new Label(composite, SWT.NONE);
new Label(composite, SWT.NONE);
new Label(composite, SWT.NONE);
Button btnAnalyzeColumnData = new Button(composite, SWT.NONE);
btnAnalyzeColumnData.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
_log.debug("Do column analysis");
}
});
btnAnalyzeColumnData.setText("Analyze column data");
new Label(composite, SWT.NONE);
new Label(composite, SWT.NONE);
......@@ -299,7 +318,7 @@ public class SheetDisplay extends Composite {
txtHeaderRowIndex.setEnabled(false);
txtHeaderRowIndex.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
new Label(compoHeaders, SWT.NONE);
Button btnReload2 = new Button(compoHeaders, SWT.NONE);
btnReload2.addSelectionListener(new SelectionAdapter() {
@Override
......@@ -375,7 +394,7 @@ public class SheetDisplay extends Composite {
}
});
btnReload.setText("Reload");
sashForm.setWeights(new int[] {274, 254});
sashForm.setWeights(new int[] { 274, 254 });
tableViewer.setContentProvider(new ContentProvider());
tableViewer.setLabelProvider(new TableLabelProvider());
......@@ -403,6 +422,27 @@ public class SheetDisplay extends Composite {
});
}
protected void doDoubleClickOnRow(Object[] row) {
DataSourceSheet dataSourceSheet = getDataSourceSheet();
if (dataSourceSheet == null)
return;
Map<String, ?> map1 = RowConverter.toMap(dataSourceSheet, row, AppConfig.instance.getColumnDefs());
try {
final ObjectNode jsonObject = RowConverter.toJson(map1);
getDisplay().syncExec(new Runnable() {
@Override
public void run() {
MessageBox mb = new MessageBox(getShell());
mb.setMessage(jsonObject.toString());
mb.setText("Genesys JSON Preview");
mb.open();
}
});
} catch (Exception e) {
_log.error(e.getMessage(), e);
}
}
protected void doDataReload() {
_log.info("Force reload of CSV data sheet");
DataSourceSheet currentSheet = dsw.getDataSourceSheet();
......@@ -470,6 +510,7 @@ public class SheetDisplay extends Composite {
bindingContext.bindValue(observeTextTxtCsvQuoteCharObserveWidget, dataSourceSheetsheetQuoteCharDswObserveValue, null, null);
}
protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
......
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