-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathextension.ts
179 lines (163 loc) · 6.36 KB
/
extension.ts
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
/**
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/
import { ExtensionContext, ProgressLocation, TreeItemCollapsibleState, window } from "vscode";
import { CICSSessionTree } from "./trees/CICSSessionTree";
import { CICSTree } from "./trees/CICSTree";
import { plexExpansionHandler, regionContainerExpansionHandler, sessionExpansionHandler } from "./utils/expansionHandler";
import { ProfileManagement } from "./utils/profileManagement";
import { getFolderIcon, getIconFilePathFromName } from "./utils/iconUtils";
import { getZoweExplorerVersion } from "./utils/workspaceUtils";
import { Logger } from "@zowe/imperative";
import { getCommands } from "./commands";
/**
* Initializes the extension
* @param context
* @returns
*/
export async function activate(context: ExtensionContext) {
const zeVersion = getZoweExplorerVersion();
const logger = Logger.getAppLogger();
let treeDataProv: CICSTree = null;
if (!zeVersion) {
window.showErrorMessage("Zowe Explorer was not found: Please ensure Zowe Explorer v2.0.0 or higher is installed");
return;
} else if (zeVersion[0] !== "3") {
window.showErrorMessage(`Current version of Zowe Explorer is ${zeVersion}. Please ensure Zowe Explorer v3.0.0 or higher is installed`);
return;
}
if (ProfileManagement.apiDoesExist()) {
try {
// Register 'cics' profiles as a ZE extender
await ProfileManagement.registerCICSProfiles();
ProfileManagement.getProfilesCache().registerCustomProfilesType("cics");
const apiRegister = await ProfileManagement.getExplorerApis();
await apiRegister.getExplorerExtenderApi().reloadProfiles();
if (apiRegister.onProfilesUpdate) {
apiRegister.onProfilesUpdate(async () => {
await treeDataProv.refreshLoadedProfiles();
});
}
logger.debug("Zowe Explorer was modified for the CICS Extension.");
} catch (error) {
logger.error("IBM CICS for Zowe Explorer was not initialized correctly");
return;
}
} else {
window.showErrorMessage(
"Zowe Explorer was not found: either it is not installed or you are using an older version without extensibility API. " +
"Please ensure Zowe Explorer v2.0.0-next.202202221200 or higher is installed",
);
return;
}
treeDataProv = new CICSTree();
const treeview = window.createTreeView("cics-view", {
treeDataProvider: treeDataProv,
showCollapseAll: true,
canSelectMany: true,
});
const expandCombinedTree = async (node: any) => {
if (node.element.getActiveFilter()) {
await node.element.loadContents(treeDataProv);
}
node.element.collapsibleState = TreeItemCollapsibleState.Expanded;
};
const expandResourceTree = (node: any) => {
window.withProgress(
{
location: ProgressLocation.Notification,
title: "Loading resources...",
cancellable: true,
},
async (_progress, _token) => {
await node.element.loadContents();
node.element.collapsibleState = TreeItemCollapsibleState.Expanded;
treeDataProv._onDidChangeTreeData.fire(undefined);
},
);
};
const contextMap: { [key: string]: (node: any) => Promise<void> | void; } = {
cicscombinedprogramtree: expandCombinedTree,
cicscombinedtransactiontree: expandCombinedTree,
cicscombinedlocalfiletree: expandCombinedTree,
cicscombinedtasktree: expandCombinedTree,
cicscombinedlibrarytree: expandCombinedTree,
cicscombinedtcpipstree: expandCombinedTree,
cicscombinedurimapstree: expandCombinedTree,
cicscombinedpipelinetree: expandCombinedTree,
cicscombinedwebservicetree: expandCombinedTree,
cicstreeweb: expandResourceTree,
cicstreeprogram: expandResourceTree,
cicstreetransaction: expandResourceTree,
cicstreelocalfile: expandResourceTree,
cicstreetask: expandResourceTree,
cicstreelibrary: expandResourceTree,
cicslibrary: expandResourceTree,
cicsdatasets: expandResourceTree,
cicstreetcpips: expandResourceTree,
cicstreewebservice: expandResourceTree,
cicstreepipeline: expandResourceTree,
cicstreeurimaps: expandResourceTree,
cicssession: async (node: any) => {
await sessionExpansionHandler(node.element, treeDataProv);
},
cicsplex: (node: any) => {
try {
plexExpansionHandler(node.element, treeDataProv);
} catch (error) {
const newSessionTree = new CICSSessionTree(node.element.getParent().profile, getIconFilePathFromName("profile-disconnected"));
treeDataProv.loadedProfiles.splice(treeDataProv.getLoadedProfiles().indexOf(node.element.getParent()), 1, newSessionTree);
treeDataProv._onDidChangeTreeData.fire(undefined);
}
},
cicsregionscontainer: (node: any) => {
node.element.iconPath = getFolderIcon(true);
regionContainerExpansionHandler(node.element, treeDataProv);
treeDataProv._onDidChangeTreeData.fire(undefined);
},
};
treeview.onDidExpandElement((node) => {
const contextValue = node.element.contextValue;
const initialContext = contextValue.split(".")[0];
if (initialContext in contextMap) {
contextMap[initialContext](node);
}
});
treeview.onDidCollapseElement((node) => {
const interestedContextValues = [
"cicsregionscontainer.",
"cicscombinedprogramtree.",
"cicscombinedtransactiontree.",
"cicscombinedlocalfiletree.",
"cicscombinedtasktree.",
"cicscombinedlibrarytree.",
"cicscombinedtcpipstree.",
"cicscombinedurimapstree.",
"cicscombinedpipelinetree.",
"cicscombinedwebservicetree.",
"cicstreeprogram.",
"cicstreetransaction.",
"cicstreelocalfile.",
"cicstreetask.",
"cicstreelibrary.",
"cicstreeweb.",
"cicstreetcpips.",
"cicstreepipeline.",
"cicstreewebservice.",
"cicstreeurimaps.",
];
if (interestedContextValues.some((item) => node.element.contextValue.includes(item))) {
node.element.iconPath = getFolderIcon(false);
}
node.element.collapsibleState = TreeItemCollapsibleState.Collapsed;
treeDataProv._onDidChangeTreeData.fire(undefined);
});
context.subscriptions.concat(getCommands(treeDataProv, treeview));
}