KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > refactoring > safedelete > AbstractSafeDeleteRefactoringElement


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.safedelete;
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  * @author pfiala
34  */

35 public abstract class AbstractSafeDeleteRefactoringElement extends SimpleRefactoringElementImpl implements RefactoringElementImplementation {
36
37     private int status = RefactoringElementImplementation.NORMAL;
38
39     protected boolean enabled = true;
40     protected FileObject parentFile;
41
42     protected AbstractSafeDeleteRefactoringElement(FileObject parentFile) {
43         this.parentFile = parentFile;
44     }
45
46     protected AbstractSafeDeleteRefactoringElement(){
47     }
48
49     /** Indicates whether this refactoring element is enabled.
50      * @return <code>true</code> if this element is enabled, otherwise <code>false</code>.
51      */

52     public boolean isEnabled() {
53         return enabled;
54     }
55
56     /** Enables/disables this element.
57      * @param enabled If <code>true</code> the element is enabled, otherwise it is disabled.
58      */

59     public void setEnabled(boolean enabled) {
60         this.enabled = enabled;
61     }
62
63     /** Returns text describing the refactoring element.
64      * @return Text.
65      */

66     public String JavaDoc getText() {
67         return getDisplayText();
68     }
69
70     /** Returns Java element associated with this refactoring element.
71      * @return MDR Java element.
72      */

73     public Element getJavaElement() {
74         return null;
75     }
76
77     /** Returns file that the element affects (relates to)
78      * @return File
79      */

80     public FileObject getParentFile() {
81         return parentFile;
82     }
83
84     /** Returns position bounds of the text to be affected by this refactoring element.
85      */

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

99     public int getStatus() {
100         return status;
101     }
102
103     public void setStatus(int status) {
104         this.status = status;
105     }
106 }
Popular Tags