KickJava   Java API By Example, From Geeks To Geeks.

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


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.ui.IEditorInput;
20 import org.eclipse.ui.texteditor.AddMarkerAction;
21 import org.eclipse.ui.texteditor.ITextEditor;
22
23 import org.eclipse.jdt.core.IClassFile;
24 import org.eclipse.jdt.core.JavaCore;
25 import org.eclipse.jdt.core.JavaModelException;
26
27 import org.eclipse.jdt.internal.ui.IResourceLocator;
28
29
30
31 class AddClassFileMarkerAction extends AddMarkerAction {
32
33
34     /**
35      * Creates a marker action.
36      */

37     public AddClassFileMarkerAction(String JavaDoc prefix, ITextEditor textEditor, String JavaDoc markerType, boolean askForLabel) {
38         super(JavaEditorMessages.getBundleForConstructedKeys(), prefix, textEditor, markerType, askForLabel);
39     }
40
41     /**
42      * @see AddMarkerAction#getResource()
43      */

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

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