]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/typicals/SyncCurrentTypicalInstanceWithTemplate.java
Red background color & tooltip for invalid derived property expression
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / typicals / SyncCurrentTypicalInstanceWithTemplate.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  */
23 public class SyncCurrentTypicalInstanceWithTemplate extends AbstractHandler {
24
25     @Override
26     public Object execute(ExecutionEvent event) throws ExecutionException {
27         Shell shell = HandlerUtil.getActiveShell(event);
28         IEditorPart activeEditor = HandlerUtil.getActiveEditorChecked(event);
29         IResourceEditorInput input = (IResourceEditorInput) activeEditor.getEditorInput();
30         Session session = Simantics.getSession();
31
32 //        if (!MessageDialog
33 //                .openConfirm(shell,
34 //                        "Synchronize Typical Instance With Template",
35 //                        "Are you sure you want to synchronize this typical instance with its template?"))
36 //            return null;
37
38         try {
39             if (!TypicalPropertyTester.isTypicalInstanceEditor(session, input.getResource())) {
40                 MessageDialog.openInformation(shell, "Not Synchronizing", "Currently active editor is not a typical diagram instance editor.");
41                 return null;
42             }
43
44             RuleChooserDialog.RuleResult result = RuleChooserDialog.choose(shell, "Synchronizing typical instance with its template.", new Resource[] { input.getResource() });
45             if(result == null) return null;
46
47             session.markUndoPoint();
48             SyncTypicalTemplatesToInstances req = SyncTypicalTemplatesToInstances.syncSingleInstance(result.selectedRules, input.getResource()).logging(result.logging); 
49             session.syncRequest(req);
50             if (result.logging) {
51                 for(Resource log : req.logs)
52                     new OpenPlainTextDocumentAdapter().openEditor(log);
53             }
54         } catch (Exception e) {
55             ErrorLogger.defaultLogError(e);
56         }
57         return null;
58         
59     }
60
61 }