X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Ftypicals%2FSyncCurrentTypicalInstanceWithTemplate.java;fp=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Ftypicals%2FSyncCurrentTypicalInstanceWithTemplate.java;h=df049a6719009e4998bd6d6a36cb0cd25e79db25;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/typicals/SyncCurrentTypicalInstanceWithTemplate.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/typicals/SyncCurrentTypicalInstanceWithTemplate.java new file mode 100644 index 000000000..df049a671 --- /dev/null +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/typicals/SyncCurrentTypicalInstanceWithTemplate.java @@ -0,0 +1,60 @@ +package org.simantics.modeling.ui.typicals; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.Simantics; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.modeling.typicals.SyncTypicalTemplatesToInstances; +import org.simantics.modeling.ui.documents.OpenPlainTextDocumentAdapter; +import org.simantics.modeling.ui.property.TypicalPropertyTester; +import org.simantics.ui.workbench.IResourceEditorInput; +import org.simantics.utils.ui.ErrorLogger; + +/** + * @author Tuukka Lehtonen + * + */ +public class SyncCurrentTypicalInstanceWithTemplate extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + Shell shell = HandlerUtil.getActiveShell(event); + IEditorPart activeEditor = HandlerUtil.getActiveEditorChecked(event); + IResourceEditorInput input = (IResourceEditorInput) activeEditor.getEditorInput(); + Session session = Simantics.getSession(); + +// if (!MessageDialog +// .openConfirm(shell, +// "Synchronize Typical Instance With Template", +// "Are you sure you want to synchronize this typical instance with its template?")) +// return null; + + try { + if (!TypicalPropertyTester.isTypicalInstanceEditor(session, input.getResource())) { + MessageDialog.openInformation(shell, "Not Synchronizing", "Currently active editor is not a typical diagram instance editor."); + return null; + } + + RuleChooserDialog.RuleResult result = RuleChooserDialog.choose(shell, "Synchronizing typical instance with its template.", new Resource[] { input.getResource() }); + if(result == null) return null; + + SyncTypicalTemplatesToInstances req = SyncTypicalTemplatesToInstances.syncSingleInstance(result.selectedRules, input.getResource()).logging(result.logging); + session.syncRequest(req); + if (result.logging) { + for(Resource log : req.logs) + new OpenPlainTextDocumentAdapter().openEditor(log); + } + } catch (Exception e) { + ErrorLogger.defaultLogError(e); + } + return null; + + } + +}