From 7764c5eb7685ee406ba139765ed6f1a49bd2e22b Mon Sep 17 00:00:00 2001 From: Dominik Wojciechowski Date: Thu, 21 May 2020 20:50:54 +0200 Subject: [PATCH 1/4] Fix for linking run Remote Command with other configurations (#18) Fix for linking run Remote Command with other configurations --- build.gradle.kts | 8 +-- .../execution/RemoteCommandConfigType.kt | 19 ++++++ .../command}/RemoteCommandFactory.kt | 5 +- .../command/RemoteCommandProcessHandler.kt | 68 +++++++++++++++++++ .../command/RemoteCommandRunConfig.kt} | 33 ++++----- .../command/RemoteCommandSettings.kt | 12 ++++ .../command/RemoteCommandSettingsEditor.form} | 14 +++- .../command}/RemoteCommandSettingsEditor.kt | 17 +++-- .../execution/command/RemoteCommandState.kt | 22 ++++++ .../run/RemoteCommandConfigurationType.kt | 16 ----- .../run/state/RemoteCommandState.kt | 41 ----------- .../dwojciechowski/service/RemoteService.kt | 1 + .../service/impl/RemoteServiceImpl.kt | 11 ++- .../ui/panel/CommandLogPanel.kt | 9 ++- src/main/resources/META-INF/plugin.xml | 2 +- 15 files changed, 178 insertions(+), 100 deletions(-) create mode 100644 src/main/kotlin/pl/dwojciechowski/execution/RemoteCommandConfigType.kt rename src/main/kotlin/pl/dwojciechowski/{run/factory => execution/command}/RemoteCommandFactory.kt (71%) create mode 100644 src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandProcessHandler.kt rename src/main/kotlin/pl/dwojciechowski/{run/config/RemoteCommandConfigurationBase.kt => execution/command/RemoteCommandRunConfig.kt} (57%) create mode 100644 src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandSettings.kt rename src/main/kotlin/pl/dwojciechowski/{run/editor/RemoteSettingEditor.form => execution/command/RemoteCommandSettingsEditor.form} (80%) rename src/main/kotlin/pl/dwojciechowski/{run/editor => execution/command}/RemoteCommandSettingsEditor.kt (76%) create mode 100644 src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandState.kt delete mode 100644 src/main/kotlin/pl/dwojciechowski/run/RemoteCommandConfigurationType.kt delete mode 100644 src/main/kotlin/pl/dwojciechowski/run/state/RemoteCommandState.kt diff --git a/build.gradle.kts b/build.gradle.kts index 35e89ef..f322833 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,13 +2,13 @@ import com.google.protobuf.gradle.* import org.jetbrains.kotlin.gradle.tasks.KotlinCompile group = "pl.dwojciechowski" -version = "0.7.0" -val protobufVersion = "3.12.0" +version = "0.7.1" +val protobufVersion = "3.12.1" val rsocketRpcVersion = "0.2.18" val rsocketVersion = "1.0.0-RC7" -val coroutinesVersion = "1.3.6" +val coroutinesVersion = "1.3.7" val fuelVersion = "2.2.2" -val rxJavaVersion = "3.0.3" +val rxJavaVersion = "3.0.4" plugins { id("com.github.ben-manes.versions") version "0.28.0" diff --git a/src/main/kotlin/pl/dwojciechowski/execution/RemoteCommandConfigType.kt b/src/main/kotlin/pl/dwojciechowski/execution/RemoteCommandConfigType.kt new file mode 100644 index 0000000..7e3b2d5 --- /dev/null +++ b/src/main/kotlin/pl/dwojciechowski/execution/RemoteCommandConfigType.kt @@ -0,0 +1,19 @@ +package pl.dwojciechowski.execution + +import com.intellij.execution.configurations.ConfigurationFactory +import com.intellij.execution.configurations.ConfigurationTypeBase +import pl.dwojciechowski.execution.command.RemoteCommandFactory +import pl.dwojciechowski.ui.PluginIcons + +class RemoteCommandConfigType : ConfigurationTypeBase( + id = "PLMCompanion.RemoteCommand", + displayName = "Remote Command", + description = "Remote Command execution configuration", + icon = PluginIcons.PLUGIN +) { + + override fun getConfigurationFactories(): Array { + return arrayOf(RemoteCommandFactory(this)) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/pl/dwojciechowski/run/factory/RemoteCommandFactory.kt b/src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandFactory.kt similarity index 71% rename from src/main/kotlin/pl/dwojciechowski/run/factory/RemoteCommandFactory.kt rename to src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandFactory.kt index a2778f1..8481c37 100644 --- a/src/main/kotlin/pl/dwojciechowski/run/factory/RemoteCommandFactory.kt +++ b/src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandFactory.kt @@ -1,15 +1,14 @@ -package pl.dwojciechowski.run.factory +package pl.dwojciechowski.execution.command import com.intellij.execution.configurations.ConfigurationFactory import com.intellij.execution.configurations.ConfigurationType import com.intellij.openapi.project.Project -import pl.dwojciechowski.run.config.RemoteCommandConfigurationBase class RemoteCommandFactory(configurationType: ConfigurationType) : ConfigurationFactory(configurationType) { override fun createTemplateConfiguration(project: Project) = - RemoteCommandConfigurationBase(project, this, "") + RemoteCommandRunConfig(project, this, "") override fun getId() = "PLM_COMPANION.REMOTE_COMMAND" diff --git a/src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandProcessHandler.kt b/src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandProcessHandler.kt new file mode 100644 index 0000000..e0bac5c --- /dev/null +++ b/src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandProcessHandler.kt @@ -0,0 +1,68 @@ +package pl.dwojciechowski.execution.command + +import com.intellij.execution.Executor +import com.intellij.execution.process.NopProcessHandler +import com.intellij.execution.runners.ExecutionEnvironment +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.wm.ToolWindowManager +import pl.dwojciechowski.model.CommandBean +import pl.dwojciechowski.service.RemoteService +import java.time.LocalTime + +class RemoteCommandProcessHandler( + private val environment: ExecutionEnvironment, + private val executor: Executor? +) : NopProcessHandler() { + + private val remoteServiceManager = RemoteService.getInstance(environment.project) + private val runProfile = environment.runProfile as RemoteCommandRunConfig + + private val command = CommandBean(runProfile.settings.command, runProfile.settings.command, LocalTime.now()) + + override fun destroyProcess() { + super.destroyProcess() + switch() + } + + override fun startNotify() { + super.startNotify() + ApplicationManager.getApplication().invokeLater { + executeCommand() + } + } + + private fun executeCommand() { + if (runProfile.settings.async.not()) { + focusOnPluginTab() + remoteServiceManager.executeStreaming(command) { + destroyProcess() + } + } else { + remoteServiceManager.executeStreaming(command) + destroyProcess() + } + } + + private fun switch() { + getToolWindow(executor?.toolWindowId) + ?.let { toolWindow -> + toolWindow.contentManager.selectedContent?.let { + toolWindow.contentManager.removeContent(it, true) + focusOnPluginTab() + } + } + } + + private fun focusOnPluginTab() { + getToolWindow("PLM Companion Log")?.let { toolWindow -> + val contentManager = toolWindow.contentManager + contentManager.getContent(2)?.let { content -> + toolWindow.show() + contentManager.setSelectedContent(content, true, false) + } + } + } + + private fun getToolWindow(id: String?) = ToolWindowManager.getInstance(environment.project).getToolWindow(id) + +} \ No newline at end of file diff --git a/src/main/kotlin/pl/dwojciechowski/run/config/RemoteCommandConfigurationBase.kt b/src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandRunConfig.kt similarity index 57% rename from src/main/kotlin/pl/dwojciechowski/run/config/RemoteCommandConfigurationBase.kt rename to src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandRunConfig.kt index bc96dbd..c2a160e 100644 --- a/src/main/kotlin/pl/dwojciechowski/run/config/RemoteCommandConfigurationBase.kt +++ b/src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandRunConfig.kt @@ -1,25 +1,26 @@ -package pl.dwojciechowski.run.config +package pl.dwojciechowski.execution.command import com.intellij.execution.Executor -import com.intellij.execution.configurations.ConfigurationFactory -import com.intellij.execution.configurations.RunConfiguration -import com.intellij.execution.configurations.RunConfigurationBase -import com.intellij.execution.configurations.RunProfileState +import com.intellij.execution.configurations.* import com.intellij.execution.runners.ExecutionEnvironment import com.intellij.openapi.options.SettingsEditor import com.intellij.openapi.project.Project import com.intellij.util.xmlb.XmlSerializer import org.jdom.Element -import pl.dwojciechowski.run.editor.RemoteCommandSettingsEditor -import pl.dwojciechowski.run.state.RemoteCommandState -class RemoteCommandConfigurationBase( +class RemoteCommandRunConfig( project: Project, factory: ConfigurationFactory, name: String -) : RunConfigurationBase(project, factory, name) { +) : RunConfigurationBase(project, factory, name) { - var settings = RemoteCommandSettings("") + var settings = RemoteCommandSettings() + + override fun clone(): RunConfiguration { + val runConfiguration = super.clone() + (runConfiguration as RemoteCommandRunConfig).settings = RemoteCommandSettings() + return runConfiguration + } override fun getConfigurationEditor(): SettingsEditor { return RemoteCommandSettingsEditor(project) @@ -30,17 +31,9 @@ class RemoteCommandConfigurationBase( } override fun checkConfiguration() { - } - - data class RemoteCommandSettings(var command: String) : Cloneable { - companion object { - const val TAG = "RemoteCommandSettings" + if (settings.command.isEmpty()) { + throw RuntimeConfigurationWarning("Command may not be empty, provide non empty command") } - - /** - * For serialization - */ - constructor() : this(command = "") } override fun readExternal(element: Element) { diff --git a/src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandSettings.kt b/src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandSettings.kt new file mode 100644 index 0000000..b96f2fb --- /dev/null +++ b/src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandSettings.kt @@ -0,0 +1,12 @@ +package pl.dwojciechowski.execution.command + +data class RemoteCommandSettings( + var command: String = "", + var async: Boolean = true +) : Cloneable { + + companion object { + const val TAG = "RemoteCommandSettings" + } + +} \ No newline at end of file diff --git a/src/main/kotlin/pl/dwojciechowski/run/editor/RemoteSettingEditor.form b/src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandSettingsEditor.form similarity index 80% rename from src/main/kotlin/pl/dwojciechowski/run/editor/RemoteSettingEditor.form rename to src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandSettingsEditor.form index b03ccdd..646e93c 100644 --- a/src/main/kotlin/pl/dwojciechowski/run/editor/RemoteSettingEditor.form +++ b/src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandSettingsEditor.form @@ -1,5 +1,5 @@ -
+ @@ -8,7 +8,7 @@ - + @@ -26,7 +26,7 @@ - + @@ -37,6 +37,14 @@ + + + + + + + + diff --git a/src/main/kotlin/pl/dwojciechowski/run/editor/RemoteCommandSettingsEditor.kt b/src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandSettingsEditor.kt similarity index 76% rename from src/main/kotlin/pl/dwojciechowski/run/editor/RemoteCommandSettingsEditor.kt rename to src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandSettingsEditor.kt index c1e69b4..27e7ffe 100644 --- a/src/main/kotlin/pl/dwojciechowski/run/editor/RemoteCommandSettingsEditor.kt +++ b/src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandSettingsEditor.kt @@ -1,15 +1,14 @@ -package pl.dwojciechowski.run.editor +package pl.dwojciechowski.execution.command import com.intellij.openapi.components.ServiceManager import com.intellij.openapi.options.SettingsEditor import com.intellij.openapi.project.Project import pl.dwojciechowski.configuration.PluginConfiguration import pl.dwojciechowski.model.CommandBean -import pl.dwojciechowski.run.config.RemoteCommandConfigurationBase import pl.dwojciechowski.ui.component.CommandList import javax.swing.* -class RemoteCommandSettingsEditor(private val project: Project) : SettingsEditor() { +class RemoteCommandSettingsEditor(project: Project) : SettingsEditor() { private val config: PluginConfiguration = ServiceManager.getService(project, PluginConfiguration::class.java) @@ -18,6 +17,7 @@ class RemoteCommandSettingsEditor(private val project: Project) : SettingsEditor private lateinit var commandTF: JTextField private lateinit var commandHistory: CommandList private lateinit var listModel: DefaultListModel + private lateinit var async: JCheckBox private val splitPattern = "|#*#$" @@ -41,17 +41,16 @@ class RemoteCommandSettingsEditor(private val project: Project) : SettingsEditor } } - override fun resetEditorFrom(s: RemoteCommandConfigurationBase) { + override fun resetEditorFrom(s: RemoteCommandRunConfig) { commandTF.text = s.settings.command + async.isSelected = s.settings.async } - override fun applyEditorTo(s: RemoteCommandConfigurationBase) { + override fun applyEditorTo(s: RemoteCommandRunConfig) { s.settings.command = commandTF.text + s.settings.async = async.isSelected } - override fun createEditor(): JComponent { - return myPanel - } - + override fun createEditor() = myPanel } \ No newline at end of file diff --git a/src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandState.kt b/src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandState.kt new file mode 100644 index 0000000..18aead4 --- /dev/null +++ b/src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandState.kt @@ -0,0 +1,22 @@ +package pl.dwojciechowski.execution.command + +import com.intellij.execution.DefaultExecutionResult +import com.intellij.execution.ExecutionException +import com.intellij.execution.ExecutionResult +import com.intellij.execution.Executor +import com.intellij.execution.configurations.RunProfileState +import com.intellij.execution.runners.ExecutionEnvironment +import com.intellij.execution.runners.ProgramRunner + +class RemoteCommandState(private val environment: ExecutionEnvironment) : RunProfileState { + + private val runProfile = environment.runProfile as RemoteCommandRunConfig + + override fun execute(executor: Executor?, runner: ProgramRunner<*>): ExecutionResult? { + if (runProfile.settings.command.isEmpty()) { + throw ExecutionException("Could not execute command, no command provided") + } + return DefaultExecutionResult(RemoteCommandProcessHandler(environment, executor)) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/pl/dwojciechowski/run/RemoteCommandConfigurationType.kt b/src/main/kotlin/pl/dwojciechowski/run/RemoteCommandConfigurationType.kt deleted file mode 100644 index 9b8c5b6..0000000 --- a/src/main/kotlin/pl/dwojciechowski/run/RemoteCommandConfigurationType.kt +++ /dev/null @@ -1,16 +0,0 @@ -package pl.dwojciechowski.run - -import com.intellij.execution.configurations.ConfigurationFactory -import com.intellij.execution.configurations.ConfigurationTypeBase -import pl.dwojciechowski.run.factory.RemoteCommandFactory -import pl.dwojciechowski.ui.PluginIcons - -class RemoteCommandConfigurationType : ConfigurationTypeBase( - "PLMCompanion.RemoteCommand", "Remote Command", "Remote Command execution configuration", PluginIcons.PLUGIN -) { - - override fun getConfigurationFactories(): Array { - return arrayOf(RemoteCommandFactory(this)) - } - -} \ No newline at end of file diff --git a/src/main/kotlin/pl/dwojciechowski/run/state/RemoteCommandState.kt b/src/main/kotlin/pl/dwojciechowski/run/state/RemoteCommandState.kt deleted file mode 100644 index 1927fbf..0000000 --- a/src/main/kotlin/pl/dwojciechowski/run/state/RemoteCommandState.kt +++ /dev/null @@ -1,41 +0,0 @@ -package pl.dwojciechowski.run.state - -import com.intellij.execution.ExecutionResult -import com.intellij.execution.Executor -import com.intellij.execution.configurations.RunProfileState -import com.intellij.execution.runners.ExecutionEnvironment -import com.intellij.execution.runners.ProgramRunner -import com.intellij.openapi.wm.ToolWindowManager -import pl.dwojciechowski.model.CommandBean -import pl.dwojciechowski.run.config.RemoteCommandConfigurationBase -import pl.dwojciechowski.service.RemoteService -import java.time.LocalTime.now - -class RemoteCommandState(private val environment: ExecutionEnvironment) : RunProfileState { - - private val remoteServiceManager = RemoteService.getInstance(environment.project) - - override fun execute(executor: Executor?, runner: ProgramRunner<*>): ExecutionResult? { - focusCommandPane() - remoteServiceManager.executeStreaming(buildCommandBean()) - - return null - } - - private fun buildCommandBean(): CommandBean { - val configurationBase = environment.runProfile as RemoteCommandConfigurationBase - return CommandBean(configurationBase.settings.command, configurationBase.settings.command, now()) - } - - private fun focusCommandPane() { - val instance = ToolWindowManager.getInstance(environment.project) - instance.getToolWindow("PLM Companion Log")?.let { toolWindow -> - val contentManager = toolWindow.contentManager - contentManager.getContent(2)?.let { content -> - toolWindow.show() - contentManager.setSelectedContent(content, true, false) - } - } - } - -} \ No newline at end of file diff --git a/src/main/kotlin/pl/dwojciechowski/service/RemoteService.kt b/src/main/kotlin/pl/dwojciechowski/service/RemoteService.kt index bade808..d938855 100644 --- a/src/main/kotlin/pl/dwojciechowski/service/RemoteService.kt +++ b/src/main/kotlin/pl/dwojciechowski/service/RemoteService.kt @@ -18,6 +18,7 @@ interface RemoteService { fun restartWnc() fun xconf() fun executeStreaming(commandBean: CommandBean) + fun executeStreaming(commandBean: CommandBean, doFinally: () -> Unit) fun getOutputSubject(): Subject diff --git a/src/main/kotlin/pl/dwojciechowski/service/impl/RemoteServiceImpl.kt b/src/main/kotlin/pl/dwojciechowski/service/impl/RemoteServiceImpl.kt index b78b047..4198800 100644 --- a/src/main/kotlin/pl/dwojciechowski/service/impl/RemoteServiceImpl.kt +++ b/src/main/kotlin/pl/dwojciechowski/service/impl/RemoteServiceImpl.kt @@ -39,25 +39,30 @@ class RemoteServiceImpl(private val project: Project) : RemoteService { } override fun executeStreaming(commandBean: CommandBean) { + executeStreaming(commandBean) {} + } + + override fun executeStreaming(commandBean: CommandBean, doFinally: () -> Unit) { try { val command = commandBean.getCommand() commandBean.status = CommandBean.ExecutionStatus.RUNNING PLMPluginNotification.notify(project, "$commandBean started", PluginIcons.CONFIRMATION) commandBean.response.onNext("Started execution of $commandBean") val rSocket = connector.establishConnection() - rSocket.executeStreamingCall(command, commandBean) + rSocket.executeStreamingCall(command, commandBean, doFinally) commandBean.actualSubscription = rSocket ?: commandBean.actualSubscription commandSubject.onNext(commandBean) } catch (e: Exception) { commandBean.status = CommandBean.ExecutionStatus.STOPPED commandBean.response.onNext(e.message) + doFinally() ApplicationManager.getApplication().invokeLater { Messages.showErrorDialog(project, Exceptions.unwrap(e).message ?: "", "Connection exception") } } } - private fun RSocket?.executeStreamingCall(command: Command, commandBean: CommandBean) { + private fun RSocket?.executeStreamingCall(command: Command, commandBean: CommandBean, doFinally: () -> Unit) { CommandServiceClient(this) .executeStreaming(command) .doOnNext { @@ -76,6 +81,8 @@ class RemoteServiceImpl(private val project: Project) : RemoteService { } else { PLMPluginNotification.notify(project, "Error on $commandBean", PluginIcons.ERROR) } + }.doFinally { + doFinally() }.subscribe() } diff --git a/src/main/kotlin/pl/dwojciechowski/ui/panel/CommandLogPanel.kt b/src/main/kotlin/pl/dwojciechowski/ui/panel/CommandLogPanel.kt index cba6d01..533e001 100644 --- a/src/main/kotlin/pl/dwojciechowski/ui/panel/CommandLogPanel.kt +++ b/src/main/kotlin/pl/dwojciechowski/ui/panel/CommandLogPanel.kt @@ -1,5 +1,6 @@ package pl.dwojciechowski.ui.panel +import com.intellij.execution.ui.ExecutionConsole import com.intellij.icons.AllIcons import com.intellij.openapi.components.ServiceManager import com.intellij.openapi.project.Project @@ -14,7 +15,7 @@ import javax.swing.JButton import javax.swing.JPanel import javax.swing.JTextArea -class CommandLogPanel(project: Project) : SimpleToolWindowPanel(false, true) { +class CommandLogPanel(project: Project) : SimpleToolWindowPanel(false, true), ExecutionConsole { private val commandService: RemoteService = ServiceManager.getService(project, RemoteService::class.java) @@ -106,4 +107,10 @@ class CommandLogPanel(project: Project) : SimpleToolWindowPanel(false, true) { private fun DefaultListModel.selected() = this.get(list.selectedIndex) + override fun getPreferredFocusableComponent() = panel + + override fun getComponent() = panel + + override fun dispose() {} + } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 846dd9f..eb58a49 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -7,7 +7,7 @@ - + From 35b2884e3ca12db4e7860c8f03d725190641b60c Mon Sep 17 00:00:00 2001 From: Dominik Wojciechowski Date: Thu, 21 May 2020 20:57:21 +0200 Subject: [PATCH 2/4] Update change-notes.html --- src/main/resources/META-INF/change-notes.html | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/resources/META-INF/change-notes.html b/src/main/resources/META-INF/change-notes.html index e522cdc..65e624d 100644 --- a/src/main/resources/META-INF/change-notes.html +++ b/src/main/resources/META-INF/change-notes.html @@ -1,6 +1,13 @@
    Remember, after update of this plugin, update also server-side addon. +
  • 0.7.1 +
      +
    • Fix for issue with linking run configurations.
    • +
    • Fix for shared command between run configurations.
    • +
    • Added option to wait until finish of remote command
    • +
    +
  • 0.7.0
    • Added button group to navigation bar with an option to disable it in the configuration.
    • @@ -28,4 +35,4 @@
    • 0.1.2 - Windchill basic control (stop/start/restart) with server add-on
    • 0.1.1 - Windchill status scanner
    - \ No newline at end of file + From 5af8e47bf341e6f0a6349c38ae0709459a8178db Mon Sep 17 00:00:00 2001 From: Dominik Wojciechowski Date: Fri, 22 May 2020 08:12:02 +0200 Subject: [PATCH 3/4] Fix for not persisted alias to config --- .../pl/dwojciechowski/model/CommandBean.kt | 6 ++--- .../ui/component/action/EditListAction.kt | 4 +++- .../ui/panel/CommandSubPanel.kt | 22 +++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/kotlin/pl/dwojciechowski/model/CommandBean.kt b/src/main/kotlin/pl/dwojciechowski/model/CommandBean.kt index 0c2b07c..c9ffd7f 100644 --- a/src/main/kotlin/pl/dwojciechowski/model/CommandBean.kt +++ b/src/main/kotlin/pl/dwojciechowski/model/CommandBean.kt @@ -9,11 +9,11 @@ import java.time.LocalTime data class CommandBean( var name: String, var command: String, - var executionTime: LocalTime = LocalTime.MIN, + var executionTime: LocalTime = LocalTime.now(), var status: ExecutionStatus = ExecutionStatus.NONE, var response: ReplaySubject = ReplaySubject.create(), var actualSubscription: Disposable = Disposables.never() -) { +) : Cloneable { override fun toString(): String { return if (name.isNotEmpty()) name else command @@ -25,7 +25,7 @@ data class CommandBean( .build() } - fun safeCopy() = + public override fun clone() = CommandBean(name, command, LocalTime.now(), ExecutionStatus.NONE, ReplaySubject.create(), Disposables.never()) enum class ExecutionStatus { diff --git a/src/main/kotlin/pl/dwojciechowski/ui/component/action/EditListAction.kt b/src/main/kotlin/pl/dwojciechowski/ui/component/action/EditListAction.kt index 55966cd..3a3331d 100644 --- a/src/main/kotlin/pl/dwojciechowski/ui/component/action/EditListAction.kt +++ b/src/main/kotlin/pl/dwojciechowski/ui/component/action/EditListAction.kt @@ -13,7 +13,8 @@ import javax.swing.border.EmptyBorder class EditListAction( private val list: JBList, - private val commandFieldName: String = "command" + private val commandFieldName: String = "command", + private val doFinally: () -> Unit = {} ) : AbstractAction() { private lateinit var editPopup: JPopupMenu @@ -70,6 +71,7 @@ class EditListAction( model.get(selectedIndex).name = value } editPopup.isVisible = false + doFinally() } } \ No newline at end of file diff --git a/src/main/kotlin/pl/dwojciechowski/ui/panel/CommandSubPanel.kt b/src/main/kotlin/pl/dwojciechowski/ui/panel/CommandSubPanel.kt index 722785a..b64bb76 100644 --- a/src/main/kotlin/pl/dwojciechowski/ui/panel/CommandSubPanel.kt +++ b/src/main/kotlin/pl/dwojciechowski/ui/panel/CommandSubPanel.kt @@ -13,7 +13,6 @@ import pl.dwojciechowski.service.RemoteService import pl.dwojciechowski.ui.component.CommandList import pl.dwojciechowski.ui.component.action.EditListAction import java.awt.event.KeyEvent -import java.time.LocalTime import java.util.* import javax.swing.DefaultListModel import javax.swing.JButton @@ -92,18 +91,19 @@ class CommandSubPanel( private fun addToModel() { listModel.add(0, CommandBean("", commandField.text)) - dispose() + saveToConfig() } private fun CommandList.setUpCommandHistoryRMBMenu() { - this.addRMBMenuEntry("Run") { + addRMBMenuEntry("Run") { executeSelectedCommand() } - .addRMBMenuEntry("Edit", action = EditListAction(this)) - .addRMBMenuEntry("Delete") { - listModel.remove(selectedIndex) - } - .addRMBMenuEntry("Alias", action = EditListAction(this, "name")) + addRMBMenuEntry("Delete") { + listModel.remove(selectedIndex) + saveToConfig() + } + addRMBMenuEntry("Edit", action = EditListAction(this) { saveToConfig() }) + addRMBMenuEntry("Alias", action = EditListAction(this, "name") { saveToConfig() }) } private fun executeFromInput() { @@ -122,13 +122,11 @@ class CommandSubPanel( project, "No command selected", "Missing selection error", Messages.getErrorIcon() ) } else { - val commandBean = commandHistory.selectedValue.safeCopy() - commandBean.executionTime = LocalTime.now() - windchillService.executeStreaming(commandBean) + windchillService.executeStreaming(commandHistory.selectedValue.clone()) } } - fun dispose() { + private fun saveToConfig() { config.commandsHistory = listModel.elements().toList() .reversed() .map { "${it.name}$splitPattern${it.command}" } From ef2a9dae9a9e26287bf9620c060971e61939e8b7 Mon Sep 17 00:00:00 2001 From: Dominik Wojciechowski Date: Fri, 22 May 2020 08:48:59 +0200 Subject: [PATCH 4/4] Added option to automatically switch to command pane. --- .../configuration/PluginConfiguration.kt | 1 + .../command/RemoteCommandProcessHandler.kt | 26 +++++----------- .../service/IdeControlService.kt | 16 ++++++++++ .../service/impl/IdeControlServiceImpl.kt | 21 +++++++++++++ .../ui/dialog/PluginSettingsDialog.form | 31 +++++++++++++------ .../ui/dialog/PluginSettingsDialog.kt | 3 ++ .../ui/panel/CommandSubPanel.kt | 8 +++++ src/main/resources/META-INF/change-notes.html | 4 ++- src/main/resources/META-INF/plugin.xml | 2 ++ 9 files changed, 84 insertions(+), 28 deletions(-) create mode 100644 src/main/kotlin/pl/dwojciechowski/service/IdeControlService.kt create mode 100644 src/main/kotlin/pl/dwojciechowski/service/impl/IdeControlServiceImpl.kt diff --git a/src/main/kotlin/pl/dwojciechowski/configuration/PluginConfiguration.kt b/src/main/kotlin/pl/dwojciechowski/configuration/PluginConfiguration.kt index 98b92c5..1d57235 100644 --- a/src/main/kotlin/pl/dwojciechowski/configuration/PluginConfiguration.kt +++ b/src/main/kotlin/pl/dwojciechowski/configuration/PluginConfiguration.kt @@ -21,6 +21,7 @@ class PluginConfiguration : PersistentStateComponent { var scanWindchill: Boolean = false var statusControlled: Boolean = true + var autoOpenCommandPane: Boolean = false var port: Int = 80 var addonPort: Int = 4040 diff --git a/src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandProcessHandler.kt b/src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandProcessHandler.kt index e0bac5c..f1c8325 100644 --- a/src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandProcessHandler.kt +++ b/src/main/kotlin/pl/dwojciechowski/execution/command/RemoteCommandProcessHandler.kt @@ -4,24 +4,25 @@ import com.intellij.execution.Executor import com.intellij.execution.process.NopProcessHandler import com.intellij.execution.runners.ExecutionEnvironment import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.wm.ToolWindowManager import pl.dwojciechowski.model.CommandBean +import pl.dwojciechowski.service.IdeControlService import pl.dwojciechowski.service.RemoteService import java.time.LocalTime class RemoteCommandProcessHandler( - private val environment: ExecutionEnvironment, + environment: ExecutionEnvironment, private val executor: Executor? ) : NopProcessHandler() { private val remoteServiceManager = RemoteService.getInstance(environment.project) + private val ideControlService = IdeControlService.getInstance(environment.project) private val runProfile = environment.runProfile as RemoteCommandRunConfig private val command = CommandBean(runProfile.settings.command, runProfile.settings.command, LocalTime.now()) override fun destroyProcess() { super.destroyProcess() - switch() + switchToSelectedTab() } override fun startNotify() { @@ -33,7 +34,7 @@ class RemoteCommandProcessHandler( private fun executeCommand() { if (runProfile.settings.async.not()) { - focusOnPluginTab() + ideControlService.switchToCommandTab() remoteServiceManager.executeStreaming(command) { destroyProcess() } @@ -43,26 +44,15 @@ class RemoteCommandProcessHandler( } } - private fun switch() { - getToolWindow(executor?.toolWindowId) + private fun switchToSelectedTab() { + ideControlService.getToolWindow(executor?.toolWindowId) ?.let { toolWindow -> toolWindow.contentManager.selectedContent?.let { toolWindow.contentManager.removeContent(it, true) - focusOnPluginTab() + ideControlService.switchToCommandTab() } } } - private fun focusOnPluginTab() { - getToolWindow("PLM Companion Log")?.let { toolWindow -> - val contentManager = toolWindow.contentManager - contentManager.getContent(2)?.let { content -> - toolWindow.show() - contentManager.setSelectedContent(content, true, false) - } - } - } - - private fun getToolWindow(id: String?) = ToolWindowManager.getInstance(environment.project).getToolWindow(id) } \ No newline at end of file diff --git a/src/main/kotlin/pl/dwojciechowski/service/IdeControlService.kt b/src/main/kotlin/pl/dwojciechowski/service/IdeControlService.kt new file mode 100644 index 0000000..00fab36 --- /dev/null +++ b/src/main/kotlin/pl/dwojciechowski/service/IdeControlService.kt @@ -0,0 +1,16 @@ +package pl.dwojciechowski.service + +import com.intellij.openapi.components.ServiceManager +import com.intellij.openapi.project.Project +import com.intellij.openapi.wm.ToolWindow + +interface IdeControlService { + companion object { + fun getInstance(project: Project): IdeControlService { + return ServiceManager.getService(project, IdeControlService::class.java) + } + } + + fun switchToCommandTab() + fun getToolWindow(id: String?): ToolWindow? +} \ No newline at end of file diff --git a/src/main/kotlin/pl/dwojciechowski/service/impl/IdeControlServiceImpl.kt b/src/main/kotlin/pl/dwojciechowski/service/impl/IdeControlServiceImpl.kt new file mode 100644 index 0000000..0376da7 --- /dev/null +++ b/src/main/kotlin/pl/dwojciechowski/service/impl/IdeControlServiceImpl.kt @@ -0,0 +1,21 @@ +package pl.dwojciechowski.service.impl + +import com.intellij.openapi.project.Project +import com.intellij.openapi.wm.ToolWindowManager +import pl.dwojciechowski.service.IdeControlService + +class IdeControlServiceImpl(private val project: Project) : IdeControlService { + + override fun switchToCommandTab() { + getToolWindow("PLM Companion Log")?.let { toolWindow -> + val contentManager = toolWindow.contentManager + contentManager.getContent(2)?.let { content -> + toolWindow.show() + contentManager.setSelectedContent(content, true, false) + } + } + } + + override fun getToolWindow(id: String?) = ToolWindowManager.getInstance(project).getToolWindow(id) + +} \ No newline at end of file diff --git a/src/main/kotlin/pl/dwojciechowski/ui/dialog/PluginSettingsDialog.form b/src/main/kotlin/pl/dwojciechowski/ui/dialog/PluginSettingsDialog.form index caee27a..5c1c8e4 100644 --- a/src/main/kotlin/pl/dwojciechowski/ui/dialog/PluginSettingsDialog.form +++ b/src/main/kotlin/pl/dwojciechowski/ui/dialog/PluginSettingsDialog.form @@ -3,7 +3,7 @@ - + @@ -271,14 +271,6 @@ - - - - - - - - @@ -287,6 +279,27 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/kotlin/pl/dwojciechowski/ui/dialog/PluginSettingsDialog.kt b/src/main/kotlin/pl/dwojciechowski/ui/dialog/PluginSettingsDialog.kt index 4966edc..0e10f7f 100644 --- a/src/main/kotlin/pl/dwojciechowski/ui/dialog/PluginSettingsDialog.kt +++ b/src/main/kotlin/pl/dwojciechowski/ui/dialog/PluginSettingsDialog.kt @@ -42,6 +42,7 @@ class PluginSettingsDialog(private val project: Project) : DialogWrapper(project private lateinit var addonPortSpinner: JSpinner private lateinit var actionPresentationCB: JComboBox private lateinit var statusControlled: JCheckBox + private lateinit var autoOpenCommandPane: JCheckBox fun createUIComponents() { actionPresentationCB = ComboBox(ActionPresentationOption.ALL_OPTIONS.toArray(arrayOf())) @@ -111,6 +112,7 @@ class PluginSettingsDialog(private val project: Project) : DialogWrapper(project actionPresentationCB.selectedItem = config.actionPresentation folderPathTextFile.text = config.lffFolder statusControlled.isSelected = config.statusControlled + autoOpenCommandPane.isSelected = config.autoOpenCommandPane resultingTextField.composeURL() } @@ -130,6 +132,7 @@ class PluginSettingsDialog(private val project: Project) : DialogWrapper(project config.actionPresentation = actionPresentationCB.selectedItem as String config.lffFolder = folderPathTextFile.text config.statusControlled = statusControlled.isSelected + config.autoOpenCommandPane = autoOpenCommandPane.isSelected } private fun JTextField.composeURL() { diff --git a/src/main/kotlin/pl/dwojciechowski/ui/panel/CommandSubPanel.kt b/src/main/kotlin/pl/dwojciechowski/ui/panel/CommandSubPanel.kt index b64bb76..f3fba99 100644 --- a/src/main/kotlin/pl/dwojciechowski/ui/panel/CommandSubPanel.kt +++ b/src/main/kotlin/pl/dwojciechowski/ui/panel/CommandSubPanel.kt @@ -9,6 +9,7 @@ import com.intellij.ui.RawCommandLineEditor import com.intellij.util.ui.UIUtil import pl.dwojciechowski.configuration.PluginConfiguration import pl.dwojciechowski.model.CommandBean +import pl.dwojciechowski.service.IdeControlService import pl.dwojciechowski.service.RemoteService import pl.dwojciechowski.ui.component.CommandList import pl.dwojciechowski.ui.component.action.EditListAction @@ -25,6 +26,7 @@ class CommandSubPanel( private val config: PluginConfiguration = ServiceManager.getService(project, PluginConfiguration::class.java) private val windchillService = ServiceManager.getService(project, RemoteService::class.java) + private val ideControlService = ServiceManager.getService(project, IdeControlService::class.java) private val splitPattern = "|#*#$" @@ -114,6 +116,9 @@ class CommandSubPanel( } else { windchillService.executeStreaming(CommandBean("", commandField.text)) } + if (config.autoOpenCommandPane) { + ideControlService.switchToCommandTab() + } } private fun executeSelectedCommand() { @@ -124,6 +129,9 @@ class CommandSubPanel( } else { windchillService.executeStreaming(commandHistory.selectedValue.clone()) } + if (config.autoOpenCommandPane) { + ideControlService.switchToCommandTab() + } } private fun saveToConfig() { diff --git a/src/main/resources/META-INF/change-notes.html b/src/main/resources/META-INF/change-notes.html index 65e624d..fb45917 100644 --- a/src/main/resources/META-INF/change-notes.html +++ b/src/main/resources/META-INF/change-notes.html @@ -5,7 +5,9 @@
    • Fix for issue with linking run configurations.
    • Fix for shared command between run configurations.
    • -
    • Added option to wait until finish of remote command
    • +
    • Fix for Alias not being saved
    • +
    • Added option to wait until the finish of remote command
    • +
    • Added option to immediately switch to command pane
  • 0.7.0 diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index eb58a49..71ebc6b 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -28,6 +28,8 @@ serviceImplementation="pl.dwojciechowski.service.impl.ConnectorServiceImpl"/> +