KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > debug > model > AntDebugModelPresentation


1 /*******************************************************************************
2  * Copyright (c) 2004, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ant.internal.ui.debug.model;
13
14 import java.io.File JavaDoc;
15
16 import org.eclipse.ant.internal.ui.AntUIPlugin;
17 import org.eclipse.ant.internal.ui.preferences.AntObjectLabelProvider;
18 import org.eclipse.core.filesystem.EFS;
19 import org.eclipse.core.filesystem.IFileStore;
20 import org.eclipse.core.resources.IFile;
21 import org.eclipse.core.resources.IMarker;
22 import org.eclipse.core.runtime.CoreException;
23 import org.eclipse.debug.core.DebugException;
24 import org.eclipse.debug.core.model.IBreakpoint;
25 import org.eclipse.debug.core.model.ILineBreakpoint;
26 import org.eclipse.debug.core.model.IValue;
27 import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
28 import org.eclipse.debug.ui.IDebugModelPresentation;
29 import org.eclipse.debug.ui.IValueDetailListener;
30 import org.eclipse.jface.viewers.LabelProvider;
31 import org.eclipse.swt.graphics.Image;
32 import org.eclipse.ui.IEditorInput;
33 import org.eclipse.ui.ide.FileStoreEditorInput;
34 import org.eclipse.ui.part.FileEditorInput;
35
36 import com.ibm.icu.text.MessageFormat;
37
38 /**
39  * Renders Ant debug elements
40  */

41 public class AntDebugModelPresentation extends LabelProvider implements IDebugModelPresentation {
42     
43     /* (non-Javadoc)
44      * @see org.eclipse.debug.ui.IDebugModelPresentation#setAttribute(java.lang.String, java.lang.Object)
45      */

46     public void setAttribute(String JavaDoc attribute, Object JavaDoc value) {
47     }
48     
49     /* (non-Javadoc)
50      * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
51      */

52     public Image getImage(Object JavaDoc element) {
53         if (element instanceof AntProperty) {
54             return AntObjectLabelProvider.getPropertyImage();
55         } else if (element instanceof AntProperties) {
56             return AntObjectLabelProvider.getPropertyImage();
57         }
58         return null;
59     }
60     
61     /* (non-Javadoc)
62      * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
63      */

64     public String JavaDoc getText(Object JavaDoc element) {
65         if (element instanceof AntStackFrame) {
66             AntStackFrame frame= (AntStackFrame) element;
67             return getStackFrameText(frame);
68         } else if (element instanceof AntThread) {
69             AntThread thread= (AntThread) element;
70             return getThreadText(thread);
71         } else if (element instanceof AntProperty) {
72             AntProperty property= (AntProperty) element;
73             return property.getText();
74         } else if (element instanceof AntProperties) {
75            return ((AntProperties)element).getName();
76         }
77         
78         return null;
79     }
80
81     private String JavaDoc getThreadText(AntThread thread) {
82         String JavaDoc name= thread.getName();
83         if (name != null) {
84             StringBuffer JavaDoc text= new StringBuffer JavaDoc(name);
85             if (thread.isSuspended()) {
86                 IBreakpoint[] breakpoints= thread.getBreakpoints();
87                 if (breakpoints.length > 0) {
88                     AntLineBreakpoint breakpoint= (AntLineBreakpoint) breakpoints[0];
89                     IMarker marker= breakpoint.getMarker();
90                     String JavaDoc fileName= marker.getResource().getFullPath().lastSegment();
91                     String JavaDoc lineNumber= Integer.toString(marker.getAttribute(IMarker.LINE_NUMBER, -1));
92                     String JavaDoc breakpointString= null;
93                     if (breakpoint.isRunToLine()) {
94                         breakpointString= MessageFormat.format(DebugModelMessages.AntDebugModelPresentation_5, new String JavaDoc[] {lineNumber, fileName});
95                     } else {
96                         breakpointString= MessageFormat.format(DebugModelMessages.AntDebugModelPresentation_2, new String JavaDoc[]{lineNumber, fileName});
97                     }
98                     text.append(MessageFormat.format(DebugModelMessages.AntDebugModelPresentation_3, new String JavaDoc[]{breakpointString}));
99                 } else {
100                     text.append(DebugModelMessages.AntDebugModelPresentation_4);
101                 }
102             }
103             
104             return text.toString();
105         }
106         return null;
107     }
108
109     private String JavaDoc getStackFrameText(AntStackFrame frame) {
110         String JavaDoc name= frame.getName();
111         if (name != null) {
112             StringBuffer JavaDoc text= new StringBuffer JavaDoc(name);
113             int lineNumber= frame.getLineNumber();
114             String JavaDoc lineNumberString= null;
115             if (lineNumber == 0) {
116                 lineNumberString= DebugModelMessages.AntDebugModelPresentation_0;
117             } else {
118                 lineNumberString= Integer.toString(lineNumber);
119             }
120             text.append(MessageFormat.format(DebugModelMessages.AntDebugModelPresentation_1, new String JavaDoc[]{lineNumberString}));
121             return text.toString();
122         }
123         return null;
124     }
125
126     /* (non-Javadoc)
127      * @see org.eclipse.debug.ui.IDebugModelPresentation#computeDetail(org.eclipse.debug.core.model.IValue, org.eclipse.debug.ui.IValueDetailListener)
128      */

129     public void computeDetail(IValue value, IValueDetailListener listener) {
130         String JavaDoc detail = ""; //$NON-NLS-1$
131
try {
132             detail = value.getValueString();
133         } catch (DebugException e) {
134         }
135         listener.detailComputed(value, detail);
136     }
137     
138     /* (non-Javadoc)
139      * @see org.eclipse.debug.ui.ISourcePresentation#getEditorInput(java.lang.Object)
140      */

141     public IEditorInput getEditorInput(Object JavaDoc element) {
142         if (element instanceof IFile) {
143             return new FileEditorInput((IFile)element);
144         }
145         if (element instanceof ILineBreakpoint) {
146             return new FileEditorInput((IFile)((ILineBreakpoint)element).getMarker().getResource());
147         }
148         if (element instanceof LocalFileStorage) {
149             File JavaDoc file= ((LocalFileStorage)element).getFile();
150             IFileStore fileStore;
151             try {
152                 fileStore = EFS.getStore(file.toURI());
153                 return new FileStoreEditorInput(fileStore);
154             } catch (CoreException e) {
155                 AntUIPlugin.log(e);
156                 return null;
157             }
158         }
159         return null;
160     }
161     
162     /* (non-Javadoc)
163      * @see org.eclipse.debug.ui.ISourcePresentation#getEditorId(org.eclipse.ui.IEditorInput, java.lang.Object)
164      */

165     public String JavaDoc getEditorId(IEditorInput input, Object JavaDoc element) {
166         return "org.eclipse.ant.ui.internal.editor.AntEditor"; //$NON-NLS-1$
167
}
168 }
169
Popular Tags