]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.document.ui/src/org/simantics/document/ui/actions/ExportDocumentFile.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.document.ui / src / org / simantics / document / ui / actions / ExportDocumentFile.java
index 090437081ffca668b16b9d64b73dcb457911d04a..4a02837261f0374cdbcbd2ca9633214e742c8077 100644 (file)
@@ -1,85 +1,85 @@
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.document.ui.actions;\r
-\r
-import java.io.File;\r
-\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.swt.widgets.FileDialog;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.adapter.ActionFactory;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.document.DocumentResource;\r
-import org.simantics.graphfile.ontology.GraphFileResource;\r
-import org.simantics.graphfile.util.GraphFileUtil;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.ui.SimanticsUI;\r
-import org.simantics.utils.ui.ExceptionUtils;\r
-\r
-/**\r
- * Action for exporting file based documents.\r
- * \r
- * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
- *\r
- */\r
-public class ExportDocumentFile implements ActionFactory {\r
-\r
-       \r
-       @Override\r
-       public Runnable create(Object target) {\r
-\r
-               if(!(target instanceof Resource))\r
-                       return null;\r
-\r
-               final Resource resource = (Resource)target;\r
-\r
-               return new Runnable() {\r
-                       @Override\r
-                       public void run() {\r
-                               try {\r
-                                       String name = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
-                                               public String perform(ReadGraph graph) throws DatabaseException {\r
-                                                       DocumentResource doc = DocumentResource.getInstance(graph);\r
-                                                       GraphFileResource gf = GraphFileResource.getInstance(graph);\r
-                                                       if (!graph.isInstanceOf(resource, doc.FileDocument))\r
-                                                               return null;\r
-                                                       String resourceName = graph.getPossibleRelatedValue(resource, gf.HasResourceName);\r
-                                                       if (resourceName != null) {\r
-                                                               return resourceName;\r
-                                                       } else {\r
-                                                               Layer0 L0 = Layer0.getInstance(graph);\r
-                                                               return graph.getPossibleRelatedValue(resource, L0.HasName);\r
-                                                       }\r
-                                               };\r
-                                       });\r
-                                       \r
-                                       FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(),SWT.SAVE);\r
-                                       dialog.setFileName(name);\r
-                                       final String filename = dialog.open();\r
-                                       if (filename == null)\r
-                                               return;\r
-                                       exportDocument(resource, filename);\r
-                               } catch (DatabaseException e) {\r
-                                       ExceptionUtils.logAndShowError("Cannot export document.", e);\r
-                               }\r
-\r
-                       }\r
-               };\r
-       }\r
-       \r
-       public static void exportDocument(Resource document, String fileName) throws DatabaseException {\r
-           GraphFileUtil.writeDataToFile(document, new File(fileName));\r
-       }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.document.ui.actions;
+
+import java.io.File;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.FileDialog;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.ActionFactory;
+import org.simantics.db.request.Read;
+import org.simantics.document.DocumentResource;
+import org.simantics.graphfile.ontology.GraphFileResource;
+import org.simantics.graphfile.util.GraphFileUtil;
+import org.simantics.layer0.Layer0;
+import org.simantics.ui.SimanticsUI;
+import org.simantics.utils.ui.ExceptionUtils;
+
+/**
+ * Action for exporting file based documents.
+ * 
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
+ *
+ */
+public class ExportDocumentFile implements ActionFactory {
+
+       
+       @Override
+       public Runnable create(Object target) {
+
+               if(!(target instanceof Resource))
+                       return null;
+
+               final Resource resource = (Resource)target;
+
+               return new Runnable() {
+                       @Override
+                       public void run() {
+                               try {
+                                       String name = SimanticsUI.getSession().syncRequest(new Read<String>() {
+                                               public String perform(ReadGraph graph) throws DatabaseException {
+                                                       DocumentResource doc = DocumentResource.getInstance(graph);
+                                                       GraphFileResource gf = GraphFileResource.getInstance(graph);
+                                                       if (!graph.isInstanceOf(resource, doc.FileDocument))
+                                                               return null;
+                                                       String resourceName = graph.getPossibleRelatedValue(resource, gf.HasResourceName);
+                                                       if (resourceName != null) {
+                                                               return resourceName;
+                                                       } else {
+                                                               Layer0 L0 = Layer0.getInstance(graph);
+                                                               return graph.getPossibleRelatedValue(resource, L0.HasName);
+                                                       }
+                                               };
+                                       });
+                                       
+                                       FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(),SWT.SAVE);
+                                       dialog.setFileName(name);
+                                       final String filename = dialog.open();
+                                       if (filename == null)
+                                               return;
+                                       exportDocument(resource, filename);
+                               } catch (DatabaseException e) {
+                                       ExceptionUtils.logAndShowError("Cannot export document.", e);
+                               }
+
+                       }
+               };
+       }
+       
+       public static void exportDocument(Resource document, String fileName) throws DatabaseException {
+           GraphFileUtil.writeDataToFile(document, new File(fileName));
+       }
+}