fix for FELIX-2154 do not call dispose on shared image!
also fixed handling of project during edits related to change made in FELIX-2153

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@918046 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/ui/editors/project/SigilProjectEditorPart.java b/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/ui/editors/project/SigilProjectEditorPart.java
index e6471c2..93025d7 100644
--- a/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/ui/editors/project/SigilProjectEditorPart.java
+++ b/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/ui/editors/project/SigilProjectEditorPart.java
@@ -66,7 +66,8 @@
 {
 
     private final Set<IModelElement> unresolvedElements = Collections.synchronizedSet( new HashSet<IModelElement>() );
-    private ISigilProjectModel project;
+    private ISigilProjectModel projectx;
+    private ISigilProjectModel tempProject;
     private volatile boolean saving = false;
     private int dependenciesPageIndex;
 
@@ -94,34 +95,14 @@
             saving = true;
             new ProgressMonitorDialog( getSite().getShell() ).run( true, true, new IRunnableWithProgress()
             {
-                public void run( final IProgressMonitor monitor ) throws InvocationTargetException,
+                public void run( IProgressMonitor monitor ) throws InvocationTargetException,
                     InterruptedException
                 {
                     try
                     {
-                        if ( textPage.isDirty() )
-                        {
-                            SigilUI.runInUISync( new Runnable()
-                            {
-                                public void run()
-                                {
-                                    textPage.doSave( monitor );
-                                }
-                            } );
-                            project.setBundle( null );
-                            project.rebuildDependencies(monitor);
-                        }
-                        else if ( isDirty() )
-                        {
-                            commitPages( true );
-                            project.save( monitor );
-                            SigilUI.runInUISync( new Runnable()
-                            {
-                                public void run()
-                                {
-                                    editorDirtyStateChanged();
-                                }
-                            } );
+                        if ( doInternalSave(monitor) ) {
+                            projectx.setBundle( null );
+                            projectx.rebuildDependencies(monitor);                            
                         }
 
                         monitor.done();
@@ -135,7 +116,7 @@
         }
         catch ( InvocationTargetException e )
         {
-            SigilCore.error( "Failed to save " + project, e.getTargetException() );
+            SigilCore.error( "Failed to save " + projectx, e.getTargetException() );
         }
         catch ( InterruptedException e )
         {
@@ -150,6 +131,38 @@
     }
 
 
+    private boolean doInternalSave(final IProgressMonitor monitor) throws CoreException
+    {
+        if ( textPage.isDirty() )
+        {
+            SigilUI.runInUISync( new Runnable()
+            {
+                public void run()
+                {
+                    textPage.doSave( monitor );
+                }
+            } );
+            return true;
+        }
+        else if ( isDirty() )
+        {
+            commitPages( true );
+            tempProject.save( monitor );
+            SigilUI.runInUISync( new Runnable()
+            {
+                public void run()
+                {
+                    editorDirtyStateChanged();
+                }
+            } );
+            return true;
+        }
+        
+        // ok no changes
+        return false;
+    }
+
+
     /* (non-Javadoc)
      * @see org.eclipse.ui.forms.editor.FormEditor#addPages()
      */
@@ -158,13 +171,13 @@
     {
         try
         {
-            addPage( new OverviewForm( this, project ) );
-            addPage( new ContentsForm( this, project ) );
-            dependenciesPageIndex = addPage( new DependenciesForm( this, project, unresolvedElements ) );
-            addPage( new ExportsForm( this, project ) );
-            textPage = new PropertiesForm( this, project );
+            addPage( new OverviewForm( this, tempProject ) );
+            addPage( new ContentsForm( this, tempProject ) );
+            dependenciesPageIndex = addPage( new DependenciesForm( this, tempProject, unresolvedElements ) );
+            addPage( new ExportsForm( this, tempProject ) );
+            textPage = new PropertiesForm( this, tempProject );
             addPage( textPage, getEditorInput() );
-            setPartName( project.getSymbolicName() );
+            setPartName( projectx.getSymbolicName() );
 
             refreshTabImages();
         }
@@ -212,9 +225,6 @@
     public void dispose()
     {
         ResourcesPlugin.getWorkspace().removeResourceChangeListener( this );
-        if ( errorImage != null ) {
-            errorImage.dispose();
-        }
         super.dispose();
     }
 
@@ -264,7 +274,7 @@
                                     {
                                         public void run()
                                         {
-                                            setPartName( project.getSymbolicName() );
+                                            setPartName( projectx.getSymbolicName() );
                                         }
                                     } );
                                     break;
@@ -309,7 +319,7 @@
                     }
                 }
                 firePropertyChange( IEditorPart.PROP_DIRTY );
-                setPartName( project.getSymbolicName() );
+                setPartName( projectx.getSymbolicName() );
                 refreshTabImages();
             }
         };
@@ -319,7 +329,7 @@
 
     protected void reload()
     {
-        project.setBundle( null );
+        projectx.setBundle( null );
         refreshAllPages();
     }
 
@@ -331,7 +341,8 @@
 
         try
         {
-            this.project = SigilCore.create( getProject() );
+            this.projectx = SigilCore.create( getProject() );
+            this.tempProject = (ISigilProjectModel) projectx.clone();
         }
         catch ( CoreException e )
         {