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.Iterator;
030:
031: import org.cougaar.core.mts.MessageAddress;
032: import org.cougaar.planning.ldm.asset.AggregateAsset;
033: import org.cougaar.planning.ldm.asset.Asset;
034: import org.cougaar.planning.ldm.plan.Aggregation;
035: import org.cougaar.planning.ldm.plan.Allocation;
036: import org.cougaar.planning.ldm.plan.AllocationResult;
037: import org.cougaar.planning.ldm.plan.AssetTransfer;
038: import org.cougaar.planning.ldm.plan.Expansion;
039: import org.cougaar.planning.ldm.plan.PlanElement;
040: import org.cougaar.planning.ldm.plan.Schedule;
041: import org.cougaar.planning.ldm.plan.ScheduleElement;
042: import org.cougaar.planning.ldm.plan.Task;
043: import org.cougaar.planning.ldm.plan.Verb;
044: import org.cougaar.planning.ldm.plan.Workflow;
045:
046: /** A tree node for a PlanElement.
047: Overrides the UITreeNode loadChildren, toString and isLeaf
048: methods to dynamically display the children (tasks and dispositions)
049: of plan elements.
050: */
051:
052: public class UIPlanElementNode extends UITreeNode {
053: PlanElement planElement;
054:
055: /** Creates a tree node for a plan element by calling
056: the UITreeNode constructor.
057: @param planElement plan element for which to create a tree node
058: */
059:
060: public UIPlanElementNode(PlanElement planElement) {
061: super (planElement);
062: this .planElement = planElement;
063: }
064:
065: /** PlanElement is never a leaf.
066: @return false
067: */
068:
069: public boolean isLeaf() {
070: return false;
071: }
072:
073: /** Representation of a PlanElement in the tree.
074: @return PlanElement, type of PlanElement, Task Verb
075: */
076:
077: public String toString() {
078: // return planElement.toString();
079: String disp = "disposition";
080: if (planElement instanceof Allocation)
081: disp = "Allocation";
082: else if (planElement instanceof Aggregation)
083: disp = "Aggregation";
084: else if (planElement instanceof AssetTransfer)
085: disp = "Asset Transfer";
086: else if (planElement instanceof Expansion)
087: disp = "Expansion";
088: Task task = planElement.getTask();
089: Verb verb = task.getVerb();
090: String verbString = "";
091: if (verb != null)
092: verbString = verb.toString();
093: return "Plan Element" + " " + disp + " " + verbString;
094: }
095:
096: private int loadAssets(AggregateAsset a, int position, String prefix) {
097: int count = 0;
098: if (a.getAsset() == null)
099: return 0; // no nodes added
100: int quantity = 1;
101: //if ( aggregateProp instanceof SimpleAggregateAssetProperty ) {
102: //SimpleAggregateAssetProperty saap = (SimpleAggregateAssetProperty)aggregateProp;
103: quantity = (int) a.getQuantity();
104:
105: insert(new UIStringNode("Number of assets: "
106: + String.valueOf(quantity)), position++);
107: //int quantityhack = 9999;
108: //insert(new UIStringNode("Number of assets: " + String.valueOf(quantityhack)), position++);
109: insert(new UIAssetNode(a.getAsset(), prefix), position++);
110: count++;
111:
112: return count + 1;// number of assets inserted +1 for count field
113: }
114:
115: /** The children of all dispositions are:
116: current schedule, penalty value, and direct objects (assets)
117: A disposition can be an allocation, expansion or asset transfer.
118: The children of an allocation are:
119: asset, estinated schedule, estimated penalty value
120: The children of an expansion are:
121: workflow
122: The children of an asset transfer are:
123: asset, assignor cluster, assignee cluster, schedule
124: Any asset can be an aggregate asset, in which case this
125: steps through the enumeration of assets and creates a node for each.
126: */
127:
128: public synchronized void loadChildren() {
129: Task task = planElement.getTask();
130: ScheduleElement schedule = null;
131: //PenaltyValue penaltyValue;
132: AllocationResult allocationresult = null;
133: Asset asset;
134:
135: int i = 0;
136:
137: insert(new UITaskNode(task), i++);
138:
139: //Schedule schedule;
140:
141: /*
142: Enumeration e = planElement.getDirectObjects();
143: if (e != null) {
144: while (e.hasMoreElements()) {
145: asset = (Asset)e.nextElement();
146: if (asset != null)
147: if (asset instanceof AggregateAsset)
148: i = i + loadAssets((AggregateAsset)asset, i, "Direct Object: ");
149: else
150: insert(new UIAssetNode(asset, "Direct Object: "), i++);
151: else
152: insert(new UIStringNode("null"), i++);
153: }
154: }
155: */
156: if (planElement instanceof Allocation) {
157: Allocation allocation = (Allocation) planElement;
158: asset = (Asset) allocation.getAsset();
159: if (asset != null)
160: if (asset instanceof AggregateAsset)
161: i = i
162: + loadAssets((AggregateAsset) asset, i,
163: "Allocated Asset: ");
164: else
165: insert(new UIAssetNode(asset, "Allocated Asset: "),
166: i++);
167: //schedule = allocation.getEstimatedSchedule();
168: if (schedule != null)
169: insert(new UIScheduleElementNode(schedule,
170: "Estimated Schedule: "), i++);
171: allocationresult = planElement.getEstimatedResult();
172: if (allocationresult != null)
173: insert(new UIPenaltyValueNode(allocationresult,
174: "Estimated Result: "), i++);
175: //schedule = allocation.getReportedSchedule();
176: if (schedule != null)
177: insert(new UIScheduleElementNode(schedule,
178: "Reported Schedule: "), i++);
179: allocationresult = planElement.getReportedResult();
180: if (allocationresult != null)
181: insert(new UIPenaltyValueNode(allocationresult,
182: "Reported Result: "), i++);
183: } else if (planElement instanceof Expansion) {
184: // uncomment to display estimated schedule and penalty
185: //schedule = ((Expansion)planElement).getEstimatedSchedule();
186: //if (schedule != null)
187: //insert(new UIScheduleElementNode(schedule, "Estimated Schedule: "), i++);
188:
189: // jlv test - uncomment to show EPV
190: allocationresult = planElement.getEstimatedResult();
191: if (allocationresult != null)
192: insert(new UIPenaltyValueNode(allocationresult,
193: "Estimated Result: "), i++);
194:
195: Workflow workflow = ((Expansion) planElement).getWorkflow();
196: insert(new UIWorkflowNode(workflow), i++);
197: } else if (planElement instanceof AssetTransfer) {
198: asset = (Asset) ((AssetTransfer) planElement).getAsset();
199: if (asset != null)
200: if (asset instanceof AggregateAsset)
201: i = i + loadAssets((AggregateAsset) asset, i, "");
202: else
203: insert(new UIAssetNode(asset, ""), i++);
204: MessageAddress assignor = ((AssetTransfer) planElement)
205: .getAssignor();
206: String assignorString = "Assigned By: ";
207: if (assignor != null)
208: assignorString = assignorString + assignor.getAddress();
209: insert(new UIStringNode(assignorString), i++);
210: Asset assignee = ((AssetTransfer) planElement)
211: .getAssignee();
212: String assigneeString = "Assigned To: ";
213: if (assignee != null)
214: if (assignee instanceof AggregateAsset)
215: i = i
216: + loadAssets((AggregateAsset) assignee, i,
217: "");
218: else
219: insert(new UIAssetNode(assignee, ""), i++);
220: Schedule availSchedule = ((AssetTransfer) planElement)
221: .getSchedule();
222: if ((availSchedule != null) && (availSchedule.size() > 0)) {
223: Iterator iterator = availSchedule.iterator();
224: while (iterator.hasNext()) {
225: schedule = (ScheduleElement) iterator.next();
226: insert(new UIScheduleElementNode(schedule, ""), i++);
227: }
228: }
229: allocationresult = ((AssetTransfer) planElement)
230: .getEstimatedResult();
231: if (allocationresult != null)
232: insert(new UIPenaltyValueNode(allocationresult,
233: "Estimated Result: "), i++);
234: }
235: }
236:
237: }
|