Commit 7f4c0c0a authored by Matija Obreza's avatar Matija Obreza
Browse files

Drag-n-drop

parent 6a453d96
......@@ -8,7 +8,6 @@ import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.commons.lang3.ArrayUtils;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
......@@ -21,6 +20,12 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.custom.SashForm;
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;
import org.eclipse.swt.events.MenuAdapter;
......@@ -37,8 +42,12 @@ 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;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.wb.swt.SWTResourceManager;
import org.genesys2.anno.parser.CsvDataSourceParser;
import org.genesys2.anno.parser.XlsxDataSourceParser;
......@@ -140,8 +149,10 @@ public class AppWindow {
protected DataSourceLoader dataSourceLoader;
private static Image archiveIcon;
private static Image spreadsheetIcon;
private static Image openPackageIcon;
private Tree filesTree;
private Display display;
private TreeViewer treeViewer;
/**
* Launch the application.
......@@ -188,6 +199,9 @@ public class AppWindow {
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();
......@@ -208,7 +222,7 @@ public class AppWindow {
shlGenesysMagic.setMinimumSize(new Point(100, 22));
shlGenesysMagic.setSize(744, 528);
shlGenesysMagic.setText("Genesys Magic");
shlGenesysMagic.setLayout(new BorderLayout(5, 5));
shlGenesysMagic.setLayout(new BorderLayout(0, 0));
Menu menu = new Menu(shlGenesysMagic, SWT.BAR);
shlGenesysMagic.setMenuBar(menu);
......@@ -248,10 +262,14 @@ public class AppWindow {
MenuItem mntmVersion = new MenuItem(menu_2, SWT.NONE);
mntmVersion.setText("Version...");
SashForm sashForm = new SashForm(shlGenesysMagic, SWT.NONE);
sashForm.setLayoutData(BorderLayout.CENTER);
SashForm sashForm_1 = new SashForm(shlGenesysMagic, SWT.VERTICAL);
sashForm_1.setBackground(SWTResourceManager
.getColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
sashForm_1.setLayoutData(BorderLayout.CENTER);
SashForm sashForm = new SashForm(sashForm_1, SWT.NONE);
final TreeViewer treeViewer = new TreeViewer(sashForm, SWT.BORDER);
treeViewer = new TreeViewer(sashForm, SWT.BORDER);
treeViewer.setColumnProperties(new String[] {});
filesTree = treeViewer.getTree();
filesTree.setLinesVisible(true);
......@@ -266,24 +284,7 @@ public class AppWindow {
mntmAddFile.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
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", "*.*" });
String response = fd.open();
if (response != null) {
for (String file : fd.getFileNames()) {
System.err.println(fd.getFilterPath() + " " + file);
builder.addDataSource(dataSourceLoader
.loadDataSource(new File(fd.getFilterPath(),
file)));
}
}
treeViewer.refresh();
addSourceFile();
}
});
mntmAddFile.setText("Add file...");
......@@ -339,6 +340,8 @@ public class AppWindow {
});
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));
......@@ -353,6 +356,26 @@ public class AppWindow {
TableColumn tblclmnRdfTerm = new TableColumn(table, SWT.NONE);
tblclmnRdfTerm.setWidth(200);
tblclmnRdfTerm.setText("Ontology Term");
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.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;
}
});
sashForm.setWeights(new int[] { 3, 6, 2 });
treeViewer.addDoubleClickListener(new IDoubleClickListener() {
......@@ -418,5 +441,40 @@ 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.setLayoutData(BorderLayout.NORTH);
ToolItem tltmAddFile = new ToolItem(toolBar, SWT.NONE);
tltmAddFile.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
addSourceFile();
}
});
tltmAddFile.setText("Open");
tltmAddFile.setImage(openPackageIcon);
}
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", "*.*" });
String response = fd.open();
if (response != null) {
for (String file : fd.getFileNames()) {
System.err.println(fd.getFilterPath() + " " + file);
builder.addDataSource(dataSourceLoader.loadDataSource(new File(
fd.getFilterPath(), file)));
}
}
treeViewer.refresh();
}
}
......@@ -10,14 +10,24 @@ import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.ScrolledComposite;
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;
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;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
......@@ -29,10 +39,6 @@ import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import swing2swt.layout.BorderLayout;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Combo;
public class SheetDisplay extends Composite {
private static class ContentProvider implements IStructuredContentProvider {
......@@ -102,7 +108,7 @@ public class SheetDisplay extends Composite {
* @param style
*/
public SheetDisplay(Composite parent, int style) {
super(parent, style);
super(parent, SWT.NONE);
setLayout(new BorderLayout(0, 0));
SashForm sashForm = new SashForm(this, SWT.VERTICAL);
......@@ -123,9 +129,9 @@ public class SheetDisplay extends Composite {
scrolledComposite.setExpandVertical(true);
tbtmColumnProperties.setControl(scrolledComposite);
scrolledComposite.setExpandHorizontal(true);
Composite composite = new Composite(scrolledComposite, SWT.NO_BACKGROUND);
Composite composite = new Composite(scrolledComposite,
SWT.NO_BACKGROUND);
composite.setLayout(new GridLayout(3, false));
scrolledComposite.setContent(composite);
scrolledComposite.setMinSize(new Point(10, 200));
......@@ -180,14 +186,45 @@ public class SheetDisplay extends Composite {
txtRdfTerm.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
false, 1, 1));
new Label(composite, SWT.NONE);
Label lblData = new Label(composite, SWT.NONE);
lblData.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblData.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false,
1, 1));
lblData.setText("Data type");
Combo combo = new Combo(composite, SWT.NONE);
combo.setItems(new String[] {"Text (general blah-blah)", "Number", "Date, time, timestamp"});
combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
combo.setItems(new String[] { "Text (general blah-blah)", "Number",
"Date, time, timestamp" });
combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1,
1));
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) {
System.err.println("Do column analysis");
}
});
btnAnalyzeColumnData.setText("Analyze column data");
DropTarget dropTarget = new DropTarget(composite, DND.DROP_MOVE
| DND.DROP_COPY | DND.DROP_DEFAULT | DND.DROP_LINK);
dropTarget.setTransfer(new Transfer[] { TextTransfer.getInstance() });
dropTarget.addDropListener(new DropTargetAdapter() {
@Override
public void drop(DropTargetEvent event) {
System.err.println("Dropped " + event.data);
}
@Override
public void dragEnter(DropTargetEvent event) {
System.err.println("dragenter " + event.detail);
event.detail = DND.DROP_LINK;
}
});
TabItem tbtmSheet = new TabItem(tabFolder, SWT.NONE);
tbtmSheet.setText("Headers");
......@@ -285,9 +322,8 @@ public class SheetDisplay extends Composite {
txtQuoteChar.setText("\"");
txtQuoteChar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
false, 1, 1));
sashForm.setWeights(new int[] {237, 258});
sashForm.setWeights(new int[] { 5, 2 });
tableViewer.setContentProvider(new ContentProvider());
tableViewer.setLabelProvider(new TableLabelProvider());
......@@ -318,10 +354,15 @@ public class SheetDisplay extends Composite {
if (dataSourceSheet.isHeadersIncluded()) {
clone = new ArrayList<Object[]>(rows.size());
int headerRowIndex = dataSourceSheet.getHeaderRowIndex();
headerRow = rows.get(headerRowIndex);
System.err.println("HEADERS: " + ArrayUtils.toString(headerRow));
for (int i = headerRowIndex + 1; i < rows.size(); i++) {
clone.add(rows.get(i));
try {
headerRow = rows.get(headerRowIndex);
System.err
.println("HEADERS: " + ArrayUtils.toString(headerRow));
for (int i = headerRowIndex + 1; i < rows.size(); i++) {
clone.add(rows.get(i));
}
} catch (IndexOutOfBoundsException e) {
// No data
}
}
......
......@@ -13,7 +13,7 @@ public final class SheetTabFactory {
static {
spreadsheetIcon = ImageDescriptor.createFromURL(
SheetTabFactory.class.getResource("/icon/spreadsheet.png"))
SheetTabFactory.class.getResource("/icon/spreadsheet16.png"))
.createImage();
}
......
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