-/*******************************************************************************\r
- * Copyright (c) 2012 Association for Decentralized Information Management in\r
- * 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.modeling.adapters;\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.eclipse.swt.widgets.Shell;\r
-import org.simantics.Simantics;\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.common.primitiverequest.PossibleRelatedValue;\r
-import org.simantics.db.common.request.UniqueRead;\r
-import org.simantics.db.common.utils.Logger;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.adapter.ActionFactory;\r
-import org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest;\r
-import org.simantics.db.layer0.util.TransferableGraphConfiguration2;\r
-import org.simantics.graph.db.TransferableGraphSource;\r
-import org.simantics.graph.db.TransferableGraphs;\r
-import org.simantics.layer0.Layer0;\r
-\r
-public class ExportModelActionFactory implements ActionFactory {\r
-\r
- String format;\r
- String extension;\r
- \r
- public ExportModelActionFactory(String extension, String format) {\r
- this.extension = extension;\r
- this.format = format;\r
- }\r
-\r
- @Override\r
- public Runnable create(Object target_) {\r
- final Resource target = (Resource)target_;\r
- return new Runnable() {\r
- @Override\r
- public void run() {\r
-\r
- Shell shell = Display.getDefault().getActiveShell();\r
- \r
- Session session = Simantics.getSession();\r
-\r
- try {\r
-\r
- final Layer0 L0 = Layer0.getInstance(session);\r
-\r
- final String name = session.syncRequest(new PossibleRelatedValue<String>(target, L0.HasName, Bindings.STRING));\r
-\r
- FileDialog dialog = new FileDialog(shell, SWT.SAVE);\r
- dialog.setFilterExtensions(new String[] { "*." + extension });\r
- dialog.setFileName(name + "." + extension);\r
- String newFileName = dialog.open();\r
- if(newFileName == null) return;\r
-\r
- if(!newFileName.endsWith(extension))\r
- newFileName += "." + extension;\r
-\r
- try (TransferableGraphSource s = session.sync(new ModelTransferableGraphSourceRequest(createConf(session, target)))) {\r
- TransferableGraphs.writeTransferableGraph(session, format, 1, s, new File(newFileName));\r
- }\r
- \r
- } catch (Exception e) {\r
- Logger.defaultLogError(e);\r
- }\r
-\r
- }\r
- };\r
- }\r
-\r
- private TransferableGraphConfiguration2 createConf(Session session, final Resource model) throws DatabaseException {\r
- return session.sync(new UniqueRead<TransferableGraphConfiguration2>() {\r
- @Override\r
- public TransferableGraphConfiguration2 perform(ReadGraph graph) throws DatabaseException {\r
- return new TransferableGraphConfiguration2(graph, model, true, false);\r
- }\r
- });\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 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.modeling.adapters;
+
+import java.io.File;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.simantics.Simantics;
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.common.primitiverequest.PossibleRelatedValue;
+import org.simantics.db.common.request.UniqueRead;
+import org.simantics.db.common.utils.Logger;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.ActionFactory;
+import org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest;
+import org.simantics.db.layer0.util.TransferableGraphConfiguration2;
+import org.simantics.graph.db.TransferableGraphSource;
+import org.simantics.graph.db.TransferableGraphs;
+import org.simantics.layer0.Layer0;
+
+public class ExportModelActionFactory implements ActionFactory {
+
+ String format;
+ String extension;
+
+ public ExportModelActionFactory(String extension, String format) {
+ this.extension = extension;
+ this.format = format;
+ }
+
+ @Override
+ public Runnable create(Object target_) {
+ final Resource target = (Resource)target_;
+ return new Runnable() {
+ @Override
+ public void run() {
+
+ Shell shell = Display.getDefault().getActiveShell();
+
+ Session session = Simantics.getSession();
+
+ try {
+
+ final Layer0 L0 = Layer0.getInstance(session);
+
+ final String name = session.syncRequest(new PossibleRelatedValue<String>(target, L0.HasName, Bindings.STRING));
+
+ FileDialog dialog = new FileDialog(shell, SWT.SAVE);
+ dialog.setFilterExtensions(new String[] { "*." + extension });
+ dialog.setFileName(name + "." + extension);
+ String newFileName = dialog.open();
+ if(newFileName == null) return;
+
+ if(!newFileName.endsWith(extension))
+ newFileName += "." + extension;
+
+ try (TransferableGraphSource s = session.sync(new ModelTransferableGraphSourceRequest(createConf(session, target)))) {
+ TransferableGraphs.writeTransferableGraph(session, format, 1, s, new File(newFileName));
+ }
+
+ } catch (Exception e) {
+ Logger.defaultLogError(e);
+ }
+
+ }
+ };
+ }
+
+ private TransferableGraphConfiguration2 createConf(Session session, final Resource model) throws DatabaseException {
+ return session.sync(new UniqueRead<TransferableGraphConfiguration2>() {
+ @Override
+ public TransferableGraphConfiguration2 perform(ReadGraph graph) throws DatabaseException {
+ return new TransferableGraphConfiguration2(graph, model, true, false);
+ }
+ });
+ }
+
+}