]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/typicals/SyncActiveModelTypicals.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / typicals / SyncActiveModelTypicals.java
index 441702dd564ad375c92d5e851f0977d8ad13db8a..1f1cc7c0fe0df97df603fff429417cef4090cb3e 100644 (file)
-package org.simantics.modeling.ui.typicals;\r
-\r
-import java.util.Collection;\r
-import java.util.HashSet;\r
-import java.util.Set;\r
-\r
-import org.eclipse.core.commands.AbstractHandler;\r
-import org.eclipse.core.commands.ExecutionEvent;\r
-import org.eclipse.core.commands.ExecutionException;\r
-import org.eclipse.jface.dialogs.MessageDialog;\r
-import org.eclipse.swt.widgets.Shell;\r
-import org.eclipse.ui.handlers.HandlerUtil;\r
-import org.simantics.Simantics;\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.ObjectsWithType;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.adapter.Instances;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.modeling.ModelingResources;\r
-import org.simantics.modeling.typicals.SyncTypicalTemplatesToInstances;\r
-import org.simantics.modeling.ui.documents.OpenPlainTextDocumentAdapter;\r
-import org.simantics.operation.Layer0X;\r
-import org.simantics.simulation.ontology.SimulationResource;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class SyncActiveModelTypicals extends AbstractHandler {\r
-\r
-    @Override\r
-    public Object execute(ExecutionEvent event) throws ExecutionException {\r
-        Shell shell = HandlerUtil.getActiveShell(event);\r
-        Session session = Simantics.getSession();\r
-        try {\r
-            Resource[] activeModelTypicalTemplates = session.syncRequest(new Read<Resource[]>() {\r
-                @Override\r
-                public Resource[] perform(ReadGraph graph) throws DatabaseException {\r
-                    Layer0X L0X = Layer0X.getInstance(graph);\r
-                    ModelingResources MOD = ModelingResources.getInstance(graph);\r
-                    SimulationResource SIMU = SimulationResource.getInstance(graph);\r
-\r
-                    Collection<Resource> activeModels = graph.syncRequest(new ObjectsWithType(Simantics.getProjectResource(), L0X.Activates, SIMU.Model));\r
-                    Instances query = graph.adapt(MOD.MasterTypicalCompositeType, Instances.class);\r
-\r
-                    Set<Resource> result = new HashSet<Resource>();\r
-                    for (Resource activeModel : activeModels) {\r
-                        Collection<Resource> typicalComposites = query.find(graph, activeModel);\r
-                        for (Resource typicalComposite : typicalComposites) {\r
-                            for (Resource typicalDiagram : graph.getObjects(typicalComposite, MOD.CompositeToDiagram)) {\r
-                                result.add(typicalDiagram);\r
-                            }\r
-                        }\r
-                    }\r
-                    return result.toArray(Resource.NONE);\r
-                }\r
-            });\r
-\r
-            if (activeModelTypicalTemplates.length > 0) {\r
-//                StringBuilder msg = new StringBuilder("Are you sure you want to synchronize ")\r
-//                .append(activeModelTypicalTemplates.length)\r
-//                .append(" typical template");\r
-//                if (activeModelTypicalTemplates.length > 1)\r
-//                    msg.append("s to all their instances?");\r
-//                else\r
-//                    msg.append(" to all its instances?");\r
-//                if (!MessageDialog.openConfirm(shell, "Synchronize All Typical Templates with Instances", msg.toString()))\r
-//                    return null;\r
-\r
-                StringBuilder msg = new StringBuilder("Synchronizing ")\r
-                .append(activeModelTypicalTemplates.length)\r
-                .append(" typical template");\r
-                if (activeModelTypicalTemplates.length > 1)\r
-                    msg.append("s to all their instances.");\r
-                else\r
-                    msg.append(" to all its instances.");\r
-\r
-                RuleChooserDialog.RuleResult result = RuleChooserDialog.choose(shell, msg.toString(), activeModelTypicalTemplates);\r
-                if(result == null) return null;\r
-\r
-                session.markUndoPoint();\r
-                SyncTypicalTemplatesToInstances req = new SyncTypicalTemplatesToInstances(result.selectedRules, activeModelTypicalTemplates).logging(result.logging); \r
-                session.syncRequest(req);\r
-                if (result.logging) {\r
-                    for(Resource log : req.logs)\r
-                        new OpenPlainTextDocumentAdapter().openEditor(log);\r
-                }\r
-\r
-            } else {\r
-                MessageDialog.openInformation(shell, "No Typical Templates", "The currently active model doesn't contain any typical diagram templates.");\r
-            }\r
-        } catch (Exception e) {\r
-            ErrorLogger.defaultLogError(e);\r
-        }\r
-        return null;\r
-    }\r
-\r
-}\r
+package org.simantics.modeling.ui.typicals;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.handlers.HandlerUtil;
+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.operation.Layer0X;
+import org.simantics.simulation.ontology.SimulationResource;
+import org.simantics.utils.ui.ErrorLogger;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class SyncActiveModelTypicals extends AbstractHandler {
+
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        Shell shell = HandlerUtil.getActiveShell(event);
+        Session session = Simantics.getSession();
+        try {
+            Resource[] activeModelTypicalTemplates = session.syncRequest(new Read<Resource[]>() {
+                @Override
+                public Resource[] perform(ReadGraph graph) throws DatabaseException {
+                    Layer0X L0X = Layer0X.getInstance(graph);
+                    ModelingResources MOD = ModelingResources.getInstance(graph);
+                    SimulationResource SIMU = SimulationResource.getInstance(graph);
+
+                    Collection<Resource> activeModels = graph.syncRequest(new ObjectsWithType(Simantics.getProjectResource(), L0X.Activates, SIMU.Model));
+                    Instances query = graph.adapt(MOD.MasterTypicalCompositeType, Instances.class);
+
+                    Set<Resource> result = new HashSet<Resource>();
+                    for (Resource activeModel : activeModels) {
+                        Collection<Resource> 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 null;
+
+                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 null;
+    }
+
+}