001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.refactoring.api;
042:
043: import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
044: import org.netbeans.modules.refactoring.spi.ui.TreeElement;
045: import org.netbeans.modules.refactoring.spi.ui.TreeElementFactory;
046: import org.openide.filesystems.FileObject;
047: import org.openide.text.PositionBounds;
048: import org.openide.util.Lookup;
049:
050: /** Interface representing a refactoring element (object affected by a refactoring)
051: * returned in a collection from {@link org.netbeans.modules.refactoring.api.AbstractRefactoring#prepare} operation.
052: * <p>
053: *
054: * @see RefactoringElementImplementation
055: * @author Martin Matula
056: */
057: public final class RefactoringElement {
058: /** Status corresponding to a normal element */
059: public static final int NORMAL = 0;
060: /** Status corresponding to an element that has a warning associated with it */
061: public static final int WARNING = 1;
062: /** Status flag that indicates that the element cannot be enabled (if a fatal
063: * problem is associated with it) */
064: public static final int GUARDED = 2;
065: /** This element is in read-only file */
066: public static final int READ_ONLY = 3;
067:
068: // delegate
069: final RefactoringElementImplementation impl;
070:
071: RefactoringElement(RefactoringElementImplementation impl) {
072: assert impl != null;
073: this .impl = impl;
074: }
075:
076: /** Returns text describing the refactoring element.
077: * @return Text.
078: */
079: public String getText() {
080: return impl.getText();
081: }
082:
083: /** Returns text describing the refactoring formatted for display (using HTML tags).
084: * @return Formatted text.
085: */
086: public String getDisplayText() {
087: return impl.getDisplayText();
088: }
089:
090: /** Indicates whether this refactoring element is enabled.
091: * @return <code>true</code> if this element is enabled, otherwise <code>false</code>.
092: */
093: public boolean isEnabled() {
094: return impl.isEnabled();
095: }
096:
097: /** Enables/disables this element.
098: * @param enabled If <code>true</code> the element is enabled, otherwise it is disabled.
099: */
100: public void setEnabled(boolean enabled) {
101: impl.setEnabled(enabled);
102: }
103:
104: /**
105: * Returns Lookup associated with this element.
106: * Lookup items might be used by TreeElementFactories to build refactoring
107: * preview trees.
108: * @see org.netbeans.modules.refactoring.spi.ui.TreeElement
109: * @see org.netbeans.modules.refactoring.spi.ui.TreeElementFactoryImplementation
110: * @return Lookup.
111: */
112: public Lookup getLookup() {
113: return impl.getLookup();
114: }
115:
116: /** Returns file that the element affects (relates to)
117: * @return File
118: */
119: public FileObject getParentFile() {
120: return impl.getParentFile();
121: }
122:
123: /** Returns position bounds of the text to be affected by this refactoring element.
124: * @return position bounds
125: */
126: public PositionBounds getPosition() {
127: return impl.getPosition();
128: }
129:
130: /** Returns the status of this refactoring element (whether it is a normal element,
131: * or a warning.
132: * @return Status of this element.
133: */
134: public int getStatus() {
135: return impl.getStatus();
136: }
137:
138: /**
139: * Shows this element in refactoring preview are
140: * @see org.netbeans.modules.refactoring.api.ui.UI#setComponentForRefactoringPreview
141: */
142: public void showPreview() {
143: impl.showPreview();
144: }
145:
146: /**
147: * opens this RefactoringElement in the editor
148: */
149: public void openInEditor() {
150: impl.openInEditor();
151: }
152: }
|