1 19 20 package org.netbeans.modules.xml.refactoring; 21 22 import java.util.Collection ; 23 import java.util.List ; 24 import java.util.concurrent.ExecutionException ; 25 import org.netbeans.modules.refactoring.api.AbstractRefactoring; 26 import org.netbeans.modules.refactoring.api.Problem; 27 import org.netbeans.modules.refactoring.api.ProgressEvent; 28 import org.netbeans.modules.refactoring.spi.ProgressProviderAdapter; 29 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag; 30 import org.netbeans.modules.refactoring.api.WhereUsedQuery; 31 import org.netbeans.modules.refactoring.spi.RefactoringPlugin; 32 import org.netbeans.modules.xml.xam.Component; 33 import org.netbeans.modules.xml.xam.Named; 34 import org.netbeans.modules.xml.xam.Referenceable; 35 import org.openide.ErrorManager; 36 37 38 39 43 public class XMLWhereUsedRefactoringPlugin extends ProgressProviderAdapter implements RefactoringPlugin { 44 45 46 47 public void cancelRequest() { 48 49 } 50 51 public Problem fastCheckParameters() { 52 return null; 53 } 54 55 private WhereUsedQuery query; 56 57 58 61 public XMLWhereUsedRefactoringPlugin(WhereUsedQuery refactoring) { 62 this.query = refactoring; 63 } 64 65 68 public Problem preCheck() { 69 return null; 70 } 71 72 75 public Problem checkParameters() { 76 Problem problem = null; 77 78 return problem; 79 } 80 81 87 public Problem prepare(RefactoringElementsBag refactoringElements) { 88 Referenceable ref = query.getRefactoringSource().lookup(Referenceable.class); 89 if (ref == null) 90 return null; 91 fireProgressListenerStart(ProgressEvent.START, -1); 93 FindUsageResult fuResult =RefactoringManager.getInstance().findUsages(ref); 94 UsageSet us = null; 95 try { 96 us = fuResult.get(); 97 } catch (InterruptedException ex) { 98 ErrorManager.getDefault().notify(ex); 99 } catch (ExecutionException ex) { 100 ErrorManager.getDefault().notify(ex); 101 } 102 Collection <UsageGroup> usageGroups = us.getUsages(); 103 for (UsageGroup ug:usageGroups){ 104 int count = ug.getItems().size(); 105 List <Usage> usage = ug.getItems(); 106 for(Usage u:usage){ 107 refactoringElements.add(query, new XMLRefactoringElement(u)); 108 fireProgressListenerStep(); 109 } 110 } 111 fireProgressListenerStop(); 112 114 return null; 115 } 116 117 118 119 } 120 121 | Popular Tags |