1 package org.simantics.modeling.ui.typicals;
\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
20 * @author Tuukka Lehtonen
\r
22 public class SyncCurrentTypicalTemplateToInstances extends AbstractHandler {
\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
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
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
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
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
52 } catch (Exception e) {
\r
53 ErrorLogger.defaultLogError(e);
\r