001: //$Header$
002: /*
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: */
019:
020: package org.apache.jmeter.report.gui.tree;
021:
022: import java.awt.Image;
023: import java.beans.BeanInfo;
024: import java.beans.IntrospectionException;
025: import java.beans.Introspector;
026: import java.util.Collection;
027:
028: import javax.swing.ImageIcon;
029: import javax.swing.JPopupMenu;
030: import javax.swing.tree.DefaultMutableTreeNode;
031:
032: import org.apache.jmeter.gui.GUIFactory;
033: import org.apache.jmeter.gui.ReportGuiPackage;
034: import org.apache.jmeter.gui.tree.NamedTreeNode;
035: import org.apache.jmeter.testbeans.TestBean;
036: import org.apache.jmeter.testelement.AbstractTestElement;
037: import org.apache.jmeter.testelement.TestElement;
038: import org.apache.jmeter.testelement.property.BooleanProperty;
039: import org.apache.jmeter.testelement.property.StringProperty;
040: import org.apache.jorphan.logging.LoggingManager;
041: import org.apache.log.Logger;
042:
043: /**
044: * @author Peter Lin
045: * @version $Revision: 493793 $
046: */
047: public class ReportTreeNode extends DefaultMutableTreeNode implements
048: NamedTreeNode {
049: transient private static Logger log = LoggingManager
050: .getLoggerForClass();
051:
052: private ReportTreeModel treeModel;
053:
054: // boolean enabled = true;
055:
056: public ReportTreeNode() {// Allow serializable test to work
057: // TODO: is the serializable test necessary now that JMeterTreeNode is
058: // no longer a GUI component?
059: this (null, null);
060: }
061:
062: public ReportTreeNode(TestElement userObj, ReportTreeModel treeModel) {
063: super (userObj);
064: this .treeModel = treeModel;
065: }
066:
067: public boolean isEnabled() {
068: return ((AbstractTestElement) getTestElement())
069: .getPropertyAsBoolean(TestElement.ENABLED);
070: }
071:
072: public void setEnabled(boolean enabled) {
073: getTestElement().setProperty(
074: new BooleanProperty(TestElement.ENABLED, enabled));
075: treeModel.nodeChanged(this );
076: }
077:
078: public ImageIcon getIcon() {
079: return getIcon(true);
080: }
081:
082: public ImageIcon getIcon(boolean enabled) {
083: try {
084: if (getTestElement() instanceof TestBean) {
085: try {
086: Image img = Introspector.getBeanInfo(
087: getTestElement().getClass()).getIcon(
088: BeanInfo.ICON_COLOR_16x16);
089: // If icon has not been defined, then use GUI_CLASS property
090: if (img == null) {//
091: Object clazz = Introspector.getBeanInfo(
092: getTestElement().getClass())
093: .getBeanDescriptor().getValue(
094: TestElement.GUI_CLASS);
095: if (clazz == null) {
096: log.error("Can't obtain GUI class for "
097: + getTestElement().getClass()
098: .getName());
099: return null;
100: }
101: return GUIFactory.getIcon(Class
102: .forName((String) clazz), enabled);
103: }
104: return new ImageIcon(img);
105: } catch (IntrospectionException e1) {
106: log.error("Can't obtain icon", e1);
107: throw new org.apache.jorphan.util.JMeterError(e1);
108: }
109: } else {
110: return GUIFactory.getIcon(Class
111: .forName(getTestElement().getPropertyAsString(
112: TestElement.GUI_CLASS)), enabled);
113: }
114: } catch (ClassNotFoundException e) {
115: log.warn("Can't get icon for class " + getTestElement(), e);
116: return null;
117: }
118: }
119:
120: public Collection getMenuCategories() {
121: try {
122: return ReportGuiPackage.getInstance().getGui(
123: getTestElement()).getMenuCategories();
124: } catch (Exception e) {
125: log.error("Can't get popup menu for gui", e);
126: return null;
127: }
128: }
129:
130: public JPopupMenu createPopupMenu() {
131: try {
132: return ReportGuiPackage.getInstance().getGui(
133: getTestElement()).createPopupMenu();
134: } catch (Exception e) {
135: log.error("Can't get popup menu for gui", e);
136: return null;
137: }
138: }
139:
140: public TestElement getTestElement() {
141: return (TestElement) getUserObject();
142: }
143:
144: public String getStaticLabel() {
145: return ReportGuiPackage.getInstance().getGui(
146: (TestElement) getUserObject()).getStaticLabel();
147: }
148:
149: public String getDocAnchor() {
150: return ReportGuiPackage.getInstance().getGui(
151: (TestElement) getUserObject()).getDocAnchor();
152: }
153:
154: public void setName(String name) {
155: ((TestElement) getUserObject()).setProperty(new StringProperty(
156: TestElement.NAME, name));
157: }
158:
159: public String getName() {
160: return ((TestElement) getUserObject())
161: .getPropertyAsString(TestElement.NAME);
162: }
163:
164: public void nameChanged() {
165: treeModel.nodeChanged(this);
166: }
167: }
|