Fixes for renaming issues

1. From diagram changed to package
2. Rename lost all cointained componenets etc etc
diff --git a/core/org.eclipse.tigerstripe.api/src/main/java/org/eclipse/tigerstripe/workbench/model/deprecated_/IArtifactManagerSession.java b/core/org.eclipse.tigerstripe.api/src/main/java/org/eclipse/tigerstripe/workbench/model/deprecated_/IArtifactManagerSession.java
index 779a241..1a7b189 100644
--- a/core/org.eclipse.tigerstripe.api/src/main/java/org/eclipse/tigerstripe/workbench/model/deprecated_/IArtifactManagerSession.java
+++ b/core/org.eclipse.tigerstripe.api/src/main/java/org/eclipse/tigerstripe/workbench/model/deprecated_/IArtifactManagerSession.java
@@ -89,6 +89,9 @@
      */
     public void removeArtifact(IAbstractArtifact artifact)
             throws TigerstripeException;
+    
+    public void removeArtifact(IAbstractArtifact artifact, boolean dispose)
+            throws TigerstripeException;
 
     public IAbstractArtifact getArtifactByFullyQualifiedName(String fqn)
             throws TigerstripeException;
@@ -213,6 +216,7 @@
     public void renameArtifact(IAbstractArtifact artifact, String toFQN)
             throws TigerstripeException;
 
+
     public void generationStart();
 
     public void generationComplete();
diff --git a/core/org.eclipse.tigerstripe.core/src/main/java/org/eclipse/tigerstripe/workbench/internal/api/impl/BaseArtifactManagerSessionImpl.java b/core/org.eclipse.tigerstripe.core/src/main/java/org/eclipse/tigerstripe/workbench/internal/api/impl/BaseArtifactManagerSessionImpl.java
index 662e902..e3edf50 100644
--- a/core/org.eclipse.tigerstripe.core/src/main/java/org/eclipse/tigerstripe/workbench/internal/api/impl/BaseArtifactManagerSessionImpl.java
+++ b/core/org.eclipse.tigerstripe.core/src/main/java/org/eclipse/tigerstripe/workbench/internal/api/impl/BaseArtifactManagerSessionImpl.java
@@ -238,6 +238,11 @@
         // TODO Auto-generated method stub

         

     }

+    

+    @Override

+    public void removeArtifact(IAbstractArtifact artifact, boolean dispose) throws TigerstripeException {

+        // TODO Auto-generated method stub    

+    }

 

     @Override

     public IAbstractArtifact extractArtifact(Reader reader, IProgressMonitor monitor) throws TigerstripeException {

diff --git a/plugins/org.eclipse.tigerstripe.workbench.base/src/java/org/eclipse/tigerstripe/workbench/internal/api/impl/ArtifactManagerSessionImpl.java b/plugins/org.eclipse.tigerstripe.workbench.base/src/java/org/eclipse/tigerstripe/workbench/internal/api/impl/ArtifactManagerSessionImpl.java
index da26af7..36e1a91 100644
--- a/plugins/org.eclipse.tigerstripe.workbench.base/src/java/org/eclipse/tigerstripe/workbench/internal/api/impl/ArtifactManagerSessionImpl.java
+++ b/plugins/org.eclipse.tigerstripe.workbench.base/src/java/org/eclipse/tigerstripe/workbench/internal/api/impl/ArtifactManagerSessionImpl.java
@@ -184,9 +184,13 @@
     }

 

     public void removeArtifact(IAbstractArtifact artifact) throws TigerstripeException {

+        removeArtifact(artifact, true);

+    }

+    

