KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > refactoring > api > RefactoringElement


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 package org.netbeans.modules.refactoring.api;
20
21 import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
22 import org.openide.filesystems.FileObject;
23 import org.openide.text.PositionBounds;
24
25 /** Interface representing a refactoring element (object affected by a refactoring)
26  * returned in a collection from {@link org.netbeans.modules.refactoring.api.AbstractRefactoring#prepare} operation.
27  * <p>
28  *
29  * @see RefactoringElementImplementation
30  * @author Martin Matula
31  */

32 public final class RefactoringElement {
33     /** Status corresponding to a normal element */
34     public static final int NORMAL = 0;
35     /** Status corresponding to an element that has a warning associated with it */
36     public static final int WARNING = 1;
37     /** Status flag that indicates that the element cannot be enabled (if a fatal
38      * problem is associated with it) */

39     public static final int GUARDED = 2;
40     /** This element is in read-only file */
41     public static final int READ_ONLY = 3;
42     
43     // delegate
44
final RefactoringElementImplementation impl;
45     
46     RefactoringElement(RefactoringElementImplementation impl) {
47         assert impl != null;
48         this.impl = impl;
49     }
50     
51     /** Returns text describing the refactoring element.
52      * @return Text.
53      */

54     public String JavaDoc getText() {
55         return impl.getText();
56     }
57     
58     /** Returns text describing the refactoring formatted for display (using HTML tags).
59      * @return Formatted text.
60      */

61     public String JavaDoc getDisplayText() {
62         return impl.getDisplayText();
63     }
64     
65     /** Indicates whether this refactoring element is enabled.
66      * @return <code>true</code> if this element is enabled, otherwise <code>false</code>.
67      */

68     public boolean isEnabled() {
69         return impl.isEnabled();
70     }
71     
72     /** Enables/disables this element.
73      * @param enabled If <code>true</code> the element is enabled, otherwise it is disabled.
74      */

75     public void setEnabled(boolean enabled) {
76         impl.setEnabled(enabled);
77     }
78     
79     /**
80      * Returns element associated with this refactoring element.
81      * For instance Java Implementation returns internal representation of method
82      * from getComposite() of RefectoringElement representing reference inside
83      * of method body.
84      * @see org.netbeans.modules.refactoring.spi.ui.TreeElement
85      * @see org.netbeans.modules.refactoring.spi.ui.TreeElementFactoryImplementation
86      * @return element.
87      */

88     public Object JavaDoc getComposite() {
89         Object JavaDoc o = impl.getComposite();
90         if (o==null)
91             return getParentFile();
92         return o;
93     }
94     
95     /** Returns file that the element affects (relates to)
96      * @return File
97      */

98     public FileObject getParentFile() {
99         return impl.getParentFile();
100     }
101     
102     /** Returns position bounds of the text to be affected by this refactoring element.
103      * @return position bounds
104      */

105     public PositionBounds getPosition() {
106         return impl.getPosition();
107     }
108     
109     /** Returns the status of this refactoring element (whether it is a normal element,
110      * or a warning.
111      * @return Status of this element.
112      */

113     public int getStatus() {
114         return impl.getStatus();
115     }
116     
117     /**
118      * Shows this element in refactoring preview are
119      * @see org.netbeans.modules.refactoring.api.ui.UI#setComponentForRefactoringPreview
120      */

121     public void showPreview() {
122         impl.showPreview();
123     }
124     
125     /**
126      * opens this RefactoringElement in the editor
127      */

128     public void openInEditor() {
129         impl.openInEditor();
130     }
131 }
132
Popular Tags