Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@
"dark": "images/dark/icon-refresh.svg",
"light": "images/light/icon-refresh.svg"
}
},
{
"command": "java.view.package.changeRepresentation",
"title": "Change package representation",
"category": "Java",
"icon": {
"dark": "images/dark/package.svg",
"light": "images/light/package.svg"
}
}
],
"configuration": {
Expand All @@ -62,6 +71,15 @@
"type": "boolean",
"description": "Synchronize dependency viewer selection with folder explorer",
"default": true
},
"java.dependency.packagePresentation": {
"type": "string",
"enum": [
"flat",
"hierarchical"
],
"description": "Package presentation mode: flat or hierarchical",
"default": "flat"
}
}
},
Expand All @@ -70,6 +88,11 @@
{
"command": "java.view.package.refresh",
"when": "view == javaDependencyExplorer",
"group": "navigation@1"
},
{
"command": "java.view.package.changeRepresentation",
"when": "view == javaDependencyExplorer",
"group": "navigation@0"
}
]
Expand Down
2 changes: 2 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export namespace Commands {
*/
export const EXECUTE_WORKSPACE_COMMAND = "java.execute.workspaceCommand";

export const VIEW_PACKAGE_CHANGEREPRESENTATION = "java.view.package.changeRepresentation";

export const VIEW_PACKAGE_REFRESH = "java.view.package.refresh";

export const VIEW_PACKAGE_OPEN_FILE = "java.view.package.openFile";
Expand Down
72 changes: 72 additions & 0 deletions src/java/hierachicalPackageNodeData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import { INodeData, NodeKind } from "./nodeData";

export class HierachicalPackageNodeData implements INodeData {

public static createHierachicalNodeDataByPackageList(packageList: INodeData[]): HierachicalPackageNodeData {
const result = new HierachicalPackageNodeData("", "");
packageList.forEach((nodeData) => result.addSubPackage(nodeData.name.split("."), nodeData));
result.compressTree();
return result;
}

public name: string;
public children = [];
public displayName: string;
private nodeData: INodeData = null;

public get uri() {
return this.nodeData.uri;
}

public get moduleName() {
return this.nodeData.moduleName;
}

public get path() {
return this.nodeData.path;
}

public get kind() {
return this.nodeData ? this.nodeData.kind : NodeKind.Package;
}

public get isPackage() {
return this.nodeData !== null;
}

private constructor(displayName: string, parentName: string) {
this.displayName = displayName;
this.name = parentName === "" ? displayName : parentName + "." + displayName;
}

private compressTree(): void {
// Don't compress the root node
while (this.name !== "" && this.children.length === 1 && !this.isPackage) {
const child = this.children[0];
this.name = this.name + "." + child.displayName;
this.displayName = this.displayName + "." + child.displayName;
this.children = child.children;
this.nodeData = child.nodeData;
}
this.children.forEach((child) => child.compressTree());
}

private addSubPackage(packages: string[], nodeData: INodeData): void {
if (!packages.length) {
this.nodeData = nodeData;
return;
}
const subPackageDisplayName = packages.shift();
const childNode = this.children.find((child) => child.displayName === subPackageDisplayName);
if (childNode) {
childNode.addSubPackage(packages);
} else {
const newNode = new HierachicalPackageNodeData(subPackageDisplayName, this.name);
newNode.addSubPackage(packages, nodeData);
this.children.push(newNode);
}
}
}
21 changes: 20 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

import { commands, ConfigurationChangeEvent, ExtensionContext, workspace, WorkspaceConfiguration } from "vscode";
import { instrumentOperation } from "vscode-extension-telemetry-wrapper";
import { Commands } from "./commands";

export class Settings {
Expand All @@ -12,12 +13,21 @@ export class Settings {
return;
}
const updatedConfig = workspace.getConfiguration("java.dependency");
if (updatedConfig.showOutline !== this._depdendencyConfig.showOutline) {
if (updatedConfig.showOutline !== this._depdendencyConfig.showOutline
|| updatedConfig.packagePresentation !== this._depdendencyConfig.packagePresentation) {
commands.executeCommand(Commands.VIEW_PACKAGE_REFRESH);
}
this._depdendencyConfig = updatedConfig;

}));

