Skip to content

Commit

Permalink
Provided displaying spaceName/projectName on statusBar of MDE (#3506)
Browse files Browse the repository at this point in the history
* Provided displaying spaceName/projectName on statusBar of MDE

* Addressed PR comments

* Addressed PR comments

* Feedback comments

* Replaced with TextPresentation

* PR comments

* Addressed feedback comment
  • Loading branch information
vchikoti1998 committed Apr 17, 2023
1 parent 38ee416 commit 6a30bd2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions jetbrains-core/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ with what features/services are supported.

<statusBarWidgetFactory implementation="software.aws.toolkits.jetbrains.core.credentials.AwsSettingsPanelInstaller"/>
<statusBarWidgetFactory implementation="software.aws.toolkits.jetbrains.services.codewhisperer.status.CodeWhispererStatusBarWidgetFactory"/>
<statusBarWidgetFactory implementation="software.aws.toolkits.jetbrains.services.caws.CawsStatusBarInstaller"/>

<postStartupActivity implementation="software.aws.toolkits.jetbrains.core.AwsTelemetryPrompter"/>
<postStartupActivity implementation="software.aws.toolkits.jetbrains.core.executables.ExecutableLoader"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package software.aws.toolkits.jetbrains.services.caws

import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.wm.StatusBar
import com.intellij.openapi.wm.StatusBarWidget
import com.intellij.openapi.wm.StatusBarWidgetFactory
import com.intellij.util.Consumer
import java.awt.Component
import java.awt.event.MouseEvent

private const val WIDGET_ID = "CawsSpaceProjectInfo"

class CawsStatusBarInstaller : StatusBarWidgetFactory {
private val spaceName: String? = System.getenv(CawsConstants.CAWS_ENV_ORG_NAME_VAR)
private val projectName: String? = System.getenv(CawsConstants.CAWS_ENV_PROJECT_NAME_VAR)

override fun getId(): String = WIDGET_ID

override fun getDisplayName(): String = "$spaceName/$projectName"

override fun isAvailable(project: Project): Boolean = spaceName != null && projectName != null

override fun createWidget(project: Project): StatusBarWidget = CawsSpaceProjectInfo(spaceName, projectName)

override fun disposeWidget(widget: StatusBarWidget) {
Disposer.dispose(widget)
}

override fun canBeEnabledOn(statusBar: StatusBar): Boolean = true
}

private class CawsSpaceProjectInfo(val spaceName: String?, val projectName: String?) :
StatusBarWidget,
StatusBarWidget.TextPresentation {

override fun ID(): String = WIDGET_ID

override fun getPresentation(): StatusBarWidget.WidgetPresentation = this

override fun getTooltipText(): String = "$spaceName/$projectName"
override fun getClickConsumer(): Consumer<MouseEvent>? = null

override fun getText(): String = "$spaceName/$projectName"

override fun getAlignment(): Float = Component.CENTER_ALIGNMENT

override fun dispose() {}

override fun install(statusBar: StatusBar) {}
}

0 comments on commit 6a30bd2

Please sign in to comment.