001: /*
002: * <copyright>
003: *
004: * Copyright 2000-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.tools.csmart.ui.experiment;
028:
029: import org.cougaar.core.agent.AgentManager;
030: import org.cougaar.core.component.ComponentDescription;
031: import org.cougaar.core.plugin.PluginManager;
032: import org.cougaar.tools.csmart.core.cdata.ComponentData;
033: import org.cougaar.tools.csmart.experiment.DBExperiment;
034: import org.cougaar.tools.csmart.experiment.Experiment;
035: import org.cougaar.tools.csmart.ui.viewer.CSMART;
036: import org.cougaar.util.log.Logger;
037:
038: import javax.swing.*;
039: import java.awt.*;
040: import java.util.ArrayList;
041:
042: /**
043: * Window to show the detailed contents of an Agent
044: **/
045: public class AgentInfoPanel extends JPanel {
046: private transient Logger log;
047:
048: public AgentInfoPanel(Experiment experiment, String agentName) {
049: super ();
050: log = CSMART.createLogger(this .getClass().getName());
051:
052: // Warning: This next line may save the whole experiment
053: ComponentData societyComponentData = experiment
054: .getSocietyComponentData();
055:
056: if (societyComponentData == null) {
057: JOptionPane.showMessageDialog(this ,
058: "No information available", "No Information",
059: JOptionPane.PLAIN_MESSAGE);
060: if (log.isDebugEnabled()) {
061: log.debug("Experiment returned no component data: "
062: + experiment.getExperimentName());
063: }
064: return;
065: }
066: ComponentData agentComponentData = null;
067: ComponentData[] children = societyComponentData.getChildren();
068:
069: // Yuck this is ugly.....
070: if (societyComponentData.getType().equals(ComponentData.NODE)
071: || societyComponentData.getType().equals(
072: ComponentData.AGENT)) {
073: if (societyComponentData.getName().equals(agentName)) {
074: agentComponentData = societyComponentData;
075: }
076: }
077:
078: if (agentComponentData == null) {
079:
080: // Loop to find the Agent we want
081: for (int i = 0; i < children.length; i++) {
082: if (agentComponentData != null)
083: break;
084: if (children[i].getType().equals(ComponentData.NODE)) {
085: // Let it possibly be the Node itself
086: if (agentName.equals(children[i].getName())) {
087: agentComponentData = children[i];
088: break;
089: }
090:
091: ComponentData[] agents = children[i].getChildren();
092: for (int k = 0; k < agents.length; k++) {
093: if (agentComponentData != null)
094: break;
095: if (agents[k].getName().equals(agentName)) {
096: agentComponentData = agents[k];
097: break;
098: }
099: }
100: } else if (children[i].getType().equals(
101: ComponentData.AGENT)) {
102: // Let it possibly be the Node itself
103: if (agentName.equals(children[i].getName())) {
104: agentComponentData = children[i];
105: break;
106: }
107: } else if (children[i].getType().equals(
108: ComponentData.HOST)) {
109: ComponentData[] nodes = children[i].getChildren();
110:
111: for (int j = 0; j < nodes.length; j++) {
112: if (agentComponentData != null)
113: break;
114: // Let it possibly be the Node itself
115: if (agentName.equals(nodes[j].getName())) {
116: agentComponentData = nodes[j];
117: break;
118: }
119:
120: ComponentData[] agents = nodes[j].getChildren();
121: for (int k = 0; k < agents.length; k++) {
122: if (agentComponentData != null)
123: break;
124: if (agents[k].getName().equals(agentName)) {
125: agentComponentData = agents[k];
126: break;
127: }
128: }
129: }
130: }
131: }
132: }
133:
134: if (agentComponentData == null) {
135: JOptionPane.showMessageDialog(this ,
136: "No information available", "No Information",
137: JOptionPane.PLAIN_MESSAGE);
138: if (log.isDebugEnabled()) {
139: log.debug("Got null agentComponentData after search?");
140: }
141: return;
142: }
143:
144: ComponentData[] agentChildren = agentComponentData
145: .getChildren();
146: ArrayList entries = new ArrayList(agentChildren.length);
147: for (int i = 0; i < agentChildren.length; i++) {
148: StringBuffer sb = new StringBuffer();
149: if (agentChildren[i].getType().equals(
150: ComponentData.AGENTBINDER)) {
151: sb.append(PluginManager.INSERTION_POINT + ".Binder");
152: } else if (agentChildren[i].getType().equals(
153: ComponentData.NODEBINDER)) {
154: sb.append(AgentManager.INSERTION_POINT + ".Binder");
155: } else {
156: sb.append(agentChildren[i].getType());
157: }
158: if (ComponentDescription.parsePriority(agentChildren[i]
159: .getPriority()) != ComponentDescription.PRIORITY_COMPONENT) {
160: sb.append("(" + agentChildren[i].getPriority() + ")");
161: }
162: sb.append(" = ");
163: sb.append(agentChildren[i].getClassName());
164: if (agentChildren[i].parameterCount() != 0) {
165: sb.append("(");
166: Object[] params = agentChildren[i].getParameters();
167: sb.append(params[0].toString());
168: for (int j = 1; j < agentChildren[i].parameterCount(); j++) {
169: sb.append(",");
170: sb.append(params[j].toString());
171: }
172: sb.append(")");
173: }
174: entries.add(sb.toString());
175: }
176: JList plugInsList = new JList(entries.toArray());
177: JScrollPane jsp = new JScrollPane(plugInsList);
178: jsp.setPreferredSize(new Dimension(550, 200));
179: setLayout(new GridBagLayout());
180: plugInsList.setBackground(getBackground());
181: int x = 0;
182: int y = 0;
183: add(new JLabel("SubComponents:"), new GridBagConstraints(x++,
184: y, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
185: GridBagConstraints.NONE, new Insets(10, 0, 5, 5), 0, 0));
186: add(jsp, new GridBagConstraints(x, y++, 1, 1, 0.0, 0.0,
187: GridBagConstraints.WEST, GridBagConstraints.NONE,
188: new Insets(0, 0, 5, 0), 0, 0));
189: setSize(400, 400);
190: }
191: }
|