KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > loadgenerator > nodes > ProcessNode


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.nodes;
21
22 import java.awt.Image JavaDoc;
23 import java.beans.PropertyChangeEvent JavaDoc;
24 import java.beans.PropertyChangeListener JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.List JavaDoc;
27 import javax.swing.Action JavaDoc;
28 import org.netbeans.modules.loadgenerator.actions.StartAction;
29 import org.netbeans.modules.loadgenerator.actions.StopAction;
30 import org.netbeans.modules.loadgenerator.spi.ProcessInstance;
31 import org.openide.nodes.AbstractNode;
32 import org.openide.nodes.Children;
33 import org.openide.util.NbBundle;
34 import org.openide.util.WeakListeners;
35
36 /**
37  *
38  * @author Jaroslav Bachorik
39  */

40 public class ProcessNode extends AbstractNode {
41   private ProcessInstance provider;
42   private final static Action JavaDoc[] ACTIONARRAY = new Action JavaDoc[]{};
43   private List JavaDoc<Action JavaDoc> actions;
44   private String JavaDoc lastDisplayName = null;
45   
46   private PropertyChangeListener JavaDoc listener = new PropertyChangeListener JavaDoc() {
47     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
48       fireDisplayNameChange(lastDisplayName, getDisplayName());
49       lastDisplayName = getDisplayName();
50     }
51   };
52   
53   /**
54    * Creates a new instance of ProcessNode
55    */

56   private ProcessNode() {
57     super(Children.LEAF);
58     actions = new ArrayList JavaDoc<Action JavaDoc>();
59   }
60   
61   public static final ProcessNode getInstance() {
62     return new ProcessNode();
63   }
64   
65   public void setProvider(final ProcessInstance provider) {
66     this.provider = provider;
67     actions.add(new StartAction(this.provider));
68     actions.add(new StopAction(this.provider));
69     
70     for(Action JavaDoc action : actions) {
71       action.addPropertyChangeListener(WeakListeners.propertyChange(listener, this.provider));
72     }
73   }
74   
75   @Override JavaDoc
76   public String JavaDoc getDisplayName() {
77     return (provider.isRunning() ? NbBundle.getMessage(ProcessNode.class, "ProcessNode_Running") : NbBundle.getMessage(ProcessNode.class, "ProcessNode_Stopped")) + " : " + provider.getDisplayName(); // NOI18N
78
}
79   
80   @Override JavaDoc
81   public Image JavaDoc getIcon(int i) {
82     Image JavaDoc retValue;
83     
84     retValue = provider.getIcon();
85     return retValue != null ? retValue : super.getIcon(i);
86   }
87   
88   @Override JavaDoc
89   public Image JavaDoc getOpenedIcon(int i) {
90     return getIcon(i);
91   }
92   
93   @Override JavaDoc
94   public Action JavaDoc[] getActions(boolean b) {
95     return actions.toArray(ACTIONARRAY);
96   }
97   
98 }
99
Popular Tags