diff --git a/src/main/kotlin/org/zowe/explorer/explorer/actions/CreateUssEntityAction.kt b/src/main/kotlin/org/zowe/explorer/explorer/actions/CreateUssEntityAction.kt index dd926a2a4..ca98561db 100644 --- a/src/main/kotlin/org/zowe/explorer/explorer/actions/CreateUssEntityAction.kt +++ b/src/main/kotlin/org/zowe/explorer/explorer/actions/CreateUssEntityAction.kt @@ -32,6 +32,7 @@ import org.zowe.explorer.utils.castOrNull import org.zowe.explorer.utils.service // TODO: remove in v1.*.*-223 and greater import org.zowe.explorer.vfs.MFVirtualFile import org.zowe.kotlinsdk.ChangeMode +import org.zowe.kotlinsdk.FileModeValue import org.zowe.kotlinsdk.FileType /** @@ -58,67 +59,73 @@ abstract class CreateUssEntityAction : AnAction() { val view = e.getExplorerView() ?: return val selected = view.mySelectedNodesData[0] val selectedNode = selected.node - val node = if (selectedNode is UssFileNode) { - selectedNode.parent?.takeIf { it is UssDirNode } + + val node: UssDirNode = if (selectedNode is UssFileNode) { + selectedNode.parent?.takeIf { it is UssDirNode } as UssDirNode } else { - selectedNode.takeIf { it is UssDirNode } + selectedNode.takeIf { it is UssDirNode } as UssDirNode } ?: return + + val connectionConfig = node.unit.connectionConfig ?: return + val dataOpsManager = DataOpsManager.instance + val file = node.virtualFile - // TODO: Why is it highlighted ??? - if (node is ExplorerUnitTreeNodeBase<*, *, *>) { - val connectionConfig = node.unit.connectionConfig.castOrNull() ?: return - val dataOpsManager = node.unit.explorer.componentManager.service() - val filePath = if (file != null) { - dataOpsManager.getAttributesService() - .getAttributes(file)?.path + val attributes = file?.let { + dataOpsManager.getAttributesService() + .getAttributes(it) + } + + val filePath = attributes?.path ?: node.value.path + + showUntilDone( + initialState = fileType.apply { path = filePath }, + { initState -> CreateFileDialog(e.project, state = initState, filePath = filePath) } + ) { + var res = false + val allocationParams = it.toAllocationParams() + val fileType = if (allocationParams.parameters.type == FileType.FILE) { + "File" } else { - (node as UssDirNode).value.path + "Directory" } - if (filePath != null) { - showUntilDone( - initialState = fileType.apply { path = filePath }, - { initState -> CreateFileDialog(e.project, state = initState, filePath = filePath) } - ) { - var res = false - val allocationParams = it.toAllocationParams() - val fileType = if (allocationParams.parameters.type == FileType.FILE) { - "File" - } else { - "Directory" + runModalTask( + title = "Creating $fileType ${allocationParams.fileName}", + project = e.project, + cancellable = true + ) { indicator -> + runCatching { + dataOpsManager.performOperation( + operation = UssAllocationOperation( + request = allocationParams, + connectionConfig = connectionConfig + ), + progressIndicator = indicator + ) + + val fileFetchProvider = dataOpsManager + .getFileFetchProvider, MFVirtualFile>( + UssQuery::class.java, RemoteQuery::class.java, MFVirtualFile::class.java + ) + + attributes?.fileMode?.let { fm -> + if (checkReadPermissionsBeforeReload(fm.owner)) { + node.query?.let { query -> fileFetchProvider.reload(query) } + } } - runModalTask( - title = "Creating $fileType ${allocationParams.fileName}", - project = e.project, - cancellable = true - ) { indicator -> - val ussDirNode = node.castOrNull() - runCatching { - dataOpsManager.performOperation( - operation = UssAllocationOperation( - request = allocationParams, - connectionConfig = connectionConfig - ), - progressIndicator = indicator - ) - - val fileFetchProvider = dataOpsManager - .getFileFetchProvider, MFVirtualFile>( - UssQuery::class.java, RemoteQuery::class.java, MFVirtualFile::class.java - ) - ussDirNode?.query?.let { query -> fileFetchProvider.reload(query) } - - changeFileModeIfNeeded(file, allocationParams, connectionConfig, indicator) - - }.onSuccess { - ussDirNode?.cleanCache(false) - res = true - }.onFailure { t -> - view.explorer.reportThrowable(t, e.project) + + changeFileModeIfNeeded(file, allocationParams, connectionConfig, indicator) + }.onSuccess { + attributes?.fileMode?.let { fm -> + if (checkReadPermissionsBeforeReload(fm.owner)) { + node.cleanCache(false) } } - res + res = true + }.onFailure { t -> + view.explorer.reportThrowable(t, e.project) } } + res } } @@ -175,4 +182,11 @@ abstract class CreateUssEntityAction : AnAction() { e.presentation.isEnabled = false } } + + private fun checkReadPermissionsBeforeReload(permission: Int): Boolean { + return permission == FileModeValue.READ.mode || + permission == FileModeValue.READ_EXECUTE.mode || + permission == FileModeValue.READ_WRITE.mode || + permission == FileModeValue.READ_WRITE_EXECUTE.mode + } } diff --git a/src/main/kotlin/org/zowe/explorer/explorer/ui/ExplorerTreeView.kt b/src/main/kotlin/org/zowe/explorer/explorer/ui/ExplorerTreeView.kt index 2abb20d6c..798c9a77d 100644 --- a/src/main/kotlin/org/zowe/explorer/explorer/ui/ExplorerTreeView.kt +++ b/src/main/kotlin/org/zowe/explorer/explorer/ui/ExplorerTreeView.kt @@ -57,11 +57,11 @@ val EXPLORER_VIEW = DataKey.create>("explorerView") private val log = log>() -fun > AnActionEvent.getExplorerView(clazz: Class): ExplorerView? { +fun > AnActionEvent.getExplorerView(clazz: Class): ExplorerView? { return getData(EXPLORER_VIEW).castOrNull(clazz) } -inline fun > AnActionEvent.getExplorerView(): ExplorerView? { +inline fun > AnActionEvent.getExplorerView(): ExplorerView? { return getExplorerView(ExplorerView::class.java) } @@ -74,7 +74,7 @@ inline fun > AnActionEvent.getEx * @param rootNodeProvider the root node provider for the root node of the explorer * @param cutProviderUpdater the cut provider updater to store the information about the cut elements */ -abstract class ExplorerTreeView, UnitConfig : EntityWithUuid> +abstract class ExplorerTreeView, UnitConfig : EntityWithUuid> ( val explorer: Explorer, private val project: Project, @@ -201,7 +201,7 @@ abstract class ExplorerTreeView onAddDelete(explorer: Explorer) { + private fun onAddDelete(explorer: Explorer) { if (explorer == this@ExplorerTreeView.explorer) { myFsTreeStructure.findByValue(explorer).forEach { myStructure.invalidate(it, true) @@ -209,12 +209,18 @@ abstract class ExplorerTreeView onAdded(explorer: Explorer,unit: ExplorerUnit) { + override fun onAdded( + explorer: Explorer, + unit: ExplorerUnit + ) { onAddDelete(explorer) } - override fun onChanged(explorer: Explorer, unit: ExplorerUnit) { + override fun onChanged( + explorer: Explorer, + unit: ExplorerUnit + ) { if (explorer == this@ExplorerTreeView.explorer) { myFsTreeStructure.findByValue(unit).forEach { myStructure.invalidate(it, true) @@ -222,7 +228,10 @@ abstract class ExplorerTreeView onDeleted(explorer: Explorer, unit: ExplorerUnit) { + override fun onDeleted( + explorer: Explorer, + unit: ExplorerUnit + ) { onAddDelete(explorer) } }, @@ -292,9 +301,9 @@ abstract class ExplorerTreeView { + this@ExplorerTreeView + .ignoreVFileDeleteEvents + .compareAndSet(true, true) -> { null } @@ -399,7 +408,8 @@ abstract class ExplorerTreeView(explorer, it) } ?: listOf() + mySelectedNodesData = + tree.selectionPaths?.mapNotNull { makeNodeDataFromTreePath(explorer, it) } ?: listOf() } tree.addTreeWillExpandListener(object : TreeWillExpandListener {