Skip to content
Browse files

Completed view export and import functionality.

  • Loading branch information...
1 parent c7ef6a2 commit 138639b28b63b7730ddd11840da597fddd6a34e9 @cderoove committed Jan 30, 2013
View
21 ExapusRAP/src/exapus/gui/views/store/StoreView.java
@@ -1,5 +1,10 @@
package exapus.gui.views.store;
+import java.io.File;
+import java.io.FileNotFoundException;
+
+import javax.xml.bind.JAXBException;
+
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
@@ -68,7 +73,7 @@ public String isValid(String newText) {
public void createPartControl(final Composite parent) {
parent.setLayout(new FillLayout());
- listView = new ListViewer(parent);
+ listView = new ListViewer(parent, SWT.SINGLE);
listView.setContentProvider(new StoreListContentProvider());
listView.addDoubleClickListener(this);
listView.setInput(Store.getCurrent());
@@ -166,11 +171,19 @@ public void run() {
fileDialog.setAutoUpload(true);
fileDialog.open();
String[] fileNames = fileDialog.getFileNames();
- for(String fileName : fileNames)
- System.out.println(fileName);
+ for(String fileName : fileNames) {
+ File file = new File(fileName);
+ try {
+ Store.getCurrent().registerViewFromFile(file);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (JAXBException e) {
+ e.printStackTrace();
+ }
+ }
}
};
- loadViewAction.setText("Import view");
+ loadViewAction.setText("Import views");
loadViewAction.setId("exapus.gui.views.store.actions.ImportViewAction");
loadViewAction.setImageDescriptor(getImageDescriptor("import.gif"));
loadViewAction.setEnabled(true);
View
2 ExapusRAP/src/exapus/gui/views/store/ViewDownloadServiceHandler.java
@@ -46,7 +46,7 @@ private static void appendHandlerParameter(StringBuilder url, String viewName) {
public void service() throws IOException, ServletException {
String viewName = RWT.getRequest().getParameter("viewName");
- File xmlFile = Store.getCurrent().xmlForRegisteredView(viewName);
+ File xmlFile = Store.getCurrent().fileForRegisteredView(viewName);
if(xmlFile != null) {
HttpServletResponse response = RWT.getResponse();
response.setContentType( "application/octet-stream" );
View
16 ExapusRAP/src/exapus/model/forest/QName.java
@@ -10,6 +10,7 @@
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlValue;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.dom.IMethodBinding;
@@ -46,10 +47,21 @@ public static QName forMemberBinding(IMethodBinding mb, ITypeBinding tb) {
}
private ArrayList<UqName> components;
-
- @XmlAttribute
+
private String identifier;
+ @XmlValue
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ public void setIdentifier(String id) {
+ components = new ArrayList<UqName>();
+ for (String s : Splitter.on('.').split(id))
+ components.add(new UqName(s));
+ this.identifier = id;
+ }
+
public QName(Iterable<String> i) {
components = new ArrayList<UqName>();
if (!(i.iterator().hasNext()))
View
16 ExapusRAP/src/exapus/model/store/Store.java
@@ -2,11 +2,15 @@
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
+import javax.xml.bind.JAXBException;
+
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -18,6 +22,8 @@
import exapus.model.forest.FactForest;
import exapus.model.view.View;
import exapus.model.view.ViewFactory;
+import exapus.model.view.ViewReader;
+import exapus.model.view.ViewWriter;
public class Store extends Observable {
@@ -133,14 +139,20 @@ public File graphForRegisteredView(String name) {
return getView(name).draw();
}
- public File xmlForRegisteredView(String name) {
+ public File fileForRegisteredView(String name) {
try {
- return getView(name).xml();
+ return getView(name).toFile();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
+
+ public void registerViewFromFile(File file) throws FileNotFoundException, JAXBException {
+ ViewReader reader = new ViewReader();
+ View view = reader.read(new FileInputStream(file));
+ registerView(view);
+ }
// This file should be located in the same dir as eclipse.ini
// I.e., for Mac OS: PATH_TO_THE_ECLPSE_DIR/Eclipse.app/Contents/MacOS/
View
2 ExapusRAP/src/exapus/model/view/View.java
@@ -241,7 +241,7 @@ public static View fromView(View original) {
return duplicate;
}
- public File xml() throws Exception {
+ public File toFile() throws Exception {
ViewWriter viewWriter = new ViewWriter(this);
return viewWriter.writeTemporary();
}
View
20 ExapusRAP/src/exapus/model/view/ViewReader.java
@@ -0,0 +1,20 @@
+package exapus.model.view;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+
+public class ViewReader {
+
+ public View read(InputStream s) throws JAXBException {
+ JAXBContext jaxbContext = JAXBContext.newInstance(View.class);
+ Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
+ View view = (View) jaxbUnmarshaller.unmarshal(s);
+ return view;
+ }
+
+}
View
3 ExapusRAP/src/exapus/model/view/ViewWriter.java
@@ -26,7 +26,8 @@ public void write(OutputStream s) throws JAXBException {
}
public File writeTemporary() throws IOException, JAXBException {
- File xmlFile = File.createTempFile(view.getName(), ".xml");
+ File xmlFile = new File(view.getName() + ".xml");
+ //File xmlFile = File.createTempFile(view.getName(), ".xml");
this.write(new FileOutputStream(xmlFile));
return xmlFile;
}

0 comments on commit 138639b

Please sign in to comment.
Something went wrong with that request. Please try again.