author | Eugene Ostroukhov <eugeneo@symbian.org> |
Fri, 05 Feb 2010 09:22:26 -0800 | |
changeset 101 | 15f3b303bbb1 |
parent 52 | f577ea64429e |
permissions | -rw-r--r-- |
2 | 1 |
// Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 |
// Use of this source code is governed by a BSD-style license that can be |
|
3 |
// found in the LICENSE file. |
|
4 |
||
5 |
package org.chromium.debug.ui; |
|
6 |
||
7 |
import org.chromium.debug.core.model.Value; |
|
8 |
import org.chromium.debug.ui.editors.JsEditor; |
|
9 |
import org.eclipse.core.resources.IFile; |
|
10 |
import org.eclipse.core.resources.IResource; |
|
11 |
import org.eclipse.debug.core.model.IBreakpoint; |
|
12 |
import org.eclipse.debug.core.model.ILineBreakpoint; |
|
13 |
import org.eclipse.debug.core.model.IValue; |
|
14 |
import org.eclipse.debug.ui.IDebugModelPresentation; |
|
15 |
import org.eclipse.debug.ui.IValueDetailListener; |
|
16 |
import org.eclipse.jface.viewers.LabelProvider; |
|
17 |
import org.eclipse.swt.graphics.Image; |
|
18 |
import org.eclipse.ui.IEditorInput; |
|
19 |
import org.eclipse.ui.PartInitException; |
|
20 |
import org.eclipse.ui.ide.IDE; |
|
21 |
import org.eclipse.ui.part.FileEditorInput; |
|
22 |
||
23 |
/** |
|
24 |
* An IDebugModelPresentation for the Chromium JavaScript debug model. |
|
25 |
*/ |
|
26 |
public class JsDebugModelPresentation extends LabelProvider implements IDebugModelPresentation { |
|
27 |
||
28 |
public void setAttribute(String attribute, Object value) { |
|
29 |
} |
|
30 |
||
31 |
@Override |
|
32 |
public Image getImage(Object element) { |
|
33 |
// use default image |
|
34 |
return null; |
|
35 |
} |
|
36 |
||
37 |
@Override |
|
38 |
public String getText(Object element) { |
|
39 |
// use default label text |
|
40 |
return null; |
|
41 |
} |
|
42 |
||
43 |
public void computeDetail(IValue value, IValueDetailListener listener) { |
|
44 |
String detail = ""; //$NON-NLS-1$ |
|
45 |
if (value instanceof Value) { |
|
46 |
// Avoid quoting string JavaScript values by getting the value string |
|
47 |
// from the underlying JsValue. |
|
48 |
detail = ((Value) value).getJsValue().getValueString(); |
|
49 |
} |
|
50 |
||
51 |
listener.detailComputed(value, detail); |
|
52 |
} |
|
53 |
||
54 |
public IEditorInput getEditorInput(Object element) { |
|
55 |
return toEditorInput(element); |
|
56 |
} |
|
57 |
||
58 |
public static IEditorInput toEditorInput(Object element) { |
|
59 |
if (element instanceof IFile) { |
|
60 |
return new FileEditorInput((IFile) element); |
|
61 |
} |
|
62 |
||
63 |
if (element instanceof ILineBreakpoint) { |
|
64 |
return new FileEditorInput( |
|
65 |
(IFile) ((ILineBreakpoint) element).getMarker().getResource()); |
|
66 |
} |
|
67 |
||
68 |
return null; |
|
69 |
} |
|
70 |
||
71 |
public String getEditorId(IEditorInput input, Object element) { |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
72 |
IFile file; |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
73 |
if (element instanceof IFile) { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
74 |
file = (IFile) element; |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
75 |
} else if (element instanceof IBreakpoint) { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
76 |
IBreakpoint breakpoint = (IBreakpoint) element; |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
77 |
IResource resource = breakpoint.getMarker().getResource(); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
78 |
// Can the breakpoint resource be folder or project? Better check for it. |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
79 |
if (resource instanceof IFile == false) { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
80 |
return null; |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
81 |
} |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
82 |
file = (IFile) resource; |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
83 |
} else { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
84 |
return null; |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
85 |
} |
2 | 86 |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
87 |
// Pick the editor based on the file extension, taking user preferences into account. |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
88 |
try { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
89 |
return IDE.getEditorDescriptor(file).getId(); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
90 |
} catch (PartInitException e) { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
91 |
// TODO(peter.rybin): should it really be the default case? There might be no virtual project. |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
92 |
return JsEditor.EDITOR_ID; |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
93 |
} |
2 | 94 |
} |
95 |
} |