Commit 0856d8b4 authored by igoshin's avatar igoshin Committed by Matija Obreza
Browse files

Feature #12626 "Save" and "Load" workspace

parent 7aad9140
......@@ -52,15 +52,15 @@
<artifactId>swing2swt</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>
<dependency>
<groupId>
org.eclipse.swt.org.eclipse.swt.cocoa.macosx.x86_64.4.3.swt
</groupId>
</groupId>
<artifactId>org.eclipse.swt.cocoa.macosx.x86_64</artifactId>
<version>4.3</version>
<version>4.3</version>
<scope>provided</scope>
</dependency>
<dependency>
</dependency>
<dependency>
<groupId>net.sf.supercsv</groupId>
<artifactId>super-csv</artifactId>
<version>2.2.0</version>
......@@ -144,7 +144,12 @@
<artifactId>jackson-databind</artifactId>
<version>2.4.1.1</version>
</dependency>
</dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
</dependencies>
<build>
<plugins>
......
......@@ -16,14 +16,6 @@
package org.genesys2.anno.gui;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.log4j.Logger;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeansObservables;
......@@ -35,50 +27,28 @@ import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.*;
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.Transfer;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.MenuAdapter;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.dnd.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Menu;
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.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.widgets.*;
import org.eclipse.wb.swt.SWTResourceManager;
import org.genesys2.anno.model.ColumnDef;
import org.json.JSONException;
import swing2swt.layout.BorderLayout;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.DisposeEvent;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class AppWindow {
private static final Logger _log = Logger.getLogger(AppWindow.class);
......@@ -484,9 +454,64 @@ public class AppWindow {
});
tltmPush.setText("Push");
tltmPush.setImage(pushDataIcon);
ToolItem saveWorkSpace = new ToolItem(toolBar, SWT.NONE);
saveWorkSpace.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
saveWorkSpace();
}
});
saveWorkSpace.setText("Save workspace");
ToolItem loadWorkSpace = new ToolItem(toolBar, SWT.NONE);
loadWorkSpace.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
loadWorkSpace();
}
});
loadWorkSpace.setText("Load workspace");
m_bindingContext = initDataBindings();
}
private void saveWorkSpace() {
FileDialog dialog = new FileDialog(shlGenesysMagic, SWT.SAVE);
dialog.setFilterNames(new String[]{"JSON Format"});
dialog.setFilterExtensions(new String[]{"*.json"});
dialog.setFileName("workspace.json");
String path = dialog.open();
if (path!=null){
try {
builder.saveWorkspace(path);
} catch (JSONException e) {
_log.error(e.getMessage());
} catch (IOException e) {
_log.error(e.getMessage());
}
}
}
private void loadWorkSpace() {
FileDialog dialog = new FileDialog(shlGenesysMagic, SWT.MULTI);
dialog.setFilterNames(new String[]{"JSON Format"});
dialog.setFilterExtensions(new String[]{"*.json"});
String path = dialog.open();
if (path != null) {
try {
builder.loadWorkspace(path);
} catch (FileNotFoundException e) {
_log.error(e.getMessage());
} catch (JSONException e) {
_log.error(e.getMessage());
}
}
treeViewer.refresh();
}
protected void doShutdown() {
_log.info("Shutting down.");
AppConfig.shutdown();
......
......@@ -16,6 +16,13 @@
package org.genesys2.anno.gui;
import org.genesys2.anno.model.Column;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
......@@ -37,4 +44,84 @@ public class DwcaBuilder extends AbstractModelObject {
fileRoots.remove(dataSource);
firePropertyChange("fileRoots", null, this);
}
public void saveWorkspace(String filePath) throws JSONException, IOException {
JSONObject main = new JSONObject();
JSONArray files = new JSONArray();
for (DataSourceFile sourceFile : getFileRoots()) {
String path = sourceFile.getFile().getPath();
JSONObject file = new JSONObject();
JSONArray sheets = new JSONArray();
file.put("path", path);
file.put("sheets", sheets);
files.put(file);
for (DataSourceSheet sourceSheet : sourceFile.getSheets()) {
JSONObject sheet = new JSONObject();
JSONArray columns = new JSONArray();
String name = sourceSheet.getSheetName();
sheet.put("name", name);
sheet.put("columns", columns);
sheets.put(sheet);
for (Column column : sourceSheet.getColumns()) {
columns.put(column.getPreferredName());
}
}
}
main.put("files", files);
main.put("dateCreated", System.currentTimeMillis());
main.put("version", 1);
FileWriter fileWriter = new FileWriter(filePath);
fileWriter.write(main.toString());
fileWriter.flush();
fileWriter.close();
System.out.println(main.toString());
}
public void loadWorkspace(String filePath) throws FileNotFoundException, JSONException {
fileRoots.clear();
FileReader reader = new FileReader(filePath);
JSONTokener tokener = new JSONTokener(reader);
JSONObject root = new JSONObject(tokener);
JSONArray files = root.getJSONArray("files");
for (int i = 0; i < files.length(); i++) {
String path = files.getJSONObject(i).getString("path");
File file = new File(path);
JSONArray sheets = files.getJSONObject(i).getJSONArray("sheets");
DataSourceFile sourceFile = new DataSourceFile();
List<DataSourceSheet> sourceSheetList = new ArrayList<DataSourceSheet>();
for (int j = 0; j < sheets.length(); j++) {
DataSourceSheet sourceSheet = new DataSourceSheet(file);
sourceSheet.setSheetName(sheets.getJSONObject(j).getString("name"));
sourceSheetList.add(sourceSheet);
}
sourceFile.setFile(file);
sourceFile.setSheets(sourceSheetList);
addDataSource(sourceFile);
}
}
}
Markdown is supported
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