[hg] main-silver: Issue #221295 - Inspect and Transform report c...

  • From: Ralph Benjamin Ruijs < >
  • To: ,
  • Subject: [hg] main-silver: Issue #221295 - Inspect and Transform report c...
  • Date: Thu, 29 Nov 2012 03:31:30 -0800

changeset 61c15968923c in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/61c15968923c
description:
        Issue #221295 - Inspect and Transform report complete when still 
working

diffstat:

 refactoring.api/apichanges.xml                                               
       |  16 ++
 refactoring.api/nbproject/project.properties                                 
       |   2 +-
 
refactoring.api/src/org/netbeans/modules/refactoring/api/RefactoringSession.java
    |  75 ++++++++-
 
refactoring.api/src/org/netbeans/modules/refactoring/spi/ProgressProvider.java
      |   6 +-
 
refactoring.api/src/org/netbeans/modules/refactoring/spi/RefactoringCommit.java
     |  55 +++++++-
 
refactoring.api/src/org/netbeans/modules/refactoring/spi/impl/RefactoringPanel.java
 |   6 +-
 6 files changed, 142 insertions(+), 18 deletions(-)

diffs (325 lines):

diff --git a/refactoring.api/apichanges.xml b/refactoring.api/apichanges.xml
--- a/refactoring.api/apichanges.xml
+++ b/refactoring.api/apichanges.xml
@@ -49,6 +49,22 @@
     <apidef name="refactoring">Refactoring API</apidef>
 </apidefs>
 <changes>
+    <change id="TransactionProgress">
+        <api name="refactoring"/>
+        <summary>RefactoringCommit implements the interface 
ProgressProvider.</summary>
+        <version major="1" minor="33"/>
+        <date day="27" month="11" year="2012"/>
+        <author login="ralphbenjamin"/>
+        <compatibility addition="yes"/>
+        <description>
+            <p>
+                RefactoringCommit now implements the interface 
ProgressProvider
+                to notify the progress of the commit.
+            </p>
+        </description>
+        <class package="org.netbeans.modules.refactoring.spi" 
name="RefactoringCommit"/>
+        <issue number="221295"/>
+    </change>
     <change id="ServerSideQueries">
         <api name="refactoring"/>
         <summary>Added support for Scope Providers and 
ExpandableTreeElements.</summary>
diff --git a/refactoring.api/nbproject/project.properties 
b/refactoring.api/nbproject/project.properties
--- a/refactoring.api/nbproject/project.properties
+++ b/refactoring.api/nbproject/project.properties
@@ -4,5 +4,5 @@
 javadoc.apichanges=${basedir}/apichanges.xml
 javadoc.title=Refactoring API
 