const instrumented = instrumentOperation(Commands.VIEW_PACKAGE_CHANGEREPRESENTATION, Settings.changePackageRepresentation);
context.subscriptions.push(commands.registerCommand(Commands.VIEW_PACKAGE_CHANGEREPRESENTATION, instrumented));
}

public static changePackageRepresentation(): void {
const representationSetting = Settings.isHierarchicalView() ? PackagePresentation.Flat : PackagePresentation.Hierarchical;
workspace.getConfiguration().update("java.dependency.packagePresentation", representationSetting, false);
}

public static showOutline(): boolean {
Expand All @@ -28,5 +38,14 @@ export class Settings {
return this._depdendencyConfig.get("syncWithFolderExplorer");
}

public static isHierarchicalView(): boolean {
return this._depdendencyConfig.get("packagePresentation") === PackagePresentation.Hierarchical;
}

private static _depdendencyConfig: WorkspaceConfiguration = workspace.getConfiguration("java.dependency");
}

enum PackagePresentation {
Flat = "flat",
Hierarchical = "hierarchical",
}
4 changes: 2 additions & 2 deletions src/views/containerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Jdtls } from "../java/jdtls";
import { INodeData, NodeKind } from "../java/nodeData";
import { DataNode } from "./dataNode";
import { ExplorerNode } from "./explorerNode";
import { PackageRootNode } from "./packageRootNode";
import { NodeFactory } from "./nodeFactory";
import { ProjectNode } from "./projectNode";

export class ContainerNode extends DataNode {
Expand All @@ -21,7 +21,7 @@ export class ContainerNode extends DataNode {
if (this.nodeData.children && this.nodeData.children.length) {
this.sort();
this.nodeData.children.forEach((classpathNode) => {
result.push(new PackageRootNode(classpathNode, this, this._project));
result.push(NodeFactory.createPackageRootNode(classpathNode, this, this._project));
});
}
return result;
Expand Down
9 changes: 8 additions & 1 deletion src/views/dataNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Telemetry } from "../telemetry";
import { ExplorerNode } from "./explorerNode";

export abstract class DataNode extends ExplorerNode {
constructor(private _nodeData: INodeData, parent: DataNode) {
constructor(protected _nodeData: INodeData, parent: DataNode) {
super(parent);
}

Expand All @@ -32,6 +32,13 @@ export abstract class DataNode extends ExplorerNode {
return this._nodeData.path;
}

public async revealPaths(paths: INodeData[]): Promise<DataNode> {
const childNodeData = paths.shift();
const childs: ExplorerNode[] = await this.getChildren();
const childNode = <DataNode>childs.find((child: DataNode) => child.nodeData.name === childNodeData.name && child.path === childNodeData.path);
return childNode === null ? null : (paths.length ? childNode.revealPaths(paths) : childNode);
}

public getChildren(): ProviderResult<ExplorerNode[]> {
if (!this._nodeData.children) {
return this.loadData().then((res) => {
Expand Down
23 changes: 23 additions & 0 deletions src/views/dependencyDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Commands } from "../commands";
import { Jdtls } from "../java/jdtls";
import { INodeData, NodeKind } from "../java/nodeData";
import { Telemetry } from "../telemetry";
import { DataNode } from "./dataNode";
import { ExplorerNode } from "./explorerNode";
import { ProjectNode } from "./projectNode";
import { WorkspaceNode } from "./workspaceNode";
Expand Down Expand Up @@ -67,6 +68,28 @@ export class DependencyDataProvider implements TreeDataProvider<ExplorerNode> {
return element.getParent();
}

public async revealPaths(paths: INodeData[]): Promise<DataNode> {
const projectNodeData = paths.shift();
const projects = await this.getRootProjects();
const correspondProject = <DataNode>projects.find((node: DataNode) =>
node.path === projectNodeData.path && node.nodeData.name === projectNodeData.name);
return correspondProject.revealPaths(paths);
}

private async getRootProjects(): Promise<ExplorerNode[]> {
const rootElements = this._rootItems ? this._rootItems : await this.getChildren();
if (rootElements[0] instanceof ProjectNode) {
return rootElements;
} else {
let result = [];
for (const singleworkspace of rootElements) {
const projects = await singleworkspace.getChildren();
result = result.concat(projects);
}
return result;
}
}

private getRootNodes(): Thenable<ExplorerNode[]> {
return new Promise((resolve, reject) => {
this._rootItems = new Array<ExplorerNode>();
Expand Down
Loading