diff options
Diffstat (limited to 'org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src')
9 files changed, 326 insertions, 0 deletions
diff --git a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ProblemServlet.java b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ProblemServlet.java new file mode 100644 index 00000000..5de708f0 --- /dev/null +++ b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ProblemServlet.java | |||
@@ -0,0 +1,36 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.25.0 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.web; | ||
5 | |||
6 | import com.google.inject.Injector; | ||
7 | import javax.servlet.ServletException; | ||
8 | import javax.servlet.annotation.WebServlet; | ||
9 | import org.eclipse.xtext.util.DisposableRegistry; | ||
10 | import org.eclipse.xtext.web.servlet.XtextServlet; | ||
11 | |||
12 | /** | ||
13 | * Deploy this class into a servlet container to enable DSL-specific services. | ||
14 | */ | ||
15 | @WebServlet(name = "XtextServices", urlPatterns = "/xtext-service/*") | ||
16 | public class ProblemServlet extends XtextServlet { | ||
17 | |||
18 | private static final long serialVersionUID = 1L; | ||
19 | |||
20 | DisposableRegistry disposableRegistry; | ||
21 | |||
22 | public void init() throws ServletException { | ||
23 | super.init(); | ||
24 | Injector injector = new ProblemWebSetup().createInjectorAndDoEMFRegistration(); | ||
25 | this.disposableRegistry = injector.getInstance(DisposableRegistry.class); | ||
26 | } | ||
27 | |||
28 | public void destroy() { | ||
29 | if (disposableRegistry != null) { | ||
30 | disposableRegistry.dispose(); | ||
31 | disposableRegistry = null; | ||
32 | } | ||
33 | super.destroy(); | ||
34 | } | ||
35 | |||
36 | } | ||
diff --git a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ProblemWebModule.java b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ProblemWebModule.java new file mode 100644 index 00000000..0eea7f1e --- /dev/null +++ b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ProblemWebModule.java | |||
@@ -0,0 +1,11 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.25.0 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.web; | ||
5 | |||
6 | |||
7 | /** | ||
8 | * Use this class to register additional components to be used within the web application. | ||
9 | */ | ||
10 | public class ProblemWebModule extends AbstractProblemWebModule { | ||
11 | } | ||
diff --git a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ProblemWebSetup.java b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ProblemWebSetup.java new file mode 100644 index 00000000..8d5778af --- /dev/null +++ b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ProblemWebSetup.java | |||
@@ -0,0 +1,23 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.25.0 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.web; | ||
5 | |||
6 | import com.google.inject.Guice; | ||
7 | import com.google.inject.Injector; | ||
8 | import org.eclipse.viatra.solver.language.ProblemRuntimeModule; | ||
9 | import org.eclipse.viatra.solver.language.ProblemStandaloneSetup; | ||
10 | import org.eclipse.viatra.solver.language.ide.ProblemIdeModule; | ||
11 | import org.eclipse.xtext.util.Modules2; | ||
12 | |||
13 | /** | ||
14 | * Initialization support for running Xtext languages in web applications. | ||
15 | */ | ||
16 | public class ProblemWebSetup extends ProblemStandaloneSetup { | ||
17 | |||
18 | @Override | ||
19 | public Injector createInjector() { | ||
20 | return Guice.createInjector(Modules2.mixin(new ProblemRuntimeModule(), new ProblemIdeModule(), new ProblemWebModule())); | ||
21 | } | ||
22 | |||
23 | } | ||
diff --git a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ServerLauncher.java b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ServerLauncher.java new file mode 100644 index 00000000..d25f4ae9 --- /dev/null +++ b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ServerLauncher.java | |||
@@ -0,0 +1,65 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.25.0 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.web; | ||
5 | |||
6 | import java.net.InetSocketAddress; | ||
7 | import org.eclipse.jetty.annotations.AnnotationConfiguration; | ||
8 | import org.eclipse.jetty.server.Server; | ||
9 | import org.eclipse.jetty.util.log.Slf4jLog; | ||
10 | import org.eclipse.jetty.webapp.Configuration; | ||
11 | import org.eclipse.jetty.webapp.MetaInfConfiguration; | ||
12 | import org.eclipse.jetty.webapp.WebAppContext; | ||
13 | import org.eclipse.jetty.webapp.WebInfConfiguration; | ||
14 | import org.eclipse.jetty.webapp.WebXmlConfiguration; | ||
15 | |||
16 | /** | ||
17 | * This program starts an HTTP server for testing the web integration of your DSL. | ||
18 | * Just execute it and point a web browser to http://localhost:8080/ | ||
19 | */ | ||
20 | public class ServerLauncher { | ||
21 | public static void main(String[] args) { | ||
22 | Server server = new Server(new InetSocketAddress("localhost", 1313)); | ||
23 | WebAppContext ctx = new WebAppContext(); | ||
24 | ctx.setResourceBase("src/main/webapp"); | ||
25 | ctx.setWelcomeFiles(new String[] {"index.html"}); | ||
26 | ctx.setContextPath("/"); | ||
27 | ctx.setConfigurations(new Configuration[] { | ||
28 | new AnnotationConfiguration(), | ||
29 | new WebXmlConfiguration(), | ||
30 | new WebInfConfiguration(), | ||
31 | new MetaInfConfiguration() | ||
32 | }); | ||
33 | ctx.setAttribute(WebInfConfiguration.CONTAINER_JAR_PATTERN, | ||
34 | ".*/org\\.eclipse\\.viatra\\.solver\\.language\\.web/.*,.*\\.jar"); | ||
35 | ctx.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false"); | ||
36 | server.setHandler(ctx); | ||
37 | Slf4jLog log = new Slf4jLog(ServerLauncher.class.getName()); | ||
38 | try { | ||
39 | server.start(); | ||
40 | log.info("Server started " + server.getURI() + "..."); | ||
41 | new Thread() { | ||
42 | |||
43 | public void run() { | ||
44 | try { | ||
45 | log.info("Press enter to stop the server..."); | ||
46 | int key = System.in.read(); | ||
47 | if (key != -1) { | ||
48 | server.stop(); | ||
49 | } else { | ||
50 | log.warn( | ||
51 | "Console input is not available. In order to stop the server, you need to cancel process manually."); | ||
52 | } | ||
53 | } catch (Exception e) { | ||
54 | log.warn(e); | ||
55 | } | ||
56 | } | ||
57 | |||
58 | }.start(); | ||
59 | server.join(); | ||
60 | } catch (Exception exception) { | ||
61 | log.warn(exception.getMessage()); | ||
62 | System.exit(1); | ||
63 | } | ||
64 | } | ||
65 | } | ||
diff --git a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/webapp/index.html b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/webapp/index.html new file mode 100644 index 00000000..bf55f237 --- /dev/null +++ b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/webapp/index.html | |||
@@ -0,0 +1,43 @@ | |||
1 | <!DOCTYPE html> | ||
2 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
3 | <meta http-equiv="Content-Language" content="en-us"> | ||
4 | <title>Example Web Editor</title> | ||
5 | <link rel="stylesheet" type="text/css" href="webjars/codemirror/5.41.0/lib/codemirror.css" /> | ||
6 | <link rel="stylesheet" type="text/css" href="webjars/codemirror/5.41.0/addon/hint/show-hint.css" /> | ||
7 | <link rel="stylesheet" type="text/css" href="xtext/2.26.0.M1/xtext-codemirror.css" /> | ||
8 | <link rel="stylesheet" type="text/css" href="style.css" /> | ||
9 | <body> | ||
10 | <div class="container"> | ||
11 | <div class="header"> | ||
12 | <h1>Example Problem Web Editor</h1> | ||
13 | </div> | ||
14 | <div class="content"> | ||
15 | <div class="xtext-editor" | ||
16 | data-editor-xtext-lang="problem" | ||
17 | data-editor-enable-formatting-action="true" | ||
18 | data-editor-send-full-text="false" | ||
19 | ><pre>class Family | ||
20 | contains Person[0..*] members. | ||
21 | |||
22 | class Person | ||
23 | refers Person[0..*] children opposite parent, | ||
24 | refers Person[0..1] parent opposite children. | ||
25 | |||
26 | error loop(Person p) := children+(p, p). | ||
27 | |||
28 | error multipleRoots(Person p, Person q) := | ||
29 | !equals(p, q), !parent(p, _), !parent(q, _). | ||
30 | |||
31 | Family(family). | ||
32 | members(family, anne). | ||
33 | members(family, bob). | ||
34 | members(family, ciri). | ||
35 | children(anne, ciri). | ||
36 | ?children(bob, ciri). | ||
37 | |||
38 | scope Family = 1, Person += 5..10.</pre></div> | ||
39 | </div> | ||
40 | </div> | ||
41 | <script type="text/javascript" src="webjars/requirejs/2.3.6/require.min.js"></script> | ||
42 | <script type="text/javascript" src="script.js"></script> | ||
43 | </body> | ||
diff --git a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/webapp/script.js b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/webapp/script.js new file mode 100644 index 00000000..fcaca4a4 --- /dev/null +++ b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/webapp/script.js | |||
@@ -0,0 +1,20 @@ | |||
1 | var baseUrl = window.location.pathname; | ||
2 | var fileIndex = baseUrl.indexOf("index.html"); | ||
3 | if (fileIndex > 0) | ||
4 | baseUrl = baseUrl.slice(0, fileIndex) | ||
5 | require.config({ | ||
6 | baseUrl: baseUrl, | ||
7 | paths: { | ||
8 | "text": "webjars/requirejs-text/2.26.0.M1/text", | ||
9 | "jquery": "webjars/jquery/3.6.0/jquery.min", | ||
10 | "xtext/xtext-codemirror": "xtext/2.26.0.M1/xtext-codemirror", | ||
11 | }, | ||
12 | packages: [{ | ||
13 | name: "codemirror", | ||
14 | location: "webjars/codemirror/5.41.0", | ||
15 | main: "lib/codemirror" | ||
16 | }] | ||
17 | }); | ||
18 | require(["xtext-resources/generated/mode-problem", "xtext/xtext-codemirror"], function(mode, xtext) { | ||
19 | window.xtextEditor = xtext.createEditor({baseUrl: baseUrl,}); | ||
20 | }); | ||
diff --git a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/webapp/style.css b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/webapp/style.css new file mode 100644 index 00000000..f1551c3d --- /dev/null +++ b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/webapp/style.css | |||
@@ -0,0 +1,91 @@ | |||
1 | body { | ||
2 | width: 100%; | ||
3 | height: 100%; | ||
4 | overflow: hidden; | ||
5 | font: 16px Helvetica,sans-serif; | ||
6 | } | ||
7 | |||
8 | a { | ||
9 | color: #22a; | ||
10 | text-decoration: none; | ||
11 | } | ||
12 | |||
13 | a:hover { | ||
14 | text-decoration: underline; | ||
15 | } | ||
16 | |||
17 | .container { | ||
18 | display: block; | ||
19 | position: absolute; | ||
20 | top: 0; | ||
21 | bottom: 0; | ||
22 | left: 0; | ||
23 | right: 0; | ||
24 | margin: 24px 24px 36px 24px; | ||
25 | } | ||
26 | |||
27 | .header { | ||
28 | display: block; | ||
29 | position: absolute; | ||
30 | top: 0; | ||
31 | left: 0; | ||
32 | right: 0; | ||
33 | padding: 16px; | ||
34 | background: #dbdbdb; | ||
35 | border-radius: 16px; | ||
36 | color: #383838; | ||
37 | } | ||
38 | |||
39 | .header h1 { | ||
40 | font-size: 36px; | ||
41 | margin: 0; | ||
42 | } | ||
43 | |||
44 | .content { | ||
45 | display: block; | ||
46 | position: absolute; | ||
47 | top: 108px; | ||
48 | bottom: 0; | ||
49 | left: 0; | ||
50 | width: 50%; | ||
51 | box-shadow: 0 0 8px rgba(80, 10, 98, .25), 0 10px 24px rgba(80, 10, 98, .35); | ||
52 | border-radius: 16px; | ||
53 | } | ||
54 | |||
55 | .xtext-editor { | ||
56 | display: block; | ||
57 | position: absolute; | ||
58 | top: 16px; | ||
59 | bottom: 16px; | ||
60 | left: 16px; | ||
61 | right: 16px; | ||
62 | border: 1px solid #aaa; | ||
63 | } | ||
64 | |||
65 | .problem-class { | ||
66 | color: #005032; | ||
67 | } | ||
68 | |||
69 | .problem-abstract { | ||
70 | color: #8b8816; | ||
71 | } | ||
72 | |||
73 | .problem-reference, .problem-containment, .problem-predicate { | ||
74 | color: #0000c0; | ||
75 | } | ||
76 | |||
77 | .problem-error { | ||
78 | color: #ab3000; | ||
79 | } | ||
80 | |||
81 | .problem-containment { | ||
82 | font-weight: bold; | ||
83 | } | ||
84 | |||
85 | .problem-parameter, .problem-variable { | ||
86 | color: #6a3e3e; | ||
87 | } | ||
88 | |||
89 | .problem-node { | ||
90 | text-decoration: underline; | ||
91 | } | ||
diff --git a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/webapp/xtext-resources/generated/mode-problem.js b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/webapp/xtext-resources/generated/mode-problem.js new file mode 100644 index 00000000..ab748b03 --- /dev/null +++ b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/webapp/xtext-resources/generated/mode-problem.js | |||
@@ -0,0 +1,23 @@ | |||
1 | define(["codemirror", "codemirror/addon/mode/simple"], function(CodeMirror, SimpleMode) { | ||
2 | var keywords = "abstract|class|contains|error|extends|false|opposite|pred|refers|scope|true|unknown"; | ||
3 | CodeMirror.defineSimpleMode("xtext/problem", { | ||
4 | start: [ | ||
5 | {token: "comment", regex: "\\/\\/.*$"}, | ||
6 | {token: "comment", regex: "\\/\\*", next : "comment"}, | ||
7 | {token: "string", regex: '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'}, | ||
8 | {token: "string", regex: "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"}, | ||
9 | {token: "constant.numeric", regex: "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"}, | ||
10 | {token: "lparen", regex: "[\\[(]"}, | ||
11 | {token: "rparen", regex: "[\\])]"}, | ||
12 | {token: "keyword", regex: "\\b(?:" + keywords + ")\\b"} | ||
13 | ], | ||
14 | comment: [ | ||
15 | {token: "comment", regex: ".*?\\*\\/", next : "start"}, | ||
16 | {token: "comment", regex: ".+"} | ||
17 | ], | ||
18 | meta: { | ||
19 | dontIndentStates: ["comment"], | ||
20 | lineComment: "//" | ||
21 | } | ||
22 | }); | ||
23 | }); | ||
diff --git a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/xtext-gen/org/eclipse/viatra/solver/language/web/AbstractProblemWebModule.java b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/xtext-gen/org/eclipse/viatra/solver/language/web/AbstractProblemWebModule.java new file mode 100644 index 00000000..fefb7da3 --- /dev/null +++ b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/xtext-gen/org/eclipse/viatra/solver/language/web/AbstractProblemWebModule.java | |||
@@ -0,0 +1,14 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.26.0.M1 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.web; | ||
5 | |||
6 | import org.eclipse.xtext.web.server.DefaultWebModule; | ||
7 | |||
8 | /** | ||
9 | * Manual modifications go to {@link ProblemWebModule}. | ||
10 | */ | ||
11 | @SuppressWarnings("all") | ||
12 | public abstract class AbstractProblemWebModule extends DefaultWebModule { | ||
13 | |||
14 | } | ||