X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Fhandlers%2Fe4%2FSyncActiveModelTypicals.java;h=3cb4ef5a6b7f848dfe52d12e7bc6a004df7f730f;hb=8ded56d0a440f78cbf649b1e59b8a464e8650fdc;hp=882e04f0d20db2dcd5cdbd9eaf1b55d4213d97a9;hpb=7684baeb8bc7963700676af20db6f4a860581e46;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/handlers/e4/SyncActiveModelTypicals.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/handlers/e4/SyncActiveModelTypicals.java index 882e04f0d..3cb4ef5a6 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/handlers/e4/SyncActiveModelTypicals.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/handlers/e4/SyncActiveModelTypicals.java @@ -1,100 +1,100 @@ -package org.simantics.modeling.ui.handlers.e4; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -import javax.inject.Named; - -import org.eclipse.e4.core.di.annotations.Execute; -import org.eclipse.e4.ui.services.IServiceConstants; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.swt.widgets.Shell; -import org.simantics.Simantics; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.Session; -import org.simantics.db.common.request.ObjectsWithType; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.adapter.Instances; -import org.simantics.db.request.Read; -import org.simantics.modeling.ModelingResources; -import org.simantics.modeling.typicals.SyncTypicalTemplatesToInstances; -import org.simantics.modeling.ui.documents.OpenPlainTextDocumentAdapter; -import org.simantics.modeling.ui.typicals.RuleChooserDialog; -import org.simantics.operation.Layer0X; -import org.simantics.simulation.ontology.SimulationResource; -import org.simantics.utils.ui.ErrorLogger; - -/** - * @author Tuukka Lehtonen - */ -public class SyncActiveModelTypicals { - - @Execute - public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell) { - Session session = Simantics.getSession(); - try { - Resource[] activeModelTypicalTemplates = session.syncRequest(new Read() { - @Override - public Resource[] perform(ReadGraph graph) throws DatabaseException { - Layer0X L0X = Layer0X.getInstance(graph); - ModelingResources MOD = ModelingResources.getInstance(graph); - SimulationResource SIMU = SimulationResource.getInstance(graph); - - Collection activeModels = graph.syncRequest(new ObjectsWithType(Simantics.getProjectResource(), L0X.Activates, SIMU.Model)); - Instances query = graph.adapt(MOD.MasterTypicalCompositeType, Instances.class); - - Set result = new HashSet(); - for (Resource activeModel : activeModels) { - Collection typicalComposites = query.find(graph, activeModel); - for (Resource typicalComposite : typicalComposites) { - for (Resource typicalDiagram : graph.getObjects(typicalComposite, MOD.CompositeToDiagram)) { - result.add(typicalDiagram); - } - } - } - return result.toArray(Resource.NONE); - } - }); - - if (activeModelTypicalTemplates.length > 0) { -// StringBuilder msg = new StringBuilder("Are you sure you want to synchronize ") -// .append(activeModelTypicalTemplates.length) -// .append(" typical template"); -// if (activeModelTypicalTemplates.length > 1) -// msg.append("s to all their instances?"); -// else -// msg.append(" to all its instances?"); -// if (!MessageDialog.openConfirm(shell, "Synchronize All Typical Templates with Instances", msg.toString())) -// return null; - - StringBuilder msg = new StringBuilder("Synchronizing ") - .append(activeModelTypicalTemplates.length) - .append(" typical template"); - if (activeModelTypicalTemplates.length > 1) - msg.append("s to all their instances."); - else - msg.append(" to all its instances."); - - RuleChooserDialog.RuleResult result = RuleChooserDialog.choose(shell, msg.toString(), activeModelTypicalTemplates); - if(result == null) return; - - session.markUndoPoint(); - SyncTypicalTemplatesToInstances req = new SyncTypicalTemplatesToInstances(result.selectedRules, activeModelTypicalTemplates).logging(result.logging); - session.syncRequest(req); - if (result.logging) { - for(Resource log : req.logs) - new OpenPlainTextDocumentAdapter().openEditor(log); - } - - } else { - MessageDialog.openInformation(shell, "No Typical Templates", "The currently active model doesn't contain any typical diagram templates."); - } - } catch (Exception e) { - ErrorLogger.defaultLogError(e); - } - return; - } - -} +package org.simantics.modeling.ui.handlers.e4; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import javax.inject.Named; + +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.ui.services.IServiceConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Shell; +import org.simantics.Simantics; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.Instances; +import org.simantics.db.request.Read; +import org.simantics.modeling.ModelingResources; +import org.simantics.modeling.typicals.SyncTypicalTemplatesToInstances; +import org.simantics.modeling.ui.documents.OpenPlainTextDocumentAdapter; +import org.simantics.modeling.ui.typicals.RuleChooserDialog; +import org.simantics.operation.Layer0X; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.utils.ui.ErrorLogger; + +/** + * @author Tuukka Lehtonen + */ +public class SyncActiveModelTypicals { + + @Execute + public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell) { + Session session = Simantics.getSession(); + try { + Resource[] activeModelTypicalTemplates = session.syncRequest(new Read() { + @Override + public Resource[] perform(ReadGraph graph) throws DatabaseException { + Layer0X L0X = Layer0X.getInstance(graph); + ModelingResources MOD = ModelingResources.getInstance(graph); + SimulationResource SIMU = SimulationResource.getInstance(graph); + + Collection activeModels = graph.syncRequest(new ObjectsWithType(Simantics.getProjectResource(), L0X.Activates, SIMU.Model)); + Instances query = graph.adapt(MOD.MasterTypicalCompositeType, Instances.class); + + Set result = new HashSet(); + for (Resource activeModel : activeModels) { + Collection typicalComposites = query.find(graph, activeModel); + for (Resource typicalComposite : typicalComposites) { + for (Resource typicalDiagram : graph.getObjects(typicalComposite, MOD.CompositeToDiagram)) { + result.add(typicalDiagram); + } + } + } + return result.toArray(Resource.NONE); + } + }); + + if (activeModelTypicalTemplates.length > 0) { +// StringBuilder msg = new StringBuilder("Are you sure you want to synchronize ") +// .append(activeModelTypicalTemplates.length) +// .append(" typical template"); +// if (activeModelTypicalTemplates.length > 1) +// msg.append("s to all their instances?"); +// else +// msg.append(" to all its instances?"); +// if (!MessageDialog.openConfirm(shell, "Synchronize All Typical Templates with Instances", msg.toString())) +// return null; + + StringBuilder msg = new StringBuilder("Synchronizing ") + .append(activeModelTypicalTemplates.length) + .append(" typical template"); + if (activeModelTypicalTemplates.length > 1) + msg.append("s to all their instances."); + else + msg.append(" to all its instances."); + + RuleChooserDialog.RuleResult result = RuleChooserDialog.choose(shell, msg.toString(), activeModelTypicalTemplates); + if(result == null) return; + + session.markUndoPoint(); + SyncTypicalTemplatesToInstances req = new SyncTypicalTemplatesToInstances(result.selectedRules, activeModelTypicalTemplates).logging(result.logging); + session.syncRequest(req); + if (result.logging) { + for(Resource log : req.logs) + new OpenPlainTextDocumentAdapter().openEditor(log); + } + + } else { + MessageDialog.openInformation(shell, "No Typical Templates", "The currently active model doesn't contain any typical diagram templates."); + } + } catch (Exception e) { + ErrorLogger.defaultLogError(e); + } + return; + } + +}