@@ -10,12 +10,13 @@ import { Ec2Instance } from '../../shared/clients/ec2Client'
10
10
import globals from '../../shared/extensionGlobals'
11
11
import { Ec2Selection , getIconCodeForInstanceStatus } from '../utils'
12
12
13
+ type Ec2InstanceNodeContext = 'awsEc2RunningNode' | 'awsEc2StoppedNode' | 'awsEc2PendingNode'
14
+
13
15
export class Ec2InstanceNode extends AWSTreeNodeBase implements AWSResourceNode {
14
16
public constructor (
15
17
public override readonly regionCode : string ,
16
18
private readonly partitionId : string ,
17
- private instance : Ec2Instance ,
18
- public override readonly contextValue : string
19
+ private instance : Ec2Instance
19
20
) {
20
21
super ( '' )
21
22
this . update ( instance )
@@ -24,10 +25,23 @@ export class Ec2InstanceNode extends AWSTreeNodeBase implements AWSResourceNode
24
25
public update ( newInstance : Ec2Instance ) {
25
26
this . setInstance ( newInstance )
26
27
this . label = `${ this . name } (${ this . InstanceId } )`
28
+ this . contextValue = this . getContext ( )
27
29
this . iconPath = new vscode . ThemeIcon ( getIconCodeForInstanceStatus ( this . instance ) )
28
30
this . tooltip = `${ this . name } \n${ this . InstanceId } \n${ this . instance . status } \n${ this . arn } `
29
31
}
30
32
33
+ private getContext ( ) : Ec2InstanceNodeContext {
34
+ if ( this . instance . status == 'running' ) {
35
+ return 'awsEc2RunningNode'
36
+ }
37
+
38
+ if ( this . instance . status == 'stopped' ) {
39
+ return 'awsEc2StoppedNode'
40
+ }
41
+
42
+ return 'awsEc2PendingNode'
43
+ }
44
+
31
45
public setInstance ( newInstance : Ec2Instance ) {
32
46
this . instance = newInstance
33
47
}
0 commit comments