KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > designer > StepCell


1 /**
2  * Created on Feb 3, 2003
3  * Copyright (C) 2002 Aditisoft Inc
4  */

5 package com.opensymphony.workflow.designer;
6
7 import java.util.Iterator JavaDoc;
8 import java.util.List JavaDoc;
9
10 import com.opensymphony.workflow.designer.proxy.StepProxy;
11 import com.opensymphony.workflow.loader.ActionDescriptor;
12 import com.opensymphony.workflow.loader.ConditionalResultDescriptor;
13 import com.opensymphony.workflow.loader.ResultDescriptor;
14 import com.opensymphony.workflow.loader.StepDescriptor;
15 import org.jgraph.graph.GraphConstants;
16
17 /**
18  * @author apatel
19  */

20 public class StepCell extends WorkflowCell implements ResultAware
21 {
22   private StepDescriptor descriptor;
23
24   // Construct Cell for Userobject
25
public StepCell(StepDescriptor userObject)
26   {
27     super(new StepProxy(userObject));
28     GraphConstants.setEditable(attributes, true);
29     descriptor = userObject;
30     id = descriptor.getId();
31     name = descriptor.getName();
32   }
33
34   public String JavaDoc toString()
35   {
36     return descriptor.getName() + " " + descriptor.getId();
37   }
38
39   public String JavaDoc getName()
40   {
41     return descriptor.getName();
42   }
43
44   public StepDescriptor getDescriptor()
45   {
46     return descriptor;
47   }
48
49   public boolean removeResult(ResultDescriptor result)
50   {
51     Iterator JavaDoc iter = descriptor.getActions().iterator();
52     while(iter.hasNext())
53     {
54       ActionDescriptor action = (ActionDescriptor)iter.next();
55       if(result instanceof ConditionalResultDescriptor)
56       {
57         List JavaDoc list = action.getConditionalResults();
58         if(list != null)
59         {
60           for(int i = 0; i < list.size(); i++)
61           {
62             if(list.get(i) == result)
63             {
64               list.remove(i);
65               if(action.getUnconditionalResult()==null)
66               {
67                 iter.remove();
68               }
69               return true;
70             }
71           }
72         }
73       }
74       else
75       {
76         if(action.getUnconditionalResult() == result)
77         {
78           action.setUnconditionalResult(null);
79           if(action.getConditionalResults().size()==0)
80           {
81             iter.remove();
82           }
83           return true;
84         }
85       }
86     }
87     return false;
88   }
89 }
90
Popular Tags