1 19 package org.netbeans.modules.xml.refactoring; 20 21 import java.util.Set ; 22 import org.netbeans.modules.xml.refactoring.impl.RefactoringUtil; 23 import org.netbeans.modules.xml.xam.Component; 24 import org.netbeans.modules.xml.xam.Model; 25 26 30 public class FileRenameRequest extends RefactorRequest { 31 private String oldFileName; 32 private String newFileName; 33 private Model target; 34 35 36 public FileRenameRequest(Model target) { 37 this(target, (Set <Component>)null); 38 } 39 40 public FileRenameRequest(Model target, Set <Component> scope) { 41 super(scope); 42 if (! (target instanceof Model)) { 43 throw new IllegalArgumentException ("Expect refactor target is a Model instance"); 44 } 45 this.target = target; 46 oldFileName = getTargetName(); 47 } 48 49 public FileRenameRequest(Model target, String newFileName) { 50 this(target, (Set <Component>)null); 51 this.newFileName = newFileName; 52 } 53 54 public Class <FileRenameRequest> getType() { 55 return FileRenameRequest.class; 56 } 57 58 public boolean confirmChangePerformed() { 59 return getFileObject().getName().equals(newFileName); 60 } 61 62 public Model getTarget() { 63 return target; 64 } 65 66 public String getOldFileName() { 67 return oldFileName; 68 } 69 70 public String getNewFileName() { 71 return newFileName; 72 } 73 74 public void setNewFileName(String v) { 75 newFileName = v; 76 } 77 78 public String getTargetName() { 79 return this.getFileObject().getName(); 80 } 81 82 public String calculateNewLocationString(String currentLocationString) { 83 StringBuilder sb = new StringBuilder (); 84 int i = currentLocationString.lastIndexOf('/'); 85 if (i > -1) { 86 sb.append(currentLocationString.substring(0, i+1)); 87 } 88 sb.append(getNewFileName()); 89 sb.append("."); sb.append(getFileObject().getExt()); 91 return sb.toString(); 92 } 93 94 public void precheckChange() { 95 super.precheckChange(); 96 ErrorItem error = RefactoringUtil.precheck(this); 97 if (error != null) { 98 addError(error); 99 } 100 } 101 102 } 103 | Popular Tags |