01: /*
02: * <copyright>
03: *
04: * Copyright 1997-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.mlm.debug.ui;
28:
29: import java.text.DateFormat;
30: import java.util.Date;
31: import java.util.TimeZone;
32:
33: import org.cougaar.planning.ldm.plan.ScheduleElement;
34:
35: /** A tree node for a ScheduleElement.
36: Overrides the UITreeNode loadChildren, toString and isLeaf
37: methods to dynamically display the Schedule which has no children.
38: */
39:
40: public class UIScheduleElementNode extends UITreeNode {
41: ScheduleElement schedule;
42: String prefix;
43:
44: /** Create a tree node for the schedule element.
45: @param scheduleelement scheduleelement for which to create a tree node
46: */
47: public UIScheduleElementNode(ScheduleElement scheduleelement,
48: String prefix) {
49: super (scheduleelement);
50: this .schedule = scheduleelement;
51: this .prefix = prefix;
52: }
53:
54: /** The Schedule is a leaf.
55: @return true
56: */
57: public boolean isLeaf() {
58: return true;
59: }
60:
61: /** This shouldn't be called because this is a leaf.
62: */
63:
64: public void loadChildren() {
65: System.out
66: .println("UIScheduleElementNode:loadChildren called, but ScheduleElement is a leaf.");
67: }
68:
69: /** Return representation of a ScheduleElement in a tree:
70: The startLocation and endLocation are displayed only if they are
71: specified in the scheduleelement (LocationRangeScheduleElement).
72: @return From (startLocation) (startDate) to (endLocation) (endDate).
73: */
74:
75: public String toString() {
76: //String startLocation = schedule.getStartLocation();
77: //String endLocation = schedule.getEndLocation();
78: String s = "From ";
79: //if (startLocation != null)
80: //s = s + startLocation + " ";
81: s = s + getDateLabel(schedule.getStartDate()) + " to ";
82: //if (endLocation != null)
83: //s = s + endLocation + " ";
84: s = s + getDateLabel(schedule.getEndDate());
85: return prefix + s;
86: }
87:
88: /** Return a string for the date and time in GMT.
89: */
90:
91: private String getDateLabel(Date date) {
92: DateFormat dateFormat = DateFormat.getDateTimeInstance(
93: DateFormat.LONG, DateFormat.SHORT);
94: dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
95: return dateFormat.format(date);
96: }
97:
98: }
|