forked from redhat-developer/intellij-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: impl'd describe for resources (redhat-developer#553)
Signed-off-by: Andre Dietisheim <[email protected]>
- Loading branch information
Showing
43 changed files
with
4,925 additions
and
90 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/main/kotlin/com/redhat/devtools/intellij/kubernetes/actions/DescribeResourceAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 Red Hat, Inc. | ||
* Distributed under license by Red Hat, Inc. All rights reserved. | ||
* This program is made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, | ||
* and is available at http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
******************************************************************************/ | ||
package com.redhat.devtools.intellij.kubernetes.actions | ||
|
||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.diagnostic.logger | ||
import com.redhat.devtools.intellij.common.actions.StructureTreeAction | ||
import com.redhat.devtools.intellij.kubernetes.editor.describe.DescriptionViewerFactory | ||
import com.redhat.devtools.intellij.kubernetes.model.Notification | ||
import io.fabric8.kubernetes.api.model.HasMetadata | ||
import io.fabric8.kubernetes.api.model.Pod | ||
import javax.swing.tree.TreePath | ||
|
||
class DescribeResourceAction: StructureTreeAction() { | ||
|
||
override fun actionPerformed(event: AnActionEvent?, path: TreePath?, selected: Any?) { | ||
// not called | ||
} | ||
|
||
override fun actionPerformed(event: AnActionEvent?, path: Array<out TreePath>?, selected: Array<out Any>?) { | ||
val descriptor = selected?.get(0)?.getDescriptor() ?: return | ||
val project = descriptor.project ?: return | ||
val toDescribe: HasMetadata = descriptor.element as? HasMetadata? ?: return | ||
try { | ||
DescriptionViewerFactory.instance.openEditor(toDescribe, project) | ||
} catch (e: RuntimeException) { | ||
logger<DescribeResourceAction>().warn("Error opening editor ${toDescribe.metadata.name}", e) | ||
Notification().error( | ||
"Error opening editor ${toDescribe.metadata.name}", | ||
"Could not open editor for ${toDescribe.kind} '${toDescribe.metadata.name}'." | ||
) | ||
} | ||
} | ||
|
||
override fun isVisible(selected: Array<out Any>?): Boolean { | ||
return selected?.size == 1 | ||
&& isVisible(selected.firstOrNull()) | ||
} | ||
|
||
override fun isVisible(selected: Any?): Boolean { | ||
val element = selected?.getElement<HasMetadata>() | ||
return element is Pod | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...otlin/com/redhat/devtools/intellij/kubernetes/editor/KubernetesEditorsTabTitleProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 Red Hat, Inc. | ||
* Distributed under license by Red Hat, Inc. All rights reserved. | ||
* This program is made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, | ||
* and is available at http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
******************************************************************************/ | ||
package com.redhat.devtools.intellij.kubernetes.editor | ||
|
||
import com.intellij.openapi.fileEditor.impl.EditorTabTitleProvider | ||
import com.intellij.openapi.fileEditor.impl.UniqueNameEditorTabTitleProvider | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.redhat.devtools.intellij.kubernetes.editor.describe.DescriptionViewerTabTitleProvider | ||
|
||
open class KubernetesEditorsTabTitleProvider( | ||
private val fallback: EditorTabTitleProvider = UniqueNameEditorTabTitleProvider() | ||
) : EditorTabTitleProvider { | ||
|
||
override fun getEditorTabTitle(project: Project, file: VirtualFile): String? { | ||
return ResourceEditorTabTitleProvider().getEditorTabTitle(project, file) | ||
?: DescriptionViewerTabTitleProvider().getEditorTabTitle(project, file) | ||
?: fallback.getEditorTabTitle(project, file) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.