-spec.version.base=1.32.0
+spec.version.base=1.33.0
 test.config.stableBTD.includes=**/*Test.class
diff --git 
a/refactoring.api/src/org/netbeans/modules/refactoring/api/RefactoringSession.java
 
b/refactoring.api/src/org/netbeans/modules/refactoring/api/RefactoringSession.java
--- 
a/refactoring.api/src/org/netbeans/modules/refactoring/api/RefactoringSession.java
+++ 
b/refactoring.api/src/org/netbeans/modules/refactoring/api/RefactoringSession.java
@@ -54,6 +54,7 @@
 import org.netbeans.api.editor.mimelookup.MimeLookup;
 import org.netbeans.modules.refactoring.api.impl.ProgressSupport;
 import org.netbeans.modules.refactoring.api.impl.SPIAccessor;
+import org.netbeans.modules.refactoring.spi.ProgressProvider;
 import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
 import org.netbeans.modules.refactoring.spi.Transaction;
@@ -83,6 +84,7 @@
     private UndoManager undoManager = UndoManager.getDefault();
     boolean realcommit = true;
     private AtomicBoolean finished = new AtomicBoolean(false);
+    private static final int COMMITSTEPS = 100;
     
     private RefactoringSession(String description) {
         //internalList = new LinkedList();
@@ -116,7 +118,11 @@
         long time = System.currentTimeMillis();
         
         Iterator it = internalList.iterator();
-        fireProgressListenerStart(0, internalList.size()+1);
+        ArrayList<Transaction> commits = SPIAccessor.DEFAULT.getCommits(bag);
+        float progressStep = (float)COMMITSTEPS / internalList.size();
+        float current = 0F;
+        fireProgressListenerStart(0, COMMITSTEPS + commits.size() * 
COMMITSTEPS + 1);
+        ProgressListener progressListener = new ProgressL(commits, 
COMMITSTEPS);
         if (realcommit) {
             undoManager.transactionStarted();
             undoManager.setUndoDescription(description);
@@ -124,32 +130,46 @@
         try {
             try {
                 while (it.hasNext()) {
-                    fireProgressListenerStep();
                     RefactoringElementImplementation element = 
(RefactoringElementImplementation) it.next();
                     if (element.isEnabled() && !((element.getStatus() == 
RefactoringElement.GUARDED) || (element.getStatus() == 
RefactoringElement.READ_ONLY))) {
                         element.performChange();
                     }
+                    current += progressStep;
+                    fireProgressListenerStep((int) current);
                 }
             } finally {
-                for (Transaction commit:SPIAccessor.DEFAULT.getCommits(bag)) 
{
+                for (Transaction commit : commits) {
                     SPIAccessor.DEFAULT.check(commit, false);
                 }
 
                 UndoableWrapper wrapper = 
MimeLookup.getLookup("").lookup(UndoableWrapper.class);
-                for (Transaction commit:SPIAccessor.DEFAULT.getCommits(bag)) 
{
-                    if (wrapper !=null)
+                for (Transaction commit : commits) {
+                    if (wrapper != null) {
                         setWrappers(commit, wrapper);
+                    }
                     
+                    if(commit instanceof ProgressProvider) {
+                        ProgressProvider progressProvider = 
(ProgressProvider) commit;
+                        
progressProvider.addProgressListener(progressListener);
+                    }
+                    try {
                     commit.commit();
-                    if (wrapper !=null)
+                    } finally {
+                        if(commit instanceof ProgressProvider) {
+                            ProgressProvider progressProvider = 
(ProgressProvider) commit;
+                            
progressProvider.removeProgressListener(progressListener);
+                        }
+                    }
+                    if (wrapper != null) {
                         unsetWrappers(commit, wrapper);
                 }
-                if (wrapper !=null)
+                }
+                if (wrapper != null) {
                     wrapper.close();
-                for (Transaction commit : 
SPIAccessor.DEFAULT.getCommits(bag)) {
+                }
+                for (Transaction commit : commits) {
                     SPIAccessor.DEFAULT.sum(commit);
                 }
-                
             }
             if (saveAfterDone) {
                 LifecycleManager.getDefault().saveAll();
@@ -184,6 +204,37 @@
         return null;
     }
     
+    private class ProgressL implements ProgressListener {
+
+        private float progressStep;
+        private float current;
+        private final ArrayList<Transaction> commits;
+        private final int start;
+
+        ProgressL(ArrayList<Transaction> commits, int start) {
+            this.commits = commits;
+            this.start = start;
+        }
+
+        @Override
+        public void start(ProgressEvent event) {
+            progressStep = (float) COMMITSTEPS / event.getCount();
+            current = start + commits.indexOf(event.getSource()) * 
COMMITSTEPS;
+            fireProgressListenerStep((int) current);
+        }
+
+        @Override
+        public void step(ProgressEvent event) {
+            current = current + progressStep;
+            fireProgressListenerStep((int) current);
+        }
+
+        @Override
+        public void stop(ProgressEvent event) {
+            // do not rely on plugins;
+        }
+    }
+    
     /**
      * do undo of previous doRefactoring()
      * @param saveAfterDone save all if true
@@ -297,6 +348,12 @@
         }
     }
 
+    private void fireProgressListenerStep(int count) {
+        if (progressSupport != null) {
+            progressSupport.fireProgressListenerStep(this, count);
+        }
+    }
+
     private void fireProgressListenerStop() {
         if (progressSupport != null) {
             progressSupport.fireProgressListenerStop(this);
diff --git 
a/refactoring.api/src/org/netbeans/modules/refactoring/spi/ProgressProvider.java
 
b/refactoring.api/src/org/netbeans/modules/refactoring/spi/ProgressProvider.java
--- 
a/refactoring.api/src/org/netbeans/modules/refactoring/spi/ProgressProvider.java
+++ 
b/refactoring.api/src/org/netbeans/modules/refactoring/spi/ProgressProvider.java
@@ -47,8 +47,10 @@
 import org.netbeans.modules.refactoring.api.ProgressListener;
 
 /**
- * Refactoring plugins should implement this interface, if they want to 
notify their progress of preCheck,
- * prepare and checkParameters method.
+ * Refactoring plugins and transactions should implement this interface, if 
they
+ * want to notify their progress of commit, preCheck, prepare and
+ * checkParameters method.
+ *
  * @author Jan Becicka
  */
 public interface ProgressProvider {
diff --git 
a/refactoring.api/src/org/netbeans/modules/refactoring/spi/RefactoringCommit.java
 
b/refactoring.api/src/org/netbeans/modules/refactoring/spi/RefactoringCommit.java
--- 
a/refactoring.api/src/org/netbeans/modules/refactoring/spi/RefactoringCommit.java
+++ 
b/refactoring.api/src/org/netbeans/modules/refactoring/spi/RefactoringCommit.java
@@ -49,8 +49,11 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import org.netbeans.api.annotations.common.NonNull;
+import org.netbeans.modules.refactoring.api.ProgressEvent;
+import org.netbeans.modules.refactoring.api.ProgressListener;
 import org.netbeans.modules.refactoring.api.impl.CannotRedoRefactoring;
 import org.netbeans.modules.refactoring.api.impl.CannotUndoRefactoring;
+import org.netbeans.modules.refactoring.api.impl.ProgressSupport;
 import org.netbeans.modules.refactoring.spi.BackupFacility2.Handle;
 import org.openide.cookies.EditorCookie;
 import org.openide.filesystems.FileObject;
@@ -64,10 +67,10 @@
  * @author Jan Becicka
  * @since 1.23
  */
-
- public final class RefactoringCommit implements Transaction {
+ public final class RefactoringCommit implements Transaction, 
ProgressProvider {
  
      private static final Logger LOG = 
Logger.getLogger(RefactoringCommit.class.getName());
+     private ProgressSupport progressSupport;
  
      /**
       * FileObjects modified by this Transaction
@@ -127,6 +130,7 @@
     
     @Override
     public void commit() {
+        fireProgressListenerStart(ProgressEvent.START, results.size());
         try {
             if (commited) {
                 for (BackupFacility2.Handle id:ids) {
@@ -153,12 +157,14 @@
                     }
 
                     openNewFiles(result.getNewFiles());
+                    fireProgressListenerStep();
                 }
             }
         
         } catch (IOException ex) {
             throw new RuntimeException(ex);
         }
+        fireProgressListenerStop();
     }
     
      private boolean newFilesStored = false;
@@ -194,5 +200,50 @@
             }
         }
     }
+
+     /**
+      * Registers ProgressListener to receive events.
+      *
+      * @param listener The listener to register.
+      * @since 1.33
+      */
+     @Override
+     public synchronized void addProgressListener(ProgressListener listener) 
{
+         if (progressSupport == null) {
+             progressSupport = new ProgressSupport();
+         }
+         progressSupport.addProgressListener(listener);
 }
             
+     /**
+      * Removes ProgressListener from the list of listeners.
+      *
+      * @param listener The listener to remove.
+      * @since 1.33
+      */
+     @Override
+     public synchronized void removeProgressListener(ProgressListener 
listener) {
+         if (progressSupport != null) {
+             progressSupport.removeProgressListener(listener);
+         }
+     }
+    
+    private void fireProgressListenerStart(int type, int count) {
+        if (progressSupport != null) {
+            progressSupport.fireProgressListenerStart(this, type, count);
+        }
+    }
+    
+    private void fireProgressListenerStep() {
+        if (progressSupport != null) {
+            progressSupport.fireProgressListenerStep(this);
+        }
+    }
+    
+    private void fireProgressListenerStop() {
+        if (progressSupport != null) {
+            progressSupport.fireProgressListenerStop(this);
+        }
+    }
+}
+            
diff --git 
a/refactoring.api/src/org/netbeans/modules/refactoring/spi/impl/RefactoringPanel.java
 
b/refactoring.api/src/org/netbeans/modules/refactoring/spi/impl/RefactoringPanel.java
--- 
a/refactoring.api/src/org/netbeans/modules/refactoring/spi/impl/RefactoringPanel.java
+++ 
b/refactoring.api/src/org/netbeans/modules/refactoring/spi/impl/RefactoringPanel.java
@@ -1302,14 +1302,12 @@
         
         private ProgressHandle handle;
         private Dialog d;
-        private int counter;
         
         @Override
         public void start(final ProgressEvent event) {
             SwingUtilities.invokeLater(new Runnable() {
                 @Override
                 public void run() {
-                    counter = 0;
                     final String lab = 
NbBundle.getMessage(RefactoringPanel.class, "LBL_RefactorProgressLabel");
                     handle = ProgressHandleFactory.createHandle(lab);
                     JComponent progress = 
ProgressHandleFactory.createProgressComponent(handle);
@@ -1333,12 +1331,12 @@
         }
         
         @Override
-        public void step(ProgressEvent event) {
+        public void step(final ProgressEvent event) {
             SwingUtilities.invokeLater(new Runnable() {
                 @Override
                 public void run() {
                     try {
-                        handle.progress(++counter);
+                        handle.progress(event.getCount());
                     } catch (Throwable e) {
                         
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
                     }

[hg] main-silver: Issue #221295 - Inspect and Transform report c...

Ralph Benjamin Ruijs 11/29/2012

Project Features

About this Project

Editor was started in November 2009, is owned by Martin Ryzl, and has 147 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close