plugins/org.symbian.tools.tmw.debug/src/org/symbian/tools/wrttools/debug/internal/launch/WrtLabelProvider.java
changeset 471 06589bf52fa7
parent 470 d4809db37847
child 472 bd9f2d7c64a6
equal deleted inserted replaced
470:d4809db37847 471:06589bf52fa7
     1 package org.symbian.tools.wrttools.debug.internal.launch;
       
     2 
       
     3 import org.chromium.debug.core.model.DebugTargetImpl;
       
     4 import org.chromium.debug.core.model.JavascriptThread;
       
     5 import org.chromium.debug.core.model.Messages;
       
     6 import org.chromium.debug.core.model.StackFrame;
       
     7 import org.chromium.debug.core.model.WorkspaceBridge.JsLabelProvider;
       
     8 import org.chromium.sdk.CallFrame;
       
     9 import org.chromium.sdk.DebugContext;
       
    10 import org.chromium.sdk.ExceptionData;
       
    11 import org.chromium.sdk.Script;
       
    12 import org.eclipse.core.filesystem.IFileStore;
       
    13 import org.eclipse.core.resources.IFile;
       
    14 import org.eclipse.debug.core.DebugException;
       
    15 import org.eclipse.osgi.util.NLS;
       
    16 
       
    17 public class WrtLabelProvider implements JsLabelProvider {
       
    18 
       
    19     public String getStackFrameLabel(StackFrame stackFrame) throws DebugException {
       
    20         CallFrame callFrame = stackFrame.getCallFrame();
       
    21         String name = callFrame.getFunctionName();
       
    22         Script script = callFrame.getScript();
       
    23         if (script == null) {
       
    24             return "<unknown>";
       
    25         }
       
    26         Object element = stackFrame.getLaunch().getSourceLocator().getSourceElement(stackFrame);
       
    27         if (element instanceof IFile) {
       
    28             IFile resource = (IFile) element;
       
    29             int line = script.getStartLine() + stackFrame.getLineNumber();
       
    30             if (line != -1) {
       
    31                 String resourcePath = resource != null ? resource.getProjectRelativePath().toString() : script
       
    32                         .getName();
       
    33                 name = NLS.bind("{0} [{1}:{2}]", new Object[] { name, resourcePath, line });
       
    34             }
       
    35         } else if (element instanceof IFileStore) {
       
    36             return "(WRT System Library)";
       
    37         }
       
    38         return name;
       
    39     }
       
    40 
       
    41     public String getTargetLabel(DebugTargetImpl debugTarget) throws DebugException {
       
    42         return "WRT Runtime";
       
    43     }
       
    44 
       
    45     public String getThreadLabel(JavascriptThread thread) throws DebugException {
       
    46         return NLS.bind("JavaScript Thread ({0})", getThreadStateLabel(thread));
       
    47     }
       
    48 
       
    49     private String getThreadStateLabel(JavascriptThread thread) {
       
    50         if (thread.isSuspended()) {
       
    51             DebugContext context = thread.getDebugTarget().getDebugContext();
       
    52             ExceptionData exceptionData = context.getExceptionData();
       
    53             if (exceptionData != null) {
       
    54                 return NLS.bind(Messages.JsThread_ThreadLabelSuspendedExceptionFormat,
       
    55                         exceptionData.getExceptionMessage());
       
    56             } else {
       
    57                 return Messages.JsThread_ThreadLabelSuspended;
       
    58             }
       
    59         } else {
       
    60             return Messages.JsThread_ThreadLabelRunning;
       
    61         }
       
    62     }
       
    63 
       
    64 }