]> gerrit.simantics Code Review - simantics/platform.git/blob
931e3f7fac5da25d3031ec0ecec2227cb1ce25be
[simantics/platform.git] /
1 package org.simantics.modeling.ui.typicals;\r
2 \r
3 import org.eclipse.core.commands.AbstractHandler;\r
4 import org.eclipse.core.commands.ExecutionEvent;\r
5 import org.eclipse.core.commands.ExecutionException;\r
6 import org.eclipse.jface.dialogs.MessageDialog;\r
7 import org.eclipse.swt.widgets.Shell;\r
8 import org.eclipse.ui.IEditorPart;\r
9 import org.eclipse.ui.handlers.HandlerUtil;\r
10 import org.simantics.Simantics;\r
11 import org.simantics.db.Resource;\r
12 import org.simantics.db.Session;\r
13 import org.simantics.modeling.typicals.SyncTypicalTemplatesToInstances;\r
14 import org.simantics.modeling.ui.documents.OpenPlainTextDocumentAdapter;\r
15 import org.simantics.modeling.ui.property.TypicalPropertyTester;\r
16 import org.simantics.ui.workbench.IResourceEditorInput;\r
17 import org.simantics.utils.ui.ErrorLogger;\r
18 \r
19 /**\r
20  * @author Tuukka Lehtonen\r
21  */\r
22 public class SyncCurrentTypicalTemplateToInstances extends AbstractHandler {\r
23 \r
24     @Override\r
25     public Object execute(ExecutionEvent event) throws ExecutionException {\r
26         Shell shell = HandlerUtil.getActiveShell(event);\r
27         IEditorPart activeEditor = HandlerUtil.getActiveEditorChecked(event);\r
28         IResourceEditorInput input = (IResourceEditorInput) activeEditor.getEditorInput();\r
29         Session session = Simantics.getSession();\r
30 \r
31 //        if (!MessageDialog\r
32 //                .openConfirm(shell,\r
33 //                        "Synchronize Typical Template With Instances",\r
34 //                        "Are you sure you want to synchronize all instances of this typical template with the template?"))\r
35 //            return null;\r
36 \r
37         try {\r
38             if (!TypicalPropertyTester.isTypicalMasterEditor(session, input.getResource())) {\r
39                 MessageDialog.openInformation(shell, "Not Synchronizing", "Currently active editor is not a typical diagram template editor.");\r
40                 return null;\r
41             }\r
42 \r
43             RuleChooserDialog.RuleResult result = RuleChooserDialog.choose(shell, "Synchronizing typical template to all its instances in the currently active model.", new Resource[] { input.getResource() });\r
44             if(result == null) return null;\r
45 \r
46             SyncTypicalTemplatesToInstances req = new SyncTypicalTemplatesToInstances(result.selectedRules, input.getResource()).logging(result.logging); \r
47             session.syncRequest(req);\r
48             if (result.logging) {\r
49                 for(Resource log : req.logs)\r
50                     new OpenPlainTextDocumentAdapter().openEditor(log);\r
51             }\r
52         } catch (Exception e) {\r
53             ErrorLogger.defaultLogError(e);\r
54         }\r
55         return null;\r
56     }\r
57 \r
58 }\r