1 19 package org.netbeans.modules.javacore; 20 import org.netbeans.api.progress.aggregate.AggregateProgressFactory; 21 import org.netbeans.api.progress.aggregate.AggregateProgressHandle; 22 import org.netbeans.api.progress.aggregate.ProgressContributor; 23 import org.netbeans.spi.java.classpath.ClassPathImplementation; 24 import org.netbeans.modules.javacore.classpath.MergedClassPathImplementation; 25 import org.netbeans.modules.javacore.internalapi.ProgressListener; 26 import org.netbeans.modules.javacore.internalapi.ProgressEvent; 27 28 import java.beans.PropertyChangeListener ; 29 import java.beans.PropertyChangeEvent ; 30 import java.text.MessageFormat ; 31 import org.netbeans.api.progress.*; 32 import org.openide.util.NbBundle; 33 34 35 public class ProgressDisplayer implements ProgressListener, PropertyChangeListener { 36 private ClassPathImplementation cp; 37 private JMManager model; 38 private boolean dirty = false; 39 private ProgressContributor progressContributor; 40 private ProgressContributor startFake; 41 private ProgressContributor endFake; 42 private AggregateProgressHandle globalProgress; 43 44 45 private ProgressDisplayer (JMManager model) { 46 this.model = model; 47 this.cp = model.getMergedClassPathImpl(); 48 this.cp.addPropertyChangeListener (this); 49 this.model.getProgressSupport().addProgressListener (this); 50 globalProgress = AggregateProgressFactory.createHandle(NbBundle.getMessage(ProgressDisplayer.class, "TXT_ApplyingPathsTitle"), new ProgressContributor[]{}, null, null); 51 globalProgress.start(); 52 startFake = AggregateProgressFactory.createProgressContributor("startFake"); endFake = AggregateProgressFactory.createProgressContributor("endFake"); globalProgress.addContributor(startFake); 55 globalProgress.addContributor(endFake); 56 startFake.start(1); 57 endFake.start(1); 58 } 59 60 public void start(ProgressEvent event) { 61 int ec = event.getCount(); 62 progressContributor = AggregateProgressFactory.createProgressContributor(Integer.toString(event.hashCode())); 63 globalProgress.addContributor(progressContributor); 64 progressContributor.start(ec); 65 startFake.finish(); 66 } 67 68 public void step(final ProgressEvent event) { 69 progressContributor.progress(event.getCount()); 70 } 71 72 public void stop(ProgressEvent event) { 73 if (JMManager.SCAN_DEBUG) System.err.println("ProgressDisplayer: stop1"); if (this.getDirty()) { 75 if (JMManager.SCAN_DEBUG) System.err.println("ProgressDisplayer: stop2 - dirty"); progressContributor.finish(); 77 this.startResolution (); 78 } 79 else { 80 if (JMManager.SCAN_DEBUG) System.err.println("ProgressDisplayer: stop3"); endFake.finish(); 82 globalProgress.finish(); 83 this.model.getProgressSupport().removeProgressListener (this); 84 this.cp.removePropertyChangeListener(this); 85 instance=null; 86 } 87 } 88 89 public synchronized void propertyChange(PropertyChangeEvent evt) { 90 if (MergedClassPathImplementation.PROP_UNRESOLVED_ROOTS.equals(evt.getPropertyName())) { 91 if (JMManager.SCAN_DEBUG) System.err.println("ProgressDisplayer: globalpath changed"); this.dirty = true; 93 } 94 } 95 96 private synchronized boolean getDirty () { 97 boolean res = this.dirty; 98 this.dirty = false; 99 return res; 100 } 101 102 private void startResolution() { 103 if (JMManager.SCAN_DEBUG) System.err.println("ProgressDisplayer: startResolution"); model.startResolution(); 105 } 106 107 private static ProgressDisplayer instance = null; 108 109 private String formatMessage(String message, String parameter) { 110 return MessageFormat.format(message, new Object [] {parameter}); 111 } 112 113 public void updatePackage(final String packageName) { 114 progressContributor.progress(formatMessage(NbBundle.getMessage(ProgressDisplayer.class, "MSG_ScanningPackage"), packageName)); 115 } 116 117 public static ProgressDisplayer getVisibleProgressDisplayer() { 118 return instance; 119 } 120 121 public static boolean showProgress(JMManager model) { 122 if (JMManager.SCAN_DEBUG) System.err.println("ProgressDisplayer: openProgressDialog"); instance = new ProgressDisplayer(model); 124 instance.startResolution(); 125 return true; 126 } 127 128 } 129 | Popular Tags |