-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraceabilityApproachViewProvider.ts
More file actions
255 lines (226 loc) · 10.5 KB
/
traceabilityApproachViewProvider.ts
File metadata and controls
255 lines (226 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
import * as vscode from 'vscode';
import * as fs from 'fs';
import * as path from 'path';
import { CONSTANTS_FILE_PATH_ARDOCO_CONFIG, CONSTANTS_FILE_PATH_ARDOCO_CODE_MODEL, CONSTANTS_FILE_PATH_ARDOCO_TRACE_LINKS } from '../constants';
import { TraceVizStorageUtil } from '../utils/traceVizStorage.util';
/**
* Tree data provider for the Traceability Approach view
* Displays available traceability approaches and their configuration status
*/
export class TraceabilityApproachViewProvider implements vscode.TreeDataProvider<ApproachItem>, vscode.Disposable {
private readonly onDidChangeTreeDataEmitter = new vscode.EventEmitter<ApproachItem | undefined | null | void>();
readonly onDidChangeTreeData: vscode.Event<ApproachItem | undefined | null | void> = this.onDidChangeTreeDataEmitter.event;
private readonly disposables: vscode.Disposable[] = [];
constructor() {
// Listen for workspace changes to refresh the view
this.disposables.push(
vscode.workspace.onDidChangeWorkspaceFolders(() => {
this.refresh();
})
);
// Listen for file system changes in the .trace-viz folder
this.disposables.push(
vscode.workspace.onDidSaveTextDocument((document) => {
if (document.uri.fsPath.includes('.trace-viz')) {
this.refresh();
}
})
);
// Listen for file creation/deletion in the .trace-viz folder
const watcher = vscode.workspace.createFileSystemWatcher('**/.trace-viz/**');
watcher.onDidCreate(() => this.refresh());
watcher.onDidDelete(() => this.refresh());
watcher.onDidChange(() => this.refresh());
this.disposables.push(watcher);
}
getTreeItem(element: ApproachItem): vscode.TreeItem {
return element;
}
getChildren(element?: ApproachItem): Thenable<ApproachItem[]> {
if (!element) {
return Promise.resolve([
new ApproachItem('CSV Direct', vscode.TreeItemCollapsibleState.None),
new ApproachItem('ArDoCo', vscode.TreeItemCollapsibleState.Collapsed, 'traceViz.ardoCoItem'),
new ApproachItem('LiSSA', vscode.TreeItemCollapsibleState.None)
]);
}
if (element.label === 'ArDoCo') {
const hasConfig = checkArDoCoConfigExists();
const hasCodeModel = checkArDoCoCodeModelExists();
const hasTraceLinks = checkArDoCoTraceLinksExist();
const traceLinksPrerequisitesMet = hasConfig && hasCodeModel;
return Promise.resolve([
new ApproachItem('ArDoCo Config', vscode.TreeItemCollapsibleState.None, 'traceViz.ardoCoConfig', hasConfig),
new ApproachItem('Generate Code Model', vscode.TreeItemCollapsibleState.None, 'traceViz.ardoCoGenerateModel', hasCodeModel, hasConfig, hasConfig && !hasCodeModel),
new ApproachItem('Generate Trace Links', vscode.TreeItemCollapsibleState.Collapsed, 'traceViz.ardoCoGenerateLinks', undefined, undefined, traceLinksPrerequisitesMet)
]);
}
if (element.label === 'Generate Trace Links') {
const samCodePrerequisitesMet = checkSamCodePrerequisites();
const sadSamPrerequisitesMet = checkSadSamPrerequisites();
const sadSamCodePrerequisitesMet = checkSadSamCodePrerequisites();
const sadCodePrerequisitesMet = checkSadCodePrerequisites();
return Promise.resolve([
new ApproachItem('SAM-Code', vscode.TreeItemCollapsibleState.None, 'traceViz.samCode', undefined, samCodePrerequisitesMet, samCodePrerequisitesMet),
new ApproachItem('SAD-SAM', vscode.TreeItemCollapsibleState.None, 'traceViz.sadSam', undefined, sadSamPrerequisitesMet, sadSamPrerequisitesMet),
new ApproachItem('SAD-SAM-Code', vscode.TreeItemCollapsibleState.None, 'traceViz.sadSamCode', undefined, sadSamCodePrerequisitesMet, sadSamCodePrerequisitesMet),
new ApproachItem('SAD-Code', vscode.TreeItemCollapsibleState.None, 'traceViz.sadCode', undefined, sadCodePrerequisitesMet, sadCodePrerequisitesMet)
]);
}
return Promise.resolve([]);
}
refresh(): void {
this.onDidChangeTreeDataEmitter.fire();
}
dispose(): void {
this.disposables.forEach(d => d.dispose());
this.onDidChangeTreeDataEmitter.dispose();
}
}
/**
* Tree item representing a traceability approach or configuration step
*/
export class ApproachItem extends vscode.TreeItem {
constructor(
public readonly label: string,
public readonly collapsibleState: vscode.TreeItemCollapsibleState,
public readonly contextValue?: string,
public readonly isComplete?: boolean,
public readonly isEnabled?: boolean,
public readonly prerequisitesMet?: boolean
) {
super(label, collapsibleState);
this.contextValue = contextValue || 'traceViz.approachItem';
// Add status icon
if (isComplete === true) {
// Task completed - green check
this.iconPath = new vscode.ThemeIcon('check', new vscode.ThemeColor('charts.green'));
} else if (prerequisitesMet !== undefined) {
// Prerequisites status - green circle if met, red X if not met
this.iconPath = prerequisitesMet ? new vscode.ThemeIcon('circle-filled', new vscode.ThemeColor('charts.green')) : new vscode.ThemeIcon('x', new vscode.ThemeColor('charts.red'));
} else if (isComplete === false) {
// Task not completed and no prerequisites info - red X
this.iconPath = new vscode.ThemeIcon('x', new vscode.ThemeColor('charts.red'));
}
// Add commands for different items
if (label === 'CSV Direct') {
this.command = {
command: 'trace-viz.csvDirect',
title: 'Select CSV File'
};
} else if (label === 'LiSSA') {
this.command = {
command: 'trace-viz.openLissaWebview',
title: 'Open LiSSA Configuration'
};
} else if (label === 'ArDoCo Config') {
this.command = {
command: 'trace-viz.openArDoCoWebview',
title: 'Open ArDoCo Configuration'
};
} else if (label === 'Generate Code Model' && isEnabled) {
this.command = {
command: 'trace-viz.ardoCoGenerateModel',
title: 'Generate Code Model'
};
} else if (label === 'SAD-Code' && isEnabled) {
this.command = {
command: 'trace-viz.sadCode',
title: 'Generate SAD-Code Trace Links'
};
} else if (label === 'SAM-Code' && isEnabled) {
this.command = {
command: 'trace-viz.samCode',
title: 'Generate SAM-Code Trace Links'
};
} else if (label === 'SAD-SAM' && isEnabled) {
this.command = {
command: 'trace-viz.sadSam',
title: 'Generate SAD-SAM Trace Links'
};
} else if (label === 'SAD-SAM-Code' && isEnabled) {
this.command = {
command: 'trace-viz.sadSamCode',
title: 'Generate SAD-SAM-Code Trace Links'
};
}
}
}
function checkArDoCoConfigExists(): boolean {
const workspaceFolder = TraceVizStorageUtil.getWorkspaceFolder();
if (!workspaceFolder) {
return false;
}
return TraceVizStorageUtil.fileExists(CONSTANTS_FILE_PATH_ARDOCO_CONFIG, workspaceFolder);
}
function checkArDoCoCodeModelExists(): boolean {
const workspaceFolder = TraceVizStorageUtil.getWorkspaceFolder();
if (!workspaceFolder) {
return false;
}
return TraceVizStorageUtil.fileExists(CONSTANTS_FILE_PATH_ARDOCO_CODE_MODEL, workspaceFolder);
}
function checkArDoCoTraceLinksExist(): boolean {
const workspaceFolder = TraceVizStorageUtil.getWorkspaceFolder();
if (!workspaceFolder) {
return false;
}
return TraceVizStorageUtil.fileExists(CONSTANTS_FILE_PATH_ARDOCO_TRACE_LINKS, workspaceFolder);
}
function checkSamCodePrerequisites(): boolean {
const workspaceFolder = TraceVizStorageUtil.getWorkspaceFolder();
if (!workspaceFolder) {
return false;
}
const config = TraceVizStorageUtil.readJsonFile<any>(CONSTANTS_FILE_PATH_ARDOCO_CONFIG, workspaceFolder);
if (!config) {
return false;
}
// SAM-Code requires: Architecture Model Path and Code Path
return !!(config.architectureModelPath && config.codePath &&
fs.existsSync(config.architectureModelPath) &&
fs.existsSync(config.codePath));
}
function checkSadSamPrerequisites(): boolean {
const workspaceFolder = TraceVizStorageUtil.getWorkspaceFolder();
if (!workspaceFolder) {
return false;
}
const config = TraceVizStorageUtil.readJsonFile<any>(CONSTANTS_FILE_PATH_ARDOCO_CONFIG, workspaceFolder);
if (!config) {
return false;
}
// SAD-SAM requires: Documentation Path and Architecture Model Path
return !!(config.documentationPath && config.architectureModelPath &&
fs.existsSync(config.documentationPath) &&
fs.existsSync(config.architectureModelPath));
}
function checkSadSamCodePrerequisites(): boolean {
const workspaceFolder = TraceVizStorageUtil.getWorkspaceFolder();
if (!workspaceFolder) {
return false;
}
const config = TraceVizStorageUtil.readJsonFile<any>(CONSTANTS_FILE_PATH_ARDOCO_CONFIG, workspaceFolder);
if (!config) {
return false;
}
// SAD-SAM-Code requires: Documentation Path and Architecture Model Path and Code Path
return !!(config.documentationPath && config.architectureModelPath && config.codePath &&
fs.existsSync(config.documentationPath) &&
fs.existsSync(config.architectureModelPath) &&
fs.existsSync(config.codePath));
}
function checkSadCodePrerequisites(): boolean {
const workspaceFolder = TraceVizStorageUtil.getWorkspaceFolder();
if (!workspaceFolder) {
return false;
}
const config = TraceVizStorageUtil.readJsonFile<any>(CONSTANTS_FILE_PATH_ARDOCO_CONFIG, workspaceFolder);
if (!config) {
return false;
}
// SAD-Code requires: Documentation Path and Code Path
return !!(config.documentationPath && config.codePath &&
fs.existsSync(config.documentationPath) &&
fs.existsSync(config.codePath));
}