1 package org.simantics.modeling.ui.typicals;
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;
20 * @author Tuukka Lehtonen
22 public class SyncCurrentTypicalTemplateToInstances extends AbstractHandler {
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();
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?"))
38 if (!TypicalPropertyTester.isTypicalMasterEditor(session, input.getResource())) {
39 MessageDialog.openInformation(shell, "Not Synchronizing", "Currently active editor is not a typical diagram template editor.");
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;
46 session.markUndoPoint();
47 SyncTypicalTemplatesToInstances req = new SyncTypicalTemplatesToInstances(result.selectedRules, input.getResource()).logging(result.logging);
48 session.syncRequest(req);
50 for(Resource log : req.logs)
51 new OpenPlainTextDocumentAdapter().openEditor(log);
53 } catch (Exception e) {
54 ErrorLogger.defaultLogError(e);