KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > loadgenerator > api > impl > ManagerOutputWindow


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.loadgenerator.api.impl;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.util.Map JavaDoc;
25 import java.util.WeakHashMap JavaDoc;
26 import javax.swing.Action JavaDoc;
27 import org.netbeans.modules.loadgenerator.spi.*;
28 import org.openide.windows.IOProvider;
29 import org.openide.windows.InputOutput;
30
31 /**
32  *
33  * @author Jaroslav Bachorik
34  */

35 public class ManagerOutputWindow {
36   private String JavaDoc script;
37   
38   private Map JavaDoc<ProcessInstance, InputOutput> iomap = new WeakHashMap JavaDoc<ProcessInstance, InputOutput>();
39   private Action JavaDoc[] sharedActions;
40   
41   /**
42    * Creates a new instance of ManagerOutputWindow
43    */

44   public ManagerOutputWindow(final Action JavaDoc[] 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 JavaDoc() {
55       public void propertyChange(PropertyChangeEvent JavaDoc 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