ruby.refactoring/src/org/netbeans/modules/refactoring/ruby/DiffElement.java
changeset 4559 7a0a8afa3e90
parent 4117 6e1f647524a5
     1.1 --- a/ruby.refactoring/src/org/netbeans/modules/refactoring/ruby/DiffElement.java	Mon May 17 14:16:07 2010 -0400
     1.2 +++ b/ruby.refactoring/src/org/netbeans/modules/refactoring/ruby/DiffElement.java	Tue Apr 22 15:36:21 2014 -0500
     1.3 @@ -48,10 +48,9 @@
     1.4  import org.netbeans.modules.csl.spi.support.ModificationResult;
     1.5  import org.netbeans.modules.csl.spi.support.ModificationResult.Difference;
     1.6  import org.netbeans.modules.refactoring.spi.SimpleRefactoringElementImplementation;
     1.7 -import org.netbeans.modules.refactoring.ruby.ui.tree.ElementGripFactory;
     1.8 +import org.openide.filesystems.FileLock;
     1.9  import org.openide.filesystems.FileObject;
    1.10  import org.openide.text.PositionBounds;
    1.11 -import org.openide.text.PositionRef;
    1.12  import org.openide.util.Exceptions;
    1.13  import org.openide.util.Lookup;
    1.14  import org.openide.util.lookup.Lookups;
    1.15 @@ -77,15 +76,18 @@
    1.16          this.modification = modification;
    1.17      }
    1.18  
    1.19 +    @Override
    1.20      public String getDisplayText() {
    1.21          return displayText;
    1.22      }
    1.23  
    1.24 +    @Override
    1.25      public Lookup getLookup() {
    1.26 -        Object composite = ElementGripFactory.getDefault().get(parentFile, bounds.getBegin().getOffset());
    1.27 -        if (composite==null) 
    1.28 -            composite = parentFile;
    1.29 -        return Lookups.fixed(composite, diff);
    1.30 +//        Object composite = ElementGripFactory.getDefault().get(parentFile, bounds.getBegin().getOffset());
    1.31 +//        if (composite==null)
    1.32 +//            composite = parentFile;
    1.33 +//        return Lookups.fixed(composite, diff);
    1.34 +        return Lookups.fixed(diff);
    1.35      }
    1.36      
    1.37      @Override
    1.38 @@ -95,6 +97,7 @@
    1.39          super.setEnabled(enabled);
    1.40      }
    1.41  
    1.42 +    @Override
    1.43      public PositionBounds getPosition() {
    1.44          return bounds;
    1.45      }
    1.46 @@ -103,9 +106,24 @@
    1.47          return displayText;
    1.48      }
    1.49  
    1.50 +    @Override
    1.51      public void performChange() {
    1.52 +        String oldFileName = diff.getOldText();
    1.53 +        String newFileName = diff.getNewText();
    1.54 +
    1.55 +        if (parentFile.getName().equals(oldFileName)) {
    1.56 +            try {
    1.57 +                FileLock fileLock = parentFile.lock();
    1.58 +                parentFile.rename(fileLock, newFileName, "ruby"); // NOI18N
    1.59 +                fileLock.releaseLock();
    1.60 +            } catch (IOException e) {
    1.61 +                Exceptions.printStackTrace(e);
    1.62 +            }
    1.63 +        }
    1.64 +
    1.65      }
    1.66  
    1.67 +    @Override
    1.68      public FileObject getParentFile() {
    1.69          return parentFile;
    1.70      }
    1.71 @@ -129,9 +147,8 @@
    1.72      }
    1.73      
    1.74      public static DiffElement create(Difference diff, FileObject fileObject, ModificationResult modification) {
    1.75 -        PositionRef start = diff.getStartPosition();
    1.76 -        PositionRef end = diff.getEndPosition();
    1.77 -        PositionBounds bounds = new PositionBounds(start, end);
    1.78 +        PositionBounds bounds = new PositionBounds(diff.getStartPosition(), diff.getEndPosition());
    1.79 +        
    1.80          return new DiffElement(diff, bounds, fileObject, modification);
    1.81      }    
    1.82  }