Prevent unnecessary read transaction for synch master typical handle
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / handlers / e4 / SyncCurrentTypicalInstanceWithTemplate.java
index 0c9641a27f45275ce221c06b4e58c3d68c071c17..714e72eb6c05b7ee19637ff533bc2f6630c5a3ac 100644 (file)
@@ -10,11 +10,13 @@ import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor;
+import org.simantics.DatabaseJob;
 import org.simantics.Simantics;
 import org.simantics.db.Resource;
 import org.simantics.db.Session;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.modeling.typicals.SyncTypicalTemplatesToInstances;
+import org.simantics.modeling.ui.diagramEditor.DiagramEditor;
 import org.simantics.modeling.ui.documents.OpenPlainTextDocumentAdapter;
 import org.simantics.modeling.ui.property.TypicalPropertyTester;
 import org.simantics.modeling.ui.typicals.RuleChooserDialog;
@@ -39,10 +41,16 @@ public class SyncCurrentTypicalInstanceWithTemplate {
             // TODO: This is not good practice with E4 but an OK fallback for now
             activeEditor = WorkbenchUtils.getActiveEditor();
         }
-        if (activeEditor == null)
+        if (activeEditor == null || (!(activeEditor instanceof DiagramEditor)))
             return false;
-        IResourceEditorInput input = (IResourceEditorInput) activeEditor.getEditorInput();
-        return TypicalPropertyTester.isTypicalInstanceEditor(Simantics.getSession(), input.getResource());
+        if (DatabaseJob.inProgress())
+            return false;
+        if (activeEditor.getEditorInput() instanceof IResourceEditorInput) {
+            IResourceEditorInput input = (IResourceEditorInput) activeEditor.getEditorInput();
+            return TypicalPropertyTester.isTypicalInstanceEditor(Simantics.getSession(), input.getResource());
+        } else {
+            return false;
+        }
     }
     
     @Execute