]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/CompilePGraphsAction.java
(refs #7561) Allow extra parameters to the application of type alias
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / actions / CompilePGraphsAction.java
1 package org.simantics.modeling.ui.actions;
2
3 import java.io.IOException;
4
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;
20
21 /**
22  * @author Antti Villberg
23  */
24 public class CompilePGraphsAction implements ActionFactory {
25
26     @Override
27     public Runnable create(Object target) {
28         if (!(target instanceof Resource))
29             return null;
30         return () -> {
31             try {
32                 CompilePGraphs.compilePGraphs((Resource) target, new CompileUserAgent());
33             } catch (IOException | DatabaseException e) {
34                 ExceptionUtils.logAndShowError(e);
35             }
36         };
37     }
38
39     public static class CompileUserAgent implements CompilePGraphs.UserAgent {
40         @Override
41         public void reportProblems(CompilationResult result) {
42             class ErrorMessageDialog extends MessageDialog {
43                 public ErrorMessageDialog(Shell shell) {
44                     super(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);
48                 }
49
50                 @Override
51                 protected Control createCustomArea(Composite composite) {
52                     GridLayoutFactory.fillDefaults().applyTo(composite);
53
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");
60
61                     return composite;
62                 }
63             }
64
65             ErrorMessageDialog md = new ErrorMessageDialog(Display.getCurrent().getActiveShell());
66             md.open();
67         }
68     }
69
70 }