1 19 package org.netbeans.modules.refactoring.java; 20 21 import java.io.Reader ; 22 import java.io.StringReader ; 23 import javax.swing.text.StyledDocument ; 24 import org.netbeans.api.java.source.ModificationResult; 25 import org.netbeans.api.java.source.ModificationResult.Difference; 26 import org.netbeans.modules.refactoring.spi.SimpleRefactoringElementImpl; 27 import org.netbeans.modules.refactoring.java.ui.tree.ElementGripFactory; 28 import org.openide.filesystems.FileObject; 29 import org.openide.text.PositionBounds; 30 import static org.netbeans.modules.refactoring.java.RetoucheUtils.*; 31 import org.openide.text.PositionRef; 32 33 37 public class DiffElement extends SimpleRefactoringElementImpl { 38 private PositionBounds bounds; 39 private String displayText; 40 private FileObject parentFile; 41 private Difference diff; 42 private ModificationResult modification; 43 44 public DiffElement(Difference diff, PositionBounds bounds, FileObject parentFile, ModificationResult modification) { 45 this.bounds = bounds; 46 this.displayText = diff.getDescription(); 47 this.parentFile = parentFile; 48 this.diff = diff; 49 this.modification = modification; 50 } 51 52 public String getDisplayText() { 53 return displayText; 54 } 55 56 public Object getComposite() { 57 Object composite = ElementGripFactory.getDefault().get(parentFile, bounds.getBegin().getOffset()); 58 if (composite==null) 59 composite = parentFile; 60 return composite; 61 } 62 63 public void setEnabled(boolean enabled) { 64 diff.exclude(!enabled); 65 super.setEnabled(enabled); 66 } 67 68 public PositionBounds getPosition() { 69 return bounds; 70 } 71 72 public String getText() { 73 return displayText; 74 } 75 76 public void performChange() { 77 } 78 79 public FileObject getParentFile() { 80 return parentFile; 81 } 82 83 public Reader getReader() { 84 try { 85 return new StringReader (modification.getResultingSource(parentFile)); 86 } catch (Exception e) { 87 return null; 88 } 89 } 90 91 117 public static DiffElement create(Difference diff, FileObject fileObject, ModificationResult modification) { 118 PositionRef start = diff.getStartPosition(); 119 PositionRef end = diff.getEndPosition(); 120 StyledDocument doc = null; 121 PositionBounds bounds = new PositionBounds(start, end); 122 return new DiffElement(diff, bounds, fileObject, modification); 123 } 124 } 125 | Popular Tags |