1 19 20 package org.netbeans.modules.apisupport.refactoring; 21 22 import javax.swing.text.Position ; 23 import org.netbeans.jmi.javamodel.Element; 24 import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation; 25 import org.netbeans.modules.refactoring.spi.SimpleRefactoringElementImpl; 26 import org.openide.cookies.EditorCookie; 27 import org.openide.filesystems.FileObject; 28 import org.openide.loaders.DataObject; 29 import org.openide.loaders.DataObjectNotFoundException; 30 import org.openide.text.CloneableEditorSupport; 31 import org.openide.text.PositionBounds; 32 33 37 public abstract class AbstractRefactoringElement extends SimpleRefactoringElementImpl implements RefactoringElementImplementation { 38 39 private int status = RefactoringElementImplementation.NORMAL; 40 41 protected String name; 42 protected FileObject parentFile; 43 protected boolean enabled = true; 44 45 public AbstractRefactoringElement() { 46 } 47 48 public boolean isEnabled() { 49 return enabled; 50 } 51 52 public String getText() { 53 return getDisplayText(); 54 } 55 56 public void setEnabled(boolean enabled) { 57 this.enabled = enabled; 58 } 59 60 public Element getJavaElement() { 61 return null; 62 } 63 64 public FileObject getParentFile() { 65 return parentFile; 66 } 67 68 69 protected int[] location() { 70 return new int[] {0, 0}; 71 } 72 private int[] loc; 74 public PositionBounds getPosition() { 75 try { 76 DataObject dobj = DataObject.find(getParentFile()); 77 if (dobj != null) { 78 EditorCookie.Observable obs = (EditorCookie.Observable)dobj.getCookie(EditorCookie.Observable.class); 79 if (obs != null && obs instanceof CloneableEditorSupport) { 80 CloneableEditorSupport supp = (CloneableEditorSupport)obs; 81 82 if (loc == null) { 83 loc = location(); 84 } 85 PositionBounds bounds = new PositionBounds( 86 supp.createPositionRef(loc[0], Position.Bias.Forward), 87 supp.createPositionRef(Math.max(loc[0], loc[1]), Position.Bias.Forward) 88 ); 89 90 return bounds; 91 } 92 } 93 } catch (DataObjectNotFoundException ex) { 94 ex.printStackTrace(); 95 } 96 return null; 97 } 98 99 public int getStatus() { 100 return status; 101 } 102 103 public void setStatus(int status) { 104 this.status = status; 105 } 106 107 public void performChange() { } 108 109 } 110 | Popular Tags |