X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.export.core%2Fsrc%2Forg%2Fsimantics%2Fexport%2Fcore%2FExportContext.java;h=5c1074ef815bfef569f03bc2fc6b350434dbe7f1;hb=c26409b1caf2f1e560d37c5befd11b442399c3fe;hp=abe5d82a5f48288eea9146626e33fbac84b8cdc2;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.export.core/src/org/simantics/export/core/ExportContext.java b/bundles/org.simantics.export.core/src/org/simantics/export/core/ExportContext.java index abe5d82a5..5c1074ef8 100644 --- a/bundles/org.simantics.export.core/src/org/simantics/export/core/ExportContext.java +++ b/bundles/org.simantics.export.core/src/org/simantics/export/core/ExportContext.java @@ -1,113 +1,113 @@ -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 activeModels; - - // Other data - /** Selected content */ - public List 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(); - result.activeModels = new ArrayList(); - 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 contents) - { - int hash = _hash(contents); - return store.node( "Selection-"+hash ); - } - - public static int _hash(List contents) { - int hash = 0x234234; - for ( Content c : contents ) { - hash = 13*hash + c.url.hashCode(); - hash = 13*hash + c.formatId.hashCode(); - } - return hash; - } - -} +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 activeModels; + + // Other data + /** Selected content */ + public List 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(); + result.activeModels = new ArrayList(); + 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 contents) + { + int hash = _hash(contents); + return store.node( "Selection-"+hash ); + } + + public static int _hash(List contents) { + int hash = 0x234234; + for ( Content c : contents ) { + hash = 13*hash + c.url.hashCode(); + hash = 13*hash + c.formatId.hashCode(); + } + return hash; + } + +}