[136524] fix for EARArtifactEdit module uri
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/operation/RemoveReferenceComponentOperation.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/operation/RemoveReferenceComponentOperation.java
index 0787829..204b4c4 100644
--- a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/operation/RemoveReferenceComponentOperation.java
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/operation/RemoveReferenceComponentOperation.java
@@ -24,6 +24,7 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
import org.eclipse.wst.common.componentcore.datamodel.properties.ICreateReferenceComponentsDataModelProperties;
+import org.eclipse.wst.common.componentcore.internal.resources.VirtualComponent;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import org.eclipse.wst.common.componentcore.resources.IVirtualReference;
import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
@@ -85,13 +86,7 @@
}
protected void removeRefereneceInComponent(IVirtualComponent component, IVirtualReference reference) {
- List refList = new ArrayList();
- IVirtualReference[] refArray = component.getReferences();
- for (int i = 0; i < refArray.length; i++) {
- if (refArray[i].getReferencedComponent() != null && !refArray[i].getReferencedComponent().equals(reference.getReferencedComponent()))
- refList.add(refArray[i]);
- }
- component.setReferences((IVirtualReference[]) refList.toArray(new IVirtualReference[refList.size()]));
+ ((VirtualComponent)component.getComponent()).removeReference(reference);
}
public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/resources/VirtualComponent.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/resources/VirtualComponent.java
index a3b3c53..f44a4a1 100644
--- a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/resources/VirtualComponent.java
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/resources/VirtualComponent.java
@@ -429,4 +429,54 @@
result[i] = ComponentCore.createComponent(handles[i]);
return result;
}
+
+ /**
+ * Remove the associated ReferencedComponent for the virtual reference from the workbench component
+ * associated with this virtual component
+ *
+ * @param aReference
+ */
+ public void removeReference(IVirtualReference aReference) {
+ StructureEdit core = null;
+ try {
+ core = StructureEdit.getStructureEditForWrite(getProject());
+ if (core == null || aReference == null)
+ return;
+ WorkbenchComponent component = core.getComponent();
+ ReferencedComponent refComponent = getWorkbenchReferencedComponent(aReference, component);
+ if (component != null && refComponent != null)
+ component.getReferencedComponents().remove(refComponent);
+ } finally {
+ if(core != null) {
+ core.saveIfNecessary(null);
+ core.dispose();
+ }
+ }
+ }
+
+ /**
+ * Return the associated structure edit ReferencedComponent object for the given IVirtualReference based on the handle
+ * and module URI.
+ *
+ * @param aReference
+ * @param core
+ * @return ReferencedComponent
+ */
+ protected ReferencedComponent getWorkbenchReferencedComponent(IVirtualReference aReference, WorkbenchComponent component) {
+ if (aReference == null || aReference.getReferencedComponent() == null || component == null)
+ return null;
+ List referencedComponents = component.getReferencedComponents();
+ for (int i=0; i<referencedComponents.size(); i++) {
+ ReferencedComponent ref = (ReferencedComponent) referencedComponents.get(i);
+ if (!aReference.getReferencedComponent().isBinary()) {
+ if (ref.getHandle().equals(ModuleURIUtil.fullyQualifyURI(aReference.getReferencedComponent().getProject())))
+ return ref;
+ }
+ else {
+ if (ref.getHandle().equals(ModuleURIUtil.archiveComponentfullyQualifyURI(aReference.getReferencedComponent().getName())))
+ return ref;
+ }
+ }
+ return null;
+ }
}