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

Commit 30cfb71

Browse files
committed
Added classpath
1 parent 0f961a0 commit 30cfb71

28 files changed

+2377
-1084
lines changed

browser-app/package.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
"name": "browser-app",
44
"version": "0.0.1",
55
"dependencies": {
6-
"@theia/core": "0.3.13",
7-
"@theia/filesystem": "0.3.13",
8-
"@theia/workspace": "0.3.13",
9-
"@theia/preferences": "0.3.13",
10-
"@theia/navigator": "0.3.13",
11-
"@theia/process": "0.3.13",
12-
"@theia/terminal": "0.3.13",
13-
"@theia/editor": "0.3.13",
14-
"@theia/languages": "0.3.13",
15-
"@theia/markers": "0.3.13",
16-
"@theia/monaco": "0.3.13",
17-
"@theia/file-search": "0.3.13",
18-
"@theia/typescript": "0.3.13",
19-
"@theia/messages": "0.3.13",
20-
"@theia/java": "0.3.13",
6+
"@theia/core": "0.3.14",
7+
"@theia/filesystem": "0.3.14",
8+
"@theia/workspace": "0.3.14",
9+
"@theia/preferences": "0.3.14",
10+
"@theia/navigator": "0.3.14",
11+
"@theia/process": "0.3.14",
12+
"@theia/terminal": "0.3.14",
13+
"@theia/editor": "0.3.14",
14+
"@theia/languages": "0.3.14",
15+
"@theia/markers": "0.3.14",
16+
"@theia/monaco": "0.3.14",
17+
"@theia/file-search": "0.3.14",
18+
"@theia/typescript": "0.3.14",
19+
"@theia/messages": "0.3.14",
20+
"@theia/java": "0.3.14",
2121
"@eclipse-che/theia-java-extension": "0.0.1"
2222
},
2323
"devDependencies": {
24-
"@theia/cli": "0.3.13"
24+
"@theia/cli": "0.3.14"
2525
},
2626
"scripts": {
2727
"prepare": "theia build",

che-theia-java-extension/package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
"src"
1010
],
1111
"dependencies": {
12-
"@theia/core": "0.3.13",
13-
"@theia/java": "0.3.13",
14-
"@theia/editor": "0.3.13",
15-
"@theia/languages": "0.3.13"
12+
"@theia/core": "0.3.14",
13+
"@theia/java": "0.3.14",
14+
"@theia/editor": "0.3.14",
15+
"@theia/languages": "0.3.14",
16+
"@theia/filesystem": "0.3.14",
17+
"@theia/navigator": "0.3.14",
18+
"@theia/workspace": "0.3.14"
1619
},
1720
"devDependencies": {
1821
"rimraf": "2.6.2",
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (c) 2012-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 { inject, injectable } from "inversify";
14+
import { ClasspathContainer, ClasspathEntry, ClasspathEntryKind } from "../classpath/classpath-container";
15+
import { CommandContribution, MenuContribution, SelectionService, CommandRegistry, MenuModelRegistry, Command } from "@theia/core";
16+
import { UriAwareCommandHandler, UriCommandHandler } from "@theia/core/lib/common/uri-command-handler";
17+
import URI from "@theia/core/lib/common/uri";
18+
import { NAVIGATOR_CONTEXT_MENU } from "@theia/navigator/lib/browser/navigator-contribution";
19+
import { CompositeTreeNode, WidgetManager } from "@theia/core/lib/browser";
20+
import { WorkspaceService } from "@theia/workspace/lib/browser";
21+
import { FileNavigatorWidget, FILE_NAVIGATOR_ID } from "@theia/navigator/lib/browser/navigator-widget";
22+
import { JavaUtils } from "../java-utils";
23+
import { SourceView } from "../classpath/pages/source/source-view";
24+
25+
26+
export const MARKSOURCEDIR = [...NAVIGATOR_CONTEXT_MENU, '7_sourcedir'];
27+
28+
29+
export namespace JavaCommands {
30+
export const MARKSOURCEDIR: Command = {
31+
id: 'java:mark-source-dir',
32+
label: 'Mark Dir as Source'
33+
};
34+
}
35+
36+
@injectable()
37+
export class MarkDirAsSourceAction implements CommandContribution, MenuContribution {
38+
39+
constructor(@inject(ClasspathContainer) protected readonly classpathContainer: ClasspathContainer,
40+
@inject(SelectionService) protected readonly selectionService: SelectionService,
41+
@inject(WidgetManager) protected readonly widgetManager: WidgetManager,
42+
@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService,
43+
@inject(SourceView) protected readonly sourceView: SourceView) {
44+
}
45+
46+
async performAction(projectURI: string, treeNodeID: string) {
47+
const classpathItems = await this.classpathContainer.getClassPathEntries(projectURI);
48+
const newClasspathItem = {
49+
children: [],
50+
entryKind: ClasspathEntryKind.SOURCE,
51+
path: JavaUtils.getIDFromMultiRootID(treeNodeID)
52+
} as ClasspathEntry
53+
classpathItems.push(newClasspathItem);
54+
this.classpathContainer.resolveClasspathEntries(classpathItems);
55+
this.classpathContainer.updateClasspath(projectURI);
56+
this.sourceView.classpathModel.addClasspathNodes(newClasspathItem);
57+
}
58+
59+
registerCommands(commands: CommandRegistry): void {
60+
commands.registerCommand(JavaCommands.MARKSOURCEDIR, this.newUriAwareCommandHandler({
61+
execute: async fileUri => {
62+
const fileWidget = await this.widgetManager.tryGetWidget(FILE_NAVIGATOR_ID) as FileNavigatorWidget;
63+
if (fileWidget) {
64+
65+
const roots = await this.workspaceService.roots;
66+
const root = JavaUtils.getRootProjectURI(roots, fileUri.toString());
67+
if (roots && root) {
68+
const multiRootURI = JavaUtils.getMultiRootReadyURI(root, fileUri.toString());
69+
const treeNode = fileWidget.model.getNode(multiRootURI);
70+
if (treeNode && CompositeTreeNode.is(treeNode)) {
71+
this.performAction(root, treeNode.id);
72+
}
73+
}
74+
}
75+
76+
}
77+
}));
78+
}
79+
80+
registerMenus(menus: MenuModelRegistry): void {
81+
menus.registerMenuAction(MARKSOURCEDIR, {
82+
commandId: JavaCommands.MARKSOURCEDIR.id
83+
});
84+
}
85+
86+
protected newUriAwareCommandHandler(handler: UriCommandHandler<URI>): UriAwareCommandHandler<URI> {
87+
return new UriAwareCommandHandler(this.selectionService, handler);
88+
}
89+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (c) 2012-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 { inject, injectable } from "inversify";
14+
import { ClasspathContainer } from "../classpath/classpath-container";
15+
import { CommandContribution, MenuContribution, SelectionService, CommandRegistry, MenuModelRegistry, Command } from "@theia/core";
16+
import { UriAwareCommandHandler, UriCommandHandler } from "@theia/core/lib/common/uri-command-handler";
17+
import URI from "@theia/core/lib/common/uri";
18+
import { CompositeTreeNode, WidgetManager } from "@theia/core/lib/browser";
19+
import { WorkspaceService } from "@theia/workspace/lib/browser";
20+
import { FileNavigatorWidget, FILE_NAVIGATOR_ID } from "@theia/navigator/lib/browser/navigator-widget";
21+
import { JavaUtils } from "../java-utils";
22+
import { MARKSOURCEDIR } from "./mark-dir-as-source";
23+
import { SourceView } from "../classpath/pages/source/source-view";
24+
25+
export const UNMARKSOURCEDIR: Command = {
26+
id: 'java:unmark-source-dir',
27+
label: 'Unmark Dir as Source'
28+
};
29+
30+
@injectable()
31+
export class UnmarkDirAsSourceAction implements CommandContribution, MenuContribution {
32+
33+
constructor(@inject(ClasspathContainer) protected readonly classpathContainer: ClasspathContainer,
34+
@inject(SelectionService) protected readonly selectionService: SelectionService,
35+
@inject(WidgetManager) protected readonly widgetManager: WidgetManager,
36+
@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService,
37+
@inject(SourceView) protected readonly sourceView: SourceView
38+
) {
39+
}
40+
41+
async performAction(projectURI: string, treeNodeID: string) {
42+
const classpathItems = await this.classpathContainer.getClassPathEntries(projectURI);
43+
this.classpathContainer.clearClasspathEntries();
44+
const realID = JavaUtils.getIDFromMultiRootID(treeNodeID);
45+
const filteredClasspathItems = classpathItems.filter(item => item.path !== realID);
46+
this.classpathContainer.resolveClasspathEntries(filteredClasspathItems);
47+
this.classpathContainer.updateClasspath(projectURI);
48+
this.sourceView.classpathModel.removeClasspathNode(realID);
49+
}
50+
51+
registerCommands(commands: CommandRegistry): void {
52+
commands.registerCommand(UNMARKSOURCEDIR, this.newUriAwareCommandHandler({
53+
execute: async fileUri => {
54+
const fileWidget = await this.widgetManager.tryGetWidget(FILE_NAVIGATOR_ID) as FileNavigatorWidget;
55+
if (fileWidget) {
56+
57+
const roots = await this.workspaceService.roots;
58+
const root = JavaUtils.getRootProjectURI(roots, fileUri.toString());
59+
if (roots && root) {
60+
const multiRootURI = JavaUtils.getMultiRootReadyURI(root, fileUri.toString());
61+
const treeNode = fileWidget.model.getNode(multiRootURI);
62+
if (treeNode && CompositeTreeNode.is(treeNode)) {
63+
this.performAction(root, treeNode.id);
64+
}
65+
}
66+
}
67+
68+
}
69+
}));
70+
}
71+
72+
registerMenus(menus: MenuModelRegistry): void {
73+
menus.registerMenuAction(MARKSOURCEDIR, {
74+
commandId: UNMARKSOURCEDIR.id
75+
});
76+
}
77+
78+
protected newUriAwareCommandHandler(handler: UriCommandHandler<URI>): UriAwareCommandHandler<URI> {
79+
return new UriAwareCommandHandler(this.selectionService, handler);
80+
}
81+
}

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,42 @@
1010
* Red Hat, Inc. - initial API and implementation
1111
*/
1212

13-
import { injectable } from "inversify";
14-
import { CommandContribution, CommandRegistry, MenuContribution, MenuModelRegistry } from "@theia/core/lib/common";
15-
import { KeybindingContribution, KeybindingRegistry } from "@theia/core/lib/browser";
13+
import { injectable, inject } from "inversify";
14+
import { CommandContribution, CommandRegistry, MenuContribution, MenuModelRegistry, MAIN_MENU_BAR, Command } from "@theia/core/lib/common";
15+
import { KeybindingContribution, KeybindingRegistry, WidgetManager } from "@theia/core/lib/browser";
16+
import { ClassPathDialog } from "./classpath/classpath-dialog";
17+
import { WorkspaceService } from "@theia/workspace/lib/browser";
18+
19+
export const HELP = [...MAIN_MENU_BAR, '5_classpath'];
20+
21+
export const CONFIGURE_CLASSPATH_COMMAND: Command = {
22+
id: 'java.configure.classpath',
23+
label: 'Configure Classpath'
24+
};
1625

1726
@injectable()
1827
export class JavaExtensionContribution implements CommandContribution, MenuContribution, KeybindingContribution {
1928

29+
constructor(
30+
@inject(ClassPathDialog) protected readonly aboutDialog: ClassPathDialog,
31+
@inject(WidgetManager) protected readonly widgetManager: WidgetManager,
32+
@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService) {
33+
}
34+
2035
registerCommands(registry: CommandRegistry): void {
36+
registry.registerCommand(CONFIGURE_CLASSPATH_COMMAND, {
37+
execute: e => {
38+
this.aboutDialog.open();
39+
}
40+
});
2141
}
2242

2343
registerMenus(menus: MenuModelRegistry): void {
44+
menus.registerMenuAction(HELP, {
45+
commandId: CONFIGURE_CLASSPATH_COMMAND.id,
46+
label: CONFIGURE_CLASSPATH_COMMAND.label,
47+
order: '10'
48+
});
2449
}
2550

2651
registerKeybindings(keybindings: KeybindingRegistry): void {

0 commit comments

Comments
 (0)