diff options
Diffstat (limited to 'Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner/application')
3 files changed, 201 insertions, 7 deletions
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner/application/ui/execute/ExecuteScriptHandler.java b/Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner/application/ui/execute/ExecuteScriptHandler.java index 43d22ab3..380410d0 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner/application/ui/execute/ExecuteScriptHandler.java +++ b/Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner/application/ui/execute/ExecuteScriptHandler.java | |||
@@ -8,21 +8,15 @@ import org.eclipse.core.commands.ExecutionException; | |||
8 | import org.eclipse.core.commands.IHandler; | 8 | import org.eclipse.core.commands.IHandler; |
9 | import org.eclipse.core.resources.IFile; | 9 | import org.eclipse.core.resources.IFile; |
10 | import org.eclipse.emf.common.util.URI; | 10 | import org.eclipse.emf.common.util.URI; |
11 | import org.eclipse.emf.ecore.EObject; | ||
12 | import org.eclipse.emf.ecore.resource.Resource; | ||
13 | import org.eclipse.emf.ecore.resource.ResourceSet; | ||
14 | import org.eclipse.emf.ecore.resource.URIConverter; | ||
15 | import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; | ||
16 | import org.eclipse.jface.viewers.ISelection; | 11 | import org.eclipse.jface.viewers.ISelection; |
17 | import org.eclipse.jface.viewers.StructuredSelection; | 12 | import org.eclipse.jface.viewers.StructuredSelection; |
18 | import org.eclipse.ui.handlers.HandlerUtil; | 13 | import org.eclipse.ui.handlers.HandlerUtil; |
19 | 14 | ||
20 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigurationScript; | ||
21 | import hu.bme.mit.inf.dslreasoner.application.execution.ScriptExecutor; | 15 | import hu.bme.mit.inf.dslreasoner.application.execution.ScriptExecutor; |
22 | 16 | ||
23 | public class ExecuteScriptHandler extends AbstractHandler implements IHandler { | 17 | public class ExecuteScriptHandler extends AbstractHandler implements IHandler { |
24 | 18 | ||
25 | ScriptExecutor scriptExecutor = new ScriptExecutor(); | 19 | ScriptExecutor scriptExecutor = new ScriptExecutor(RuntimeConsoleBasedScriptConsole.FACTORY); |
26 | 20 | ||
27 | @Override | 21 | @Override |
28 | public Object execute(ExecutionEvent event) throws ExecutionException { | 22 | public Object execute(ExecutionEvent event) throws ExecutionException { |
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner/application/ui/execute/RuntimeConsoleBasedScriptConsole.xtend b/Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner/application/ui/execute/RuntimeConsoleBasedScriptConsole.xtend new file mode 100644 index 00000000..d344ffba --- /dev/null +++ b/Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner/application/ui/execute/RuntimeConsoleBasedScriptConsole.xtend | |||
@@ -0,0 +1,172 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.ui.execute | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.application.execution.ScriptConsole | ||
4 | import hu.bme.mit.inf.dslreasoner.application.execution.ScriptConsoleDecorator | ||
5 | import java.util.concurrent.CompletableFuture | ||
6 | import org.eclipse.emf.common.util.URI | ||
7 | import org.eclipse.jface.text.BadLocationException | ||
8 | import org.eclipse.jface.text.DocumentEvent | ||
9 | import org.eclipse.jface.text.IDocumentListener | ||
10 | import org.eclipse.swt.graphics.Color | ||
11 | import org.eclipse.ui.console.ConsolePlugin | ||
12 | import org.eclipse.ui.console.MessageConsole | ||
13 | import org.eclipse.ui.console.MessageConsoleStream | ||
14 | |||
15 | class RuntimeConsoleBasedScriptConsole extends ScriptConsole { | ||
16 | /** | ||
17 | * Console is identified with the name of this class. | ||
18 | */ | ||
19 | static val consoleID = ScriptConsole.name | ||
20 | |||
21 | val MessageConsole runtimeConsole | ||
22 | |||
23 | new(boolean cleanFiles, URI messageConsoleURI, URI errorConsoleURI, URI statisticsConsoleURI) { | ||
24 | super(!hasConsolePlugin, cleanFiles, messageConsoleURI, errorConsoleURI, statisticsConsoleURI) | ||
25 | runtimeConsole = prepareRuntimeConsole | ||
26 | writeErrorMessagesDuringInitialisation() | ||
27 | } | ||
28 | |||
29 | override writeMessage(CharSequence message, String separator, ScriptConsoleDecorator[] decorators) { | ||
30 | super.writeMessage(message, separator, decorators) | ||
31 | if (runtimeConsole !== null) { | ||
32 | writeToRuntimeConsole(message, separator, decorators) | ||
33 | } | ||
34 | } | ||
35 | |||
36 | override writeMessage(String message) { | ||
37 | super.writeMessage(message) | ||
38 | if (runtimeConsole !== null) { | ||
39 | writeToRuntimeConsole(message) | ||
40 | } | ||
41 | } | ||
42 | |||
43 | override writeError(CharSequence message, String separator, ScriptConsoleDecorator[] decorators) { | ||
44 | super.writeError(message, separator, decorators) | ||
45 | if (runtimeConsole !== null) { | ||
46 | writeToRuntimeConsole(message, separator, decorators) | ||
47 | } | ||
48 | } | ||
49 | |||
50 | override writeError(String message) { | ||
51 | super.writeError(message) | ||
52 | if (runtimeConsole !== null) { | ||
53 | writeToRuntimeConsole(message) | ||
54 | } | ||
55 | } | ||
56 | |||
57 | private def MessageConsole prepareRuntimeConsole() { | ||
58 | val plugin = ConsolePlugin.getDefault(); | ||
59 | if (plugin === null) { | ||
60 | return null | ||
61 | } else { | ||
62 | val conMan = plugin.getConsoleManager(); | ||
63 | val existingConsoles = conMan.getConsoles(); | ||
64 | val existingConsolesWithID = existingConsoles.filter[it.name.equals(consoleID)] | ||
65 | if (existingConsolesWithID.empty) { | ||
66 | val MessageConsole res = new MessageConsole(consoleID, null) | ||
67 | conMan.addConsoles(#[res]); | ||
68 | |||
69 | return res | ||
70 | } else { | ||
71 | return existingConsolesWithID.head as MessageConsole | ||
72 | } | ||
73 | } | ||
74 | } | ||
75 | |||
76 | private def writeToRuntimeConsole(CharSequence message) { | ||
77 | // 1. reveal the console view | ||
78 | ConsolePlugin.getDefault().getConsoleManager().showConsoleView(this.runtimeConsole); | ||
79 | val stream = this.runtimeConsole.newMessageStream | ||
80 | stream.println(message.toString) | ||
81 | stream.close | ||
82 | } | ||
83 | |||
84 | private def writeToRuntimeConsole(CharSequence message, String separator, ScriptConsoleDecorator[] decorators) { | ||
85 | val messageString = message.toString | ||
86 | // 0. split the message | ||
87 | val separatedMessage = if (messageString.startsWith(separator)) { | ||
88 | #[""] + messageString.split(separator, -1) | ||
89 | } else { | ||
90 | messageString.split(separator, -1).toList | ||
91 | } | ||
92 | if (separatedMessage.size - 1 !== decorators.size) { | ||
93 | throw new IllegalArgumentException | ||
94 | } | ||
95 | |||
96 | // 1. reveal the console view | ||
97 | ConsolePlugin.getDefault().getConsoleManager().showConsoleView(this.runtimeConsole); | ||
98 | val stream = this.runtimeConsole.newMessageStream | ||
99 | |||
100 | // 2. print the segments of the view | ||
101 | for (i : 0 ..< decorators.size) { | ||
102 | stream.print(separatedMessage.get(i)) | ||
103 | writeDecoratedTextToRuntimeConsole(decorators.get(i), stream) | ||
104 | |||
105 | } | ||
106 | // 2.1 write the last segment of | ||
107 | stream.println(separatedMessage.last) | ||
108 | |||
109 | // stream.println(message.toString) | ||
110 | stream.close | ||
111 | } | ||
112 | |||
113 | private def writeDecoratedTextToRuntimeConsole(ScriptConsoleDecorator message, MessageConsoleStream stream) { | ||
114 | val originalBackgroundColor = this.runtimeConsole.background | ||
115 | var Color newColor = null; | ||
116 | |||
117 | val text = '''[«message.text»]''' | ||
118 | if (message.red >= 0 && message.green >= 0 && message.blue >= 0) { | ||
119 | newColor = new Color(originalBackgroundColor.device, message.red, message.green, message.blue) | ||
120 | this.runtimeConsole.setBackground(newColor) | ||
121 | } | ||
122 | stream.flush | ||
123 | val CompletableFuture<Boolean> finished = new CompletableFuture<Boolean> | ||
124 | val listener = new IDocumentListener() { | ||
125 | override documentAboutToBeChanged(DocumentEvent event) {} | ||
126 | |||
127 | override documentChanged(DocumentEvent event) { | ||
128 | // println('''ftext="«event.fText»", message="«message.text»" endswith=«event.fText.endsWith(message.text)»''') | ||
129 | if (event.fText.endsWith(text)) { | ||
130 | val from = event.fDocument.length - text.length + 1 | ||
131 | val length = message.text.length | ||
132 | // println('''from: «from» length «length»''') | ||
133 | try { | ||
134 | runtimeConsole.addHyperlink( | ||
135 | new ScriptConsoleFileHiperlink(message.hyperlink), | ||
136 | from, | ||
137 | length | ||
138 | ) | ||
139 | // println("link added") | ||
140 | } catch (BadLocationException e) { | ||
141 | } finally { | ||
142 | runtimeConsole.document.removeDocumentListener(this) | ||
143 | finished.complete(true) | ||
144 | } | ||
145 | } | ||
146 | |||
147 | } | ||
148 | } | ||
149 | runtimeConsole.document.addDocumentListener(listener) | ||
150 | stream.print(text) | ||
151 | stream.flush | ||
152 | finished.get | ||
153 | // stream.console.new | ||
154 | if (message.red >= 0 && message.green >= 0 && message.blue >= 0) { | ||
155 | newColor.dispose | ||
156 | this.runtimeConsole.setBackground(originalBackgroundColor) | ||
157 | } | ||
158 | } | ||
159 | |||
160 | private static def hasConsolePlugin() { | ||
161 | ConsolePlugin.getDefault() !== null | ||
162 | } | ||
163 | |||
164 | public static val FACTORY = new ScriptConsole.Factory { | ||
165 | |||
166 | override createScriptConsole(boolean cleanFiles, URI messageConsoleURI, URI errorConsoleURI, | ||
167 | URI statisticsConsoleURI) { | ||
168 | new RuntimeConsoleBasedScriptConsole(cleanFiles, messageConsoleURI, errorConsoleURI, statisticsConsoleURI) | ||
169 | } | ||
170 | |||
171 | } | ||
172 | } | ||
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner/application/ui/execute/ScriptConsoleFileHiperlink.xtend b/Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner/application/ui/execute/ScriptConsoleFileHiperlink.xtend new file mode 100644 index 00000000..16d78a31 --- /dev/null +++ b/Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner/application/ui/execute/ScriptConsoleFileHiperlink.xtend | |||
@@ -0,0 +1,28 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.ui.execute | ||
2 | |||
3 | import java.io.File | ||
4 | import java.net.URI | ||
5 | import org.eclipse.core.filesystem.EFS | ||
6 | import org.eclipse.ui.PlatformUI | ||
7 | import org.eclipse.ui.console.IHyperlink | ||
8 | import org.eclipse.ui.ide.IDE | ||
9 | |||
10 | class ScriptConsoleFileHiperlink implements IHyperlink { | ||
11 | |||
12 | val URI path | ||
13 | |||
14 | new(File file) { | ||
15 | this.path = file.toURI() | ||
16 | } | ||
17 | |||
18 | override linkActivated() { | ||
19 | // println("open path: "+path.toString) | ||
20 | val page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | ||
21 | val fileStore = EFS.getStore(path) | ||
22 | IDE.openEditorOnFileStore(page, fileStore) | ||
23 | } | ||
24 | |||
25 | override linkEntered() {} | ||
26 | |||
27 | override linkExited() {} | ||
28 | } | ||