001: package tools.tracesviewer;
002:
003: import java.awt.*;
004: import java.awt.event.*;
005:
006: public class TracesSessionsList extends List {
007:
008: protected TracesSessions tracesSessions;
009: protected TracesCanvas tracesCanvas;
010: protected int index = 0;
011:
012: public TracesSessionsList() {
013: //super(new DefaultListModel());
014: }
015:
016: public void setTracesCanvas(TracesCanvas tracesCanvas) {
017: this .tracesCanvas = tracesCanvas;
018: }
019:
020: /**
021: * Get the call identifier for a given trace session.
022: *
023: *@param name is the session name for the trace session.
024: *
025: */
026:
027: public String getCallId(String name) {
028: try {
029: int index = name.indexOf("//");
030: int firstIndex = name.indexOf("/", index + 2);
031: return name.substring(firstIndex + 1);
032: } catch (Exception e) {
033: return name;
034: }
035: }
036:
037: /**
038: * Get the origin for a trace session.
039: *
040: *@param name is the name of the trace session.
041: *
042: */
043: public String getOrigin(String name) {
044: try {
045: int firstIndex = name.indexOf("//");
046: int secondIndex = name.indexOf("/", 2);
047: String origin = name.substring(2, secondIndex);
048: if (origin.equals(TracesViewer.stackId))
049: return "the proxy";
050: else
051: return "a user agent (" + origin + ")";
052: } catch (Exception e) {
053: return "unknown";
054: }
055: }
056:
057: public void setTracesSessions(TracesSessions tracesSessions) {
058: removeAll();
059: //((DefaultListModel)getModel()).removeAllElements();
060: this .tracesSessions = tracesSessions;
061: for (int i = 0; i < tracesSessions.size(); i++) {
062: TracesSession tracesSession = (TracesSession) tracesSessions
063: .elementAt(i);
064: String name = tracesSession.getName();
065: String logDescription = tracesSession.getLogDescription();
066: //System.out.println("logDesc1:"+logDescription);
067: String callId = getCallId(name);
068: String origin = getOrigin(name);
069: if (name.equals("No available session, refresh")) {
070: add(name);
071: } else if (logDescription == null
072: || logDescription.trim().equals("")) {
073: add("Trace " + (i + 1) + " from " + origin
074: + "; callId: " + callId);
075: } else {
076: add("Trace " + (i + 1) + " from " + logDescription
077: + "; callId: " + callId);
078:
079: }
080: }
081: if (tracesSessions.size() != 0)
082: select(0);
083: }
084:
085: public void updateTracesCanvas() {
086: if (tracesSessions == null || tracesSessions.isEmpty())
087: return;
088: // We take the first trace from the list
089: TracesSession tracesSession = (TracesSession) tracesSessions
090: .firstElement();
091:
092: String name = tracesSession.getName();
093: String logDescription = tracesSession.getLogDescription();
094: String callId = getCallId(name);
095: String origin = getOrigin(name);
096: if (name.equals("No available session, refresh")) {
097: tracesCanvas.refreshTracesCanvas(tracesSession, "unknown");
098: } else if (logDescription == null
099: || logDescription.trim().equals("")) {
100: tracesCanvas.refreshTracesCanvas(tracesSession, origin);
101: } else {
102:
103: tracesCanvas.refreshTracesCanvas(tracesSession,
104: logDescription);
105: }
106: }
107:
108: public void updateTracesCanvas(ItemEvent e) {
109: if (tracesSessions == null || tracesSessions.isEmpty())
110: return;
111:
112: index = ((Integer) e.getItem()).intValue();
113:
114: TracesSession tracesSession = (TracesSession) tracesSessions
115: .elementAt(index);
116: String name = tracesSession.getName();
117: String logDescription = tracesSession.getLogDescription();
118: String callId = getCallId(name);
119: String origin = getOrigin(name);
120: if (name.equals("No available session, refresh")) {
121: tracesCanvas.refreshTracesCanvas(tracesSession, "unknown");
122: } else if (logDescription == null
123: || logDescription.trim().equals("")) {
124: tracesCanvas.refreshTracesCanvas(tracesSession, origin);
125: } else {
126: System.out.println("logDesc33:" + logDescription);
127: tracesCanvas.refreshTracesCanvas(tracesSession,
128: logDescription);
129: }
130: }
131:
132: }
|