X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Ftypicals%2FNewTypicalDiagramInstance.java;h=25fd46e69dd4fb914a18c78b989dcb34feacac10;hp=2bb0f9dfc706cbdd97261c89e2b6ca70f9ba2af8;hb=ffdf83729b496d5afe74c7888075bb17ce1c4bbb;hpb=d1a82fe1414c77b97bec886d6a3ae3c5d926c334 diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/typicals/NewTypicalDiagramInstance.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/typicals/NewTypicalDiagramInstance.java index 2bb0f9dfc..25fd46e69 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/typicals/NewTypicalDiagramInstance.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/typicals/NewTypicalDiagramInstance.java @@ -47,47 +47,44 @@ public class NewTypicalDiagramInstance implements ActionFactory { @Override public Runnable create(Object target_) { - final Resource target = (Resource) target_; - return new Runnable() { - @Override - public void run() { - Job job = new DatabaseJob("Instantiate Typical") { - @Override - protected IStatus run(IProgressMonitor monitor) { - monitor.beginTask("Instantiate Typical...", IProgressMonitor.UNKNOWN); + Resource target = (Resource) target_; + return () -> { + Job job = new DatabaseJob("Instantiate Typical") { + @Override + protected IStatus run(IProgressMonitor monitor) { + monitor.beginTask("Instantiate Typical...", IProgressMonitor.UNKNOWN); - final Session session = Simantics.getSession(); - session.markUndoPoint(); - try { - final AtomicReference model = new AtomicReference(); - Function2 instantiator = session.syncRequest(new UniqueRead>() { - @Override - public Function2 perform(ReadGraph graph) throws DatabaseException { - model.set( graph.sync(new PossibleModel(target)) ); - if (model.get() == null) - throw new CancelTransactionException("Cannot find a model from the input selection. Typical diagram instantiation not possible."); + Session session = Simantics.getSession(); + session.markUndoPoint(); + try { + AtomicReference model = new AtomicReference(); + Function2 instantiator = session.syncRequest(new UniqueRead>() { + @Override + public Function2 perform(ReadGraph graph) throws DatabaseException { + model.set( graph.sync(new PossibleModel(target)) ); + if (model.get() == null) + throw new CancelTransactionException("Cannot find a model from the input selection. Typical diagram instantiation not possible."); - ModelingResources MOD = ModelingResources.getInstance(graph); - Function2 instantiator = graph.getRelatedValue2(model.get(), MOD.StructuralModel_typicalInstantiationFunction); - return instantiator; - } - }); + ModelingResources MOD = ModelingResources.getInstance(graph); + Function2 instantiator = graph.getRelatedValue2(model.get(), MOD.StructuralModel_typicalInstantiationFunction); + return instantiator; + } + }); - instantiator.apply(model.get(), target); + instantiator.apply(model.get(), target); - return Status.OK_STATUS; - } catch (CancelTransactionException e) { - return new Status(IStatus.INFO , Activator.PLUGIN_ID, e.getMessage()); - } catch (DatabaseException e) { - return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); - } finally { - monitor.done(); - } + return Status.OK_STATUS; + } catch (CancelTransactionException e) { + return new Status(IStatus.INFO , Activator.PLUGIN_ID, e.getMessage()); + } catch (DatabaseException e) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); + } finally { + monitor.done(); } - }; - //job.setUser(true); - job.schedule(); - } + } + }; + //job.setUser(true); + job.schedule(); }; }