KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > javaeditor > ClassFileMarkerRulerAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.jdt.internal.ui.javaeditor;
13
14
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.core.resources.IResource;
18
19 import org.eclipse.jface.text.source.IVerticalRuler;
20
21 import org.eclipse.ui.IEditorInput;
22 import org.eclipse.ui.texteditor.ITextEditor;
23 import org.eclipse.ui.texteditor.MarkerRulerAction;
24
25 import org.eclipse.jdt.core.IClassFile;
26 import org.eclipse.jdt.core.JavaCore;
27 import org.eclipse.jdt.core.JavaModelException;
28
29 import org.eclipse.jdt.internal.ui.IResourceLocator;
30
31
32
33 class ClassFileMarkerRulerAction extends MarkerRulerAction {
34
35
36     public ClassFileMarkerRulerAction(String JavaDoc prefix, IVerticalRuler ruler, ITextEditor editor, String JavaDoc markerType, boolean askForLabel) {
37         super(JavaEditorMessages.getBundleForConstructedKeys(), prefix, editor, ruler, markerType, askForLabel);
38     }
39
40     /**
41      * @see MarkerRulerAction#getResource()
42      */

43     protected IResource getResource() {
44
45         IResource resource= null;
46
47         IEditorInput input= getTextEditor().getEditorInput();
48         if (input instanceof IClassFileEditorInput) {
49             IClassFile c= ((IClassFileEditorInput) input).getClassFile();
50             IResourceLocator locator= (IResourceLocator) c.getAdapter(IResourceLocator.class);
51             if (locator != null) {
52                 try {
53                     resource= locator.getContainingResource(c);
54                 } catch (JavaModelException x) {
55                     // ignore but should inform
56
}
57             }
58         }
59
60         return resource;
61     }
62
63     /**
64      * @see MarkerRulerAction#getInitialAttributes()
65      */

66     protected Map JavaDoc getInitialAttributes() {
67
68         Map JavaDoc attributes= super.getInitialAttributes();
69
70         IEditorInput input= getTextEditor().getEditorInput();
71         if (input instanceof IClassFileEditorInput) {
72             IClassFile classFile= ((IClassFileEditorInput) input).getClassFile();
73             JavaCore.addJavaElementMarkerAttributes(attributes, classFile);
74         }
75
76         return attributes;
77     }
78 }
79
Popular Tags