KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > module > nodes > JMeterElementNode


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.apache.jmeter.module.nodes;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.Image JavaDoc;
24 import java.beans.PropertyChangeEvent JavaDoc;
25 import java.beans.PropertyChangeListener JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Arrays JavaDoc;
28 import java.util.List JavaDoc;
29 import javax.swing.Action JavaDoc;
30 import org.apache.jmeter.gui.JMeterGUIComponent;
31 import org.apache.jmeter.module.cookies.JMeterCookie;
32 import org.apache.jmeter.module.cookies.JMeterVisualizerCookie;
33 import org.apache.jmeter.module.exceptions.InitializationException;
34 import org.apache.jmeter.module.integration.JMeterIntegrationEngine;
35 import org.apache.jmeter.reporters.ResultCollector;
36 import org.apache.jmeter.testelement.TestElement;
37 import org.apache.jorphan.collections.HashTree;
38 import org.openide.nodes.AbstractNode;
39 import org.openide.util.actions.SystemAction;
40
41 /**
42  *
43  * @author Jaroslav Bachorik
44  */

45 public class JMeterElementNode extends AbstractNode {
46   private List JavaDoc<TestElement> elements;
47   private TestElement rootElement;
48   private String JavaDoc testPlan;
49   private JMeterIntegrationEngine integration;
50   
51   private Component JavaDoc customizer;
52   
53   public JMeterElementNode(final TestElement root, final HashTree tree) {
54     super(new JMeterElementChildren(tree));
55     try {
56       integration = JMeterIntegrationEngine.getDefault();
57       rootElement = root;
58     } catch (InitializationException e) {
59       integration = null;
60       rootElement = null;
61     }
62     getCookieSet().add(new JMeterCookie(root));
63     if (root instanceof ResultCollector) {
64       getCookieSet().add(new JMeterVisualizerCookie(root));
65     }
66   }
67   
68   public String JavaDoc getName() {
69     return rootElement != null ? rootElement.getPropertyAsString(TestElement.NAME) : "...";
70   }
71   
72   public String JavaDoc getDisplayName() {
73     return getName();
74   }
75   
76   public Component JavaDoc getCustomizer() {
77     customizer.addPropertyChangeListener("ancestor", new PropertyChangeListener JavaDoc() {
78       public void propertyChange(PropertyChangeEvent JavaDoc evt) {
79         if (evt.getNewValue() == null) {
80           final String JavaDoc oldName = rootElement.getPropertyAsString(TestElement.NAME);
81           ((JMeterGUIComponent)customizer).modifyTestElement(rootElement);
82           fireDisplayNameChange(oldName, rootElement.getPropertyAsString(TestElement.NAME));
83           customizer.removePropertyChangeListener("ancestor", this);
84         }
85       }
86     });
87     ((JMeterGUIComponent)customizer).configure(rootElement);
88     return customizer;
89   }
90   
91   public boolean hasCustomizer() {
92     customizer = integration.getElementCustomizer(rootElement);
93     if (customizer == null) {
94       customizer = super.getCustomizer();
95     }
96     
97     return customizer != null;
98   }
99   
100   public Image JavaDoc getOpenedIcon(int i) {
101     return integration.getElementIcon(rootElement);
102   }
103   
104   public Image JavaDoc getIcon(int i) {
105     return integration.getElementIcon(rootElement);
106   }
107 }
108
Popular Tags