+    public void removeArtifact(IAbstractArtifact artifact, boolean dispose) throws TigerstripeException {

         URI oldURI = ((IAbstractArtifactInternal) artifact).getAdapter(URI.class);

         String simpleName = artifact.getClass().getSimpleName();

-        ((IArtifactManagerInternal) getArtifactManager()).removeArtifact(artifact);

+        ((IArtifactManagerInternal) getArtifactManager()).removeArtifact(artifact, dispose);

 

         // push a notif

         ModelChangeDelta delta = new ModelChangeDelta(IModelChangeDelta.REMOVE);

diff --git a/plugins/org.eclipse.tigerstripe.workbench.base/src/java/org/eclipse/tigerstripe/workbench/internal/core/model/ArtifactManagerImpl.java b/plugins/org.eclipse.tigerstripe.workbench.base/src/java/org/eclipse/tigerstripe/workbench/internal/core/model/ArtifactManagerImpl.java
index afadb89..b4e763b 100644
--- a/plugins/org.eclipse.tigerstripe.workbench.base/src/java/org/eclipse/tigerstripe/workbench/internal/core/model/ArtifactManagerImpl.java
+++ b/plugins/org.eclipse.tigerstripe.workbench.base/src/java/org/eclipse/tigerstripe/workbench/internal/core/model/ArtifactManagerImpl.java
@@ -462,7 +462,11 @@
      * (org.eclipse.tigerstripe.workbench.model.deprecated_.IAbstractArtifact)
      */
     public void removeArtifact(IAbstractArtifact artifact) throws TigerstripeException {
-        removeArtifact(artifact, Collections.<ITigerstripeModelProject> emptySet());
+        removeArtifact(artifact, Collections.<ITigerstripeModelProject> emptySet(), true);
+    }
+    
+    public void removeArtifact(IAbstractArtifact artifact, boolean dispose) throws TigerstripeException {
+        removeArtifact(artifact, Collections.<ITigerstripeModelProject> emptySet(), dispose);
     }
 
     /*
@@ -476,6 +480,15 @@
      */
     public void removeArtifact(IAbstractArtifact artifact, Set<ITigerstripeModelProject> ignoreProjects)
             throws TigerstripeException {
+        removeArtifact(artifact, ignoreProjects, true);
+    }
+    
+    
+    /*
+     * dispose option can be used in case of rename where we don't actually want to dispose!
+     */
+    public void removeArtifact(IAbstractArtifact artifact, Set<ITigerstripeModelProject> ignoreProjects, boolean dispose)
+            throws TigerstripeException {
 
         if (wasDisposed) {
             return;
@@ -496,8 +509,9 @@
             if (artifact instanceof IRelationship) {
                 getRelationshipCache().removeRelationship((IRelationship) artifact, ignoreProjects);
             }
-
-            ((IAbstractArtifactInternal) artifact).dispose();
+            if (dispose) {
+                artifact.dispose();
+            }
         } finally {
             mgrChanged = true;
             writeLock.unlock();
@@ -636,7 +650,7 @@
             writeLock.lock();
             shouldNotify = false; // we don't want to trigger del+add
             // notifications, only a Ren at the end
-            removeArtifact(artifact);
+            removeArtifact(artifact, false);
             ((IAbstractArtifactInternal) artifact).setProxy(false); // a side
             // effect
             // of
diff --git a/plugins/org.eclipse.tigerstripe.workbench.base/src/java/org/eclipse/tigerstripe/workbench/internal/core/model/IArtifactManagerInternal.java b/plugins/org.eclipse.tigerstripe.workbench.base/src/java/org/eclipse/tigerstripe/workbench/internal/core/model/IArtifactManagerInternal.java
index cf7b7e2..ccade8d 100644
--- a/plugins/org.eclipse.tigerstripe.workbench.base/src/java/org/eclipse/tigerstripe/workbench/internal/core/model/IArtifactManagerInternal.java
+++ b/plugins/org.eclipse.tigerstripe.workbench.base/src/java/org/eclipse/tigerstripe/workbench/internal/core/model/IArtifactManagerInternal.java
@@ -36,6 +36,8 @@
     void removeDisposeListener(IDisposeListener listener);

     

     void removeArtifact(IAbstractArtifact artifact) throws TigerstripeException;

+    

+    void removeArtifact(IAbstractArtifact artifact, boolean dispose) throws TigerstripeException;

 

     /**

      * Removes an artifact from this manager and updates all the internal

diff --git a/plugins/org.eclipse.tigerstripe.workbench.base/src/java/org/eclipse/tigerstripe/workbench/internal/refactor/ModelChangeDeltaProcessor.java b/plugins/org.eclipse.tigerstripe.workbench.base/src/java/org/eclipse/tigerstripe/workbench/internal/refactor/ModelChangeDeltaProcessor.java
index 632dba3..6977d25 100644
--- a/plugins/org.eclipse.tigerstripe.workbench.base/src/java/org/eclipse/tigerstripe/workbench/internal/refactor/ModelChangeDeltaProcessor.java
+++ b/plugins/org.eclipse.tigerstripe.workbench.base/src/java/org/eclipse/tigerstripe/workbench/internal/refactor/ModelChangeDeltaProcessor.java
@@ -493,7 +493,7 @@
 		for (String packageFqn : packagesToCleanUp) {
 			IAbstractArtifact packageArtifact = session
 					.getArtifactByFullyQualifiedName(packageFqn);
-			session.removeArtifact(packageArtifact);
+			session.removeArtifact(packageArtifact,false);
 			IResource resource = ((IAbstractArtifactInternal) packageArtifact)
 					.getAdapter(IResource.class);
 			toCleanUp.add(resource);
diff --git a/plugins/org.eclipse.tigerstripe.workbench.ui.base/src/java/org/eclipse/tigerstripe/workbench/ui/internal/wizards/refactoring/RenameModelArtifactWizardPage.java b/plugins/org.eclipse.tigerstripe.workbench.ui.base/src/java/org/eclipse/tigerstripe/workbench/ui/internal/wizards/refactoring/RenameModelArtifactWizardPage.java
index 9038837..f25b04b 100644
--- a/plugins/org.eclipse.tigerstripe.workbench.ui.base/src/java/org/eclipse/tigerstripe/workbench/ui/internal/wizards/refactoring/RenameModelArtifactWizardPage.java
+++ b/plugins/org.eclipse.tigerstripe.workbench.ui.base/src/java/org/eclipse/tigerstripe/workbench/ui/internal/wizards/refactoring/RenameModelArtifactWizardPage.java
@@ -59,16 +59,35 @@
 	}
 
 	public void init(IStructuredSelection selection) {
+	    
 
+	    // This part works for Diagrams.
+	    // NOTE : javaElement will not be set from a diagram, but that is only used for packages which don't appear on diagrams.
+	    if (selection != null && !selection.isEmpty()) {
+            Object selectedElement = selection.getFirstElement();
+            if (selectedElement instanceof IAbstractArtifact) {
+                modelArtifact = (IAbstractArtifact) selectedElement;
+                try {
+                    modelProject = modelArtifact.getProject();
+                } catch (TigerstripeException e) {
+                    modelProject = null;
+                }
+                return;
+            }
+	        
+	    }
+	    
+	    // This part works for Explorer.
 		javaElement = getSelectionJavaElement(selection);
 		if (javaElement != null) {
-			modelProject = (ITigerstripeModelProject) javaElement
+			modelProject = javaElement
 					.getJavaProject().getProject()
 					.getAdapter(ITigerstripeModelProject.class);
-			modelArtifact = (IAbstractArtifact) javaElement
+			modelArtifact = javaElement
 					.getAdapter(IAbstractArtifact.class);
 		}
 
+
 	}
 
 	private IJavaElement getSelectionJavaElement(IStructuredSelection selection) {
@@ -95,7 +114,8 @@
 		gridData.horizontalAlignment = GridData.FILL;
 		gridData.grabExcessHorizontalSpace = true;
 		nameText.setLayoutData(gridData);
-		if (javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
+		
+		if (modelArtifact instanceof IPackageArtifact) {
 			nameText.setText(modelArtifact.getFullyQualifiedName());
 		} else {
 			nameText.setText(modelArtifact.getName());
@@ -197,20 +217,17 @@
 			if (modelArtifact instanceof IPackageArtifact) {
 				request = new PackageModelRefactorRefactorRequest();
 				((PackageModelRefactorRefactorRequest)request).setRenameSubpackages(renameSubpackages.getSelection());
+				request.setDestination(modelArtifact.getProject(), nameText
+                        .getText().trim());
 			} else {
 				request = new ModelRefactorRequest();
+				request.setDestination(modelArtifact.getProject(),
+                        modelArtifact.getPackage() + '.'
+                                + nameText.getText().trim());
 			}
 			request.setOriginal(modelArtifact.getProject(),
 					modelArtifact.getFullyQualifiedName());
 
-			if (javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
-				request.setDestination(modelArtifact.getProject(), nameText
-						.getText().trim());
-			} else {
-				request.setDestination(modelArtifact.getProject(),
-						modelArtifact.getPackage() + '.'
-								+ nameText.getText().trim());
-			}
 
 			if (validateRequest(request)) {
 				wizard.addRequest(request);