diff options
Diffstat (limited to 'Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner')
4 files changed, 250 insertions, 35 deletions
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/GenerationTaskExecutor.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/GenerationTaskExecutor.xtend index 9a8ac8a3..975da665 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/GenerationTaskExecutor.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/GenerationTaskExecutor.xtend | |||
@@ -26,6 +26,8 @@ import java.util.Scanner | |||
26 | import org.eclipse.core.runtime.IProgressMonitor | 26 | import org.eclipse.core.runtime.IProgressMonitor |
27 | import org.eclipse.emf.common.util.URI | 27 | import org.eclipse.emf.common.util.URI |
28 | import hu.bme.mit.inf.dslreasoner.workspace.URIBasedWorkspace | 28 | import hu.bme.mit.inf.dslreasoner.workspace.URIBasedWorkspace |
29 | import java.util.LinkedList | ||
30 | import java.io.File | ||
29 | 31 | ||
30 | class GenerationTaskExecutor { | 32 | class GenerationTaskExecutor { |
31 | val metamodelLoader = new MetamodelLoader | 33 | val metamodelLoader = new MetamodelLoader |
@@ -212,25 +214,62 @@ class GenerationTaskExecutor { | |||
212 | outputWorkspace | 214 | outputWorkspace |
213 | } | 215 | } |
214 | 216 | ||
217 | val emfRepresentations = new LinkedList | ||
218 | val gmlRepresentations = new LinkedList | ||
219 | val dotRepresentations = new LinkedList | ||
220 | |||
215 | for(interpretationIndex : 0..<interpretations.size) { | 221 | for(interpretationIndex : 0..<interpretations.size) { |
216 | monitor.subTask('''Solving problem«IF runs>0» «run»/«runs»«ENDIF»: Visualising solution «interpretationIndex+1»/«interpretations.size»''') | 222 | monitor.subTask('''Solving problem«IF runs>0» «run»/«runs»«ENDIF»: Visualising solution «interpretationIndex+1»/«interpretations.size»''') |
217 | val interpretation = interpretations.get(interpretationIndex) | 223 | val interpretation = interpretations.get(interpretationIndex) |
218 | val model = logic2Ecore.transformInterpretation(interpretation,modelGeneration.trace) | 224 | val model = logic2Ecore.transformInterpretation(interpretation,modelGeneration.trace) |
219 | outputWorkspaceForRun.writeModel(model,'''model«IF runs>1»_«run»«ENDIF»_«interpretationIndex+1».xmi''') | 225 | val emfFileName = '''«IF runs>1»«run»_«ENDIF»«interpretationIndex+1».xmi''' |
226 | outputWorkspaceForRun.writeModel(model,emfFileName) | ||
227 | emfRepresentations += outputWorkspaceForRun.getFile(emfFileName) | ||
220 | 228 | ||
221 | val representation = solution.representation.get(interpretationIndex) | 229 | val representation = solution.representation.get(interpretationIndex) |
222 | if(representation instanceof PartialInterpretation) { | 230 | if(representation instanceof PartialInterpretation) { |
223 | val vis1 = new PartialInterpretation2Gml | 231 | val vis1 = new PartialInterpretation2Gml |
224 | val gml = vis1.transform(representation) | 232 | val gml = vis1.transform(representation) |
225 | outputWorkspaceForRun.writeText('''model«IF runs>1»_«run»«ENDIF»_«interpretationIndex+1».gml''',gml) | 233 | val glmFilename = '''«IF runs>1»«run»_«ENDIF»«interpretationIndex+1».gml''' |
234 | outputWorkspaceForRun.writeText(glmFilename,gml) | ||
235 | gmlRepresentations += outputWorkspaceForRun.getFile(glmFilename) | ||
226 | if(representation.newElements.size + representation.problem.elements.size < 150) { | 236 | if(representation.newElements.size + representation.problem.elements.size < 150) { |
227 | val vis2 = new GraphvizVisualiser | 237 | val vis2 = new GraphvizVisualiser |
228 | val dot = vis2.visualiseConcretization(representation) | 238 | val dot = vis2.visualiseConcretization(representation) |
229 | dot.writeToFile(outputWorkspaceForRun,'''model«IF runs>1»_«run»«ENDIF»_«interpretationIndex+1».png''') | 239 | val dotFileName = '''«IF runs>1»«run»_«ENDIF»«interpretationIndex+1».png''' |
240 | dot.writeToFile(outputWorkspaceForRun,dotFileName) | ||
241 | dotRepresentations += outputWorkspaceForRun.getFile(dotFileName) | ||
242 | } | ||
243 | else { | ||
244 | dotRepresentations += null | ||
230 | } | 245 | } |
246 | } else { | ||
247 | gmlRepresentations += null | ||
248 | dotRepresentations += null | ||
231 | } | 249 | } |
232 | monitor.worked(100) | 250 | monitor.worked(100) |
233 | } | 251 | } |
252 | console.writeMessage( | ||
253 | '''Models: «FOR f : emfRepresentations»#«ENDFOR»''', | ||
254 | "#", | ||
255 | emfRepresentations.map[ | ||
256 | new ScriptConsoleDecorator('''«it.fileRepresentationInConsole»''',it) | ||
257 | ] | ||
258 | ) | ||
259 | console.writeMessage( | ||
260 | '''Visualisations: «FOR f : gmlRepresentations»#«ENDFOR»''', | ||
261 | "#", | ||
262 | gmlRepresentations.map[ | ||
263 | new ScriptConsoleDecorator('''«it.fileRepresentationInConsole»''',it) | ||
264 | ] | ||
265 | ) | ||
266 | console.writeMessage( | ||
267 | '''Visualisations: «FOR f : dotRepresentations»#«ENDFOR»''', | ||
268 | "#", | ||
269 | dotRepresentations.map[ | ||
270 | new ScriptConsoleDecorator('''«it.fileRepresentationInConsole»''',it) | ||
271 | ] | ||
272 | ) | ||
234 | } else { | 273 | } else { |
235 | monitor.worked(solverConfig.solutionScope.numberOfRequiredSolution*100) | 274 | monitor.worked(solverConfig.solutionScope.numberOfRequiredSolution*100) |
236 | } | 275 | } |
@@ -261,6 +300,15 @@ class GenerationTaskExecutor { | |||
261 | } | 300 | } |
262 | } | 301 | } |
263 | 302 | ||
303 | private def fileRepresentationInConsole(File file) { | ||
304 | // if(file.name.contains('.')) { | ||
305 | // return file.name.substring(0,file.name.lastIndexOf('.')) | ||
306 | // } else { | ||
307 | // file.name | ||
308 | // } | ||
309 | file.name | ||
310 | } | ||
311 | |||
264 | private def dispatch soutionDescription(InconsistencyResult s) { | 312 | private def dispatch soutionDescription(InconsistencyResult s) { |
265 | if(s.representation.size == 0) { | 313 | if(s.representation.size == 0) { |
266 | '''Problem is inconsistent, no model is created!''' | 314 | '''Problem is inconsistent, no model is created!''' |
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScopeLoader.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScopeLoader.xtend index 9b2b4a3e..4f1a8f38 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScopeLoader.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScopeLoader.xtend | |||
@@ -15,16 +15,15 @@ import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | |||
15 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace | 15 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace |
16 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes | 16 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes |
17 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement | 17 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement |
18 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.IntLiteral | ||
19 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RealLiteral | ||
20 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.StringLiteral | ||
18 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | 21 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type |
19 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition | 22 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition |
20 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem | 23 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem |
21 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partial2logicannotations.PartialModelRelation2Assertion | 24 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partial2logicannotations.PartialModelRelation2Assertion |
22 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink | 25 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink |
23 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.IntegerElement | ||
24 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.NaryRelationLink | 26 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.NaryRelationLink |
25 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PrimitiveElement | ||
26 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.RealElement | ||
27 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.StringElement | ||
28 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.UnaryElementRelationLink | 27 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.UnaryElementRelationLink |
29 | import java.math.BigDecimal | 28 | import java.math.BigDecimal |
30 | import java.util.HashMap | 29 | import java.util.HashMap |
@@ -36,9 +35,6 @@ import org.eclipse.emf.ecore.EClass | |||
36 | import org.eclipse.xtend.lib.annotations.Data | 35 | import org.eclipse.xtend.lib.annotations.Data |
37 | 36 | ||
38 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | 37 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* |
39 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.IntLiteral | ||
40 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RealLiteral | ||
41 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.StringLiteral | ||
42 | 38 | ||
43 | @Data class KnownElements { | 39 | @Data class KnownElements { |
44 | val Map<Type,Set<DefinedElement>> knownElementsByType | 40 | val Map<Type,Set<DefinedElement>> knownElementsByType |
@@ -93,6 +89,10 @@ class ScopeLoader { | |||
93 | 89 | ||
94 | aggregated.minNewElements = updateLowerLimit(scope.isSetsNew,numberOfKnownElements,aggregated.minNewElements,getLowerLimit(scope.number)) | 90 | aggregated.minNewElements = updateLowerLimit(scope.isSetsNew,numberOfKnownElements,aggregated.minNewElements,getLowerLimit(scope.number)) |
95 | aggregated.maxNewElements = updateUpperLimit(scope.isSetsNew,numberOfKnownElements,aggregated.maxNewElements,getUpperLimit(scope.number)) | 91 | aggregated.maxNewElements = updateUpperLimit(scope.isSetsNew,numberOfKnownElements,aggregated.maxNewElements,getUpperLimit(scope.number)) |
92 | |||
93 | if(aggregated.maxNewElements < 0) { | ||
94 | inconsistencies+='''Inconsistent scope: problem already contains «numberOfKnownElements» elements, but scope sets the upper limit to «getUpperLimit(scope.number)»!''' | ||
95 | } | ||
96 | } | 96 | } |
97 | def dispatch setSpecification(ClassTypeScope scope, TypeScopes aggregated, Map<Type, Set<DefinedElement>> knownElements, Ecore2Logic ecore2Logic, Ecore2Logic_Trace trace, List<String> inconsistencies) { | 97 | def dispatch setSpecification(ClassTypeScope scope, TypeScopes aggregated, Map<Type, Set<DefinedElement>> knownElements, Ecore2Logic ecore2Logic, Ecore2Logic_Trace trace, List<String> inconsistencies) { |
98 | val target = scope.type.element | 98 | val target = scope.type.element |
@@ -161,7 +161,7 @@ class ScopeLoader { | |||
161 | val notDefinedInScope = known.filter[!definedInScope.contains(it)] | 161 | val notDefinedInScope = known.filter[!definedInScope.contains(it)] |
162 | inconsistencies += '''Inconsistent scope: problem already contains literal«IF notDefinedInScope.size > 0»s«ENDIF» that excluded by a scope: «FOR e: notDefinedInScope SEPARATOR ", "»«e»«ENDFOR».''' | 162 | inconsistencies += '''Inconsistent scope: problem already contains literal«IF notDefinedInScope.size > 0»s«ENDIF» that excluded by a scope: «FOR e: notDefinedInScope SEPARATOR ", "»«e»«ENDFOR».''' |
163 | } | 163 | } |
164 | known.clear | 164 | //known.clear |
165 | known += definedInScope | 165 | known += definedInScope |
166 | } | 166 | } |
167 | } | 167 | } |
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 | |||
3 | import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace | 3 | import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace |
4 | import hu.bme.mit.inf.dslreasoner.workspace.ProjectWorkspace | 4 | import hu.bme.mit.inf.dslreasoner.workspace.ProjectWorkspace |
5 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace | 5 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace |
6 | import java.io.File | ||
6 | import java.util.LinkedHashMap | 7 | import java.util.LinkedHashMap |
7 | import java.util.LinkedHashSet | 8 | import java.util.LinkedHashSet |
8 | import java.util.LinkedList | 9 | import java.util.LinkedList |
10 | import java.util.List | ||
9 | import java.util.Map | 11 | import java.util.Map |
10 | import org.eclipse.emf.common.util.URI | 12 | import org.eclipse.emf.common.util.URI |
11 | import org.eclipse.ui.IWorkbench | 13 | import org.eclipse.jface.text.DocumentEvent |
12 | import org.eclipse.ui.IWorkbenchPage | 14 | import org.eclipse.jface.text.IDocumentListener |
13 | import org.eclipse.ui.IWorkbenchWindow | 15 | import org.eclipse.swt.graphics.Color |
14 | import org.eclipse.ui.PlatformUI | ||
15 | import org.eclipse.ui.console.ConsolePlugin | 16 | import org.eclipse.ui.console.ConsolePlugin |
16 | import org.eclipse.ui.console.IConsoleConstants | ||
17 | import org.eclipse.ui.console.IConsoleView | ||
18 | import org.eclipse.ui.console.MessageConsole | 17 | import org.eclipse.ui.console.MessageConsole |
19 | import java.util.List | 18 | import org.eclipse.ui.console.MessageConsoleStream |
19 | import org.eclipse.xtend.lib.annotations.Data | ||
20 | import java.util.concurrent.CompletableFuture | ||
21 | import java.util.concurrent.Future | ||
22 | import 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 | ||
283 | class 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 |
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptConsoleFileHiperlink.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptConsoleFileHiperlink.xtend new file mode 100644 index 00000000..25e49c80 --- /dev/null +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptConsoleFileHiperlink.xtend | |||
@@ -0,0 +1,28 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.execution | ||
2 | |||
3 | import org.eclipse.ui.console.IHyperlink | ||
4 | import org.eclipse.ui.ide.IDE | ||
5 | import org.eclipse.ui.PlatformUI | ||
6 | import org.eclipse.core.filesystem.EFS | ||
7 | import java.io.File | ||
8 | import java.net.URI | ||
9 | |||
10 | class ScriptConsoleFileHiperlink implements IHyperlink { | ||
11 | |||
12 | private 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 | } \ No newline at end of file | ||