1 19 20 package org.netbeans.modules.loadgenerator.api.impl; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.util.Map ; 25 import java.util.WeakHashMap ; 26 import javax.swing.Action ; 27 import org.netbeans.modules.loadgenerator.spi.*; 28 import org.openide.windows.IOProvider; 29 import org.openide.windows.InputOutput; 30 31 35 public class ManagerOutputWindow { 36 private String script; 37 38 private Map <ProcessInstance, InputOutput> iomap = new WeakHashMap <ProcessInstance, InputOutput>(); 39 private Action [] sharedActions; 40 41 44 public ManagerOutputWindow(final Action [] actions) { 45 sharedActions = actions; 46 } 47 48 public void attach(final ProcessInstance provider) { 49 InputOutput io = iomap.get(provider); 50 if (io == null) { 51 io = IOProvider.getDefault().getIO("JMeter: " + provider.getCurrentScript(), sharedActions); 52 iomap.put(provider, io); 53 } 54 provider.addPropertyChangeListener(ProcessInstance.FACTORY, new PropertyChangeListener () { 55 public void propertyChange(PropertyChangeEvent evt) { 56 if (evt.getNewValue() == null) { 57 InputOutput oldIo = iomap.get(provider); 58 if (oldIo != null) { 59 oldIo.closeInputOutput(); 60 iomap.remove(provider); 61 provider.removePropertyChangeListener(ProcessInstance.FACTORY, this); 62 } 63 } 64 } 65 }); 66 67 provider.attachWriter(io.getOut()); 68 io.select(); 69 } 70 71 public void detach(final ProcessInstance provider) { 72 if (provider.isDeleted()) { 73 close(provider); 74 } 75 provider.detachWriter(); 76 } 77 78 public void close(final ProcessInstance instance) { 79 InputOutput oldIo = iomap.get(instance); 80 oldIo.closeInputOutput(); 81 } 82 } 83 | Popular Tags |