Author: dazarov
Date: 2009-04-03 12:29:01 -0400 (Fri, 03 Apr 2009)
New Revision: 14503
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/RenameComponentProcessor.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/RenameComponentWizard.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-1077
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/RenameComponentProcessor.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/RenameComponentProcessor.java 2009-04-03
16:14:46 UTC (rev 14502)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/RenameComponentProcessor.java 2009-04-03
16:29:01 UTC (rev 14503)
@@ -14,9 +14,17 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.TextFileChange;
@@ -24,6 +32,9 @@
import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant;
import org.eclipse.ltk.core.refactoring.participants.RenameProcessor;
import org.eclipse.ltk.core.refactoring.participants.SharableParticipants;
+import org.eclipse.text.edits.ReplaceEdit;
+import org.eclipse.text.edits.TextEdit;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.seam.core.ISeamComponent;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.SeamCorePlugin;
@@ -32,9 +43,12 @@
* @author Alexey Kazakov
*/
public class RenameComponentProcessor extends RenameProcessor {
+ private static final String ANNOTATION_NAME =
"Name";//"org.jboss.seam.annotations.Name";
private IFile file;
private ISeamComponent component;
+ private IAnnotation annotation;
+ private String newName;
/**
* @param component Renamed component
@@ -60,6 +74,44 @@
public void setComponent(ISeamComponent component) {
this.component = component;
}
+
+ public void setNewComponentName(String componentName){
+ if(file == null) return;
+
+ this.newName = componentName;
+
+ annotation = getAnnotation(file);
+ }
+
+ private IAnnotation getAnnotation(IFile file){
+ try{
+ ICompilationUnit unit = getCompilationUnit(file);
+ for(IType type : unit.getAllTypes()){
+ for(IAnnotation annotation : type.getAnnotations()){
+ if(annotation.getElementName().equals(ANNOTATION_NAME))
+ return annotation;
+ }
+ }
+ }catch(CoreException ex){
+ SeamCorePlugin.getDefault().logError(ex);
+ }
+ return null;
+ }
+
+ private ICompilationUnit getCompilationUnit(IFile file) throws CoreException {
+ IProject project = file.getProject();
+ IJavaProject javaProject = (IJavaProject)project.getNature(JavaCore.NATURE_ID);
+ for (IResource resource : EclipseResourceUtil.getJavaSourceRoots(project)) {
+ if(resource.getFullPath().isPrefixOf(file.getFullPath())) {
+ IPath path =
file.getFullPath().removeFirstSegments(resource.getFullPath().segmentCount());
+ IJavaElement element = javaProject.findElement(path);
+ if(element instanceof ICompilationUnit) {
+ return (ICompilationUnit)element;
+ }
+ }
+ }
+ return null;
+ }
/*
* (non-Javadoc)
@@ -93,7 +145,12 @@
@Override
public Change createChange(IProgressMonitor pm) throws CoreException,
OperationCanceledException {
- return new TextFileChange(file.getName(), file);
+ if(annotation == null)
+ return null;
+ TextFileChange change = new TextFileChange(file.getName(), file);
+ TextEdit edit = new ReplaceEdit(annotation.getSourceRange().getOffset(),
annotation.getSourceRange().getLength(),
"@"+annotation.getElementName()+"(\""+newName+"\")");
+ change.setEdit(edit);
+ return change;
}
/*
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/RenameComponentWizard.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/RenameComponentWizard.java 2009-04-03
16:14:46 UTC (rev 14502)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/RenameComponentWizard.java 2009-04-03
16:29:01 UTC (rev 14503)
@@ -12,15 +12,12 @@
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.ltk.core.refactoring.Refactoring;
-import org.eclipse.ltk.internal.core.refactoring.resource.RenameResourceProcessor;
import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
import org.jboss.tools.seam.core.ISeamComponent;
import org.jboss.tools.seam.internal.core.refactoring.RenameComponentProcessor;
import org.jboss.tools.seam.ui.widget.editor.IFieldEditor;
@@ -33,6 +30,7 @@
private ISeamComponent component;
private String componentName;
+ private IFieldEditor editor;
public RenameComponentWizard(Refactoring refactoring, ISeamComponent component) {
super(refactoring, WIZARD_BASED_USER_INTERFACE);
@@ -65,7 +63,7 @@
layout.numColumns = 2;
String defaultName = component.getName();
- IFieldEditor editor =
IFieldEditorFactory.INSTANCE.createTextEditor(componentName, "Seam component
name:", defaultName);
+ editor = IFieldEditorFactory.INSTANCE.createTextEditor(componentName, "Seam
component name:", defaultName);
editor.doFillIntoGrid(container);
setControl(container);
@@ -88,7 +86,7 @@
}
private void initializeRefactoring() {
- processor.setComponent(component);
+ processor.setNewComponentName(editor.getValueAsString());
}
}