From 049256ab3001e4cd78d484211b9b53419c64256f Mon Sep 17 00:00:00 2001 From: OszkarSemerath Date: Fri, 10 Aug 2018 21:28:26 +0200 Subject: Application puts hyperlinks of the generated files to the console --- .../execution/GenerationTaskExecutor.xtend | 54 +++++- .../application/execution/ScopeLoader.xtend | 16 +- .../application/execution/ScriptConsole.xtend | 187 ++++++++++++++++++--- .../execution/ScriptConsoleFileHiperlink.xtend | 28 +++ 4 files changed, 250 insertions(+), 35 deletions(-) create mode 100644 Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/ScriptConsoleFileHiperlink.xtend (limited to 'Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit') 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 import org.eclipse.core.runtime.IProgressMonitor import org.eclipse.emf.common.util.URI import hu.bme.mit.inf.dslreasoner.workspace.URIBasedWorkspace +import java.util.LinkedList +import java.io.File class GenerationTaskExecutor { val metamodelLoader = new MetamodelLoader @@ -212,25 +214,62 @@ class GenerationTaskExecutor { outputWorkspace } + val emfRepresentations = new LinkedList + val gmlRepresentations = new LinkedList + val dotRepresentations = new LinkedList + for(interpretationIndex : 0..0» «run»/«runs»«ENDIF»: Visualising solution «interpretationIndex+1»/«interpretations.size»''') val interpretation = interpretations.get(interpretationIndex) val model = logic2Ecore.transformInterpretation(interpretation,modelGeneration.trace) - outputWorkspaceForRun.writeModel(model,'''model«IF runs>1»_«run»«ENDIF»_«interpretationIndex+1».xmi''') + val emfFileName = '''«IF runs>1»«run»_«ENDIF»«interpretationIndex+1».xmi''' + outputWorkspaceForRun.writeModel(model,emfFileName) + emfRepresentations += outputWorkspaceForRun.getFile(emfFileName) val representation = solution.representation.get(interpretationIndex) if(representation instanceof PartialInterpretation) { val vis1 = new PartialInterpretation2Gml val gml = vis1.transform(representation) - outputWorkspaceForRun.writeText('''model«IF runs>1»_«run»«ENDIF»_«interpretationIndex+1».gml''',gml) + val glmFilename = '''«IF runs>1»«run»_«ENDIF»«interpretationIndex+1».gml''' + outputWorkspaceForRun.writeText(glmFilename,gml) + gmlRepresentations += outputWorkspaceForRun.getFile(glmFilename) if(representation.newElements.size + representation.problem.elements.size < 150) { val vis2 = new GraphvizVisualiser val dot = vis2.visualiseConcretization(representation) - dot.writeToFile(outputWorkspaceForRun,'''model«IF runs>1»_«run»«ENDIF»_«interpretationIndex+1».png''') + val dotFileName = '''«IF runs>1»«run»_«ENDIF»«interpretationIndex+1».png''' + dot.writeToFile(outputWorkspaceForRun,dotFileName) + dotRepresentations += outputWorkspaceForRun.getFile(dotFileName) + } + else { + dotRepresentations += null } + } else { + gmlRepresentations += null + dotRepresentations += null } monitor.worked(100) } + console.writeMessage( + '''Models: «FOR f : emfRepresentations»#«ENDFOR»''', + "#", + emfRepresentations.map[ + new ScriptConsoleDecorator('''«it.fileRepresentationInConsole»''',it) + ] + ) + console.writeMessage( + '''Visualisations: «FOR f : gmlRepresentations»#«ENDFOR»''', + "#", + gmlRepresentations.map[ + new ScriptConsoleDecorator('''«it.fileRepresentationInConsole»''',it) + ] + ) + console.writeMessage( + '''Visualisations: «FOR f : dotRepresentations»#«ENDFOR»''', + "#", + dotRepresentations.map[ + new ScriptConsoleDecorator('''«it.fileRepresentationInConsole»''',it) + ] + ) } else { monitor.worked(solverConfig.solutionScope.numberOfRequiredSolution*100) } @@ -261,6 +300,15 @@ class GenerationTaskExecutor { } } + private def fileRepresentationInConsole(File file) { +// if(file.name.contains('.')) { +// return file.name.substring(0,file.name.lastIndexOf('.')) +// } else { +// file.name +// } + file.name + } + private def dispatch soutionDescription(InconsistencyResult s) { if(s.representation.size == 0) { '''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 import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement +import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.IntLiteral +import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RealLiteral +import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.StringLiteral import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partial2logicannotations.PartialModelRelation2Assertion import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink -import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.IntegerElement import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.NaryRelationLink -import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PrimitiveElement -import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.RealElement -import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.StringElement import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.UnaryElementRelationLink import java.math.BigDecimal import java.util.HashMap @@ -36,9 +35,6 @@ import org.eclipse.emf.ecore.EClass import org.eclipse.xtend.lib.annotations.Data import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* -import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.IntLiteral -import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RealLiteral -import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.StringLiteral @Data class KnownElements { val Map> knownElementsByType @@ -93,6 +89,10 @@ class ScopeLoader { aggregated.minNewElements = updateLowerLimit(scope.isSetsNew,numberOfKnownElements,aggregated.minNewElements,getLowerLimit(scope.number)) aggregated.maxNewElements = updateUpperLimit(scope.isSetsNew,numberOfKnownElements,aggregated.maxNewElements,getUpperLimit(scope.number)) + + if(aggregated.maxNewElements < 0) { + inconsistencies+='''Inconsistent scope: problem already contains «numberOfKnownElements» elements, but scope sets the upper limit to «getUpperLimit(scope.number)»!''' + } } def dispatch setSpecification(ClassTypeScope scope, TypeScopes aggregated, Map> knownElements, Ecore2Logic ecore2Logic, Ecore2Logic_Trace trace, List inconsistencies) { val target = scope.type.element @@ -161,7 +161,7 @@ class ScopeLoader { val notDefinedInScope = known.filter[!definedInScope.contains(it)] inconsistencies += '''Inconsistent scope: problem already contains literal«IF notDefinedInScope.size > 0»s«ENDIF» that excluded by a scope: «FOR e: notDefinedInScope SEPARATOR ", "»«e»«ENDFOR».''' } - known.clear + //known.clear known += definedInScope } } 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 import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace import hu.bme.mit.inf.dslreasoner.workspace.ProjectWorkspace import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace +import java.io.File import java.util.LinkedHashMap import java.util.LinkedHashSet import java.util.LinkedList +import java.util.List import java.util.Map import org.eclipse.emf.common.util.URI -import org.eclipse.ui.IWorkbench -import org.eclipse.ui.IWorkbenchPage -import org.eclipse.ui.IWorkbenchWindow -import org.eclipse.ui.PlatformUI +import org.eclipse.jface.text.DocumentEvent +import org.eclipse.jface.text.IDocumentListener +import org.eclipse.swt.graphics.Color import org.eclipse.ui.console.ConsolePlugin -import org.eclipse.ui.console.IConsoleConstants -import org.eclipse.ui.console.IConsoleView import org.eclipse.ui.console.MessageConsole -import java.util.List +import org.eclipse.ui.console.MessageConsoleStream +import org.eclipse.xtend.lib.annotations.Data +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Future +import javax.swing.text.BadLocationException //import org.eclipse.ui.console.MessageConsole @@ -65,26 +68,46 @@ class ScriptConsole { ] } + public def writeMessage(CharSequence message, String separator, ScriptConsoleDecorator[] decorators) { + val resolvedText = this.resolveToText(message, separator, decorators) + if(messageWorkspace!==null) { + messageWorkspace.writeText(messageFileName,resolvedText); + } + if(printToConsole) { + println(resolvedText) + } + if(runtimeConsole!==null) { + writeToRuntimeConsole(message, separator, decorators) + } + } public def writeMessage(String message) { - if(messageWorkspace!=null) { + if(messageWorkspace!==null) { messageWorkspace.writeText(messageFileName,message); } if(printToConsole) { println(message) } if(runtimeConsole!==null) { - this.writeToRuntimeConsole(message) + writeToRuntimeConsole(message) + } + } + public def writeError(CharSequence message, String separator, ScriptConsoleDecorator[] decorators) { + val resolvedText = this.resolveToText(message, separator, decorators) + if(errorWorkspace!==null) { + errorWorkspace.writeText(errorFileName,resolvedText); + } + println(message) + if(runtimeConsole!==null) { + writeToRuntimeConsole(message, separator, decorators) } } public def writeError(String message) { - if(errorWorkspace!=null) { + if(errorWorkspace!==null) { errorWorkspace.writeText(errorFileName,message); } - if(printToConsole) { - println(message) - } + println(message) if(runtimeConsole!==null) { - this.writeToRuntimeConsole(message) + writeToRuntimeConsole(message) } } public def writeStatistics(LinkedHashMap statistics) { @@ -153,27 +176,143 @@ class ScriptConsole { if(existingConsolesWithID.empty) { val MessageConsole res = new MessageConsole(consoleID,null) conMan.addConsoles(#[res]); + return res } else { return existingConsolesWithID.head as MessageConsole } } } - + private def resolveToText(CharSequence message, String separator, ScriptConsoleDecorator[] decorators) { + val messageString = message.toString + // 0. split the message + val separatedMessage = if(messageString.startsWith(separator,-1)) { + #[""]+messageString.split(separator,-1) + } else { + messageString.split(separator,-1).toList + } + if(separatedMessage.size-1 !== decorators.size) { + throw new IllegalArgumentException + } + + return '''«FOR i : 0..= 0 && message.green >= 0 && message.blue >= 0) { + newColor = new Color(originalBackgroundColor.device,message.red,message.green,message.blue) + this.runtimeConsole.setBackground(newColor) + } + stream.flush + val CompletableFuture finished = new CompletableFuture + val listener = new IDocumentListener() { + override documentAboutToBeChanged(DocumentEvent event) { } + override documentChanged(DocumentEvent event) { + //println('''ftext="«event.fText»", message="«message.text»" endswith=«event.fText.endsWith(message.text)»''') + if(event.fText.endsWith(text)) { + val from = event.fDocument.length-text.length+1 + val length = message.text.length + //println('''from: «from» length «length»''') + try{ + runtimeConsole.addHyperlink( + new ScriptConsoleFileHiperlink(message.hyperlink), + from, + length + ) + //println("link added") + } catch(BadLocationException e) { + + } finally { + runtimeConsole.document.removeDocumentListener(this) + finished.complete(true) + } + } + + } + } + runtimeConsole.document.addDocumentListener(listener) + stream.print(text) + stream.flush + finished.get + //stream.console.new + if(message.red >= 0 && message.green >= 0 && message.blue >= 0) { + newColor.dispose + this.runtimeConsole.setBackground(originalBackgroundColor) + } + } +} +@Data +class ScriptConsoleDecorator { + String text + File hyperlink + int Red + int Green + int Blue + + public new(String text) { + this.text = text + this.hyperlink = null + this.Red = -1 + this.Green = -1 + this.Blue = -1 + } + public new(String text, File hyperlink) { + this.text = text + this.hyperlink = hyperlink + this.Red = -1 + this.Green = -1 + this.Blue = -1 + } + public new(String text, int red, int green, int blue) { + this.text = text + this.hyperlink = null + this.Red = red + this.Green = green + this.Blue = blue + } + public new(String text, File hyperlink, int red, int green, int blue) { + this.text = text + this.hyperlink = hyperlink + this.Red = red + this.Green = green + this.Blue = blue + } } \ 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 @@ +package hu.bme.mit.inf.dslreasoner.application.execution + +import org.eclipse.ui.console.IHyperlink +import org.eclipse.ui.ide.IDE +import org.eclipse.ui.PlatformUI +import org.eclipse.core.filesystem.EFS +import java.io.File +import java.net.URI + +class ScriptConsoleFileHiperlink implements IHyperlink { + + private val URI path; + + new(File file) { + this.path = file.toURI() + } + + override linkActivated() { + //println("open path: "+path.toString) + val page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + val fileStore = EFS.getStore(path) + IDE.openEditorOnFileStore(page,fileStore) + } + + override linkEntered() { } + + override linkExited() { } +} \ No newline at end of file -- cgit v1.2.3-70-g09d2