KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > refactoring > whereused > AbstractWhereUsedRefactoringElement


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.refactoring.whereused;
21
22 import org.netbeans.jmi.javamodel.Element;
23 import org.netbeans.modules.j2ee.refactoring.DefaultPositionBoundsResolver;
24 import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
25 import org.netbeans.modules.refactoring.spi.SimpleRefactoringElementImpl;
26 import org.openide.ErrorManager;
27 import org.openide.filesystems.FileObject;
28 import org.openide.loaders.DataObject;
29 import org.openide.loaders.DataObjectNotFoundException;
30 import org.openide.text.PositionBounds;
31
32 /**
33  *
34  * @author Martin Grebac
35  */

36 public abstract class AbstractWhereUsedRefactoringElement extends SimpleRefactoringElementImpl implements RefactoringElementImplementation {
37
38     private int status = RefactoringElementImplementation.NORMAL;
39     
40     protected String JavaDoc name;
41     protected FileObject parentFile;
42     
43     /** Creates a new instance of AbstractWhereUsedRefactoringElement */
44     public AbstractWhereUsedRefactoringElement() {
45     }
46     
47     /** Indicates whether this refactoring element is enabled.
48      * @return <code>true</code> if this element is enabled, otherwise <code>false</code>.
49      */

50     public boolean isEnabled() {
51         return true;
52     }
53     
54     /** Returns text describing the refactoring element.
55      * @return Text.
56      */

57     public String JavaDoc getText() {
58         return getDisplayText();
59     }
60     
61     /** Enables/disables this element.
62      * @param enabled If <code>true</code> the element is enabled, otherwise it is disabled.
63      */

64     public void setEnabled(boolean enabled) { }
65     
66     /** Returns Java element associated with this refactoring element.
67      * @return MDR Java element.
68      */

69     public Element getJavaElement() {
70         return null;
71     }
72     
73     /** Returns file that the element affects (relates to)
74      * @return File
75      */

76     public FileObject getParentFile() {
77         return parentFile;
78     }
79     
80     /** Returns position bounds of the text to be affected by this refactoring element.
81      */

82     public PositionBounds getPosition() {
83         try {
84             return new DefaultPositionBoundsResolver(DataObject.find(getParentFile()), name).getPositionBounds();
85         } catch (DataObjectNotFoundException ex) {
86             ErrorManager.getDefault().notify(ex);
87         }
88         return null;
89     }
90     
91     /** Returns the status of this refactoring element (whether it is a normal element,
92      * or a warning.
93      * @return Status of this element.
94      */

95     public int getStatus() {
96         return status;
97     }
98     
99     public void setStatus(int status) {
100         this.status = status;
101     }
102     
103     /** Performs the change represented by this refactoring element.
104      */

105     public void performChange() { }
106 }
107
Popular Tags