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
23 public class SyncCurrentTypicalInstanceWithTemplate extends AbstractHandler {
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();
33 // .openConfirm(shell,
34 // "Synchronize Typical Instance With Template",
35 // "Are you sure you want to synchronize this typical instance with its template?"))
39 if (!TypicalPropertyTester.isTypicalInstanceEditor(session, input.getResource())) {
40 MessageDialog.openInformation(shell, "Not Synchronizing", "Currently active editor is not a typical diagram instance editor.");
44 RuleChooserDialog.RuleResult result = RuleChooserDialog.choose(shell, "Synchronizing typical instance with its template.", new Resource[] { input.getResource() });
45 if(result == null) return null;
47 session.markUndoPoint();
48 SyncTypicalTemplatesToInstances req = SyncTypicalTemplatesToInstances.syncSingleInstance(result.selectedRules, input.getResource()).logging(result.logging);
49 session.syncRequest(req);
51 for(Resource log : req.logs)
52 new OpenPlainTextDocumentAdapter().openEditor(log);
54 } catch (Exception e) {
55 ErrorLogger.defaultLogError(e);