--- /dev/null
+package org.simantics.modeling.ui.typicals;\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.IEditorPart;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.Simantics;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.modeling.typicals.SyncTypicalTemplatesToInstances;\r
+import org.simantics.modeling.ui.documents.OpenPlainTextDocumentAdapter;\r
+import org.simantics.modeling.ui.property.TypicalPropertyTester;\r
+import org.simantics.ui.workbench.IResourceEditorInput;\r
+import org.simantics.utils.ui.ErrorLogger;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class SyncCurrentTypicalTemplateToInstances extends AbstractHandler {\r
+\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+ Shell shell = HandlerUtil.getActiveShell(event);\r
+ IEditorPart activeEditor = HandlerUtil.getActiveEditorChecked(event);\r
+ IResourceEditorInput input = (IResourceEditorInput) activeEditor.getEditorInput();\r
+ Session session = Simantics.getSession();\r
+\r
+// if (!MessageDialog\r
+// .openConfirm(shell,\r
+// "Synchronize Typical Template With Instances",\r
+// "Are you sure you want to synchronize all instances of this typical template with the template?"))\r
+// return null;\r
+\r
+ try {\r
+ if (!TypicalPropertyTester.isTypicalMasterEditor(session, input.getResource())) {\r
+ MessageDialog.openInformation(shell, "Not Synchronizing", "Currently active editor is not a typical diagram template editor.");\r
+ return null;\r
+ }\r
+\r
+ RuleChooserDialog.RuleResult result = RuleChooserDialog.choose(shell, "Synchronizing typical template to all its instances in the currently active model.", new Resource[] { input.getResource() });\r
+ if(result == null) return null;\r
+\r
+ SyncTypicalTemplatesToInstances req = new SyncTypicalTemplatesToInstances(result.selectedRules, input.getResource()).logging(result.logging); \r
+ session.syncRequest(req);\r
+ if (result.logging) {\r
+ for(Resource log : req.logs)\r
+ new OpenPlainTextDocumentAdapter().openEditor(log);\r
+ }\r
+ } catch (Exception e) {\r
+ ErrorLogger.defaultLogError(e);\r
+ }\r
+ return null;\r
+ }\r
+\r
+}\r