summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Pielmann2012-10-23 09:58:15 (EDT)
committer Stephan Born2012-10-23 09:58:15 (EDT)
commit7d6ae01570f5cd65519ec17cc90e5498fa5fdfd1 (patch)
tree13a689e3cf46619f4e3dbe217b9cdc70fdc0344f
parent311c8e60cf1fcceeed2dda1ec2ec152bcab19373 (diff)
downloadorg.eclipse.stardust.ui.web-7d6ae01570f5cd65519ec17cc90e5498fa5fdfd1.zip
org.eclipse.stardust.ui.web-7d6ae01570f5cd65519ec17cc90e5498fa5fdfd1.tar.gz
org.eclipse.stardust.ui.web-7d6ae01570f5cd65519ec17cc90e5498fa5fdfd1.tar.bz2
CRNT-26530 Pepper: Implement removal of model references if last referenced element has been removed
git-svn-id: http://emeafrazerg/svn/ipp/product/trunk/stardust/ui.web@60258 8100b5e0-4d52-466c-ae9c-bdeccbdeaf6b
-rw-r--r--web-modeler/src/main/java/org/eclipse/stardust/ui/web/modeler/edit/postprocessing/ExternalReferenceChangeTracker.java158
1 files changed, 158 insertions, 0 deletions
diff --git a/web-modeler/src/main/java/org/eclipse/stardust/ui/web/modeler/edit/postprocessing/ExternalReferenceChangeTracker.java b/web-modeler/src/main/java/org/eclipse/stardust/ui/web/modeler/edit/postprocessing/ExternalReferenceChangeTracker.java
new file mode 100644
index 0000000..1f02b30
--- /dev/null
+++ b/web-modeler/src/main/java/org/eclipse/stardust/ui/web/modeler/edit/postprocessing/ExternalReferenceChangeTracker.java
@@ -0,0 +1,158 @@
+package org.eclipse.stardust.ui.web.modeler.edit.postprocessing;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.change.impl.ChangeDescriptionImpl;
+import org.eclipse.stardust.model.xpdl.builder.session.Modification;
+import org.eclipse.stardust.model.xpdl.builder.utils.WebModelerConnectionManager;
+import org.eclipse.stardust.model.xpdl.carnot.IExtensibleElement;
+import org.eclipse.stardust.model.xpdl.carnot.ModelType;
+import org.eclipse.stardust.model.xpdl.carnot.util.AttributeUtil;
+import org.eclipse.stardust.model.xpdl.carnot.util.ModelUtils;
+import org.eclipse.stardust.model.xpdl.util.IConnectionManager;
+import org.eclipse.stardust.model.xpdl.xpdl2.Extensible;
+import org.eclipse.stardust.model.xpdl.xpdl2.ExternalPackage;
+import org.eclipse.stardust.model.xpdl.xpdl2.util.ExtendedAttributeUtil;
+import org.eclipse.stardust.modeling.repository.common.Connection;
+import org.eclipse.stardust.modeling.repository.common.impl.ConnectionImpl;
+import org.eclipse.stardust.ui.web.modeler.edit.spi.ChangePostprocessor;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ExternalReferenceChangeTracker implements ChangePostprocessor
+{
+
+ @Override
+ public int getInspectionPhase()
+ {
+ return 100;
+ }
+
+ @Override
+ public void inspectChange(Modification change)
+ {
+
+ Collection<EObject> removedList = change.getRemovedElements();
+
+ ModelType model = null;
+
+ if (!removedList.isEmpty())
+ {
+ EObject removedElement = (EObject) removedList.toArray()[0];
+ if (removedElement.eContainer() instanceof ChangeDescriptionImpl)
+ {
+ ChangeDescriptionImpl changeDescription = (ChangeDescriptionImpl) removedElement
+ .eContainer();
+ EObject container = changeDescription.getOldContainer(removedElement);
+ model = ModelUtils.findContainingModel(container);
+ List<String> uris = ModelUtils.getURIsForExternalPackages(model);
+ for (Iterator<String> i = uris.iterator(); i.hasNext();)
+ {
+ String uri = i.next();
+ WebModelerConnectionManager cm = (WebModelerConnectionManager) model
+ .getConnectionManager();
+ Connection connection = (Connection) cm.findConnection(uri);
+ List<EObject> references = this.getExternalReferences(model,
+ (Connection) connection);
+ if (references.size() == 1)
+ {
+ ExternalPackage externalReference = (ExternalPackage) references.get(0);
+ removeConnection(externalReference);
+ model.getExternalPackages().getExternalPackage()
+ .remove(externalReference);
+ change.markAlsoRemoved(externalReference);
+ change.markAlsoModified(model);
+ }
+ }
+ }
+
+ }
+ }
+
+ private void removeConnection(ExternalPackage externalPackage)
+ {
+ ModelType model = ModelUtils.findContainingModel(externalPackage);
+ String uri = ExtendedAttributeUtil.getAttributeValue(externalPackage,
+ IConnectionManager.URI_ATTRIBUTE_NAME);
+ ConnectionImpl connection = (ConnectionImpl) model.getConnectionManager()
+ .findConnection(uri);
+ WebModelerConnectionManager man = (WebModelerConnectionManager) model
+ .getConnectionManager();
+ man.getRepository().getConnection().remove(connection);
+ }
+
+ public List<EObject> getExternalReferences(ModelType model, Connection connection)
+ {
+ List<EObject> list = new ArrayList<EObject>();
+ for (Iterator<EObject> i = model.eAllContents(); i.hasNext();)
+ {
+ EObject modelElement = i.next();
+ if (modelElement != null)
+ {
+ if (modelElement instanceof IExtensibleElement)
+ {
+ if (AttributeUtil.getAttributeValue((IExtensibleElement) modelElement,
+ IConnectionManager.URI_ATTRIBUTE_NAME) != null)
+ {
+ String uri = AttributeUtil.getAttributeValue(
+ (IExtensibleElement) modelElement,
+ IConnectionManager.URI_ATTRIBUTE_NAME);
+ Connection refConnection = (Connection) model.getConnectionManager()
+ .findConnection(uri);
+ if (refConnection != null)
+ {
+ String importString = connection.getAttribute("importByReference"); //$NON-NLS-1$
+ if (importString != null && importString.equalsIgnoreCase("false")) //$NON-NLS-1$
+ {
+
+ }
+ else
+ {
+ if (connection.getId().equals(refConnection.getId()))
+ {
+ list.add(modelElement);
+ }
+ }
+ }
+ }
+ }
+ if (modelElement instanceof Extensible)
+ {
+ if (ExtendedAttributeUtil.getAttributeValue((Extensible) modelElement,
+ IConnectionManager.URI_ATTRIBUTE_NAME) != null)
+ {
+ String uri = ExtendedAttributeUtil.getAttributeValue(
+ (Extensible) modelElement, IConnectionManager.URI_ATTRIBUTE_NAME);
+ Connection refConnection = (Connection) model.getConnectionManager()
+ .findConnection(uri);
+ if (refConnection != null)
+ {
+ String importString = connection.getAttribute("importByReference"); //$NON-NLS-1$
+ if (importString != null && importString.equalsIgnoreCase("false")) //$NON-NLS-1$
+ {
+
+ }
+ else
+ {
+ if (connection.getId().equals(refConnection.getId()))
+ {
+ list.add(modelElement);
+ }
+ }
+ }
+
+ }
+ }
+
+ }
+
+ }
+ return list;
+
+ }
+
+}