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.blackboard.IncrementalSubscription;
032: import org.cougaar.core.mts.MessageAddress;
033: import org.cougaar.planning.ldm.plan.Expansion;
034: import org.cougaar.util.UnaryPredicate;
035:
036: /** A tree for an allocatable workflow collection.
037: */
038:
039: public class UIWorkflowCollectionNode extends UITreeNode implements
040: UISubscriber {
041: private UIPlugin uiPlugin;
042: private String planName;
043: private boolean childrenLoaded = false;
044:
045: /** Creates a tree for a workflow collection in the specified cluster
046: and for the specified plan by calling the UITreeNode constructor.
047: @param uiPlugin this user interface plug in
048: @param planName name of plan for which to display workflows
049: @param clusterId cluster from which to obtain workflows
050: @exception UINoPlanException thrown when the plan does not exist
051: */
052:
053: public UIWorkflowCollectionNode(UIPlugin uiPlugin, String planName,
054: MessageAddress clusterId) throws UINoPlanException {
055: super ();
056: this .uiPlugin = uiPlugin;
057: this .planName = planName;
058: super .setUserObject(uiPlugin.getPlan(planName));
059: }
060:
061: /** Has leaves which are the Workflows.
062: @return false
063: */
064:
065: public boolean isLeaf() {
066: return false;
067: }
068:
069: /** Get the Workflows.
070: */
071:
072: private static UnaryPredicate workflowPredicate() {
073: return new UnaryPredicate() {
074: public boolean execute(Object o) {
075: //System.out.println("Predicate called with: " + o.toString());
076: return (o instanceof Expansion);
077: }
078: };
079: }
080:
081: public synchronized void loadChildren() {
082: if (!childrenLoaded) {
083: uiPlugin.subscribe(this , workflowPredicate());
084: childrenLoaded = true;
085: }
086: }
087:
088: /** Display the plan name in the tree.
089: @return plan name
090: */
091:
092: public String toString() {
093: return planName;
094: }
095:
096: /** UISubscriber interface.
097: Actually returns dispositions which are expansions.
098: Only pay attention to the added list.
099: */
100:
101: public synchronized void subscriptionChanged(
102: IncrementalSubscription container) {
103: //System.out.println("Container changed");
104: boolean reload = false;
105: Enumeration added = container.getAddedList();
106: while (added.hasMoreElements()) {
107: Expansion expansion = (Expansion) added.nextElement();
108: UIWorkflowNode node = new UIWorkflowNode(expansion
109: .getWorkflow());
110: if (node != null) {
111: //System.out.println("Added: " + workflow.toString() + " at " +
112: // getChildCount());
113: treeModel.insertNodeInto(node, this , getChildCount());
114: reload = true;
115: }
116: }
117: if (reload)
118: treeModel.reload();
119: }
120:
121: }
|