1 package org.simantics.modeling.ui.actions;
3 import java.io.IOException;
5 import org.eclipse.jface.dialogs.MessageDialog;
6 import org.eclipse.jface.layout.GridDataFactory;
7 import org.eclipse.jface.layout.GridLayoutFactory;
8 import org.eclipse.swt.SWT;
9 import org.eclipse.swt.widgets.Composite;
10 import org.eclipse.swt.widgets.Control;
11 import org.eclipse.swt.widgets.Display;
12 import org.eclipse.swt.widgets.Shell;
13 import org.simantics.db.Resource;
14 import org.simantics.db.exception.DatabaseException;
15 import org.simantics.db.layer0.adapter.ActionFactory;
16 import org.simantics.graph.compiler.CompilationResult;
17 import org.simantics.ltk.Problem;
18 import org.simantics.modeling.CompilePGraphs;
19 import org.simantics.utils.ui.ExceptionUtils;
22 * @author Antti Villberg
24 public class CompilePGraphsAction implements ActionFactory {
27 public Runnable create(Object target) {
28 if (!(target instanceof Resource))
32 CompilePGraphs.compilePGraphs((Resource) target, new CompileUserAgent());
33 } catch (IOException | DatabaseException e) {
34 ExceptionUtils.logAndShowError(e);
39 public static class CompileUserAgent implements CompilePGraphs.UserAgent {
41 public void reportProblems(CompilationResult result) {
42 class ErrorMessageDialog extends MessageDialog {
43 public ErrorMessageDialog(Shell shell) {
45 "Unsatisfied dependencies", null,
46 "The following dependencies were missing. Please import the dependencies and try again.",
47 MessageDialog.ERROR, new String[] { "Continue" }, 0);
51 protected Control createCustomArea(Composite composite) {
52 GridLayoutFactory.fillDefaults().applyTo(composite);
54 org.eclipse.swt.widgets.List list = new org.eclipse.swt.widgets.List(composite, SWT.BORDER | SWT.READ_ONLY);
55 GridDataFactory.fillDefaults().grab(true, true).applyTo(list);
56 for (Problem problem : result.getErrors())
57 list.add(problem.getLocation() + ": " + problem.getDescription() + "\n");
58 for (Problem problem : result.getWarnings())
59 list.add(problem.getLocation() + ": " + problem.getDescription() + "\n");
65 ErrorMessageDialog md = new ErrorMessageDialog(Display.getCurrent().getActiveShell());