Example usage for org.eclipse.jface.viewers StructuredSelection toString

List of usage examples for org.eclipse.jface.viewers StructuredSelection toString

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers StructuredSelection toString.

Prototype

@Override
public String toString() 

Source Link

Document

Internal method which returns a string representation of this selection suitable for debug purposes only.

Usage

From source file:org.junithelper.plugin.util.ResourcePathUtil.java

License:Apache License

@SuppressWarnings("restriction")
public static String getPathStartsFromProjectRoot(StructuredSelection structuredSelection) {
    PreferenceLoader pref = new PreferenceLoader(store);
    String pathFromProjectRoot = StringValue.Empty;
    if (structuredSelection == null) {
        // ----------------------------------------
        // java editor
        // ----------------------------------------
        IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        pathFromProjectRoot = StringValue.DirectorySeparator.General
                + activePage.getActiveEditor().getTitleToolTip();
    } else if (structuredSelection.getFirstElement() instanceof org.eclipse.core.internal.resources.File) {
        // ----------------------------------------
        // navigator
        // ----------------------------------------
        pathFromProjectRoot = structuredSelection.toString().replace("[L", StringValue.Empty).replace("]",
                StringValue.Empty);// w w w .  j  a va2  s .  co  m
    } else if (structuredSelection.getFirstElement() instanceof org.eclipse.jdt.internal.core.CompilationUnit) {
        // ----------------------------------------
        // package explorer
        // ----------------------------------------
        // TODO better implementation
        String cuToString = structuredSelection.toString();
        String packagePath = cuToString.split("\\[in")[1].trim().replaceAll("\\.",
                StringValue.DirectorySeparator.General);
        String projectName = cuToString.split("\\[in")[3].trim().split("]")[0];
        String testTargetClassname = cuToString.split(RegExp.FileExtension.JavaFile)[0]
                .replaceAll("(\\[|\\])", StringValue.Empty).replaceAll("Working copy ", StringValue.Empty)
                .trim();
        pathFromProjectRoot = StringValue.DirectorySeparator.General + projectName
                + StringValue.DirectorySeparator.General + pref.directoryPathOfProductSourceCode
                + StringValue.DirectorySeparator.General + packagePath + StringValue.DirectorySeparator.General
                + testTargetClassname + StringValue.DirectorySeparator.General;
    }
    return pathFromProjectRoot;
}