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

Commit

Permalink
Added external libraries feature (#2)
Browse files Browse the repository at this point in the history
Added external libraries feature

Signed-off-by: jpinkney <[email protected]>
  • Loading branch information
JPinkney authored and tsmaeder committed Dec 3, 2018
1 parent 70c7ee9 commit 2c68c9b
Show file tree
Hide file tree
Showing 18 changed files with 582 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* Copyright (c) 2018 Red Hat, Inc.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which is available at http://www.eclipse.org/legal/epl-2.0.html
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* Copyright (c) 2018 Red Hat, Inc.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which is available at http://www.eclipse.org/legal/epl-2.0.html
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* Copyright (c) 2018 Red Hat, Inc.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which is available at http://www.eclipse.org/legal/epl-2.0.html
Expand All @@ -13,19 +13,26 @@
import { JavaExtensionContribution } from './che-theia-java-contribution';
import {
CommandContribution,
MenuContribution
MenuContribution,
ResourceResolver
} from "@theia/core/lib/common";

import { ContainerModule } from 'inversify';
import { KeybindingContribution, KeybindingContext } from '@theia/core/lib/browser';
import { KeybindingContribution, KeybindingContext, WidgetFactory} from '@theia/core/lib/browser';

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

export default new ContainerModule((bind) => {
import { ExternalLibrariesWidget, EXTERNAL_LIBRARIES_ID } from './libraries/external-libraries-widget';
import { createExternalLibrariesWidget } from './libraries/external-libraries-container';
import { CheLibResourceResolver } from './libraries/chelib-resource-provider';
import { FileNavigatorWidget } from '@theia/navigator/lib/browser';

import '../../src/browser/styles/icons.css';
import { FindImplementers } from './navigation/find-implementers';

export default new ContainerModule((bind, unbind, isBound) => {
bind(CommandContribution).to(JavaExtensionContribution);
bind(MenuContribution).to(JavaExtensionContribution);
bind(KeybindingContribution).to(JavaExtensionContribution);
Expand All @@ -42,4 +49,19 @@ export default new ContainerModule((bind) => {

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

bind(CheLibResourceResolver).toSelf().inSingletonScope();
bind(ResourceResolver).toDynamicValue(ctx => ctx.container.get(CheLibResourceResolver));

if (isBound(FileNavigatorWidget)) {
unbind(FileNavigatorWidget);
}

bind(ExternalLibrariesWidget).toDynamicValue(ctx => {
return createExternalLibrariesWidget(ctx.container);
});

bind(WidgetFactory).toDynamicValue(context => ({
id: EXTERNAL_LIBRARIES_ID,
createWidget: () => context.container.get<ExternalLibrariesWidget>(ExternalLibrariesWidget)
}));
});
2 changes: 1 addition & 1 deletion che-theia-java-extension/src/browser/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* Copyright (c) 2018 Red Hat, Inc.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which is available at http://www.eclipse.org/legal/epl-2.0.html
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2018 Red Hat, Inc.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which is available at http://www.eclipse.org/legal/epl-2.0.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/

import { injectable, inject } from 'inversify';
import URI from '@theia/core/lib/common/uri';
import { ResourceResolver } from '@theia/core/lib/common';
import { JavaClientContribution, JavaResource } from '@theia/java/lib/browser';

@injectable()
export class CheLibResourceResolver implements ResourceResolver {

constructor(
@inject(JavaClientContribution)
protected readonly javaClientContribution: JavaClientContribution
) { }

resolve(uri: URI): JavaResource {
if (uri.scheme !== 'chelib') {
throw new Error(`The given URI is not a valid Chelib uri: ${uri}`);
}
return new JavaResource(uri, this.javaClientContribution);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2018 Red Hat, Inc.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which is available at http://www.eclipse.org/legal/epl-2.0.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/

import { Container, interfaces } from 'inversify';
import { TreeModel, TreeProps, defaultTreeProps, Tree, TreeDecoratorService } from "@theia/core/lib/browser";
import { createFileTreeContainer, FileTreeModel, FileTree } from '@theia/filesystem/lib/browser';
import { ExternalLibrariesWidget } from './external-libraries-widget';
import { NavigatorDecoratorService, NavigatorTreeDecorator } from '@theia/navigator/lib/browser';
import { bindContributionProvider } from '@theia/core';
import { FileNavigatorTree } from '@theia/navigator/lib/browser/navigator-tree';
import { ExternalLibrariesTree } from './external-libraries-tree';
import { ExternalLibraryModel } from './external-libraries-model';

export const FILE_NAVIGATOR_PROPS = <TreeProps>{
...defaultTreeProps,
contextMenuPath: ['navigator-context-menu'],
multiSelect: false
};

export function createExternalLibrariesContainer(parent: interfaces.Container): Container {
const child = createFileTreeContainer(parent);

child.unbind(FileTree);
child.bind(FileNavigatorTree).toSelf();
child.bind(ExternalLibrariesTree).toSelf();
child.rebind(Tree).toDynamicValue(ctx => ctx.container.get(ExternalLibrariesTree));

child.unbind(FileTreeModel);
child.bind(ExternalLibraryModel).toSelf();
child.rebind(TreeModel).toDynamicValue(ctx => ctx.container.get(ExternalLibraryModel));

child.bind(ExternalLibrariesWidget).toSelf();

child.rebind(TreeProps).toConstantValue(FILE_NAVIGATOR_PROPS);

child.bind(NavigatorDecoratorService).toSelf().inSingletonScope();
child.rebind(TreeDecoratorService).toDynamicValue(ctx => ctx.container.get(NavigatorDecoratorService)).inSingletonScope();
bindContributionProvider(child, NavigatorTreeDecorator);

return child;
}

export function createExternalLibrariesWidget(parent: interfaces.Container): ExternalLibrariesWidget {
return createExternalLibrariesContainer(parent).get(ExternalLibrariesWidget);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2018 Red Hat, Inc.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which is available at http://www.eclipse.org/legal/epl-2.0.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/

import { injectable, inject } from 'inversify';
import { OpenerService, open, TreeNode } from '@theia/core/lib/browser';
import { ExternalLibrariesTree, JarFileNode } from './external-libraries-tree';
import URI from '@theia/core/lib/common/uri';
import { FileNavigatorModel } from '@theia/navigator/lib/browser';

@injectable()
export class ExternalLibraryModel extends FileNavigatorModel {

@inject(OpenerService) protected readonly openerService!: OpenerService;
@inject(ExternalLibrariesTree) readonly tree!: ExternalLibrariesTree;

protected doOpenNode(node: TreeNode): void {
if (JarFileNode.is(node)) {
open(this.openerService, new URI(node.jarEntry.uri));
} else {
super.doOpenNode(node);
}
}

}
Loading

0 comments on commit 2c68c9b

Please sign in to comment.