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.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("Compile PGraphs") {
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 {
56 public void reportProblems(CompilationResult result) {
57 class ErrorMessageDialog extends MessageDialog {
58 public ErrorMessageDialog(Shell shell) {
60 "Unsatisfied dependencies", null,
61 "The following dependencies were missing. Please import the dependencies and try again.",
62 MessageDialog.ERROR, new String[] { "Continue" }, 0);
66 protected Control createCustomArea(Composite composite) {
67 GridLayoutFactory.fillDefaults().applyTo(composite);
69 org.eclipse.swt.widgets.List list = new org.eclipse.swt.widgets.List(composite, SWT.BORDER | SWT.READ_ONLY);
70 GridDataFactory.fillDefaults().grab(true, true).applyTo(list);
71 for (Problem problem : result.getErrors())
72 list.add(problem.getLocation() + ": " + problem.getDescription() + "\n");
73 for (Problem problem : result.getWarnings())
74 list.add(problem.getLocation() + ": " + problem.getDescription() + "\n");
80 ErrorMessageDialog md = new ErrorMessageDialog(Display.getCurrent().getActiveShell());