Skip to content

Commit

Permalink
Merge branch 'zowe-release/v1.2.1-223' into zowe-release/v1.2.1-231
Browse files Browse the repository at this point in the history
Signed-off-by: Uladzislau <[email protected]>
  • Loading branch information
KUGDev committed Jun 12, 2024
2 parents 516521a + 5528799 commit 7d7ba86
Show file tree
Hide file tree
Showing 7 changed files with 343 additions and 85 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,26 @@ All notable changes to the Zowe™ Explorer plug-in for IntelliJ IDEA™ will be

## [Unreleased]

### Features
* Feature: Change dialogs as DoNotAskOption is going to be removed soon ([0d6b5d57](https://github.com/zowe/zowe-explorer-intellij/commit/0d6b5d57))
* Feature: Add 'Unknown' to fields in dataset properties dialog when there is no information for fields ([5b32a4df](https://github.com/zowe/zowe-explorer-intellij/commit/5b32a4df))
* Feature: Validate owner when receiving information from TSO ([9db42fb8](https://github.com/zowe/zowe-explorer-intellij/commit/9db42fb8))
* Feature: Conflicts dialog on copy/move improvement ([c8f4d525](https://github.com/zowe/zowe-explorer-intellij/commit/c8f4d525))
* Feature: plug-in's description in JetBrains marketplace update ([5cc0086a](https://github.com/zowe/zowe-explorer-intellij/commit/5cc0086a))

### Bugfixes
* Bugfix: Rename of the opened file causes exception ([09453311](https://github.com/zowe/zowe-explorer-intellij/commit/09453311))
* Bugfix: Refresh does not work on the first try ([7af1c668](https://github.com/zowe/zowe-explorer-intellij/commit/7af1c668))
* Bugfix: "File Cache Conflict" when downloading file ([3f84b02a](https://github.com/zowe/zowe-explorer-intellij/commit/3f84b02a))
* Bugfix: Error opening an alias ([5b6ee654](https://github.com/zowe/zowe-explorer-intellij/commit/5b6ee654))
* Bugfix: Duplicate error messages ([c8ae8ddc](https://github.com/zowe/zowe-explorer-intellij/commit/c8ae8ddc))
* Bugfix: Rename file/folder to the same name causes exception ([3587a87b](https://github.com/zowe/zowe-explorer-intellij/commit/3587a87b))
* Bugfix: SyncAction: AWT events are not allowed inside write action ([796a6b9b](https://github.com/zowe/zowe-explorer-intellij/commit/796a6b9b))
* Bugfix: Warning dialog for downloading shows unnecessary scroll ([e7dc7427](https://github.com/zowe/zowe-explorer-intellij/commit/e7dc7427))
* Bugfix: Local cache conflict when overwriting local files ([f3039ac6](https://github.com/zowe/zowe-explorer-intellij/commit/f3039ac6))
* Bugfix: java.lang.RuntimeException: Cannot invoke (class=, method=onCacheUpdated, topic=cacheUpdated) ([2fedc7f5](https://github.com/zowe/zowe-explorer-intellij/commit/2fedc7f5))
* Bugfix: "Allocate like" action causes exception when refresh on mask is started ([d13a1c72](https://github.com/zowe/zowe-explorer-intellij/commit/d13a1c72))

## [1.2.0-231] (2024-04-16)

### Features
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright IBA Group 2020
*/

package org.zowe.explorer.utils.ui

import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.messages.MessageDialog
import com.intellij.ui.components.panels.NonOpaquePanel
import com.intellij.util.ui.UIUtil
import java.awt.Component
import java.awt.event.ActionEvent
import javax.swing.*

/**
* Windows like message dialog class which does the same stuff as @see Messages.showDialog() but
* uses Windows based representation of the dialog buttons
*/
class WindowsLikeMessageDialog(
project: Project?,
parentComponent: Component?,
message: String,
title: String,
options: Array<String>,
defaultOptionIndex: Int,
focusedOptionIndex: Int,
icon: Icon?,
doNotAskOption: com.intellij.openapi.ui.DoNotAskOption?,
canBeParent: Boolean,
helpId: String?
) : MessageDialog(
project,
parentComponent,
message,
title,
options,
defaultOptionIndex,
focusedOptionIndex,
icon,
doNotAskOption,
canBeParent,
helpId) {

companion object {
/**
* Static function is used to show Windows based message dialog
*/
fun showWindowsLikeMessageDialog(project: Project?,
parentComponent: Component? = null,
message: String,
title: String,
options: Array<String>,
defaultOptionIndex: Int,
focusedOptionIndex: Int,
icon: Icon? = null,
doNotAskOption: com.intellij.openapi.ui.DoNotAskOption? = null,
canBeParent: Boolean = false,
helpId: String? = null): Int {
val windowsLikeMessageDialog = WindowsLikeMessageDialog(project, parentComponent, message, title, options, defaultOptionIndex, focusedOptionIndex, icon, doNotAskOption, canBeParent, helpId)
windowsLikeMessageDialog.show()
return windowsLikeMessageDialog.exitCode
}
}

override fun createActions(): Array<Action> {
return mutableListOf<Action>().toTypedArray()
}

override fun createLeftSideActions(): Array<Action> {
val actions = mutableListOf<Action>()
for (i in myOptions.indices) {
val option = myOptions[i]
val action = object: AbstractAction(UIUtil.replaceMnemonicAmpersand(option)) {
override fun actionPerformed(e: ActionEvent?) {
close(i, true)
}
}

if (i == myDefaultOptionIndex) {
action.putValue(DEFAULT_ACTION, true);
}

if (i == myFocusedOptionIndex) {
action.putValue(FOCUSED_ACTION, true);
}

UIUtil.assignMnemonic(option, action);
actions.add(action);
}

if (helpId != null) {
actions.add(helpAction);
}
return actions.toTypedArray();
}

override fun createButtonsPanel(buttons: MutableList<out JButton>): JPanel {
return createLayoutButtonsPanel(buttons)
}

/**
* Function is used to create the bottom JComponent of the message dialog containing N buttons followed one by one
* using vertical direction
*/
private fun createLayoutButtonsPanel(buttons: MutableList<out JButton>): JPanel {
val buttonsPanel: JPanel = NonOpaquePanel()
val jPanels = mutableListOf<JPanel>()
buttonsPanel.layout = BoxLayout(buttonsPanel, BoxLayout.Y_AXIS)

for (i in buttons.indices) {
val button: JButton = buttons[i]
val jPanel: JPanel = NonOpaquePanel()
jPanel.add(button)
jPanels.add(jPanel)
}

jPanels.forEach { buttonsPanel.add(it) }
return buttonsPanel
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fun whoAmI(connectionConfig: ConnectionConfig): String? {
TsoOperation(
state = tsoSession,
mode = TsoOperationMode.SEND_MESSAGE,
messageType = MessageType.TSO_MESSAGE,
messageType = MessageType.TSO_RESPONSE,
messageData = MessageData.DATA_DATA,
message = "oshell whoami"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.zowe.explorer.explorer.FileExplorerContentProvider
import org.zowe.explorer.utils.castOrNull
import org.zowe.explorer.utils.getMinimalCommonParents
import org.zowe.explorer.utils.runWriteActionInEdtAndWait
import org.zowe.explorer.utils.ui.WindowsLikeMessageDialog
import org.zowe.explorer.vfs.MFVirtualFile
import kotlin.concurrent.withLock

Expand Down Expand Up @@ -467,18 +468,18 @@ class ExplorerPasteProvider : PasteProvider {
conflicts.removeAll(conflictsThatCannotBeOverwritten)

if (conflicts.isNotEmpty() || conflictsThatCannotBeOverwritten.isNotEmpty()) {
val choice = Messages.showDialog(
project,
"Please, select",
"Name conflicts in ${conflicts.size + conflictsThatCannotBeOverwritten.size} file(s)",
arrayOf(
//"Decide for Each",
"Skip for All",
"Overwrite for All",
"Decide for Each"
val choice = WindowsLikeMessageDialog.showWindowsLikeMessageDialog(
project = project,
message = "The destination already has file(s) with\nthe same name.\n" +
"Please, select an action.",
title = "Name conflicts in ${conflicts.size + conflictsThatCannotBeOverwritten.size} file(s)",
options = arrayOf(
"Skip the conflicting file(s)",
"Replace the file(s) in the destination",
"Decide for each file"
),
0,
AllIcons.General.QuestionDialog
defaultOptionIndex = 0,
focusedOptionIndex = 0
)

when (choice) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright IBA Group 2020
*/

package org.zowe.explorer.utils.ui

import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.ProjectManager
import com.intellij.ui.UiInterceptors
import org.zowe.explorer.testutils.WithApplicationShouldSpec
import io.kotest.assertions.assertSoftly
import io.kotest.matchers.shouldBe
import io.mockk.*
import java.awt.EventQueue
import javax.swing.Action
import javax.swing.JButton
import javax.swing.JPanel

class WindowsLikeMessageDialogTestSpec : WithApplicationShouldSpec({

afterSpec {
clearAllMocks()
}

context("Windows dialog common spec") {
val application = ApplicationManager.getApplication()
val project = ProjectManager.getInstance().defaultProject
mockkStatic(EventQueue::class)
mockkObject(application)
every { EventQueue.isDispatchThread() } returns true
every { application.isDispatchThread } returns true

val actions = arrayOf(
"Skip the conflicting file(s)",
"Replace the file(s) in the destination",
"Decide for each file"
)

val customDialog = WindowsLikeMessageDialog(
project,
null,
"The destination already has file(s) with\nthe same name.\n" +
"Please, select an action.",
"Name conflicts in 1 file(s)",
actions,
0,
0,
null,
null,
false,
"helpId"
)

val classUnderTest = spyk(customDialog, "testDialog")

should("create right side empty actions of the dialog") {
val expected = mutableListOf<Action>().toTypedArray()
val methodToTest = classUnderTest::class.java.declaredMethods.single { it.name == "createActions" }
val result = methodToTest.invoke(classUnderTest)

assertSoftly {
result as Array<*> shouldBe expected
}
}

should("create left side actions of the dialog") {
val methodToTest = classUnderTest::class.java.declaredMethods.single { it.name == "createLeftSideActions" }
val result = methodToTest.invoke(classUnderTest) as Array<*>
val actionToPerform = (result[0] as Action)

// Call default action to be able to cover lambda expression
actionToPerform.actionPerformed(null)

assertSoftly {
// Plus help action, because helpId is not null
result.size shouldBe 4
}
}

should("create buttons panel of the dialog with 3 buttons") {
val methodToTest = classUnderTest::class.java.declaredMethods.single { it.name == "createButtonsPanel" }
val arguments = mutableListOf(JButton(actions[0]), JButton(actions[1]), JButton(actions[2]))
val result = methodToTest.invoke(classUnderTest, arguments) as JPanel

assertSoftly {
((result.getComponent(0) as JPanel).getComponent(0) as JButton).text shouldBe "Skip the conflicting file(s)"
((result.getComponent(1) as JPanel).getComponent(0) as JButton).text shouldBe "Replace the file(s) in the destination"
((result.getComponent(2) as JPanel).getComponent(0) as JButton).text shouldBe "Decide for each file"
}
}
unmockkAll()
}

context("test showWindowsLikeMessageDialog static function") {
val project = ProjectManager.getInstance().defaultProject
mockkStatic(EventQueue::class)
every { EventQueue.isDispatchThread() } returns true

val actions = arrayOf(
"Skip the conflicting file(s)",
"Replace the file(s) in the destination",
"Decide for each file"
)

should("call showWindowsLikeMessageDialog") {
mockkStatic(UiInterceptors::class)
every { UiInterceptors.tryIntercept(any()) } returns true
val exitCode = WindowsLikeMessageDialog.showWindowsLikeMessageDialog(
project,
null,
"The destination already has file(s) with\nthe same name.\n" +
"Please, select an action.",
"Name conflicts in 1 file(s)",
actions,
0,
0,
null,
null,
false,
null
)
assertSoftly {
exitCode shouldBe 1
}
}
unmockkAll()
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class PurgeJobActionTestSpec : WithApplicationShouldSpec({
response.body()
} answers {
if (jobList.isNotEmpty()) {
jobList.removeFirst()
jobList.removeAt(0)
jobList
} else {
null
Expand Down
Loading

0 comments on commit 7d7ba86

Please sign in to comment.