Skip to content

Commit

Permalink
[ML4SE-372] Fixed recursive scenario problems, resolved conflicts wit…
Browse files Browse the repository at this point in the history
…h filenames, fixed problem with file sending.
  • Loading branch information
mikrise2 committed Feb 8, 2024
1 parent b917adc commit af4e909
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.jetbrains.research.tasktracker.tracking

import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.Service
import com.intellij.openapi.project.Project
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.jetbrains.research.tasktracker.TaskTrackerPlugin
import org.jetbrains.research.tasktracker.tracking.activity.ActivityTracker
import org.jetbrains.research.tasktracker.tracking.fileEditor.FileEditorTracker
Expand Down Expand Up @@ -52,17 +53,15 @@ class TrackingService : Disposable {
trackers.forEach {
it.stopTracking()
}
ApplicationManager.getApplication().invokeAndWait {
runBlocking {
val result = trackers.all {
it.send()
}.and(
logs.all { it.send() }
)
trackers.clear()
logs.clear()
if (result) success.invoke() else failure.invoke()
}
CoroutineScope(Dispatchers.IO).launch {
val result = trackers.all {
it.send()
}.and(
logs.all { it.send() }
)
trackers.clear()
logs.clear()
if (result) success.invoke() else failure.invoke()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package org.jetbrains.research.tasktracker.tracking.logger
import com.intellij.openapi.project.Project
import org.jetbrains.research.tasktracker.tracking.fileEditor.FileEditorAction
import org.jetbrains.research.tasktracker.tracking.fileEditor.FileEditorData
import org.jetbrains.research.tasktracker.ui.main.panel.storage.GlobalPluginStorage
import org.joda.time.DateTime

class FileEditorLogger(project: Project) : BaseLogger() {
override val logPrinterFilename: String = "file_editor_${project.hashCode()}_${project.name}"
override val logPrinterFilename: String =
"file_editor_${project.hashCode()}_${project.name}_${GlobalPluginStorage.currentResearchId}"
override val loggedData: LoggedData<*, *>
get() = FileEditorLoggedData

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package org.jetbrains.research.tasktracker.tracking.logger
import com.intellij.openapi.project.Project
import org.jetbrains.research.tasktracker.tracking.toolWindow.ToolWindowAction
import org.jetbrains.research.tasktracker.tracking.toolWindow.ToolWindowData
import org.jetbrains.research.tasktracker.ui.main.panel.storage.GlobalPluginStorage
import org.joda.time.DateTime

class ToolWindowLogger(val project: Project) : BaseLogger() {
override val logPrinterFilename: String = "tool_window_${project.hashCode()}_${project.name}"
override val logPrinterFilename: String =
"tool_window_${project.hashCode()}_${project.name}_${GlobalPluginStorage.currentResearchId}"
override val loggedData: LoggedData<*, *>
get() = ToolWindowLoggedData

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import org.jetbrains.research.tasktracker.ui.main.panel.template.WebcamChoicePag
import org.jetbrains.research.tasktracker.util.UIBundle
import java.awt.BorderLayout
import java.awt.FlowLayout
import java.awt.event.ActionListener

/**
* The class is intended to manage JCEF and Swing components simultaneously,
Expand Down Expand Up @@ -177,7 +176,7 @@ class MainPluginPanelFactory : ToolWindowFactory {

fun openExternalUrl(url: String) = mainWindow.openExternalUrl(url)

fun setNextAction(listener: ActionListener) = nextButton.setListener(listener)
fun setNextAction(listener: () -> Unit = {}) = nextButton.setListener(listener)

fun setBackAction(listener: ActionListener) = backButton.setListener(listener)
fun setBackAction(listener: () -> Unit = {}) = backButton.setListener(listener)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.jetbrains.research.tasktracker.config.MainTaskTrackerConfig
import org.jetbrains.research.tasktracker.ui.main.panel.models.ButtonState
import org.jetbrains.research.tasktracker.ui.main.panel.models.LinkType
import org.jetbrains.research.tasktracker.util.UIBundle
import java.awt.event.ActionListener
import java.io.File
import javax.swing.JButton

Expand Down Expand Up @@ -55,20 +54,22 @@ fun MainPluginWindow.jslinkProcess(type: LinkType, action: (param: String) -> Un
* Creates new JButton state and return previous JButton state.
*/
fun JButton.changeState(buttonState: ButtonState) {
buttonState.actionListener?.let {
setListener(buttonState.actionListener)
}
addActionListener(buttonState.actionListener)
this.text = buttonState.text
isVisible = buttonState.isVisibleProp
}

fun JButton.getState(): ButtonState = ButtonState(text, isVisible, actionListeners.firstOrNull())

fun JButton.setListener(listener: ActionListener) {
fun JButton.setListener(listener: () -> Unit = {}) {
actionListeners.forEach {
removeActionListener(it)
}
addActionListener(listener)
addActionListener {
isEnabled = false
listener.invoke()
isEnabled = true
}
}

/**
Expand All @@ -82,7 +83,7 @@ fun saveAgreements(agreementString: String) {
agreementFile.writeText(agreementString)
}

fun<T> Promise<T>.runOnSuccess(task: (response: T) -> Unit) =
fun <T> Promise<T>.runOnSuccess(task: (response: T) -> Unit) =
onSuccess {
ApplicationManager.getApplication().invokeLater {
task(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ typealias Panel = MainPluginPanelFactory
* A page for collecting user data, and checkboxes for user agreement acceptance.
*/
fun Panel.agreementAcceptance() {
GlobalPluginStorage.resetSession()
loadBasePage(AgreementTemplate.loadCurrentTemplate(), "ui.button.next", false)
setNextAction {
checkAgreementInputs().runOnSuccess {
Expand Down Expand Up @@ -129,12 +130,15 @@ fun Panel.survey(id: String) {

fun Panel.serverErrorPage() {
loadBasePage(ServerErrorPage(), "ui.button.welcome", false)
setNextAction {
agreementAcceptance()
}
}

fun Panel.finalPage() {
loadBasePage(FinalPageTemplate.loadCurrentTemplate(), "ui.button.welcome", false)
setNextAction {
welcomePage()
agreementAcceptance()
}
}

Expand Down Expand Up @@ -174,7 +178,7 @@ fun Panel.processScenario() {
null -> {
scenario.reset()
loadBasePage(LoadTemplate())
GlobalScope.launch {
ApplicationManager.getApplication().invokeLater {
trackingService.stopTracking(::finalPage, ::serverErrorPage)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ object GlobalPluginStorage {
var agreementChecker: AgreementChecker? = null
var userId: Int? = null
var currentResearchId: Int? = null

fun resetSession() {
userId = null
currentResearchId = null
agreementChecker = null
}
}

0 comments on commit af4e909

Please sign in to comment.