001: /*
002: * <copyright>
003: *
004: * Copyright 1997-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.mlm.debug.ui;
028:
029: import java.util.Enumeration;
030:
031: import org.cougaar.core.mts.MessageAddress;
032: import org.cougaar.planning.ldm.asset.Asset;
033: import org.cougaar.planning.ldm.plan.PrepositionalPhrase;
034: import org.cougaar.planning.ldm.plan.Task;
035: import org.cougaar.planning.ldm.plan.Verb;
036:
037: /** A tree node for a Task.
038: Overrides the UITreeNode loadChildren, toString and isLeaf
039: methods to dynamically display the Task.
040: */
041:
042: public class UITaskNode extends UITreeNode {
043: Task task;
044:
045: /** Create a tree node for the task.
046: @param task task for which to create tree node
047: */
048: public UITaskNode(Task task) {
049: super (task);
050: this .task = task;
051: }
052:
053: /** The task is not a leaf.
054: @return false
055: */
056: public boolean isLeaf() {
057: return false;
058: }
059:
060: /** Get description of source and destination clusters.
061: */
062:
063: private static String getClusterIdDescription(Object o) {
064: String s = "";
065: if (o == null)
066: return s;
067: if (o instanceof MessageAddress)
068: return ((MessageAddress) o).getAddress();
069: return o.toString();
070: }
071:
072: /** The task's children are string representations of:
073: source->destination
074: verb
075: direct object
076: prepositional phrases (preposition, indirect object)
077: milstrip number (if prepositional phrase references a requisition)
078: */
079:
080: public void loadChildren() {
081: int i = 0; // child position
082: String sourceString = getClusterIdDescription(task.getSource());
083: String dstnString = getClusterIdDescription(task
084: .getDestination());
085: String description = sourceString + "->" + dstnString;
086: insert(new UIStringNode(description), i++);
087:
088: Verb verb = task.getVerb();
089: String verbString = "";
090: if (verb != null)
091: verbString = verb.toString();
092: insert(new UIStringNode(verbString), i++);
093:
094: String directObjectString = UIAsset.getDescription((Asset) task
095: .getDirectObject());
096: insert(new UIStringNode(directObjectString), i++);
097:
098: //PenaltyFunction PF = task.getPenaltyFunction();
099: //if (PF instanceof org.cougaar.planning.ldm.plan.SimplePenaltyFunction) {
100: // Date earliestDate = PF.getDesiredScheduleEarliestDate();
101: // insert(new UIStringNode(UITask.getDateString(earliestDate)), i++);
102: // Date latestDate = PF.getDesiredScheduleLatestDate();
103: // insert(new UIStringNode(UITask.getDateString(latestDate)), i++);
104: // Date bestDate = PF.getDesiredScheduleBestDate();
105: // insert(new UIStringNode(UITask.getDateString(bestDate)), i++);
106: //}
107:
108: Enumeration prepPhrases = task.getPrepositionalPhrases();
109: if (prepPhrases != null) {
110: String prepPhraseString = "";
111: PrepositionalPhrase p;
112: while (prepPhrases.hasMoreElements()) {
113: p = (PrepositionalPhrase) prepPhrases.nextElement();
114: if (p != null) {
115: Object indirectObject = p.getIndirectObject();
116: if (indirectObject instanceof Asset) {
117: prepPhraseString = p.getPreposition()
118: + " "
119: + UIAsset
120: .getDescription((Asset) indirectObject);
121: prepPhraseString.trim();
122: insert(new UIStringNode(prepPhraseString), i++);
123: /*
124: } else if (indirectObject instanceof Requisition) {
125: // prepPhraseString = p.getPreposition() + " " +
126: // UIAsset.getDescription((Requisition)indirectObject);
127: // prepPhraseString.trim();
128: // insert(new UIStringNode(prepPhraseString), i++);
129: // String milstrip = " " +
130: // ((Requisition)indirectObject).getRawMILSTRIP();
131: // insert(new UIStringNode(milstrip), i++);
132: insert(new UIRequisitionNode((Requisition)indirectObject),i++);
133: } else if (indirectObject instanceof SupplySource) {
134: // prepPhraseString = p.getPreposition() + " " +
135: // UIAsset.getDescription((SupplySource)indirectObject);
136: // prepPhraseString.trim();
137: // insert(new UIStringNode(prepPhraseString), i++);
138: // insert(new UISupplySourceNode((SupplySource)indirectObject), i++);
139: if (indirectObject instanceof DepotSupplySource) {
140: insert(new UIDepotSupplySourceNode((DepotSupplySource)indirectObject), i++);
141: } else if (indirectObject instanceof DRMSSupplySource) {
142: insert(new UIDRMSSupplySourceNode((DRMSSupplySource)indirectObject), i++);
143: } else if (indirectObject instanceof VendorSupplySource) {
144: insert(new UIVendorSupplySourceNode((VendorSupplySource)indirectObject), i++);
145: }
146: */
147: } else if (indirectObject != null) {
148: // indirectObject not Asset, Requisition, or SupplySource
149: prepPhraseString = p.getPreposition() + " "
150: + indirectObject.toString();
151: prepPhraseString.trim();
152: insert(new UIStringNode(prepPhraseString), i++);
153: }
154: }
155: }
156: }
157: }
158:
159: /** Return representation of a task in a tree, just the word "Task"
160: as the task contents are returned as the children.
161: @return Task
162: */
163:
164: public String toString() {
165: Verb verb = task.getVerb();
166: if (verb != null)
167: return verb.toString();
168: else
169: return "Task";
170: }
171: }
|