aboutsummaryrefslogtreecommitdiffstats
path: root/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptConsole.xtend
diff options
context:
space:
mode:
authorLibravatar OszkarSemerath <oszkar.semerath@gmail.com>2018-08-10 21:28:26 +0200
committerLibravatar OszkarSemerath <oszkar.semerath@gmail.com>2018-08-10 21:28:26 +0200
commit049256ab3001e4cd78d484211b9b53419c64256f (patch)
tree6d10abba65e05f1dbc20406fa05b10115dc88188 /Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptConsole.xtend
parentUpdated type provider to support java native types (diff)
downloadVIATRA-Generator-049256ab3001e4cd78d484211b9b53419c64256f.tar.gz
VIATRA-Generator-049256ab3001e4cd78d484211b9b53419c64256f.tar.zst
VIATRA-Generator-049256ab3001e4cd78d484211b9b53419c64256f.zip
Application puts hyperlinks of the generated files to the console
Diffstat (limited to 'Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptConsole.xtend')
-rw-r--r--Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptConsole.xtend187
1 files changed, 163 insertions, 24 deletions
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptConsole.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptConsole.xtend
index 030d2b9e..289bbe5c 100644
--- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptConsole.xtend
+++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptConsole.xtend
@@ -3,20 +3,23 @@ package hu.bme.mit.inf.dslreasoner.application.execution
3import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace 3import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace
4import hu.bme.mit.inf.dslreasoner.workspace.ProjectWorkspace 4import hu.bme.mit.inf.dslreasoner.workspace.ProjectWorkspace
5import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace 5import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace
6import java.io.File
6import java.util.LinkedHashMap 7import java.util.LinkedHashMap
7import java.util.LinkedHashSet 8import java.util.LinkedHashSet
8import java.util.LinkedList 9import java.util.LinkedList
10import java.util.List
9import java.util.Map 11import java.util.Map
10import org.eclipse.emf.common.util.URI 12import org.eclipse.emf.common.util.URI
11import org.eclipse.ui.IWorkbench 13import org.eclipse.jface.text.DocumentEvent
12import org.eclipse.ui.IWorkbenchPage 14import org.eclipse.jface.text.IDocumentListener
13import org.eclipse.ui.IWorkbenchWindow 15import org.eclipse.swt.graphics.Color
14import org.eclipse.ui.PlatformUI
15import org.eclipse.ui.console.ConsolePlugin 16import org.eclipse.ui.console.ConsolePlugin
16import org.eclipse.ui.console.IConsoleConstants
17import org.eclipse.ui.console.IConsoleView
18import org.eclipse.ui.console.MessageConsole 17import org.eclipse.ui.console.MessageConsole
19import java.util.List 18import org.eclipse.ui.console.MessageConsoleStream
19import org.eclipse.xtend.lib.annotations.Data
20import java.util.concurrent.CompletableFuture
21import java.util.concurrent.Future
22import javax.swing.text.BadLocationException
20 23
21//import org.eclipse.ui.console.MessageConsole 24//import org.eclipse.ui.console.MessageConsole
22 25
@@ -65,26 +68,46 @@ class ScriptConsole {
65 ] 68 ]
66 } 69 }
67 70
71 public def writeMessage(CharSequence message, String separator, ScriptConsoleDecorator[] decorators) {
72 val resolvedText = this.resolveToText(message, separator, decorators)
73 if(messageWorkspace!==null) {
74 messageWorkspace.writeText(messageFileName,resolvedText);
75 }
76 if(printToConsole) {
77 println(resolvedText)
78 }
79 if(runtimeConsole!==null) {
80 writeToRuntimeConsole(message, separator, decorators)
81 }
82 }
68 public def writeMessage(String message) { 83 public def writeMessage(String message) {
69 if(messageWorkspace!=null) { 84 if(messageWorkspace!==null) {
70 messageWorkspace.writeText(messageFileName,message); 85 messageWorkspace.writeText(messageFileName,message);
71 } 86 }
72 if(printToConsole) { 87 if(printToConsole) {
73 println(message) 88 println(message)
74 } 89 }
75 if(runtimeConsole!==null) { 90 if(runtimeConsole!==null) {
76 this.writeToRuntimeConsole(message) 91 writeToRuntimeConsole(message)
92 }
93 }
94 public def writeError(CharSequence message, String separator, ScriptConsoleDecorator[] decorators) {
95 val resolvedText = this.resolveToText(message, separator, decorators)
96 if(errorWorkspace!==null) {
97 errorWorkspace.writeText(errorFileName,resolvedText);
98 }
99 println(message)
100 if(runtimeConsole!==null) {
101 writeToRuntimeConsole(message, separator, decorators)
77 } 102 }
78 } 103 }
79 public def writeError(String message) { 104 public def writeError(String message) {
80 if(errorWorkspace!=null) { 105 if(errorWorkspace!==null) {
81 errorWorkspace.writeText(errorFileName,message); 106 errorWorkspace.writeText(errorFileName,message);
82 } 107 }
83 if(printToConsole) { 108 println(message)
84 println(message)
85 }
86 if(runtimeConsole!==null) { 109 if(runtimeConsole!==null) {
87 this.writeToRuntimeConsole(message) 110 writeToRuntimeConsole(message)
88 } 111 }
89 } 112 }
90 public def writeStatistics(LinkedHashMap<String,? extends Object> statistics) { 113 public def writeStatistics(LinkedHashMap<String,? extends Object> statistics) {
@@ -153,27 +176,143 @@ class ScriptConsole {
153 if(existingConsolesWithID.empty) { 176 if(existingConsolesWithID.empty) {
154 val MessageConsole res = new MessageConsole(consoleID,null) 177 val MessageConsole res = new MessageConsole(consoleID,null)
155 conMan.addConsoles(#[res]); 178 conMan.addConsoles(#[res]);
179
156 return res 180 return res
157 } else { 181 } else {
158 return existingConsolesWithID.head as MessageConsole 182 return existingConsolesWithID.head as MessageConsole
159 } 183 }
160 } 184 }
161 } 185 }
162 186 private def resolveToText(CharSequence message, String separator, ScriptConsoleDecorator[] decorators) {
187 val messageString = message.toString
188 // 0. split the message
189 val separatedMessage = if(messageString.startsWith(separator,-1)) {
190 #[""]+messageString.split(separator,-1)
191 } else {
192 messageString.split(separator,-1).toList
193 }
194 if(separatedMessage.size-1 !== decorators.size) {
195 throw new IllegalArgumentException
196 }
197
198 return '''«FOR i : 0..<decorators.size»«separatedMessage.get(i)»«decorators.get(i)»«ENDFOR»«separatedMessage.last»'''
199 }
163 private def writeToRuntimeConsole(CharSequence message) { 200 private def writeToRuntimeConsole(CharSequence message) {
164 // 1. reveal the console view 201 // 1. reveal the console view
165// val IWorkbench wb = PlatformUI.getWorkbench();
166// val IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
167// val IWorkbenchPage page = win.getActivePage();
168// val id = IConsoleConstants.ID_CONSOLE_VIEW;
169// val view = page.showView(id) as IConsoleView;
170// view.display(this.runtimeConsole);
171
172 ConsolePlugin.getDefault().getConsoleManager().showConsoleView(this.runtimeConsole); 202 ConsolePlugin.getDefault().getConsoleManager().showConsoleView(this.runtimeConsole);
173
174 // 2. write to the console
175 val stream = this.runtimeConsole.newMessageStream 203 val stream = this.runtimeConsole.newMessageStream
176 stream.println(message.toString) 204 stream.println(message.toString)
177 stream.close 205 stream.close
178 } 206 }
207 private def writeToRuntimeConsole(CharSequence message, String separator, ScriptConsoleDecorator[] decorators) {
208 val messageString = message.toString
209 // 0. split the message
210 val separatedMessage = if(messageString.startsWith(separator)) {
211 #[""]+messageString.split(separator,-1)
212 } else {
213 messageString.split(separator,-1).toList
214 }
215 if(separatedMessage.size-1 !== decorators.size) {
216 throw new IllegalArgumentException
217 }
218
219 // 1. reveal the console view
220 ConsolePlugin.getDefault().getConsoleManager().showConsoleView(this.runtimeConsole);
221 val stream = this.runtimeConsole.newMessageStream
222
223 // 2. print the segments of the view
224 for(i : 0..<decorators.size) {
225 stream.print(separatedMessage.get(i))
226 writeDecoratedTextToRuntimeConsole(decorators.get(i),stream)
227
228 }
229 // 2.1 write the last segment of
230 stream.println(separatedMessage.last)
231
232 //stream.println(message.toString)
233 stream.close
234 }
235 private def writeDecoratedTextToRuntimeConsole(ScriptConsoleDecorator message, MessageConsoleStream stream) {
236 val originalBackgroundColor = this.runtimeConsole.background
237 var Color newColor = null;
238
239 val text = '''[«message.text»]'''
240 if(message.red >= 0 && message.green >= 0 && message.blue >= 0) {
241 newColor = new Color(originalBackgroundColor.device,message.red,message.green,message.blue)
242 this.runtimeConsole.setBackground(newColor)
243 }
244 stream.flush
245 val CompletableFuture<Boolean> finished = new CompletableFuture<Boolean>
246 val listener = new IDocumentListener() {
247 override documentAboutToBeChanged(DocumentEvent event) { }
248 override documentChanged(DocumentEvent event) {
249 //println('''ftext="«event.fText»", message="«message.text»" endswith=«event.fText.endsWith(message.text)»''')
250 if(event.fText.endsWith(text)) {
251 val from = event.fDocument.length-text.length+1
252 val length = message.text.length
253 //println('''from: «from» length «length»''')
254 try{
255 runtimeConsole.addHyperlink(
256 new ScriptConsoleFileHiperlink(message.hyperlink),
257 from,
258 length
259 )
260 //println("link added")
261 } catch(BadLocationException e) {
262
263 } finally {
264 runtimeConsole.document.removeDocumentListener(this)
265 finished.complete(true)
266 }
267 }
268
269 }
270 }
271 runtimeConsole.document.addDocumentListener(listener)
272 stream.print(text)
273 stream.flush
274 finished.get
275 //stream.console.new
276 if(message.red >= 0 && message.green >= 0 && message.blue >= 0) {
277 newColor.dispose
278 this.runtimeConsole.setBackground(originalBackgroundColor)
279 }
280 }
281}
282@Data
283class ScriptConsoleDecorator {
284 String text
285 File hyperlink
286 int Red
287 int Green
288 int Blue
289
290 public new(String text) {
291 this.text = text
292 this.hyperlink = null
293 this.Red = -1
294 this.Green = -1
295 this.Blue = -1
296 }
297 public new(String text, File hyperlink) {
298 this.text = text
299 this.hyperlink = hyperlink
300 this.Red = -1
301 this.Green = -1
302 this.Blue = -1
303 }
304 public new(String text, int red, int green, int blue) {
305 this.text = text
306 this.hyperlink = null
307 this.Red = red
308 this.Green = green
309 this.Blue = blue
310 }
311 public new(String text, File hyperlink, int red, int green, int blue) {
312 this.text = text
313 this.hyperlink = hyperlink
314 this.Red = red
315 this.Green = green
316 this.Blue = blue
317 }
179} \ No newline at end of file 318} \ No newline at end of file