1 package org.simantics.modeling.ui.actions;
3 import java.io.IOException;
5 import org.eclipse.core.runtime.IProgressMonitor;
6 import org.eclipse.core.runtime.IStatus;
7 import org.eclipse.core.runtime.Status;
8 import org.eclipse.core.runtime.jobs.Job;
9 import org.eclipse.jface.dialogs.MessageDialog;
10 import org.eclipse.jface.layout.GridDataFactory;
11 import org.eclipse.jface.layout.GridLayoutFactory;
12 import org.eclipse.swt.SWT;
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.swt.widgets.Control;
15 import org.eclipse.swt.widgets.Display;
16 import org.eclipse.swt.widgets.Shell;
17 import org.simantics.db.Resource;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.db.layer0.adapter.ActionFactory;
20 import org.simantics.graph.compiler.CompilationResult;
21 import org.simantics.graph.compiler.internal.ltk.Problem;
22 import org.simantics.modeling.CompilePGraphs;
23 import org.simantics.modeling.ui.Activator;
24 import org.simantics.utils.ui.ExceptionUtils;
27 * @author Antti Villberg
29 public class CompilePGraphsAction implements ActionFactory {
32 public Runnable create(Object target) {
33 if (!(target instanceof Resource))
36 Job job = new Job(Messages.CompilePGraphsAction_CompilePGraphs) {
38 protected IStatus run(IProgressMonitor monitor) {
40 CompilePGraphs.compilePGraphs((Resource) target, new CompileUserAgent(), monitor);
41 return Status.OK_STATUS;
42 } catch (IOException | DatabaseException e) {
43 ExceptionUtils.logAndShowError(e);
44 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage());
54 public static class CompileUserAgent implements CompilePGraphs.UserAgent {
57 public void reportProblems(CompilationResult result) {
58 Runnable runnable = () -> {
59 class ErrorMessageDialog extends MessageDialog {
60 public ErrorMessageDialog(Shell shell) {
62 Messages.CompilePGraphsAction_ProblemsinOntologyDefinitionFile, null,
63 Messages.CompilePGraphsAction_FollowingIssuesFound,
64 MessageDialog.ERROR, new String[] { Messages.CompilePGraphsAction_Continue }, 0);
68 protected Control createCustomArea(Composite composite) {
69 GridLayoutFactory.fillDefaults().applyTo(composite);
71 org.eclipse.swt.widgets.List list = new org.eclipse.swt.widgets.List(composite, SWT.BORDER | SWT.READ_ONLY);
72 GridDataFactory.fillDefaults().grab(true, true).applyTo(list);
73 for (Problem problem : result.getErrors())
74 list.add(problem.getLocation() + ": " + problem.getDescription() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
75 for (Problem problem : result.getWarnings())
76 list.add(problem.getLocation() + ": " + problem.getDescription() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
82 ErrorMessageDialog md = new ErrorMessageDialog(Display.getCurrent().getActiveShell());
86 Display display = Display.getCurrent();
88 display = Display.getDefault();
89 display.asyncExec(runnable);