From 41379702ec48b4dc0bc2174090a4bcfd609cfac9 Mon Sep 17 00:00:00 2001 From: mikrise2 Date: Wed, 15 Nov 2023 14:24:17 +0100 Subject: [PATCH 1/6] [ML4SE-234] new Scenario Step --- .../tasktracker/config/ide/MainIdeConfig.kt | 7 +++-- .../config/scenario/ScenarioConfig.kt | 1 + .../config/scenario/{ => models}/Scenario.kt | 25 +-------------- .../config/scenario/models/ScenarioStep.kt | 31 +++++++++++++++++++ .../scenario/models/ScenarioStepMode.kt | 6 ++++ .../handler/scenario/ScenarioHandler.kt | 4 +-- 6 files changed, 46 insertions(+), 28 deletions(-) rename ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/{ => models}/Scenario.kt (70%) create mode 100644 ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioStep.kt create mode 100644 ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioStepMode.kt diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/ide/MainIdeConfig.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/ide/MainIdeConfig.kt index c7bf61d8..5d7de049 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/ide/MainIdeConfig.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/ide/MainIdeConfig.kt @@ -2,6 +2,7 @@ package org.jetbrains.research.tasktracker.config.ide import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.project.Project +import kotlinx.serialization.Serializable import org.jetbrains.research.tasktracker.config.BaseProjectConfig import org.jetbrains.research.tasktracker.config.ide.inspection.InspectionConfig import org.jetbrains.research.tasktracker.config.ide.settings.SettingsConfig @@ -10,9 +11,11 @@ import org.jetbrains.research.tasktracker.handler.BaseProjectHandler import org.jetbrains.research.tasktracker.handler.ide.IdeHandler import java.io.File -class MainIdeConfig : BaseProjectConfig { - var inspectionConfig: InspectionConfig? = null +@Serializable +data class MainIdeConfig( + var inspectionConfig: InspectionConfig? = null, var settingsConfig: SettingsConfig? = null +) : BaseProjectConfig { override val configName: String get() = "main_ide" diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/ScenarioConfig.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/ScenarioConfig.kt index 9384b304..86ecb1a9 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/ScenarioConfig.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/ScenarioConfig.kt @@ -3,6 +3,7 @@ package org.jetbrains.research.tasktracker.config.scenario import kotlinx.serialization.Serializable import org.jetbrains.research.tasktracker.config.BaseConfig import org.jetbrains.research.tasktracker.config.YamlConfigLoadStrategy +import org.jetbrains.research.tasktracker.config.scenario.models.Scenario import java.io.File @Serializable diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/Scenario.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/Scenario.kt similarity index 70% rename from ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/Scenario.kt rename to ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/Scenario.kt index 38d7161f..4e9c0f13 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/Scenario.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/Scenario.kt @@ -1,4 +1,4 @@ -package org.jetbrains.research.tasktracker.config.scenario +package org.jetbrains.research.tasktracker.config.scenario.models import com.intellij.openapi.diagnostic.Logger import kotlinx.serialization.KSerializer @@ -8,31 +8,8 @@ import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -import org.jetbrains.research.tasktracker.TaskTrackerPlugin -import org.jetbrains.research.tasktracker.config.BaseConfig import java.util.* -enum class ScenarioUnitType { - TASK_CONTENT, - - // TODO: add other types of content - IDE_SETTINGS; - - val config: BaseConfig? - get() = when (this) { - TASK_CONTENT -> TaskTrackerPlugin.mainConfig.taskContentConfig - IDE_SETTINGS -> TaskTrackerPlugin.mainConfig.mainIdeConfig - } -} - -@Serializable -data class ScenarioStep( - // TODO: sort according to the plugin's implementation to make sure in the right order - val units: List -) { - fun isValid() = units.any { it.config != null } -} - @Serializable data class Scenario( @Serializable(with = QueueSerializer::class) val steps: Queue diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioStep.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioStep.kt new file mode 100644 index 00000000..7b73be12 --- /dev/null +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioStep.kt @@ -0,0 +1,31 @@ +package org.jetbrains.research.tasktracker.config.scenario.models + +import com.intellij.openapi.project.Project +import kotlinx.serialization.Serializable +import kotlinx.serialization.Transient +import org.jetbrains.research.tasktracker.config.BaseConfig +import org.jetbrains.research.tasktracker.config.ide.MainIdeConfig +import org.jetbrains.research.tasktracker.handler.BaseProjectHandler + +@Serializable +data class ScenarioStep( + private val ideConfig: MainIdeConfig?, + val units: List, + val mode: ScenarioStepMode = ScenarioStepMode.ORDERED +) { + @Transient + private var mainIdeHandler: BaseProjectHandler? = null + + fun prepareSettings(project: Project) { + mainIdeHandler = ideConfig?.buildHandler(project) + mainIdeHandler?.setup() + } + + fun run() { + TODO() + } + + // TODO check if there are any config of specified type in units. + @Suppress("FunctionOnlyReturningConstant") + fun isValid() = true +} diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioStepMode.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioStepMode.kt new file mode 100644 index 00000000..a9b3e48d --- /dev/null +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioStepMode.kt @@ -0,0 +1,6 @@ +package org.jetbrains.research.tasktracker.config.scenario.models + +enum class ScenarioStepMode { + ORDERED, + SHUFFLED +} diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/handler/scenario/ScenarioHandler.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/handler/scenario/ScenarioHandler.kt index 166a5bec..05fb6251 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/handler/scenario/ScenarioHandler.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/handler/scenario/ScenarioHandler.kt @@ -1,8 +1,8 @@ package org.jetbrains.research.tasktracker.handler.scenario import org.jetbrains.research.tasktracker.config.MainTaskTrackerConfig -import org.jetbrains.research.tasktracker.config.scenario.ScenarioStep -import org.jetbrains.research.tasktracker.config.scenario.ScenarioUnitType +import org.jetbrains.research.tasktracker.config.scenario.models.ScenarioStep +import org.jetbrains.research.tasktracker.config.scenario.models.ScenarioUnitType @Suppress("UnusedPrivateMember") class ScenarioHandler(private val mainConfig: MainTaskTrackerConfig) { From cf6bdaa0f4e763c2366ad97604ec5d14462e7363 Mon Sep 17 00:00:00 2001 From: mikrise2 Date: Thu, 16 Nov 2023 17:09:49 +0100 Subject: [PATCH 2/6] [ML4SE-234] process new Scenario Units --- .../tasktracker/activities/InitActivity.kt | 11 +++---- .../config/scenario/models/Scenario.kt | 17 +++++++++- .../config/scenario/models/ScenarioStep.kt | 9 +++--- .../config/scenario/models/ScenarioUnit.kt | 23 +++++++++++++ .../handler/scenario/ScenarioHandler.kt | 22 ------------- .../tasktracker/ui/main/panel/Util.kt | 32 +++++++++++++++++++ 6 files changed, 81 insertions(+), 33 deletions(-) create mode 100644 ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioUnit.kt delete mode 100644 ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/handler/scenario/ScenarioHandler.kt diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/activities/InitActivity.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/activities/InitActivity.kt index e923aac2..e35b8fe1 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/activities/InitActivity.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/activities/InitActivity.kt @@ -5,7 +5,6 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.startup.StartupActivity import org.jetbrains.research.tasktracker.TaskTrackerPlugin import org.jetbrains.research.tasktracker.config.MainTaskTrackerConfig -import org.jetbrains.research.tasktracker.handler.scenario.ScenarioHandler // Put into plugin.xml class InitActivity : StartupActivity { @@ -20,11 +19,11 @@ class InitActivity : StartupActivity { override fun runActivity(project: Project) { TaskTrackerPlugin.initializationHandler.setupEnvironment(project) // TODO: move to the start point of the task TaskTrackerPlugin.mainConfig.scenarioConfig?.let { scenarioConf -> - scenarioConf.scenario.getNextStep()?.let { scenarioStep -> - with(ScenarioHandler(TaskTrackerPlugin.mainConfig)) { - scenarioStep.run() - } - } ?: logger.warn("Try to init the plugin, but the scenario is empty or invalid") +// scenarioConf.scenario.getNextStep()?.let { scenarioStep -> +// with(ScenarioHandler(TaskTrackerPlugin.mainConfig)) { +// scenarioStep.run() +// } +// } ?: logger.warn("Try to init the plugin, but the scenario is empty or invalid") } ?: logger.warn("Please, provide a scenario for the plugin behaviour") } } diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/Scenario.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/Scenario.kt index 4e9c0f13..a2d0c881 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/Scenario.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/Scenario.kt @@ -17,7 +17,10 @@ data class Scenario( @Transient private val logger: Logger = Logger.getInstance(javaClass) - fun getNextStep(): ScenarioStep? { + @Transient + private var currentStepIterator: Iterator? = null + + private fun getNextStep(): ScenarioStep? { var isValid: Boolean var step: ScenarioStep do { @@ -35,6 +38,18 @@ data class Scenario( return step } + @Suppress("ReturnCount") + fun getNextUnit(): ScenarioUnit? { + if (currentStepIterator?.hasNext() != true) { + val currentStep = getNextStep() ?: return null + currentStepIterator = currentStep.getUnits().iterator() + if (currentStepIterator?.hasNext() != true) { + return null + } + } + return currentStepIterator?.next() + } + private class QueueSerializer(private val dataSerializer: KSerializer) : KSerializer> { diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioStep.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioStep.kt index 7b73be12..a4f83260 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioStep.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioStep.kt @@ -3,16 +3,16 @@ package org.jetbrains.research.tasktracker.config.scenario.models import com.intellij.openapi.project.Project import kotlinx.serialization.Serializable import kotlinx.serialization.Transient -import org.jetbrains.research.tasktracker.config.BaseConfig import org.jetbrains.research.tasktracker.config.ide.MainIdeConfig import org.jetbrains.research.tasktracker.handler.BaseProjectHandler @Serializable data class ScenarioStep( private val ideConfig: MainIdeConfig?, - val units: List, + private val units: List, val mode: ScenarioStepMode = ScenarioStepMode.ORDERED ) { + @Transient private var mainIdeHandler: BaseProjectHandler? = null @@ -21,8 +21,9 @@ data class ScenarioStep( mainIdeHandler?.setup() } - fun run() { - TODO() + fun getUnits() = when (mode) { + ScenarioStepMode.ORDERED -> units + ScenarioStepMode.SHUFFLED -> units.shuffled() } // TODO check if there are any config of specified type in units. diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioUnit.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioUnit.kt new file mode 100644 index 00000000..5c1932d7 --- /dev/null +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioUnit.kt @@ -0,0 +1,23 @@ +package org.jetbrains.research.tasktracker.config.scenario.models + +import kotlinx.serialization.Serializable +import org.jetbrains.research.tasktracker.config.ide.MainIdeConfig +import org.jetbrains.research.tasktracker.config.survey.SurveyConfig + +@Serializable +sealed interface ScenarioUnit + +@Serializable +class TaskListUnit(val tasks: List) : ScenarioUnit + +@Serializable +class TaskUnit(val id: Int) : ScenarioUnit + +@Serializable +class IdeSettingUnit(val mainIdeConfig: MainIdeConfig) : ScenarioUnit + +@Serializable +class SurveyUnit(val surveyConfig: SurveyConfig) : ScenarioUnit + +@Serializable +class ExternalSourceUnit(val url: String) : ScenarioUnit diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/handler/scenario/ScenarioHandler.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/handler/scenario/ScenarioHandler.kt deleted file mode 100644 index 05fb6251..00000000 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/handler/scenario/ScenarioHandler.kt +++ /dev/null @@ -1,22 +0,0 @@ -package org.jetbrains.research.tasktracker.handler.scenario - -import org.jetbrains.research.tasktracker.config.MainTaskTrackerConfig -import org.jetbrains.research.tasktracker.config.scenario.models.ScenarioStep -import org.jetbrains.research.tasktracker.config.scenario.models.ScenarioUnitType - -@Suppress("UnusedPrivateMember") -class ScenarioHandler(private val mainConfig: MainTaskTrackerConfig) { - fun ScenarioStep.run() { - units.forEach { - when (it) { - ScenarioUnitType.IDE_SETTINGS -> { - // TODO: handle unit - } - - ScenarioUnitType.TASK_CONTENT -> { - // TODO: handle unit - } - } - } - } -} diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/Util.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/Util.kt index 669cd78a..1529fc1d 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/Util.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/Util.kt @@ -1,7 +1,9 @@ package org.jetbrains.research.tasktracker.ui.main.panel import com.intellij.openapi.util.io.FileUtil +import org.jetbrains.research.tasktracker.TaskTrackerPlugin import org.jetbrains.research.tasktracker.config.MainTaskTrackerConfig +import org.jetbrains.research.tasktracker.config.scenario.models.* 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 @@ -79,3 +81,33 @@ fun saveAgreements(agreementString: String) { FileUtil.createIfDoesntExist(agreementFile) agreementFile.writeText(agreementString) } + +fun processScenario() { + val scenario = + TaskTrackerPlugin.mainConfig.scenarioConfig?.scenario ?: error("Unexpected error, Scenario config must exist!") + when (TaskTrackerPlugin.mainConfig.scenarioConfig?.scenario?.getNextUnit()) { + is TaskListUnit -> { + TODO() + } + + is TaskUnit -> { + TODO() + } + + is IdeSettingUnit -> { + TODO() + } + + is SurveyUnit -> { + TODO() + } + + is ExternalSourceUnit -> { + TODO() + } + + null -> { + TODO() + } + } +} From 49c2ef8a3d92a9e064e5b79db9a61af2f8291bb8 Mon Sep 17 00:00:00 2001 From: mikrise2 Date: Sun, 19 Nov 2023 01:41:00 +0100 Subject: [PATCH 3/6] [ML4SE-234] process scenario on tasks and settings. --- .../config/scenario/models/Scenario.kt | 11 +- .../config/scenario/models/ScenarioStep.kt | 8 +- .../config/scenario/models/ScenarioUnit.kt | 12 +- .../tasktracker/handler/ide/IdeHandler.kt | 4 + .../handler/ide/InspectionHandler.kt | 5 + .../ui/main/panel/MainPluginPanelFactory.kt | 8 +- .../tasktracker/ui/main/panel/Util.kt | 32 --- .../main/panel/panelStates/DefaultStates.kt | 99 ++++---- .../ui/main/panel/storage/MainPanelStorage.kt | 3 + .../tasktracker/config/scenario_default.yaml | 215 +++++++++++++++++- 10 files changed, 313 insertions(+), 84 deletions(-) diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/Scenario.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/Scenario.kt index a2d0c881..96e15753 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/Scenario.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/Scenario.kt @@ -1,6 +1,7 @@ package org.jetbrains.research.tasktracker.config.scenario.models import com.intellij.openapi.diagnostic.Logger +import com.intellij.openapi.project.Project import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable import kotlinx.serialization.Transient @@ -8,6 +9,7 @@ import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder +import org.jetbrains.research.tasktracker.ui.main.panel.storage.MainPanelStorage import java.util.* @Serializable @@ -39,9 +41,11 @@ data class Scenario( } @Suppress("ReturnCount") - fun getNextUnit(): ScenarioUnit? { + fun getNextUnit(project: Project): ScenarioUnit? { if (currentStepIterator?.hasNext() != true) { + cleanStepSettings() val currentStep = getNextStep() ?: return null + currentStep.prepareSettings(project) currentStepIterator = currentStep.getUnits().iterator() if (currentStepIterator?.hasNext() != true) { return null @@ -50,6 +54,11 @@ data class Scenario( return currentStepIterator?.next() } + private fun cleanStepSettings() = + MainPanelStorage.activeIdeHandlers.forEach { + it.destroy() + } + private class QueueSerializer(private val dataSerializer: KSerializer) : KSerializer> { diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioStep.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioStep.kt index a4f83260..e61580be 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioStep.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioStep.kt @@ -5,11 +5,12 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.Transient import org.jetbrains.research.tasktracker.config.ide.MainIdeConfig import org.jetbrains.research.tasktracker.handler.BaseProjectHandler +import org.jetbrains.research.tasktracker.ui.main.panel.storage.MainPanelStorage @Serializable data class ScenarioStep( - private val ideConfig: MainIdeConfig?, private val units: List, + private val ideConfig: MainIdeConfig? = null, val mode: ScenarioStepMode = ScenarioStepMode.ORDERED ) { @@ -18,7 +19,10 @@ data class ScenarioStep( fun prepareSettings(project: Project) { mainIdeHandler = ideConfig?.buildHandler(project) - mainIdeHandler?.setup() + mainIdeHandler?.let { + MainPanelStorage.activeIdeHandlers.addFirst(it) + it.setup() + } } fun getUnits() = when (mode) { diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioUnit.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioUnit.kt index 5c1932d7..985b4ba8 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioUnit.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/scenario/models/ScenarioUnit.kt @@ -1,5 +1,6 @@ package org.jetbrains.research.tasktracker.config.scenario.models +import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import org.jetbrains.research.tasktracker.config.ide.MainIdeConfig import org.jetbrains.research.tasktracker.config.survey.SurveyConfig @@ -8,16 +9,25 @@ import org.jetbrains.research.tasktracker.config.survey.SurveyConfig sealed interface ScenarioUnit @Serializable +@SerialName("List") class TaskListUnit(val tasks: List) : ScenarioUnit @Serializable -class TaskUnit(val id: Int) : ScenarioUnit +@SerialName("SingleList") +class TaskListWithSingleChoiceUnit(val tasks: List) : ScenarioUnit @Serializable +@SerialName("Task") +class TaskUnit(val id: String) : ScenarioUnit + +@Serializable +@SerialName("Setting") class IdeSettingUnit(val mainIdeConfig: MainIdeConfig) : ScenarioUnit @Serializable +@SerialName("Survey") class SurveyUnit(val surveyConfig: SurveyConfig) : ScenarioUnit @Serializable +@SerialName("External") class ExternalSourceUnit(val url: String) : ScenarioUnit diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/handler/ide/IdeHandler.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/handler/ide/IdeHandler.kt index d618b848..828c7be1 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/handler/ide/IdeHandler.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/handler/ide/IdeHandler.kt @@ -18,4 +18,8 @@ class IdeHandler(override val config: MainIdeConfig, override val project: Proje it?.setup() } } + + override fun destroy() { + // TODO destroy + } } diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/handler/ide/InspectionHandler.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/handler/ide/InspectionHandler.kt index 46301f80..6f96dc84 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/handler/ide/InspectionHandler.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/handler/ide/InspectionHandler.kt @@ -14,8 +14,10 @@ import org.jetbrains.research.tasktracker.handler.BaseProjectHandler class InspectionHandler(override val config: InspectionConfig, override val project: Project) : BaseProjectHandler { private var inspectionDisposable: Disposable? = null private val logger: Logger = Logger.getInstance(InspectionHandler::class.java) + private var initialProfile: InspectionProfileImpl? = null override fun setup() { + initialProfile = ProjectInspectionProfileManager.getInstance(project).currentProfile // creating a new profile to make changes only in the current project val profile = initTaskProfile(project) applyConfig(profile) @@ -58,6 +60,9 @@ class InspectionHandler(override val config: InspectionConfig, override val proj } override fun destroy() { + initialProfile?.let { + ProjectInspectionProfileManager.getInstance(project).setCurrentProfile(it) + } inspectionDisposable?.let { Disposer.dispose(it) } } diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/MainPluginPanelFactory.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/MainPluginPanelFactory.kt index 4df90d3d..37b9d13a 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/MainPluginPanelFactory.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/MainPluginPanelFactory.kt @@ -97,18 +97,20 @@ class MainPluginPanelFactory : ToolWindowFactory { fun loadBasePage( template: HtmlTemplate, - buttonTextKey: String, - isVisibleBackButton: Boolean = true, + buttonTextKey: String? = null, + isVisibleBackButton: Boolean = false, backButtonText: String? = null, isVisibleNextButton: Boolean = true ) { mainWindow.loadHtmlTemplate(template) - nextButton.text = UIBundle.message(buttonTextKey) backButton.isVisible = isVisibleBackButton nextButton.isVisible = isVisibleNextButton backButtonText?.let { backButton.text = backButtonText } + buttonTextKey?.let { + nextButton.text = UIBundle.message(buttonTextKey) + } } @Suppress("UnusedPrivateMember") diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/Util.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/Util.kt index 1529fc1d..669cd78a 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/Util.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/Util.kt @@ -1,9 +1,7 @@ package org.jetbrains.research.tasktracker.ui.main.panel import com.intellij.openapi.util.io.FileUtil -import org.jetbrains.research.tasktracker.TaskTrackerPlugin import org.jetbrains.research.tasktracker.config.MainTaskTrackerConfig -import org.jetbrains.research.tasktracker.config.scenario.models.* 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 @@ -81,33 +79,3 @@ fun saveAgreements(agreementString: String) { FileUtil.createIfDoesntExist(agreementFile) agreementFile.writeText(agreementString) } - -fun processScenario() { - val scenario = - TaskTrackerPlugin.mainConfig.scenarioConfig?.scenario ?: error("Unexpected error, Scenario config must exist!") - when (TaskTrackerPlugin.mainConfig.scenarioConfig?.scenario?.getNextUnit()) { - is TaskListUnit -> { - TODO() - } - - is TaskUnit -> { - TODO() - } - - is IdeSettingUnit -> { - TODO() - } - - is SurveyUnit -> { - TODO() - } - - is ExternalSourceUnit -> { - TODO() - } - - null -> { - TODO() - } - } -} diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/panelStates/DefaultStates.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/panelStates/DefaultStates.kt index 503ebcc0..7b52492d 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/panelStates/DefaultStates.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/panelStates/DefaultStates.kt @@ -1,11 +1,13 @@ package org.jetbrains.research.tasktracker.ui.main.panel.panelStates import com.intellij.openapi.application.ApplicationManager +import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch +import org.jetbrains.research.tasktracker.TaskTrackerPlugin import org.jetbrains.research.tasktracker.config.content.task.base.Task import org.jetbrains.research.tasktracker.config.content.task.base.TaskWithFiles -import org.jetbrains.research.tasktracker.requests.FileRequests.send +import org.jetbrains.research.tasktracker.config.scenario.models.* import org.jetbrains.research.tasktracker.tracking.TaskFileHandler import org.jetbrains.research.tasktracker.tracking.activity.ActivityTracker import org.jetbrains.research.tasktracker.ui.main.panel.MainPluginPanelFactory @@ -43,10 +45,7 @@ fun Panel.agreementAcceptance() { fun Panel.welcomePage() { loadBasePage(MainPageTemplate.loadCurrentTemplate(), "ui.button.next", true) setNextAction { - selectTask() - } - setBackAction { - agreementAcceptance() + processScenario() } } @@ -54,6 +53,7 @@ fun Panel.welcomePage() { /** * Switches the panel to the task selection window. */ +@Suppress("UnusedPrivateMember") private fun Panel.selectTask() { loadBasePage( TasksPageTemplate(MainPanelStorage.taskIdTask.values.toList()), "ui.button.select", true @@ -73,16 +73,15 @@ private fun Panel.selectTask() { /** * Loads configs by selected task and language */ -private fun Panel.processTask(name: String) { - startTracking() - // TODO: change to task by id +fun Panel.processTask(id: String) { + startTracking() // TODO val task = - MainPanelStorage.taskIdTask.values.find { it.name == name } ?: error("Can't find task with name '$name'") + MainPanelStorage.taskIdTask.values.find { it.id == id } ?: error("Can't find task with id '$id'") ApplicationManager.getApplication().invokeAndWait { TaskFileHandler.initTask(project, task) } - (task as? TaskWithFiles)?.focusFileId?.let { id -> - focusOnfFileById(task, id) + (task as? TaskWithFiles)?.focusFileId?.let { fileId -> + focusOnfFileById(task, fileId) } solveTask(task) } @@ -93,49 +92,24 @@ private fun Panel.processTask(name: String) { */ private fun Panel.solveTask(task: Task) { val activityTracker = ActivityTracker(project) - activityTracker.startTracking() - loadBasePage( - SolvePageTemplate(task), "ui.button.submit", true - ) - setBackAction { - TaskFileHandler.disposeTask(project, task) - mainWindow.removeHandlers() - selectTask() - activityTracker.stopTracking() - } + activityTracker.startTracking() // TODO + loadBasePage(SolvePageTemplate(task)) setNextAction { TaskFileHandler.disposeTask(project, task) - mainWindow.removeHandlers() - welcomePage() - activityTracker.stopTracking() + processScenario() } listenFileRedirection(task) } -private fun Panel.survey() { - loadBasePage( - SurveyTemplate.loadCurrentTemplate(), "ui.button.submit", true - ) +@OptIn(DelicateCoroutinesApi::class) +fun Panel.survey() { + loadBasePage(SurveyTemplate.loadCurrentTemplate()) setNextAction { val surveyParser = SurveyParser(mainWindow, project) - // TODO: rewrite GlobalScope.launch { surveyParser.parseAndLog() - // TODO: unify - val isSuccessful = surveyParser.send() - if (!isSuccessful) { - serverErrorPage() - } - trackers.forEach { - it.stopTracking() - } - trackers.forEach { - if (!it.send()) { - serverErrorPage() - } - } - trackers.clear() } + processScenario() } } @@ -145,3 +119,42 @@ fun Panel.serverErrorPage() { ServerErrorPage(), "ui.button.welcome", false, isVisibleNextButton = false ) } + +fun Panel.processScenario() { + val scenario = + TaskTrackerPlugin.mainConfig.scenarioConfig?.scenario + ?: error("Unexpected error, Scenario config must exist!") + when (val unit = scenario.getNextUnit(project)) { + is TaskListUnit -> { + TODO() + } + + is TaskListWithSingleChoiceUnit -> { + TODO() + } + + is TaskUnit -> { + processTask(unit.id) + } + + is IdeSettingUnit -> { + unit.mainIdeConfig.buildHandler(project).also { + MainPanelStorage.activeIdeHandlers.addFirst(it) + it.setup() + } + processScenario() + } + + is SurveyUnit -> { + survey() + } + + is ExternalSourceUnit -> { + TODO() + } + + null -> { + TODO() + } + } +} diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/storage/MainPanelStorage.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/storage/MainPanelStorage.kt index e428afa1..fdf0512c 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/storage/MainPanelStorage.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/storage/MainPanelStorage.kt @@ -1,6 +1,8 @@ package org.jetbrains.research.tasktracker.ui.main.panel.storage import org.jetbrains.research.tasktracker.config.content.task.base.Task +import org.jetbrains.research.tasktracker.handler.BaseProjectHandler +import java.util.* /** * Stores all necessary data to build the main UI panel quickly @@ -9,4 +11,5 @@ object MainPanelStorage { var taskIdTask: MutableMap = mutableMapOf() var currentResearchId: Int? = null var userId: Int? = null + val activeIdeHandlers = LinkedList() } diff --git a/ij-plugin/src/main/resources/org/jetbrains/research/tasktracker/config/scenario_default.yaml b/ij-plugin/src/main/resources/org/jetbrains/research/tasktracker/config/scenario_default.yaml index 6cf854e1..bd39cb2d 100644 --- a/ij-plugin/src/main/resources/org/jetbrains/research/tasktracker/config/scenario_default.yaml +++ b/ij-plugin/src/main/resources/org/jetbrains/research/tasktracker/config/scenario_default.yaml @@ -1,6 +1,217 @@ scenario: steps: - units: - - "IDE_SETTINGS" + - ! + id: "hello" - units: - - "TASK_CONTENT" \ No newline at end of file + - ! + surveyConfig: + htmlQuestions: + - ! + text: Approximately how many hours did you use the plugin? + elementId: hours + type: number + required: true + min: 0 + step: 0.5 + - ! + text: 2. On a scale of 1 (very unlikely) to 5 (very likely), how likely are you to continue using the Emotion Tracker in the future? + elementId: likely + info: + - id: likely1 + value: 1 + - id: likely2 + value: 2 + - id: likely3 + value: 3 + - id: likely4 + value: 4 + - id: likely5 + value: 5 + - ! + text: 3. On a scale of 1 (not at all) to 5 (extremely), how much did the Emotion Tracker disrupt your workflow? + elementId: disrupt + info: + - id: disrupt1 + value: 1 + - id: disrupt2 + value: 2 + - id: disrupt3 + value: 3 + - id: disrupt4 + value: 4 + - id: disrupt5 + value: 5 + - ! + text: 4. On a scale of 1 (very inaccurate) to 5 (very accurate), how accurately did the Emotion Tracker capture your emotions? + elementId: accuracy + info: + - id: accuracy1 + value: 1 + - id: accuracy2 + value: 2 + - id: accuracy3 + value: 3 + - id: accuracy4 + value: 4 + - id: accuracy5 + value: 5 + - ! + text: 5. On a scale of 1 (not at all) to 5 (very comfortable), how comfortable were you with the plugin recording your emotions while coding? + elementId: comfort + info: + - id: comfort1 + value: 1 + - id: comfort2 + value: 2 + - id: comfort3 + value: 3 + - id: comfort4 + value: 4 + - id: comfort5 + value: 5 + - ! + text: 6. On a scale of 1 (not at all) to 5 (extremely), how helpful did you find the messages provided by the Emotion Tracker in aiding your self-regulation? + elementId: helpful + info: + - id: helpful1 + value: 1 + - id: helpful2 + value: 2 + - id: helpful3 + value: 3 + - id: helpful4 + value: 4 + - id: helpful5 + value: 5 + - ! + text: 7. During your experience with the Emotion Tracker, how often did you feel the following emotions? + questions: + - ! + text: Happiness + textSize: 4 + elementId: happiness + info: + - id: never_happy + value: Never + - id: rarely_happy + value: Rarely + - id: sometimes_happy + value: Sometimes + - id: often_happy + value: Often + - id: most_happy + value: Most of the time + - ! + text: Surprise + textSize: 4 + elementId: surprise + info: + - id: never_surprise + value: Never + - id: rarely_surprise + value: Rarely + - id: sometimes_surprise + value: Sometimes + - id: often_surprise + value: Often + - id: most_surprise + value: Most of the time + - ! + text: Neutral + textSize: 4 + elementId: neutral + info: + - id: never_neutral + value: Never + - id: rarely_neutral + value: Rarely + - id: sometimes_neutral + value: Sometimes + - id: often_neutral + value: Often + - id: most_neutral + value: Most of the time + - ! + text: Sadness + textSize: 4 + elementId: sadness + info: + - id: never_sad + value: Never + - id: rarely_sad + value: Rarely + - id: sometimes_sad + value: Sometimes + - id: often_sad + value: Often + - id: most_sad + value: Most of the time + - ! + text: Anger + textSize: 4 + elementId: anger + info: + - id: never_anger + value: Never + - id: rarely_anger + value: Rarely + - id: sometimes_anger + value: Sometimes + - id: often_anger + value: Often + - id: most_anger + value: Most of the time + - ! + text: Disgust + textSize: 4 + elementId: disgust + info: + - id: never_disgust + value: Never + - id: rarely_disgust + value: Rarely + - id: sometimes_disgust + value: Sometimes + - id: often_disgust + value: Often + - id: most_disgust + value: Most of the time + - ! + text: Fear + textSize: 4 + elementId: fear + info: + - id: never_fear + value: Never + - id: rarely_fear + value: Rarely + - id: sometimes_fear + value: Sometimes + - id: often_fear + value: Often + - id: most_fear + value: Most of the time + - ! + text: Contempt + textSize: 4 + elementId: contempt + info: + - id: never_contempt + value: Never + - id: rarely_contempt + value: Rarely + - id: sometimes_contempt + value: Sometimes + - id: often_contempt + value: Often + - id: most_contempt + value: Most of the time + - !