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