Author: scabanovich
Date: 2011-10-26 20:55:50 -0400 (Wed, 26 Oct 2011)
New Revision: 36032
Modified:
trunk/common/plugins/org.jboss.tools.common.model/META-INF/MANIFEST.MF
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/refactoring/ModelRenameProcessor.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/refactoring/RenameModelObjectChange.java
Log:
JBIDE-8571
https://issues.jboss.org/browse/JBIDE-8571
Refactor/Rename in ESB editor for channel id and for schedule id is implemented.
Modified: trunk/common/plugins/org.jboss.tools.common.model/META-INF/MANIFEST.MF
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model/META-INF/MANIFEST.MF 2011-10-27
00:54:11 UTC (rev 36031)
+++ trunk/common/plugins/org.jboss.tools.common.model/META-INF/MANIFEST.MF 2011-10-27
00:55:50 UTC (rev 36032)
@@ -69,14 +69,14 @@
org.eclipse.jdt.core;visibility:=reexport;bundle-version="3.7.0",
org.eclipse.swt;visibility:=reexport;bundle-version="3.7.0",
org.eclipse.ui;bundle-version="3.7.0",
- org.eclipse.jdt.ui;bundle-version="3.7.0",
+ org.eclipse.jdt.ui;visibility:=reexport;bundle-version="3.7.0",
org.eclipse.debug.core;bundle-version="3.7.0",
org.eclipse.debug.ui;bundle-version="3.7.0",
org.eclipse.help;bundle-version="3.5.0",
org.eclipse.ant.ui;bundle-version="3.5.100",
org.eclipse.ant.core;bundle-version="3.2.200",
- org.eclipse.ltk.core.refactoring;bundle-version="3.5.200",
- org.eclipse.ltk.ui.refactoring;bundle-version="3.5.100",
+
org.eclipse.ltk.core.refactoring;visibility:=reexport;bundle-version="3.5.200",
+ org.eclipse.ltk.ui.refactoring;visibility:=reexport;bundle-version="3.5.100",
org.eclipse.wst.common.uriresolver;bundle-version="1.1.401",
org.eclipse.wst.common.modulecore;bundle-version="1.2.100",
org.eclipse.jem.util;bundle-version="2.1.2",
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/refactoring/ModelRenameProcessor.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/refactoring/ModelRenameProcessor.java 2011-10-27
00:54:11 UTC (rev 36031)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/refactoring/ModelRenameProcessor.java 2011-10-27
00:55:50 UTC (rev 36032)
@@ -21,6 +21,7 @@
public abstract class ModelRenameProcessor extends RenameProcessor implements
INameUpdating, IReferenceUpdating {
protected XModelObject object;
protected String fNewElementName;
+ private boolean updateReferences = true;
public ModelRenameProcessor() {}
@@ -72,10 +73,6 @@
return object;
}
- public boolean getUpdateReferences() {
- return true;
- }
-
public RefactoringParticipant[] loadParticipants(RefactoringStatus status,
SharableParticipants shared) throws CoreException {
Object[] elements= getElements();
String[] natures= getAffectedProjectNatures();
@@ -117,4 +114,12 @@
return null;
}
+ public void setUpdateReferences(boolean update) {
+ updateReferences = update;
+ }
+
+ public boolean getUpdateReferences() {
+ return updateReferences;
+ }
+
}
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/refactoring/RenameModelObjectChange.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/refactoring/RenameModelObjectChange.java 2011-10-27
00:54:11 UTC (rev 36031)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/refactoring/RenameModelObjectChange.java 2011-10-27
00:55:50 UTC (rev 36032)
@@ -11,6 +11,9 @@
package org.jboss.tools.common.model.refactoring;
import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -21,7 +24,6 @@
import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.model.filesystems.impl.FileAnyImpl;
import org.jboss.tools.common.model.impl.XModelObjectImpl;
-import org.jboss.tools.common.model.plugin.ModelPlugin;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.model.util.PositionSearcher;
@@ -35,16 +37,22 @@
*
* Use restrictions:
* 1. All objects must belong to the same file object.
- * 2. You should not create to independent changes that
- * process the same file object. For instance, if you need
- * process two sets of objects from one file with different
- * attributes affected, this implementation may not be used.
+ * 2. If you need process two sets of objects from one file with different
+ * attributes affected, use method addEdits(XModelObject[], String, String)
+ * repeatedly.
*/
public class RenameModelObjectChange extends TextFileChange {
- private XModelObject[] objects;
+ boolean ok = false;
private String newName;
- private boolean ok = false;
- private String attributeName;
+ class ObjectSet {
+ XModelObject[] objects;
+ String attributeName;
+ ObjectSet(XModelObject[] objects, String attributeName) {
+ this.objects = objects;
+ this.attributeName = attributeName;
+ }
+ }
+ List<ObjectSet> list = new ArrayList<ObjectSet>();
public static RenameModelObjectChange createChange(XModelObject[] objects, String
newName, String attributeName) {
if(objects == null || objects.length == 0) return null;
@@ -53,16 +61,35 @@
if(f == null) return null;
return new RenameModelObjectChange(name, f, objects, newName, attributeName);
}
-
- private RenameModelObjectChange(String name, IFile file, XModelObject[] objects, String
newName, String attributeName) {
+
+ /**
+ * Creates empty change, for which one has to add edits
+ * by calling addEdits(XModelObject[], String, String)
+ *
+ * @param fileObject
+ * @param newName
+ * @return
+ */
+ public static RenameModelObjectChange createChange(XModelObject fileObject, String
newName) {
+ String name = fileObject.getPresentationString();
+ IFile f = getFile(fileObject);
+ if(f == null) return null;
+ return new RenameModelObjectChange(name, f, newName);
+ }
+
+ private RenameModelObjectChange(String name, IFile file, String newName) {
super(name, file);
- this.objects = objects;
this.newName = newName;
- this.attributeName = attributeName;
- addEdits();
}
+
+ private RenameModelObjectChange(String name, IFile file, XModelObject[] objects, String
newName, String attributeName) {
+ this(name, file, newName);
+ addEdits(objects, attributeName, "Update field reference");
+ }
- private void addEdits() {
+ public void addEdits(XModelObject[] objects, String attributeName, String textEditName)
{
+ list.add(new ObjectSet(objects, attributeName));
+
PositionSearcher searcher = new PositionSearcher();
XModelObject o = ((XModelObjectImpl)objects[0]).getResourceAncestor();
String text = ((FileAnyImpl)o).getAsText();
@@ -74,7 +101,7 @@
ok = false;
if(bp >= 0 && ep >= ep) {
ReplaceEdit edit = new ReplaceEdit(bp, ep - bp, newName);
- TextChangeCompatibility.addTextEdit(this, "Update field reference", edit);
+ TextChangeCompatibility.addTextEdit(this, textEditName, edit);
ok = true;
}
}
@@ -90,8 +117,10 @@
if(ok) {
result = super.perform(pm);
} else {
- for (int i = 0; i < objects.length; i++) {
- objects[i].getModel().changeObjectAttribute(objects[i], attributeName, newName);
+ for (ObjectSet set: list) {
+ for (int i = 0; i < set.objects.length; i++) {
+ set.objects[i].getModel().changeObjectAttribute(set.objects[i], set.attributeName,
newName);
+ }
}
}
return result;
@@ -102,7 +131,7 @@
}
public String getName() {
- return MessageFormat.format("Edit {0}", attributeName);
+ return MessageFormat.format("Edit {0}", list.get(0).attributeName);
}
}