-package org.simantics.export.core;\r
-\r
-import java.io.File;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.eclipse.core.runtime.Platform;\r
-import org.eclipse.core.runtime.preferences.ConfigurationScope;\r
-import org.eclipse.jface.viewers.IStructuredSelection;\r
-import org.osgi.service.prefs.Preferences;\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.databoard.Databoard;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.common.request.ReadRequest;\r
-import org.simantics.db.exception.AssumptionException;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.exception.ServiceException;\r
-import org.simantics.db.exception.ValidationException;\r
-import org.simantics.db.layer0.request.ActiveModels;\r
-import org.simantics.db.management.ISessionContext;\r
-import org.simantics.export.core.manager.Content;\r
-import org.simantics.project.IProject;\r
-import org.simantics.project.ProjectKeys;\r
-import org.simantics.utils.ui.AdaptionUtils;\r
-\r
-public class ExportContext {\r
-\r
- // Context data\r
- public ISessionContext sessionCtx;\r
- public Session session;\r
- public String project;\r
- public List<String> activeModels;\r
- \r
- // Other data\r
- /** Selected content */\r
- public List<String> selection;\r
- \r
- public ExportExtensionPoint eep;\r
- public File workarea;\r
- public Preferences store;\r
- public Databoard databoard;\r
- \r
- public static ExportContext create(ISessionContext ctx, final IStructuredSelection selection) throws DatabaseException {\r
- final ExportContext result = new ExportContext();\r
- result.sessionCtx = ctx;\r
- result.session = ctx.getSession();\r
- result.selection = new ArrayList<String>();\r
- result.activeModels = new ArrayList<String>();\r
- result.workarea = Platform.getLocation().toFile();\r
- result.store = ConfigurationScope.INSTANCE.getNode("org.simantics.export.core");\r
- result.databoard = new Databoard();\r
- \r
- result.session.syncRequest(new ReadRequest() {\r
- public void run(ReadGraph graph) throws DatabaseException {\r
-\r
- IProject iproject = result.sessionCtx.getHint( ProjectKeys.KEY_PROJECT );\r
- Resource project = iproject==null?null:iproject.get();\r
- if ( project != null ) {\r
- result.project = graph.getURI(project);\r
- }\r
- \r
- for (Resource activeModel : graph.sync( new ActiveModels( project ) )) {\r
- try { \r
- result.activeModels.add( graph.getURI( activeModel ) );\r
- } catch (AssumptionException e) {\r
- } catch (ValidationException e) {\r
- } catch (ServiceException e) {\r
- }\r
- }\r
-\r
- if ( selection != null ) {\r
- for (Resource r : AdaptionUtils.adaptToCollection(selection, Resource.class)) {\r
- try { \r
- result.selection.add( graph.getURI(r) );\r
- } catch (AssumptionException e) {\r
- } catch (ValidationException e) {\r
- } catch (ServiceException e) {\r
- }\r
- }\r
- }\r
- \r
- }\r
- });\r
- \r
- //IExperiment experiment = ExperimentManager.getActiveExperiment(); \r
-// ISelection selection = HandlerUtil.getCurrentSelection(event);\r
-// ImagesNode images = AdaptionUtils.adaptToSingle(selection, ImagesNode.class);\r
- return result;\r
- }\r
-\r
- /**\r
- * Get preference store for a combination of selections\r
- * @param contents\r
- * @return selections\r
- */\r
- public Preferences store(List<Content> contents)\r
- {\r
- int hash = _hash(contents); \r
- return store.node( "Selection-"+hash ); \r
- }\r
-\r
- public static int _hash(List<Content> contents) {\r
- int hash = 0x234234;\r
- for ( Content c : contents ) {\r
- hash = 13*hash + c.url.hashCode();\r
- hash = 13*hash + c.formatId.hashCode();\r
- }\r
- return hash;\r
- }\r
- \r
-}\r
+package org.simantics.export.core;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.preferences.ConfigurationScope;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.osgi.service.prefs.Preferences;
+import org.simantics.databoard.Bindings;
+import org.simantics.databoard.Databoard;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.common.request.ReadRequest;
+import org.simantics.db.exception.AssumptionException;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.ServiceException;
+import org.simantics.db.exception.ValidationException;
+import org.simantics.db.layer0.request.ActiveModels;
+import org.simantics.db.management.ISessionContext;
+import org.simantics.export.core.manager.Content;
+import org.simantics.project.IProject;
+import org.simantics.project.ProjectKeys;
+import org.simantics.utils.ui.AdaptionUtils;
+
+public class ExportContext {
+
+ // Context data
+ public ISessionContext sessionCtx;
+ public Session session;
+ public String project;
+ public List<String> activeModels;
+
+ // Other data
+ /** Selected content */
+ public List<String> selection;
+
+ public ExportExtensionPoint eep;
+ public File workarea;
+ public Preferences store;
+ public Databoard databoard;
+
+ public static ExportContext create(ISessionContext ctx, final IStructuredSelection selection) throws DatabaseException {
+ final ExportContext result = new ExportContext();
+ result.sessionCtx = ctx;
+ result.session = ctx.getSession();
+ result.selection = new ArrayList<String>();
+ result.activeModels = new ArrayList<String>();
+ result.workarea = Platform.getLocation().toFile();
+ result.store = ConfigurationScope.INSTANCE.getNode("org.simantics.export.core");
+ result.databoard = new Databoard();
+
+ result.session.syncRequest(new ReadRequest() {
+ public void run(ReadGraph graph) throws DatabaseException {
+
+ IProject iproject = result.sessionCtx.getHint( ProjectKeys.KEY_PROJECT );
+ Resource project = iproject==null?null:iproject.get();
+ if ( project != null ) {
+ result.project = graph.getURI(project);
+ }
+
+ for (Resource activeModel : graph.sync( new ActiveModels( project ) )) {
+ try {
+ result.activeModels.add( graph.getURI( activeModel ) );
+ } catch (AssumptionException e) {
+ } catch (ValidationException e) {
+ } catch (ServiceException e) {
+ }
+ }
+
+ if ( selection != null ) {
+ for (Resource r : AdaptionUtils.adaptToCollection(selection, Resource.class)) {
+ try {
+ result.selection.add( graph.getURI(r) );
+ } catch (AssumptionException e) {
+ } catch (ValidationException e) {
+ } catch (ServiceException e) {
+ }
+ }
+ }
+
+ }
+ });
+
+ //IExperiment experiment = ExperimentManager.getActiveExperiment();
+// ISelection selection = HandlerUtil.getCurrentSelection(event);
+// ImagesNode images = AdaptionUtils.adaptToSingle(selection, ImagesNode.class);
+ return result;
+ }
+
+ /**
+ * Get preference store for a combination of selections
+ * @param contents
+ * @return selections
+ */
+ public Preferences store(List<Content> contents)
+ {
+ int hash = _hash(contents);
+ return store.node( "Selection-"+hash );
+ }
+
+ public static int _hash(List<Content> contents) {
+ int hash = 0x234234;
+ for ( Content c : contents ) {
+ hash = 13*hash + c.url.hashCode();
+ hash = 13*hash + c.formatId.hashCode();
+ }
+ return hash;
+ }
+
+}