Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.

Commit 2c68c9b

Browse files
JPinkneytsmaeder
authored andcommitted
Added external libraries feature (#2)
Added external libraries feature Signed-off-by: jpinkney <[email protected]>
1 parent 70c7ee9 commit 2c68c9b

18 files changed

+582
-29
lines changed

che-theia-java-extension/src/browser/che-ls-jdt-commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012-2018 Red Hat, Inc.
2+
* Copyright (c) 2018 Red Hat, Inc.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which is available at http://www.eclipse.org/legal/epl-2.0.html

che-theia-java-extension/src/browser/che-theia-java-contribution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012-2018 Red Hat, Inc.
2+
* Copyright (c) 2018 Red Hat, Inc.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which is available at http://www.eclipse.org/legal/epl-2.0.html

che-theia-java-extension/src/browser/che-theia-java-frontend-module.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012-2018 Red Hat, Inc.
2+
* Copyright (c) 2018 Red Hat, Inc.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which is available at http://www.eclipse.org/legal/epl-2.0.html
@@ -13,19 +13,26 @@
1313
import { JavaExtensionContribution } from './che-theia-java-contribution';
1414
import {
1515
CommandContribution,
16-
MenuContribution
16+
MenuContribution,
17+
ResourceResolver
1718
} from "@theia/core/lib/common";
1819

1920
import { ContainerModule } from 'inversify';
20-
import { KeybindingContribution, KeybindingContext } from '@theia/core/lib/browser';
21+
import { KeybindingContribution, KeybindingContext, WidgetFactory} from '@theia/core/lib/browser';
2122

2223
import '../../src/browser/styles/icons.css';
2324
import { FileStructure } from './navigation/file-structure';
24-
import { FindImplementers } from './navigation/find-implementers';
2525
import { JavaEditorTextFocusContext } from './java-keybinding-contexts';
2626

27-
export default new ContainerModule((bind) => {
27+
import { ExternalLibrariesWidget, EXTERNAL_LIBRARIES_ID } from './libraries/external-libraries-widget';
28+
import { createExternalLibrariesWidget } from './libraries/external-libraries-container';
29+
import { CheLibResourceResolver } from './libraries/chelib-resource-provider';
30+
import { FileNavigatorWidget } from '@theia/navigator/lib/browser';
31+
32+
import '../../src/browser/styles/icons.css';
33+
import { FindImplementers } from './navigation/find-implementers';
2834

35+
export default new ContainerModule((bind, unbind, isBound) => {
2936
bind(CommandContribution).to(JavaExtensionContribution);
3037
bind(MenuContribution).to(JavaExtensionContribution);
3138
bind(KeybindingContribution).to(JavaExtensionContribution);
@@ -42,4 +49,19 @@ export default new ContainerModule((bind) => {
4249

4350
bind(KeybindingContext).to(JavaEditorTextFocusContext).inSingletonScope();
4451

52+
bind(CheLibResourceResolver).toSelf().inSingletonScope();
53+
bind(ResourceResolver).toDynamicValue(ctx => ctx.container.get(CheLibResourceResolver));
54+
55+
if (isBound(FileNavigatorWidget)) {
56+
unbind(FileNavigatorWidget);
57+
}
58+
59+
bind(ExternalLibrariesWidget).toDynamicValue(ctx => {
60+
return createExternalLibrariesWidget(ctx.container);
61+
});
62+
63+
bind(WidgetFactory).toDynamicValue(context => ({
64+
id: EXTERNAL_LIBRARIES_ID,
65+
createWidget: () => context.container.get<ExternalLibrariesWidget>(ExternalLibrariesWidget)
66+
}));
4567
});

che-theia-java-extension/src/browser/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012-2018 Red Hat, Inc.
2+
* Copyright (c) 2018 Red Hat, Inc.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which is available at http://www.eclipse.org/legal/epl-2.0.html
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2018 Red Hat, Inc.
3+
* This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which is available at http://www.eclipse.org/legal/epl-2.0.html
6+
*
7+
* SPDX-License-Identifier: EPL-2.0
8+
*
9+
* Contributors:
10+
* Red Hat, Inc. - initial API and implementation
11+
*/
12+
13+
import { injectable, inject } from 'inversify';
14+
import URI from '@theia/core/lib/common/uri';
15+
import { ResourceResolver } from '@theia/core/lib/common';
16+
import { JavaClientContribution, JavaResource } from '@theia/java/lib/browser';
17+
18+
@injectable()
19+
export class CheLibResourceResolver implements ResourceResolver {
20+
21+
constructor(
22+
@inject(JavaClientContribution)
23+
protected readonly javaClientContribution: JavaClientContribution
24+
) { }
25+
26+
resolve(uri: URI): JavaResource {
27+
if (uri.scheme !== 'chelib') {
28+
throw new Error(`The given URI is not a valid Chelib uri: ${uri}`);
29+
}
30+
return new JavaResource(uri, this.javaClientContribution);
31+
}
32+
33+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2018 Red Hat, Inc.
3+
* This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which is available at http://www.eclipse.org/legal/epl-2.0.html
6+
*
7+
* SPDX-License-Identifier: EPL-2.0
8+
*
9+
* Contributors:
10+
* Red Hat, Inc. - initial API and implementation
11+
*/
12+
13+
import { Container, interfaces } from 'inversify';
14+
import { TreeModel, TreeProps, defaultTreeProps, Tree, TreeDecoratorService } from "@theia/core/lib/browser";
15+
import { createFileTreeContainer, FileTreeModel, FileTree } from '@theia/filesystem/lib/browser';
16+
import { ExternalLibrariesWidget } from './external-libraries-widget';
17+
import { NavigatorDecoratorService, NavigatorTreeDecorator } from '@theia/navigator/lib/browser';
18+
import { bindContributionProvider } from '@theia/core';
19+
import { FileNavigatorTree } from '@theia/navigator/lib/browser/navigator-tree';
20+
import { ExternalLibrariesTree } from './external-libraries-tree';
21+
import { ExternalLibraryModel } from './external-libraries-model';
22+
23+
export const FILE_NAVIGATOR_PROPS = <TreeProps>{
24+
...defaultTreeProps,
25+
contextMenuPath: ['navigator-context-menu'],
26+
multiSelect: false
27+
};
28+
29+
export function createExternalLibrariesContainer(parent: interfaces.Container): Container {
30+
const child = createFileTreeContainer(parent);
31+
32+
child.unbind(FileTree);
33+
child.bind(FileNavigatorTree).toSelf();
34+
child.bind(ExternalLibrariesTree).toSelf();
35+
child.rebind(Tree).toDynamicValue(ctx => ctx.container.get(ExternalLibrariesTree));
36+
37+
child.unbind(FileTreeModel);
38+
child.bind(ExternalLibraryModel).toSelf();
39+
child.rebind(TreeModel).toDynamicValue(ctx => ctx.container.get(ExternalLibraryModel));
40+
41+
child.bind(ExternalLibrariesWidget).toSelf();
42+
43+
child.rebind(TreeProps).toConstantValue(FILE_NAVIGATOR_PROPS);
44+
45+
child.bind(NavigatorDecoratorService).toSelf().inSingletonScope();
46+
child.rebind(TreeDecoratorService).toDynamicValue(ctx => ctx.container.get(NavigatorDecoratorService)).inSingletonScope();
47+
bindContributionProvider(child, NavigatorTreeDecorator);
48+
49+
return child;
50+
}
51+
52+
export function createExternalLibrariesWidget(parent: interfaces.Container): ExternalLibrariesWidget {
53+
return createExternalLibrariesContainer(parent).get(ExternalLibrariesWidget);
54+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2018 Red Hat, Inc.
3+
* This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which is available at http://www.eclipse.org/legal/epl-2.0.html
6+
*
7+
* SPDX-License-Identifier: EPL-2.0
8+
*
9+
* Contributors:
10+
* Red Hat, Inc. - initial API and implementation
11+
*/
12+
13+
import { injectable, inject } from 'inversify';
14+
import { OpenerService, open, TreeNode } from '@theia/core/lib/browser';
15+
import { ExternalLibrariesTree, JarFileNode } from './external-libraries-tree';
16+
import URI from '@theia/core/lib/common/uri';
17+
import { FileNavigatorModel } from '@theia/navigator/lib/browser';
18+
19+
@injectable()
20+
export class ExternalLibraryModel extends FileNavigatorModel {
21+
22+
@inject(OpenerService) protected readonly openerService!: OpenerService;
23+
@inject(ExternalLibrariesTree) readonly tree!: ExternalLibrariesTree;
24+
25+
protected doOpenNode(node: TreeNode): void {
26+
if (JarFileNode.is(node)) {
27+
open(this.openerService, new URI(node.jarEntry.uri));
28+
} else {
29+
super.doOpenNode(node);
30+
}
31+
}
32+
33+
}

0 commit comments

Comments
 (0)